RFC bpf: Attach kprobe multi link to inlined functions
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest31 patches 4 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/31 | x86/ptrace: Add regs_get_dwarf_register functionarch/ arch/ include/ | +60 | 0 replies | |
| 2/31 | kprobes: Make the kprobe hash table size configurablearch/ kernel/ | +18 | 0 replies | |
| 3/31 | kprobes: Add enable_kprobes to enable multiple kprobes at oncearch/ include/ kernel/ | +99 | 0 replies | |
| 4/31 | module: Add module_sect_addr functioninclude/ kernel/ | +29 | 0 replies | |
| 5/31 | bpf: Add bpf_get_btf_vmlinux_inline functioninclude/ include/ kernel/ +1 more | +99 | 1 reply | |
| 6/31 | bpf: Use goto labels for error path in bpf_kprobe_multi_link_attachkernel/ | +10 | 0 replies | |
| 7/31 | bpf: Add support to attach inlined functions with kprobe multi linkarch/ arch/ include/ +2 more | +384 | 1 reply | |
| 8/31 | bpf: Add cookie support for kprobe multi inlined functionskernel/ | +16 | 0 replies | |
| 9/31 | bpf: Add link info support for kprobe multi inlined functionsinclude/ kernel/ tools/ | +76 | 0 replies | |
| 10/31 | bpf: Add fdinfo support for kprobe multi inlined functionskernel/ | +5 | 0 replies | |
| 11/31 | bpf: Add btf_for_each_module_inline functioninclude/ kernel/ | +75 | 0 replies | |
| 12/31 | bpf: Change get_modules_for_addrs to use struct modules_arraykernel/ | +18 | 0 replies | |
| 13/31 | tbpf: Add support to attach inlined functions in modules with kprobe multi linkkernel/ | +65 | 0 replies | |
| 14/31 | bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for kprobe multi linkinclude/ kernel/ tools/ | +19 | 0 replies | |
| 15/31 | bpf: Add get_func_arg[_cnt] support for kprobe multi functionsinclude/ include/ kernel/ +2 more | +192 | 1 reply | |
| 16/31 | bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functionsinclude/ kernel/ tools/ | +137 | 0 replies | |
| 17/31 | bpf: Add log messages for kprobe multi inline attachinclude/ kernel/ kernel/ | +68 | 0 replies | |
| 18/31 | bpf: Add inlined functions for kprobe multi inline testsnet/ | +82 | 0 replies | |
| 19/31 | libbpf: Add inline options to bpf_kprobe_multi_optstools/ tools/ | +22 | 0 replies | |
| 20/31 | libbpf: Print kernel log for failed kprobe multi attachtools/ | +11 | 0 replies | |
| 21/31 | bpftool: Display inlined functions for kprobe multi linktools/ | +303 | 0 replies | |
| 22/31 | selftests/bpf: Add inlined functions to bpf_testmodtools/ | +28 | 0 replies | |
| 23/31 | selftests/bpf: Add kprobe multi inline attach testtools/ tools/ | +254 | 0 replies | |
| 24/31 | selftests/bpf: Add kprobe multi inline mixed testtools/ | +50 | 0 replies | |
| 25/31 | selftests/bpf: Add kprobe multi inline skip testtools/ | +102 | 0 replies | |
| 26/31 | selftests/bpf: Add kprobe multi inline fails testtools/ tools/ | +174 | 0 replies | |
| 27/31 | selftests/bpf: Add kprobe multi inline module testtools/ | +114 | 0 replies | |
| 28/31 | selftests/bpf: Add kprobe multi inline strict testtools/ | +82 | 0 replies | |
| 29/31 | selftests/bpf: Add kprobe multi inline args testtools/ tools/ | +217 | 0 replies | |
| 30/31 | selftests/bpf: Add kprobe multi inline bench attach testtools/ | +50 | 0 replies | |
| 31/31 | selftests/bpf: Add kprobe multi inline link info testtools/ | +251 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions
hi,
the kprobe multi link attaches only the out-of-line copy of the function, so inlined instances are not traced and a function inlined in all its callers can't be attached at all.
This patchset adds BPF_F_KPROBE_MULTI_INLINE flag that attaches also the inlined instances of the functions in the syms array. The instances are resolved from inline BTF (CONFIG_DEBUG_INFO_BTF_INLINE) of vmlinux and modules and each gets its own kprobe.
Only instances inlined in traceable functions (with ftrace location) are attached, instances in notrace functions are likely not safe to probe. Those and the instances that kprobes refuse are skipped, or fail the attach with BPF_F_KPROBE_MULTI_INLINE_STRICT flag.
The program attached to inlined instance can use cookies, bpf_get_func_ip and bpf_get_func_arg[_cnt] helpers. The instances are visible in link info, fdinfo and bpftool.
The BPF_F_KPROBE_MULTI_INLINE flag can't be used with return probe, session program, addrs array or bpf_override_return. The support is x86_64 only for now.
- patches 1-5: x86 ptrace, kprobes, module and BTF preparation
- patches 6-16: kprobe multi inline attach
- patches 17-19: libbpf and bpftool support
- patches 20-30: selftests
The kprobe_multi_bench_attach test in KVM guest, 67295 vmlinux functions:
instances attach detach without inline - 0.324s 0.154s with inline 19947 6.443s 0.361s
The speed of the inline attach depends on several kprobe changes. Two of them are part of this series:
kprobes: Make the kprobe hash table size configurable
kprobes: Add enable_kprobes to enable multiple kprobes at once
and two were posted separately:
[1] jump_label/x86: Avoid decoding instructions for jump entry size
[2] x86/kprobes: Use ftrace_location_range in __recover_probed_insn
I think there's still space for kprobe changes that would make the attach faster, especially the follow up fixes for [3]. I'm sending this as RFC to get feedback on the interface, while I work on the kprobe attach speedup.
thanks,
jirka
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/bpf/[email protected]/
---
Jiri Olsa (31):
x86/ptrace: Add regs_get_dwarf_register function
kprobes: Make the kprobe hash table size configurable
kprobes: Add enable_kprobes to enable multiple kprobes at once
module: Add module_sect_addr function
bpf: Add bpf_get_btf_vmlinux_inline function
bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach
bpf: Add support to attach inlined functions with kprobe multi link
bpf: Add cookie support for kprobe multi inlined functions
bpf: Add link info support for kprobe multi inlined functions
bpf: Add fdinfo support for kprobe multi inlined functions
bpf: Add btf_for_each_module_inline function
bpf: Change get_modules_for_addrs to use struct modules_array
tbpf: Add support to attach inlined functions in modules with kprobe multi link
bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for kprobe multi link
bpf: Add get_func_arg[_cnt] support for kprobe multi functions
bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions
bpf: Add log messages for kprobe multi inline attach
bpf: Add inlined functions for kprobe multi inline tests
libbpf: Add inline options to bpf_kprobe_multi_opts
libbpf: Print kernel log for failed kprobe multi attach
bpftool: Display inlined functions for kprobe multi link selftests/bpf: Add inlined functions to bpf_testmod selftests/bpf: Add kprobe multi inline attach test
selftests/bpf: Add kprobe multi inline mixed test
selftests/bpf: Add kprobe multi inline skip test
selftests/bpf: Add kprobe multi inline fails test
selftests/bpf: Add kprobe multi inline module test
selftests/bpf: Add kprobe multi inline strict test
selftests/bpf: Add kprobe multi inline args test
selftests/bpf: Add kprobe multi inline bench attach test selftests/bpf: Add kprobe multi inline link info test
arch/Kconfig | 23 ++ arch/x86/Kconfig | 1 + arch/x86/include/asm/ptrace.h | 8 + arch/x86/kernel/kprobes/core.c | 13 + arch/x86/kernel/ptrace.c | 42 +++ include/linux/bpf.h | 2 + include/linux/btf.h | 17 + include/linux/kprobes.h | 7 + include/linux/module.h | 9 + include/linux/ptrace.h | 10 + include/linux/trace_events.h | 7 +- include/uapi/linux/bpf.h | 29 +- kernel/bpf/btf.c | 157 ++++++++- kernel/bpf/syscall.c | 2 +- kernel/bpf/sysfs_btf.c | 2 +- kernel/bpf/verifier.c | 3 + kernel/kprobes.c | 92 ++++- kernel/module/sysfs.c | 20 ++ kernel/trace/bpf_trace.c | 921 ++++++++++++++++++++++++++++++++++++++++++++++--- net/bpf/test_run.c | 83 ++++- tools/bpf/bpftool/link.c | 348 ++++++++++++++++--- tools/include/uapi/linux/bpf.h | 29 +- tools/lib/bpf/libbpf.c | 29 +- tools/lib/bpf/libbpf.h | 6 +- tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 251 ++++++++++++++ tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 963 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/kprobe_multi_inline.c | 79 +++++ tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 28 ++ 28 files changed, 3058 insertions(+), 123 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/kprobe_multi_inline.c