Skip to content

RFC Support kernel module ksym variables

Andrii Nakryiko bpf netdev oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest4 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4selftests/bpf: sync RCU before unloading bpf_testmodtools/testing/selftests/bpf/prog_tests/btf_map_in_map.c tools/testing/selftests/bpf/test_progs.c tools/testing/selftests/bpf/test_progs.h+41 -330 replies
2/4bpf: support BPF ksym variables in kernel modulesinclude/linux/bpf.h include/linux/bpf_verifier.h include/linux/btf.h +3 more+188 -304 replies
3/4libbpf: support kernel module ksym externstools/lib/bpf/libbpf.c+30 -170 replies
4/4selftests/bpf: test kernel module ksym externstools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c tools/testing/selftests/bpf/prog_tests/ksyms_module.c tools/testing/selftests/bpf/progs/test_ksyms_module.c+62 -00 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH RFC bpf-next 0/4] Support kernel module ksym variables

This RFC is sent to show how ksym variable access in BPF program can be supported for kernel modules and gather some feedback while necessary fixes for pahole ([0]) are reviewed and hopefully will make it into 1.20 version.

This work builds on all the previous kernel and libbpf changes to support kernel module BTFs. On top of that, BPF verifier will now support ldimm64 with src_reg=BPF_PSEUDO_BTF_ID and non-zero insn[1].imm field, which contains BTF FD for kernel module. In such case, used module BTF, similarly to used BPF map, will be recorded and refcnt will be increased for both BTF object itself and its kernel module. This makes sure kernel module won't be unloaded from under active attached BPF program.

New selftest validates all this is working as intended. bpf_testmod.ko is extended with per-CPU variable.

[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=400229&state=*

Andrii Nakryiko (4):
selftests/bpf: sync RCU before unloading bpf_testmod
bpf: support BPF ksym variables in kernel modules
libbpf: support kernel module ksym externs selftests/bpf: test kernel module ksym externs

 include/linux/bpf.h                           |   9 ++
 include/linux/bpf_verifier.h                  |   3 +
 include/linux/btf.h                           |   3 +
 kernel/bpf/btf.c                              |  31 +++-
 kernel/bpf/core.c                             |  23 +++
 kernel/bpf/verifier.c                         | 149 ++++++++++++++----
 tools/lib/bpf/libbpf.c                        |  47 ++++--
 .../selftests/bpf/bpf_testmod/bpf_testmod.c   |   3 +
 .../selftests/bpf/prog_tests/btf_map_in_map.c |  33 ----
 .../selftests/bpf/prog_tests/ksyms_module.c   |  33 ++++
 .../selftests/bpf/progs/test_ksyms_module.c   |  26 +++
 tools/testing/selftests/bpf/test_progs.c      |  40 +++++
 tools/testing/selftests/bpf/test_progs.h      |   1 +
 13 files changed, 321 insertions(+), 80 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/ksyms_module.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_module.c
Signature · 1 line
2.24.1