Skip to content

RFC BTF support for ksyms

Hao Luo bpf linux-kselftest lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: BTF support for __ksym externsinclude/uapi/linux/bpf.h kernel/bpf/verifier.c tools/include/uapi/linux/bpf.h +1 more+127 -232 replies
2/2selftests/bpf: Test __ksym externs with BTFtools/testing/selftests/bpf/prog_tests/ksyms.c tools/testing/selftests/bpf/progs/test_ksyms.c+16 -04 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [RFC PATCH bpf-next 0/2] BTF support for ksyms

This patch series extends the previously add __ksym externs with btf info.

Right now the __ksym externs are treated as pure 64-bit scalar value. Libbpf replaces ld_imm64 insn of __ksym by its kernel address at load time. This patch series extend those extern with their btf info. Note that btf support for __ksym must come with the btf that has VARs encoded to work properly. Therefore, these patches are tested against a btf generated by a patched pahole, whose change will available in released pahole soon.

There are a couple of design choices that I would like feedbacks from bpf/btf experts.

1. Because the newly added pseudo_btf_id needs to carry both a kernel address (64 bits) and a btf id (32 bits), I used the 'off' fields of ld_imm insn to carry btf id. I wonder if this breaks anything or if there is a better idea.
2. Since only a subset of vars are going to be encoded into the new btf, if a ksym that doesn't find its btf id, it doesn't get converted into pseudo_btf_id. It is still treated as pure scalar value. But we require kernel btf to be loaded in libbpf if there is any ksym in the bpf prog.

This is RFC as it requires pahole changes that encode kernel vars into btf.

Hao Luo (2):
bpf: BTF support for __ksym externs
selftests/bpf: Test __ksym externs with BTF

 include/uapi/linux/bpf.h                      | 37 ++++++++++----
 kernel/bpf/verifier.c                         | 26 ++++++++--
 tools/include/uapi/linux/bpf.h                | 37 ++++++++++----
 tools/lib/bpf/libbpf.c                        | 50 ++++++++++++++++++-
 .../testing/selftests/bpf/prog_tests/ksyms.c  |  2 +
 .../testing/selftests/bpf/progs/test_ksyms.c  | 14 ++++++
 6 files changed, 143 insertions(+), 23 deletions(-)
Signature · 1 line
2.27.0.389.gc38d7665816-goog