bpf: Support calling kernel function
Status from this message: This series was applied to bpf/bpf-next.git (refs/heads/master):
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest14 patches 24 repliesApplied 14/14
- v115 patches 32 repliesSuperseded
Changes in v2 from the cover letter
- Patch 2 in v1 is removed. No need to support extern func in kernel. Changed libbpf to adjust the .ksyms datasec for extern func in patch 11. (Andrii)
- Name change: btf_check_func_arg_match() and btf_check_subprog_arg_match() in patch 2. (Andrii)
- Always set unreliable on any error in patch 2 since it does not matter. (Andrii)
- s/kern_func/kfunc/ and s/descriptor/desc/ in this set. (Andrii)
- Remove some unnecessary changes in disasm.h and disasm.c
in patch 3. In particular, no need to change the function signature in bpf_insn_revmap_call_t. Also, removed the changes in print_bpf_insn().
- Fixed an issue in check_kfunc_call() when the calling kernel function returns a pointer in patch 3. Added a selftest.
- Adjusted the verifier selftests due to the changes in the verifier log in patch 3.
- Fixed a comparison issue in kfunc_desc_cmp_by_imm() in patch 3. (Andrii)
- Name change: is_ldimm64_insn(),
new helper: is_call_insn() in patch 10 (Andrii)
- Move btf_func_linkage() from btf.h to libbpf.c in patch 11. (Andrii)
- Fixed the linker error when CONFIG_BPF_SYSCALL is not defined. Moved the check_kfunc_call from filter.c to test_run.c in patch 14. (kernel test robot)
Patches in v2 All 14 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/14 | bpf: Simplify freeing logic in linfo and jited_linfoinclude/ kernel/ kernel/ +1 more | +17 | 0 replies | Applied |
| 2/14 | bpf: Refactor btf_check_func_arg_matchinclude/ include/ kernel/ +1 more | +95 | 0 replies | Applied |
| 3/14 | bpf: Support bpf program calling kernel functionarch/ include/ include/ +10 more | +480 | 6 replies | Applied |
| 4/14 | bpf: Support kernel function call in x86-32arch/ | +198 | 0 replies | Applied |
| 5/14 | tcp: Rename bictcp function prefix to cubictcpnet/ | +12 | 0 replies | Applied |
| 6/14 | bpf: tcp: Put some tcp cong functions in allowlist for bpf-tcp-ccnet/ | +41 | 0 replies | Applied |
| 7/14 | libbpf: Refactor bpf_object__resolve_ksyms_btf_idtools/ | +67 | 0 replies | Applied |
| 8/14 | libbpf: Refactor codes for finding btf id of a kernel symboltools/ | +33 | 0 replies | Applied |
| 9/14 | libbpf: Rename RELO_EXTERN to RELO_EXTERN_VARtools/ | +3 | 0 replies | Applied |
| 10/14 | libbpf: Record extern sym relocation firsttools/ | +34 | 0 replies | Applied |
| 11/14 | libbpf: Support extern kernel functiontools/ | +162 | 0 replies | Applied |
| 12/14 | bpf: selftests: Rename bictcp to bpf_cubictools/ | +15 | 0 replies | Applied |
| 13/14 | bpf: selftests: bpf_cubic and bpf_dctcp calling kernel functionstools/ tools/ tools/ | +11 | 0 replies | Applied |
| 14/14 | bpf: selftests: Add kfunc_call testinclude/ net/ net/ +3 more | +183 | 0 replies | Applied |
Reviews trailers per patch
7 of 14 patches have a Reviewed-by or Acked-by.
| Patch | Andrii Nakryiko |
|---|---|
| 1/14 | |
| 2/14 | |
| 3/14 | |
| 4/14 | |
| 5/14 | |
| 6/14 | A-b |
| 7/14 | A-b |
| 8/14 | A-b |
| 9/14 | A-b |
| 10/14 | A-b |
| 11/14 | |
| 12/14 | A-b |
| 13/14 | A-b |
| 14/14 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 bpf-next 00/14] bpf: Support calling kernel function
This series adds support to allow bpf program calling kernel function.
The use case included in this set is to allow bpf-tcp-cc to directly call some tcp-cc helper functions (e.g. "tcp_cong_avoid_ai()"). Those functions have already been used by some kernel tcp-cc implementations.
This set will also allow the bpf-tcp-cc program to directly call the kernel tcp-cc implementation, For example, a bpf_dctcp may only want to implement its own dctcp_cwnd_event() and reuse other dctcp_*() directly from the kernel tcp_dctcp.c instead of reimplementing (or copy-and-pasting) them.
The tcp-cc kernel functions mentioned above will be white listed for the struct_ops bpf-tcp-cc programs to use in a later patch. The white listed functions are not bounded to a fixed ABI contract. Those functions have already been used by the existing kernel tcp-cc. If any of them has changed, both in-tree and out-of-tree kernel tcp-cc implementations have to be changed. The same goes for the struct_ops bpf-tcp-cc programs which have to be adjusted accordingly.
Please see individual patch for details.
v2:
- Patch 2 in v1 is removed. No need to support extern func in kernel. Changed libbpf to adjust the .ksyms datasec for extern func in patch 11. (Andrii)
- Name change: btf_check_func_arg_match() and btf_check_subprog_arg_match() in patch 2. (Andrii)
- Always set unreliable on any error in patch 2 since it does not matter. (Andrii)
- s/kern_func/kfunc/ and s/descriptor/desc/ in this set. (Andrii)
- Remove some unnecessary changes in disasm.h and disasm.c
in patch 3. In particular, no need to change the function signature in bpf_insn_revmap_call_t. Also, removed the changes in print_bpf_insn().
- Fixed an issue in check_kfunc_call() when the calling kernel function returns a pointer in patch 3. Added a selftest.
- Adjusted the verifier selftests due to the changes in the verifier log in patch 3.
- Fixed a comparison issue in kfunc_desc_cmp_by_imm() in patch 3. (Andrii)
- Name change: is_ldimm64_insn(),
new helper: is_call_insn() in patch 10 (Andrii)
- Move btf_func_linkage() from btf.h to libbpf.c in patch 11. (Andrii)
- Fixed the linker error when CONFIG_BPF_SYSCALL is not defined. Moved the check_kfunc_call from filter.c to test_run.c in patch 14. (kernel test robot)
Martin KaFai Lau (14):
bpf: Simplify freeing logic in linfo and jited_linfo
bpf: Refactor btf_check_func_arg_match
bpf: Support bpf program calling kernel function
bpf: Support kernel function call in x86-32
tcp: Rename bictcp function prefix to cubictcp
bpf: tcp: Put some tcp cong functions in allowlist for bpf-tcp-cc
libbpf: Refactor bpf_object__resolve_ksyms_btf_id
libbpf: Refactor codes for finding btf id of a kernel symbol
libbpf: Rename RELO_EXTERN to RELO_EXTERN_VAR
libbpf: Record extern sym relocation first
libbpf: Support extern kernel function
bpf: selftests: Rename bictcp to bpf_cubic
bpf: selftests: bpf_cubic and bpf_dctcp calling kernel functions
bpf: selftests: Add kfunc_call test
arch/x86/net/bpf_jit_comp.c | 5 + arch/x86/net/bpf_jit_comp32.c | 198 +++++++++ include/linux/bpf.h | 34 +- include/linux/btf.h | 6 + include/linux/filter.h | 4 +- include/uapi/linux/bpf.h | 4 + kernel/bpf/btf.c | 218 ++++++---- kernel/bpf/core.c | 47 +-- kernel/bpf/disasm.c | 13 +- kernel/bpf/syscall.c | 4 +- kernel/bpf/verifier.c | 376 +++++++++++++++-- net/bpf/test_run.c | 28 ++ net/core/filter.c | 1 + net/ipv4/bpf_tcp_ca.c | 41 ++ net/ipv4/tcp_cubic.c | 24 +- tools/include/uapi/linux/bpf.h | 4 + tools/lib/bpf/libbpf.c | 389 +++++++++++++----- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 29 +- .../selftests/bpf/prog_tests/kfunc_call.c | 59 +++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 36 +- tools/testing/selftests/bpf/progs/bpf_dctcp.c | 22 +- .../selftests/bpf/progs/kfunc_call_test.c | 47 +++ .../bpf/progs/kfunc_call_test_subprog.c | 42 ++ tools/testing/selftests/bpf/verifier/calls.c | 12 +- .../selftests/bpf/verifier/dead_code.c | 10 +- 25 files changed, 1334 insertions(+), 319 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/kfunc_call.c create mode 100644 tools/testing/selftests/bpf/progs/kfunc_call_test.c create mode 100644 tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c
Signature · 1 line
2.30.2