Skip to content

RFC dwarves: detect BTF kinds supported by kernel

Alan Maguire bpf 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2dwarves: auto-detect maximum kind supported by vmlinuxbtf_encoder.c dwarf_loader.c dwarves.h+66 -03 replies
2/2btf_encoder: learn BTF_KIND_MAX value from base BTF when generating split BTFbtf_encoder.c btf_encoder.h pahole.c+28 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC dwarves 0/2] dwarves: detect BTF kinds supported by kernel

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/[email protected]/

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(+)
Signature · 1 line
2.39.3