Introduce BPF trampoline
Status from this message: Applied, thanks!
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest20 patches 8 repliesApplied
- v318 patches 48 repliesSuperseded
- v217 patches 27 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 7 patches | 12 replies | Superseded |
Changes in v4 from the cover letter
- Included Peter's
"86/alternatives: Teach text_poke_bp() to emulate instructions" as a first patch. If it changes between now and merge window, I'll rebease to newer version. The patch is necessary to do s/text_poke/text_poke_bp/ in patch 3 to fix the race.
- In patch 4 fixed bpf_trampoline creation race spotted by Andrii.
- Added patch 15 that annotates prog->kern bpf context types. It made patches 16 and 17 cleaner and more generic.
- Addressed Andrii's feedback in other patches.
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/20 | x86/alternatives: Teach text_poke_bp() to emulate instructionsarch/ arch/ arch/ +1 more | +130 | 0 replies | |
| 2/20 | bpf: refactor x86 JIT into helpersarch/ | +98 | 0 replies | |
| 3/20 | bpf: Add bpf_arch_text_poke() helperarch/ include/ kernel/ | +65 | 1 reply | |
| 4/20 | bpf: Introduce BPF trampolinearch/ include/ include/ +6 more | +735 | 0 replies | |
| 5/20 | libbpf: Introduce btf__find_by_name_kind()tools/ tools/ tools/ | +25 | 0 replies | |
| 6/20 | libbpf: Add support to attach to fentry/fexit tracing progstools/ tools/ tools/ +1 more | +82 | 0 replies | |
| 7/20 | selftest/bpf: Simple test for fentry/fexittools/ tools/ | +88 | 0 replies | |
| 8/20 | bpf: Add kernel test functions for fentry testingnet/ | +41 | 0 replies | |
| 9/20 | selftests/bpf: Add test for BPF trampolinetools/ tools/ tools/ | +167 | 0 replies | |
| 10/20 | selftests/bpf: Add fexit tests for BPF trampolinetools/ tools/ | +162 | 0 replies | |
| 11/20 | selftests/bpf: Add combined fentry/fexit testtools/ | +90 | 0 replies | |
| 12/20 | selftests/bpf: Add stress test for maximum number of progstools/ | +76 | 0 replies | |
| 13/20 | bpf: Reserve space for BPF trampoline in BPF programsarch/ | +7 | 0 replies | |
| 14/20 | bpf: Fix race in btf_resolve_helper_id()include/ kernel/ kernel/ +1 more | +32 | 0 replies | |
| 15/20 | bpf: Annotate context typesinclude/ include/ kernel/ +3 more | +176 | 4 replies | |
| 16/20 | bpf: Compare BTF types of functions arguments with actual typesinclude/ include/ kernel/ +2 more | +107 | 0 replies | |
| 17/20 | bpf: Support attaching tracing BPF program to other BPF programsarch/ include/ include/ +5 more | +152 | 1 reply | |
| 18/20 | libbpf: Add support for attaching BPF programs to other BPF programstools/ tools/ tools/ +2 more | +71 | 1 reply | |
| 19/20 | selftests/bpf: Extend test_pkt_access testtools/ | +36 | 0 replies | |
| 20/20 | selftests/bpf: Add a test for attaching BPF prog to another BPF prog and subprogtools/ tools/ | +167 | 0 replies |
Reviews trailers per patch
All 20 patches have a Reviewed-by or Acked-by.
| Patch | Masami Hiramatsu | Daniel Bristot de Oliveira | Song Liu | Andrii Nakryiko |
|---|---|---|---|---|
| 1/20 | R-b | R-b | ||
| 2/20 | A-b | A-b | ||
| 3/20 | A-b | A-b | ||
| 4/20 | A-b | A-b | ||
| 5/20 | A-b | A-b | ||
| 6/20 | A-b | A-b | ||
| 7/20 | A-b | A-b | ||
| 8/20 | A-b | |||
| 9/20 | A-b | |||
| 10/20 | A-b | |||
| 11/20 | A-b | |||
| 12/20 | A-b | |||
| 13/20 | A-b | A-b | ||
| 14/20 | A-b | A-b | ||
| 15/20 | A-b | |||
| 16/20 | A-b | A-b | ||
| 17/20 | A-b | |||
| 18/20 | A-b | |||
| 19/20 | A-b | A-b | ||
| 20/20 | A-b | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [PATCH v4 bpf-next 00/20] Introduce BPF trampoline
Introduce BPF trampoline that works as a bridge between kernel functions, BPF programs and other BPF programs.
The first use case is fentry/fexit BPF programs that are roughly equivalent to kprobe/kretprobe. Unlike k[ret]probe there is practically zero overhead to call a set of BPF programs before or after kernel function.
The second use case is heavily influenced by pain points in XDP development. BPF trampoline allows attaching similar fentry/fexit BPF program to any networking BPF program. It's now possible to see packets on input and output of any XDP, TC, lwt, cgroup programs without disturbing them. This greatly helps BPF-based network troubleshooting.
The third use case of BPF trampoline will be explored in the follow up patches. The BPF trampoline will be used to dynamicly link BPF programs. It's more generic mechanism than array and link list of programs used in tracing, networking, cgroups. In many cases it can be used as a replacement for bpf_tail_call-based program chaining. See [1] for long term design discussion.
v3->v4:
- Included Peter's
"86/alternatives: Teach text_poke_bp() to emulate instructions" as a first patch. If it changes between now and merge window, I'll rebease to newer version. The patch is necessary to do s/text_poke/text_poke_bp/ in patch 3 to fix the race.
- In patch 4 fixed bpf_trampoline creation race spotted by Andrii.
- Added patch 15 that annotates prog->kern bpf context types. It made patches 16 and 17 cleaner and more generic.
- Addressed Andrii's feedback in other patches.
v2->v3:
- Addressed Song's and Andrii's comments
- Fixed few minor bugs discovered while testing
- Added one more libbpf patch
v1->v2:
- Addressed Andrii's comments
- Added more test for fentry/fexit to kernel functions. Including stress test for maximum number of progs per trampoline.
- Fixed a race btf_resolve_helper_id()
- Added a patch to compare BTF types of functions arguments with actual types.
- Added support for attaching BPF program to another BPF program via trampoline
- Converted to use text_poke() API. That's the only viable mechanism to implement BPF-to-BPF attach. BPF-to-kernel attach can be refactored to use register_ftrace_direct() whenever it's available.
[1]
https://lore.kernel.org/bpf/[email protected]/
Alexei Starovoitov (19):
bpf: refactor x86 JIT into helpers
bpf: Add bpf_arch_text_poke() helper
bpf: Introduce BPF trampoline
libbpf: Introduce btf__find_by_name_kind()
libbpf: Add support to attach to fentry/fexit tracing progs selftest/bpf: Simple test for fentry/fexit
bpf: Add kernel test functions for fentry testing selftests/bpf: Add test for BPF trampoline
selftests/bpf: Add fexit tests for BPF trampoline selftests/bpf: Add combined fentry/fexit test selftests/bpf: Add stress test for maximum number of progs
bpf: Reserve space for BPF trampoline in BPF programs
bpf: Fix race in btf_resolve_helper_id()
bpf: Annotate context types
bpf: Compare BTF types of functions arguments with actual types
bpf: Support attaching tracing BPF program to other BPF programs
libbpf: Add support for attaching BPF programs to other BPF programs selftests/bpf: Extend test_pkt_access test
selftests/bpf: Add a test for attaching BPF prog to another BPF prog
and subprog
Peter Zijlstra (1):
x86/alternatives: Teach text_poke_bp() to emulate instructions
arch/x86/include/asm/text-patching.h | 24 +- arch/x86/kernel/alternative.c | 132 ++++-- arch/x86/kernel/jump_label.c | 9 +- arch/x86/kernel/kprobes/opt.c | 11 +- arch/x86/net/bpf_jit_comp.c | 424 +++++++++++++++--- include/linux/bpf.h | 138 +++++- include/linux/bpf_types.h | 78 ++-- include/linux/bpf_verifier.h | 1 + include/linux/btf.h | 1 + include/uapi/linux/bpf.h | 3 + kernel/bpf/Makefile | 1 + kernel/bpf/btf.c | 363 ++++++++++++++- kernel/bpf/core.c | 9 + kernel/bpf/syscall.c | 77 +++- kernel/bpf/trampoline.c | 253 +++++++++++ kernel/bpf/verifier.c | 131 +++++- net/bpf/test_run.c | 41 ++ net/core/filter.c | 12 +- tools/include/uapi/linux/bpf.h | 3 + tools/lib/bpf/bpf.c | 8 +- tools/lib/bpf/bpf.h | 5 +- tools/lib/bpf/bpf_helpers.h | 13 + tools/lib/bpf/btf.c | 22 + tools/lib/bpf/btf.h | 2 + tools/lib/bpf/libbpf.c | 154 +++++-- tools/lib/bpf/libbpf.h | 7 +- tools/lib/bpf/libbpf.map | 3 + .../selftests/bpf/prog_tests/fentry_fexit.c | 90 ++++ .../selftests/bpf/prog_tests/fentry_test.c | 64 +++ .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 76 ++++ .../selftests/bpf/prog_tests/fexit_stress.c | 76 ++++ .../selftests/bpf/prog_tests/fexit_test.c | 64 +++ .../selftests/bpf/prog_tests/kfree_skb.c | 39 +- .../testing/selftests/bpf/progs/fentry_test.c | 90 ++++ .../selftests/bpf/progs/fexit_bpf2bpf.c | 91 ++++ .../testing/selftests/bpf/progs/fexit_test.c | 98 ++++ tools/testing/selftests/bpf/progs/kfree_skb.c | 52 +++ .../selftests/bpf/progs/test_pkt_access.c | 38 +- 38 files changed, 2484 insertions(+), 219 deletions(-) create mode 100644 kernel/bpf/trampoline.c create mode 100644 tools/testing/selftests/bpf/prog_tests/fentry_fexit.c create mode 100644 tools/testing/selftests/bpf/prog_tests/fentry_test.c create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_stress.c create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_test.c create mode 100644 tools/testing/selftests/bpf/progs/fentry_test.c create mode 100644 tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c create mode 100644 tools/testing/selftests/bpf/progs/fexit_test.c
Signature · 1 line
2.23.0