[PATCH bpf-next v1 0/8] bpf: BTF support for ksyms

From: Hao Luo
Date: Wed Aug 19 2020 - 18:40:40 EST


This patch series extends the previously added __ksym externs with
btf support.

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 externs with their btf info. Note
that btf support for __ksym must come with the kernel btf that has
VARs encoded to work properly. The corresponding chagnes in pahole
is available at [1].

The first 5 patches in this series add support for general kernel
global variables, which includes verifier checking (01/08), libbpf
type checking (03/08) and btf_id resolving (04/08).

The last 3 patches extends that capability further by introducing a
helper bpf_per_cpu_ptr(), which allows accessing kernel percpu vars
correctly (06/08).

The tests of this feature were performed against the extended pahole.
For kernel btf that does not have VARs encoded, the selftests will be
skipped.

[1] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=f3d9054ba8ff1df0fc44e507e3a01c0964cabd42

rfc -> v1:
- Encode VAR's btf_id for PSEUDO_BTF_ID.
- More checks in verifier. Checking the btf_id passed as
PSEUDO_BTF_ID is valid VAR, its name and type.
- Checks in libbpf on type compatibility of ksyms.
- Add bpf_per_cpu_ptr() to access kernel percpu vars. Introduced
new ARG and RET types for this helper.

Hao Luo (8):
bpf: Introduce pseudo_btf_id
bpf: Propagate BPF_PSEUDO_BTF_ID to uapi headers in /tools
bpf: Introduce help function to validate ksym's type.
bpf/libbpf: BTF support for typed ksyms
bpf/selftests: ksyms_btf to test typed ksyms
bpf: Introduce bpf_per_cpu_ptr()
bpf: Propagate bpf_per_cpu_ptr() to /tools
bpf/selftests: Test for bpf_per_cpu_ptr()

include/linux/bpf.h | 3 +
include/linux/btf.h | 26 +++
include/uapi/linux/bpf.h | 52 +++++-
kernel/bpf/btf.c | 25 ---
kernel/bpf/verifier.c | 128 ++++++++++++-
kernel/trace/bpf_trace.c | 18 ++
tools/include/uapi/linux/bpf.h | 53 +++++-
tools/lib/bpf/btf.c | 171 ++++++++++++++++++
tools/lib/bpf/btf.h | 2 +
tools/lib/bpf/libbpf.c | 130 +++++++++++--
.../selftests/bpf/prog_tests/ksyms_btf.c | 81 +++++++++
.../selftests/bpf/progs/test_ksyms_btf.c | 36 ++++
12 files changed, 665 insertions(+), 60 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/ksyms_btf.c
create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_btf.c

--
2.28.0.220.ged08abb693-goog