Skip to content

Support kernel module ksym variables

Andrii Nakryiko bpf netdev 3 versions – Applied

Status from this message: Applied.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 5 repliesApplied
  2. v27 patches 19 repliesSuperseded
  3. v14 patches 0 repliesSuperseded

Changes in v3 from the cover letter

- added comments, addressed feedack (Yonghong, Hao);

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/7bpf: add bpf_patch_call_args prototype to include/linux/bpf.hinclude/linux/bpf.h+3 -00 replies
2/7bpf: avoid warning when re-casting __bpf_call_base into __bpf_call_base_argsinclude/linux/filter.h+1 -10 replies
3/7bpf: declare __bpf_free_used_maps() unconditionallyinclude/linux/bpf.h+3 -20 replies
4/7selftests/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+12 -330 replies
5/7bpf: support BPF ksym variables in kernel modulesinclude/linux/bpf.h include/linux/bpf_verifier.h include/linux/btf.h +3 more+194 -304 replies
6/7libbpf: support kernel module ksym externstools/lib/bpf/libbpf.c+32 -180 replies
7/7selftests/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+60 -01 reply

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchYonghong SongHao Luo
1/7A-b
2/7A-b
3/7A-b
4/7A-b A-b
5/7A-b A-b
6/7A-b A-b
7/7A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 bpf-next 0/7] Support kernel module ksym variables

Add support for using kernel module global variables (__ksym externs in BPF program). BPF verifier will now support ldimm64 with src_reg=BPF_PSEUDO_BTF_ID and non-zero insn[1].imm field, specifying module BTF's FD. In such case, module BTF object, similarly to BPF maps referenced from ldimm64 with src_reg=BPF_PSEUDO_MAP_FD, will be recorded in bpf_progran's auxiliary data 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. These refcounts will be dropped when BPF program is unloaded.

New selftest validates all this is working as intended. bpf_testmod.ko is extended with per-CPU variable. Selftests expects the latest pahole changes (soon to be released as v1.20) to generate per-CPU variable BTF info for kernel module.

v2->v3:
- added comments, addressed feedack (Yonghong, Hao);
v1->v2:
- fixed few compiler warnings, posted as separate pre-patches;
rfc->v1:
- use sys_membarrier(MEMBARRIER_CMD_GLOBAL) (Alexei).

Cc Hao Luo <[email protected]>

Andrii Nakryiko (7):
bpf: add bpf_patch_call_args prototype to include/linux/bpf.h
bpf: avoid warning when re-casting __bpf_call_base into
__bpf_call_base_args
bpf: declare __bpf_free_used_maps() unconditionally 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                           |  18 +-
 include/linux/bpf_verifier.h                  |   3 +
 include/linux/btf.h                           |   3 +
 include/linux/filter.h                        |   2 +-
 kernel/bpf/btf.c                              |  31 +++-
 kernel/bpf/core.c                             |  23 +++
 kernel/bpf/verifier.c                         | 154 ++++++++++++++----
 tools/lib/bpf/libbpf.c                        |  50 ++++--
 .../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   |  31 ++++
 .../selftests/bpf/progs/test_ksyms_module.c   |  26 +++
 tools/testing/selftests/bpf/test_progs.c      |  11 ++
 tools/testing/selftests/bpf/test_progs.h      |   1 +
 14 files changed, 305 insertions(+), 84 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