[PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions
From: Jiri Olsa
Date: Wed Dec 02 2026 - 07:30:45 EST
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/20261117195506.23759-1-jolsa@xxxxxxxxxx/
[2] https://lore.kernel.org/lkml/20261122200239.1481088-3-jolsa@xxxxxxxxxx/
[3] https://lore.kernel.org/bpf/20261109194916.1089703-1-jolsa@xxxxxxxxxx/
Assisted-by: LLM
---
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