Support kernel module function calls from eBPF
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v7 Latest9 patches 1 replyIn review
- v69 patches 7 repliesSuperseded
- v512 patches 6 repliesApplied
Earlier versions · 4
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v4 | 11 patches | 19 replies | Superseded | |
| v3 | 10 patches | 9 replies | Superseded | |
| v2 | 10 patches | 0 replies | Superseded | |
| v1 RFC | 8 patches | 8 replies | Superseded |
Changes in v7 from the cover letter
v6: https://lore.kernel.org/bpf/[email protected]
* Let __bpf_check_kfunc_call take kfunc_btf_id_list instead of generating callbacks (Andrii)
* Rename it to bpf_check_mod_kfunc_call to reflect usage
* Remove OOM checks (Alexei)
* Remove resolve_btfids invocation for bpf_testmod (Andrii)
* Move fd_array_cnt initialization near fd_array alloc (Andrii)
* Rename helper to btf_find_by_name_kind and pass start_id (Andrii)
* memset when data is NULL in add_data (Alexei)
* Fix other nits
Patches in v7 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/9 | bpf: Introduce BPF support for kernel module function callsinclude/ include/ kernel/ +3 more | +188 | 0 replies | |
| 2/9 | bpf: Be conservative while processing invalid kfunc callskernel/ | +18 | 0 replies | |
| 3/9 | bpf: btf: Introduce helpers for dynamic BTF set registrationinclude/ include/ kernel/ | +89 | 0 replies | |
| 4/9 | tools: Allow specifying base BTF file in resolve_btfidstools/ tools/ | +20 | 0 replies | |
| 5/9 | bpf: Enable TCP congestion control kfunc from modulesinclude/ kernel/ net/ +4 more | +85 | 0 replies | |
| 6/9 | libbpf: Support kernel module function callstools/ tools/ tools/ +1 more | +72 | 0 replies | |
| 7/9 | libbpf: Resolve invalid weak kfunc calls with imm = 0, off = 0tools/ | +13 | 0 replies | |
| 8/9 | libbpf: Update gen_loader to emit BTF_KIND_FUNC relocationstools/ tools/ tools/ | +280 | 0 replies | |
| 9/9 | bpf: selftests: Add selftests for module kfunc supportinclude/ kernel/ net/ +6 more | +132 | 0 replies |
Reviews trailers per patch
2 of 9 patches have a Reviewed-by or Acked-by.
| Patch | Andrii Nakryiko |
|---|---|
| 1/9 | |
| 2/9 | |
| 3/9 | |
| 4/9 | A-b |
| 5/9 | |
| 6/9 | |
| 7/9 | A-b |
| 8/9 | |
| 9/9 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v7 0/9] Support kernel module function calls from eBPF
This set enables kernel module function calls, and also modifies verifier logic to permit invalid kernel function calls as long as they are pruned as part of dead code elimination. This is done to provide better runtime portability for BPF objects, which can conditionally disable parts of code that are pruned later by the verifier (e.g. const volatile vars, kconfig options). libbpf modifications are made along with kernel changes to support module function calls.
It also converts TCP congestion control objects to use the module kfunc support instead of relying on IS_BUILTIN ifdef.
Changelog:
----------
v6 -> v7
v6: https://lore.kernel.org/bpf/[email protected]
* Let __bpf_check_kfunc_call take kfunc_btf_id_list instead of generating callbacks (Andrii)
* Rename it to bpf_check_mod_kfunc_call to reflect usage
* Remove OOM checks (Alexei)
* Remove resolve_btfids invocation for bpf_testmod (Andrii)
* Move fd_array_cnt initialization near fd_array alloc (Andrii)
* Rename helper to btf_find_by_name_kind and pass start_id (Andrii)
* memset when data is NULL in add_data (Alexei)
* Fix other nits
v5 -> v6
v5: https://lore.kernel.org/bpf/[email protected]
* Rework gen_loader relocation emits
* Only emit bpf_btf_find_by_name_kind call when required (Alexei)
* Refactor code to emit ksym var and func relo into separate helpers, this will be easier to add future weak/typeless ksym support to (for my followup)
* Count references for both ksym var and funcs, and avoid calling helpers unless required for both of them. This also means we share fds between ksym vars for the module BTFs. Also be careful with this when closing BTF fd so that we only close one instance of the fd for each ksym
v4 -> v5
v4: https://lore.kernel.org/bpf/[email protected]
* Address comments from Alexei
* Use reserved fd_array area in loader map instead of creating a new map
* Drop selftest testing the 256 kfunc limit, however selftest testing reuse of BTF fd for same kfunc in gen_loader and libbpf is kept
* Address comments from Andrii
* Make --no-fail the default for resolve_btfids, i.e. only fail if we find BTF section and cannot process it
* Use obj->btf_modules array to store index in the fd_array, so that we don't have to do any searching to reuse the index, instead only set it the first time a module BTF's fd is used
* Make find_ksym_btf_id to return struct module_btf * in last parameter
* Improve logging when index becomes bigger than INT16_MAX
* Add btf__find_by_name_kind_own internal helper to only start searching for kfunc ID in module BTF, since find_ksym_btf_id already checks vmlinux BTF before iterating over module BTFs.
* Fix various other nits
* Fixes for failing selftests on BPF CI
* Rearrange/cleanup selftests
* Avoid testing kfunc limit (Alexei)
* Do test gen_loader and libbpf BTF fd index dedup with 256 calls
* Move invalid kfunc failure test to verifier selftest
* Minimize duplication
* Use consistent bpf_<type>_check_kfunc_call naming for module kfunc callback
* Since we try to add fd using add_data while we can, cherry pick Alexei's patch from CO-RE RFC series to align gen_loader data.
v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]
* Address comments from Alexei
* Drop MAX_BPF_STACK change, instead move map_fd and BTF fd to BPF array map and pass fd_array using BPF_PSEUDO_MAP_IDX_VALUE
* Address comments from Andrii
* Fix selftest to store to variable for observing function call instead of printk and polluting CI logs
* Drop use of raw_tp for testing, instead reuse classifier based prog_test_run
* Drop index + 1 based insn->off convention for kfunc module calls
* Expand selftests to cover more corner cases
* Misc cleanups
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]
* Fix issues pointed out by Kernel Test Robot
* Fix find_kfunc_desc to also take offset into consideration when comparing
RFC v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]
* Address comments from Alexei
* Reuse fd_array instead of introducing kfunc_btf_fds array
* Take btf and module reference as needed, instead of preloading
* Add BTF_KIND_FUNC relocation support to gen_loader infrastructure
* Address comments from Andrii
* Drop hashmap in libbpf for finding index of existing BTF in fd_array
* Preserve invalid kfunc calls only when the symbol is weak
* Adjust verifier selftests
Kumar Kartikeya Dwivedi (9):
bpf: Introduce BPF support for kernel module function calls
bpf: Be conservative while processing invalid kfunc calls
bpf: btf: Introduce helpers for dynamic BTF set registration
tools: Allow specifying base BTF file in resolve_btfids
bpf: Enable TCP congestion control kfunc from modules
libbpf: Support kernel module function calls
libbpf: Resolve invalid weak kfunc calls with imm = 0, off = 0
libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations
bpf: selftests: Add selftests for module kfunc support
include/linux/bpf.h | 8 +- include/linux/bpf_verifier.h | 2 + include/linux/bpfptr.h | 1 + include/linux/btf.h | 39 +++ kernel/bpf/btf.c | 55 +++ kernel/bpf/core.c | 4 + kernel/bpf/verifier.c | 220 ++++++++++-- net/bpf/test_run.c | 7 +- net/ipv4/bpf_tcp_ca.c | 36 +- net/ipv4/tcp_bbr.c | 28 +- net/ipv4/tcp_cubic.c | 26 +- net/ipv4/tcp_dctcp.c | 26 +- scripts/Makefile.modfinal | 1 + tools/bpf/resolve_btfids/main.c | 28 +- tools/lib/bpf/bpf.c | 1 + tools/lib/bpf/bpf_gen_internal.h | 16 +- tools/lib/bpf/btf.c | 18 +- tools/lib/bpf/gen_loader.c | 314 +++++++++++++++--- tools/lib/bpf/libbpf.c | 104 ++++-- tools/lib/bpf/libbpf_internal.h | 3 + tools/testing/selftests/bpf/Makefile | 9 +- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 23 +- .../selftests/bpf/prog_tests/ksyms_module.c | 29 +- .../bpf/prog_tests/ksyms_module_libbpf.c | 28 ++ .../selftests/bpf/progs/test_ksyms_module.c | 46 ++- tools/testing/selftests/bpf/verifier/calls.c | 23 ++ 26 files changed, 896 insertions(+), 199 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/ksyms_module_libbpf.c
Signature · 1 line
2.33.0