bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC dwarves 0/2] dwarves: detect BTF kinds supported by kernel
@ 2023-07-20 20:14 Alan Maguire
  2023-07-20 20:14 ` [RFC dwarves 1/2] dwarves: auto-detect maximum kind supported by vmlinux Alan Maguire
  2023-07-20 20:14 ` [RFC dwarves 2/2] btf_encoder: learn BTF_KIND_MAX value from base BTF when generating split BTF Alan Maguire
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Maguire @ 2023-07-20 20:14 UTC (permalink / raw)
  To: acme
  Cc: andrii.nakryiko, ast, daniel, jolsa, martin.lau, song, yhs,
	john.fastabend, kpsingh, sdf, haoluo, mykolal, bpf, Alan Maguire

When a newer pahole is run on an older kernel, it often knows about BTF
kinds that the kernel does not support, and adds them to the BTF
representation.  This is a problem because the BTF generated is then
embedded in the kernel image.  When it is later read - possibly by
a different older toolchain or by the kernel directly - it is not usable.

The scripts/pahole-flags.sh script enumerates the various pahole options
available associated with various versions of pahole, but in the case
of an older kernel is the set of BTF kinds the kernel can handle that
is of more importance.

Because recent features such as BTF_KIND_ENUM64 are added by default
(and only skipped if --skip_encoding_btf_* is set), BTF will be
created with these newer kinds that the older kernel cannot read.
This can be fixed by stable-backporting --skip options, but this is
cumbersome and would have to be done every time a new BTF kind is
introduced.

So this series attempts to detect the BTF kinds supported by the
kernel/modules so that this can inform BTF encoding for older
kernels.  We look for BTF_KIND_MAX - either as an enumerated value
in vmlinux DWARF (patch 1) or as an enumerated value in base vmlinux
BTF (patch 2).

The aim is to minimize overhead on older stable kernels when new BTF
kinds are introduced.  Kind encoding [1] solves the parsing problem
with BTF, but this approach is intended to ensure generated BTF is
usable when newer pahole runs on older kernels.

This approach requires BTF kinds to be defined via an enumerated type,
which happened for 5.16 and later.  Older kernels than this used #defines
so the approach will only work for 5.16 stable kernels and later currently.

[1] https://lore.kernel.org/bpf/20230616171728.530116-1-alan.maguire@oracle.com/

Alan Maguire (2):
  dwarves: auto-detect maximum kind supported by vmlinux
  btf_encoder: learn BTF_KIND_MAX value from base BTF when generating
    split BTF

 btf_encoder.c  | 36 ++++++++++++++++++++++++++++++++++
 btf_encoder.h  |  2 ++
 dwarf_loader.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 dwarves.h      |  2 ++
 pahole.c       |  2 ++
 5 files changed, 94 insertions(+)

-- 
2.39.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-27 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 20:14 [RFC dwarves 0/2] dwarves: detect BTF kinds supported by kernel Alan Maguire
2023-07-20 20:14 ` [RFC dwarves 1/2] dwarves: auto-detect maximum kind supported by vmlinux Alan Maguire
2023-07-26 10:39   ` Jiri Olsa
2023-07-26 15:28     ` Alan Maguire
2023-07-27 15:47       ` Alexei Starovoitov
2023-07-20 20:14 ` [RFC dwarves 2/2] btf_encoder: learn BTF_KIND_MAX value from base BTF when generating split BTF Alan Maguire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).