bpf: add btf func info support
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest13 patches 2 repliesIn review
- v313 patches 1 replySuperseded
- v213 patches 34 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 13 patches | 12 replies | Superseded |
Changes in v4 from the cover letter
. Remove BTF_KIND_FUNC_PROTO. BTF_KIND_FUNC is used for
both function pointer and subprogram. The name_off field is used to distinguish both.
. The record size is added to the func_info subsection
in .BTF.ext to enable future extension.
. The bpf_prog_info interface change to make it similar
bpf_prog_load.
. Related kernel and libbpf changes to accommodate the
new .BTF.ext and kernel interface changes.
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/13 | bpf: btf: Break up btf_type_is_void()kernel/ | +22 | 0 replies | |
| 2/13 | bpf: btf: Add BTF_KIND_FUNCinclude/ kernel/ | +290 | 2 replies | |
| 3/13 | tools/bpf: sync kernel btf.h headertools/ | +14 | 0 replies | |
| 4/13 | tools/bpf: add btf func unit tests in selftest test_btftools/ tools/ | +265 | 0 replies | |
| 5/13 | bpf: get better bpf_prog ksyms based on btf func type_idinclude/ include/ include/ +5 more | +210 | 0 replies | |
| 6/13 | tools/bpf: sync kernel uapi bpf.h header to tools directorytools/ | +13 | 0 replies | |
| 7/13 | tools/bpf: add new fields for program load in lib/bpftools/ tools/ | +8 | 0 replies | |
| 8/13 | tools/bpf: extends test_btf to test load/retrieve func_type infotools/ | +312 | 0 replies | |
| 9/13 | tools/bpf: add support to read .BTF.ext sectionstools/ tools/ tools/ +1 more | +442 | 0 replies | |
| 10/13 | tools/bpf: do not use pahole if clang/llvm can generate BTF sectionssamples/ tools/ | +16 | 0 replies | |
| 11/13 | tools/bpf: refactor to implement btf_get_from_id() in lib/bpftools/ tools/ tools/ | +72 | 0 replies | |
| 12/13 | tools/bpf: enhance test_btf file testing to test func infotools/ tools/ tools/ | +136 | 0 replies | |
| 13/13 | tools/bpf: bpftool: add support for func typestools/ tools/ tools/ +2 more | +192 | 0 replies |
Reviews trailers per patch
5 of 13 patches have a Reviewed-by or Acked-by.
| Patch | Martin KaFai Lau |
|---|---|
| 1/13 | |
| 2/13 | |
| 3/13 | |
| 4/13 | |
| 5/13 | A-b |
| 6/13 | A-b |
| 7/13 | A-b |
| 8/13 | A-b |
| 9/13 | A-b |
| 10/13 | |
| 11/13 | |
| 12/13 | |
| 13/13 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v4 00/13] bpf: add btf func info support
The BTF support was added to kernel by Commit 69b693f0aefa ("bpf: btf: Introduce BPF Type Format (BTF)"), which introduced .BTF section into ELF file and is primarily
used for map pretty print.
pahole is used to convert dwarf to BTF for ELF files.
This patch added func info support to the kernel so we can get better ksym's for bpf function calls. Basically, function call types are passed to kernel and the kernel extract function names from these types in order to contruct ksym for these functions.
The llvm patch at https://reviews.llvm.org/D53736
will generate .BTF section and one more section .BTF.ext. The .BTF.ext section encodes function type information. The following is a sample output for selftests test_btf with file test_btf_haskv.o for translated insns and jited insns respectively.
$ bpftool prog dump xlated id 1
int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
0: (85) call pc+2#bpf_prog_2dcecc18072623fc_test_long_fname_1
1: (b7) r0 = 0
2: (95) exit
int test_long_fname_1(struct dummy_tracepoint_args * arg):
3: (85) call pc+1#bpf_prog_89d64e4abf0f0126_test_long_fname_2
4: (95) exit
int test_long_fname_2(struct dummy_tracepoint_args * arg):
5: (b7) r2 = 0
6: (63) *(u32 *)(r10 -4) = r2
7: (79) r1 = *(u64 *)(r1 +8)
...
22: (07) r1 += 1
23: (63) *(u32 *)(r0 +4) = r1
24: (95) exit $ bpftool prog dump jited id 1
int _dummy_tracepoint(struct dummy_tracepoint_args * arg):
bpf_prog_b07ccb89267cf242__dummy_tracepoint:
0: push %rbp
1: mov %rsp,%rbp
......
3c: add $0x28,%rbp
40: leaveq
41: retq int test_long_fname_1(struct dummy_tracepoint_args * arg):
bpf_prog_2dcecc18072623fc_test_long_fname_1:
0: push %rbp
1: mov %rsp,%rbp
......
3a: add $0x28,%rbp
3e: leaveq
3f: retq int test_long_fname_2(struct dummy_tracepoint_args * arg):
bpf_prog_89d64e4abf0f0126_test_long_fname_2:
0: push %rbp
1: mov %rsp,%rbp
......
80: add $0x28,%rbp
84: leaveq
85: retqFor the patchset,
Patch #1 refactors the code to break up btf_type_is_void(). Patch #2 introduces new BTF type BTF_KIND_FUNC. Patch #3 syncs btf.h header to tools directory. Patch #4 adds btf func type self tests in test_btf. Patch #5 adds kernel interface to load func_info to kernel
and pass func_info back to userspace.
Patch #6 syncs bpf.h header to tools directory.
Patch #7 adds news btf/func_info related fields in libbpf
program load function.
Patch #8 extends selftest test_btf to test load/retrieve func_info. Patch #9 adds .BTF.ext func info support.
Patch #10 changes Makefile to avoid using pahole if llvm is capable of
generating BTF sections.
Patch #11 refactors to have btf_get_from_id() in libbpf for reuse. Patch #12 enhance test_btf file testing to test func info. Patch #13 adds bpftool support for func signature dump.
Changelogs:
v3 -> v4:
. Remove BTF_KIND_FUNC_PROTO. BTF_KIND_FUNC is used for
both function pointer and subprogram. The name_off field is used to distinguish both.
. The record size is added to the func_info subsection
in .BTF.ext to enable future extension.
. The bpf_prog_info interface change to make it similar
bpf_prog_load.
. Related kernel and libbpf changes to accommodate the
new .BTF.ext and kernel interface changes.
v2 -> v3:
. Removed kernel btf extern functions btf_type_id_func()
and btf_get_name_by_id(). Instead, exposing existing functions btf_type_by_id() and btf_name_by_offset().
. Added comments about ELF section .BTF.ext layout.
. Better codes in btftool as suggested by Edward Cree.
v1 -> v2:
. Added missing sign-off.
. Limited the func_name/struct_member_name length for validity test. . Removed/changed several verifier messages.
. Modified several commit messages to remove line_off reference.
Yonghong Song (13):
bpf: btf: Break up btf_type_is_void()
bpf: btf: Add BTF_KIND_FUNC
tools/bpf: sync kernel btf.h header
tools/bpf: add btf func unit tests in selftest test_btf
bpf: get better bpf_prog ksyms based on btf func type_id tools/bpf: sync kernel uapi bpf.h header to tools directory tools/bpf: add new fields for program load in lib/bpf tools/bpf: extends test_btf to test load/retrieve func_type info tools/bpf: add support to read .BTF.ext sections tools/bpf: do not use pahole if clang/llvm can generate BTF sections tools/bpf: refactor to implement btf_get_from_id() in lib/bpf tools/bpf: enhance test_btf file testing to test func info tools/bpf: bpftool: add support for func types
include/linux/bpf.h | 5 +- include/linux/bpf_verifier.h | 1 + include/linux/btf.h | 2 + include/uapi/linux/bpf.h | 13 + include/uapi/linux/btf.h | 17 +- kernel/bpf/btf.c | 342 +++++++-- kernel/bpf/core.c | 13 + kernel/bpf/syscall.c | 59 +- kernel/bpf/verifier.c | 121 +++- samples/bpf/Makefile | 8 + tools/bpf/bpftool/btf_dumper.c | 98 +++ tools/bpf/bpftool/main.h | 2 + tools/bpf/bpftool/map.c | 68 +- tools/bpf/bpftool/prog.c | 56 ++ tools/bpf/bpftool/xlated_dumper.c | 33 + tools/bpf/bpftool/xlated_dumper.h | 3 + tools/include/uapi/linux/bpf.h | 13 + tools/include/uapi/linux/btf.h | 17 +- tools/lib/bpf/bpf.c | 50 +- tools/lib/bpf/bpf.h | 4 + tools/lib/bpf/btf.c | 346 +++++++++ tools/lib/bpf/btf.h | 51 ++ tools/lib/bpf/libbpf.c | 87 ++- tools/testing/selftests/bpf/Makefile | 8 + tools/testing/selftests/bpf/test_btf.c | 694 ++++++++++++++++++- tools/testing/selftests/bpf/test_btf_haskv.c | 16 +- tools/testing/selftests/bpf/test_btf_nokv.c | 16 +- 27 files changed, 1988 insertions(+), 155 deletions(-)
Signature · 1 line
2.17.1