* [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions
@ 2026-12-02 12:30 Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
` (30 more replies)
0 siblings, 31 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
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@kernel.org/
[2] https://lore.kernel.org/lkml/20261122200239.1481088-3-jolsa@kernel.org/
[3] https://lore.kernel.org/bpf/20261109194916.1089703-1-jolsa@kernel.org/
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
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
` (29 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add regs_get_dwarf_register function that returns value of the register
specified by its DWARF register number from pt_regs.
It will be used in following changes to read arguments of inlined
functions, where the argument location is described in inline BTF
with DWARF register numbers.
The x86_64 version maps the DWARF register numbers as defined by
psABI, other archs get the generic version that returns -EOPNOTSUPP.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/x86/include/asm/ptrace.h | 8 +++++++
arch/x86/kernel/ptrace.c | 42 +++++++++++++++++++++++++++++++++++
include/linux/ptrace.h | 10 +++++++++
3 files changed, 60 insertions(+)
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
index 7bb7bd90355d..56e8aa589d35 100644
--- a/arch/x86/include/asm/ptrace.h
+++ b/arch/x86/include/asm/ptrace.h
@@ -317,6 +317,14 @@ static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
/* Query offset/name of register from its name/offset */
extern int regs_query_register_offset(const char *name);
extern const char *regs_query_register_name(unsigned int offset);
+
+#ifdef CONFIG_X86_64
+/* Get value of the register specified by DWARF register number. */
+extern int regs_get_dwarf_register(struct pt_regs *regs, unsigned int regno,
+ unsigned long *value);
+#define regs_get_dwarf_register regs_get_dwarf_register
+#endif
+
#define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
/**
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 953d577ebadd..3c9f1dab294a 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -147,6 +147,48 @@ const char *regs_query_register_name(unsigned int offset)
return NULL;
}
+#ifdef CONFIG_X86_64
+/* DWARF register numbers as defined by x86-64 psABI. */
+static const unsigned int dwarf_regs[] = {
+ offsetof(struct pt_regs, ax),
+ offsetof(struct pt_regs, dx),
+ offsetof(struct pt_regs, cx),
+ offsetof(struct pt_regs, bx),
+ offsetof(struct pt_regs, si),
+ offsetof(struct pt_regs, di),
+ offsetof(struct pt_regs, bp),
+ offsetof(struct pt_regs, sp),
+ offsetof(struct pt_regs, r8),
+ offsetof(struct pt_regs, r9),
+ offsetof(struct pt_regs, r10),
+ offsetof(struct pt_regs, r11),
+ offsetof(struct pt_regs, r12),
+ offsetof(struct pt_regs, r13),
+ offsetof(struct pt_regs, r14),
+ offsetof(struct pt_regs, r15),
+ offsetof(struct pt_regs, ip),
+};
+
+/**
+ * regs_get_dwarf_register() - get register value from its DWARF number
+ * @regs: pt_regs from which register value is gotten.
+ * @regno: DWARF register number.
+ * @value: the register value is stored here.
+ *
+ * regs_get_dwarf_register() stores value of the register specified by its
+ * DWARF register number @regno in @value and returns 0. If there's no
+ * value for the register in @regs, this returns -EOPNOTSUPP;
+ */
+int regs_get_dwarf_register(struct pt_regs *regs, unsigned int regno,
+ unsigned long *value)
+{
+ if (regno >= ARRAY_SIZE(dwarf_regs))
+ return -EOPNOTSUPP;
+ *value = regs_get_register(regs, dwarf_regs[regno]);
+ return 0;
+}
+#endif
+
/*
* does not yet catch signals sent when the child dies.
* in exit.c or in signal.c.
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 2839d5c8eaa0..04f6e0fa7447 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -398,6 +398,16 @@ static inline void user_single_step_report(struct pt_regs *regs)
#define exception_ip(x) instruction_pointer(x)
#endif
+#ifndef regs_get_dwarf_register
+/* Get value of the register specified by DWARF register number. */
+static inline int regs_get_dwarf_register(struct pt_regs *regs,
+ unsigned int regno,
+ unsigned long *value)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
extern int task_current_syscall(struct task_struct *target, struct syscall_info *info);
extern void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
` (28 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The kprobe hash table has 64 buckets, so with 20000 probes registered
each get_kprobe() call walks a chain of more than 300 entries on
average.
On x86 the registration path calls get_kprobe() for each byte or
decoded instruction it has to check around the new probe, and most of
these lookups miss and walk the whole chain. It is also called on
every probe hit.
This matters for attaching to inlined functions, where a few functions
specified by name can end up with thousands of kprobes.
Add CONFIG_KPROBE_HASH_BITS with range 6-16. The default stays at 6
and is raised to 10 (1024 buckets, 8KB on 64-bit) with
CONFIG_DEBUG_INFO_BTF_INLINE.
Time to register the probes with the kprobe_many_example sample
module [1] in a KVM guest, mean of 5 runs:
bits buckets table memory 20000 probes 50000 probes
6 64 512 B 4.71 s 29.99 s
8 256 2 KB 2.05 s 9.90 s
10 1024 8 KB 1.39 s 4.63 s
12 4096 32 KB 1.30 s 3.64 s
14 16384 128 KB 1.28 s 3.41 s
16 65536 512 KB 1.28 s 3.38 s
With 10 bits the registration is 3.4 times faster for 20000 probes
and 6.5 times faster for 50000 probes. Bigger tables help only
with very high numbers of probes.
[1] https://lore.kernel.org/bpf/20261109195827.1091410-1-jolsa@kernel.org/
Suggested-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/Kconfig | 17 +++++++++++++++++
kernel/kprobes.c | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/arch/Kconfig b/arch/Kconfig
index 1163736de1f9..350144df6863 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -141,6 +141,23 @@ config KPROBES
for kernel debugging, non-intrusive instrumentation and testing.
If in doubt, say "N".
+config KPROBE_HASH_BITS
+ int "Kprobe hash table size in bits" if EXPERT
+ depends on KPROBES
+ range 6 16
+ default 10 if DEBUG_INFO_BTF_INLINE
+ default 6
+ help
+ Size of the kprobe hash table as a power of two. The default
+ of 6 (64 buckets) is enough for a small number of probes.
+
+ Attaching to inlined functions can register thousands of
+ kprobes at once, so the default is raised to 10 (1024 buckets,
+ 8KB on 64-bit) when the inline site information is available
+ (DEBUG_INFO_BTF_INLINE).
+
+ If in doubt, keep the default.
+
config JUMP_LABEL
bool "Optimize very unlikely/likely branches"
depends on HAVE_ARCH_JUMP_LABEL
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f14f7ff45961..eba446e8ae37 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -50,7 +50,7 @@
#include <asm/errno.h>
#include <linux/uaccess.h>
-#define KPROBE_HASH_BITS 6
+#define KPROBE_HASH_BITS CONFIG_KPROBE_HASH_BITS
#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
#if !defined(CONFIG_OPTPROBES) || !defined(CONFIG_SYSCTL)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
` (27 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Enabling kprobe puts the breakpoint in place and waits for all the
other CPUs to see it. On x86 that is an IPI to every CPU for each
kprobe, which gets expensive with thousands of kprobes.
Adding enable_kprobes function that enables array of kprobes under
single kprobe_mutex lock, installs their breakpoints without waiting
for the other CPUs and syncs them just once at the end.
To support that adding two arch functions:
arch_arm_kprobe_nosync - installs the breakpoint without the sync
arch_arm_kprobes_sync - syncs all the breakpoints installed so far
The default arch_arm_kprobe_nosync falls back to arch_arm_kprobe and
the default arch_arm_kprobes_sync does nothing, so there's no change
for other architectures. Adding the x86 version.
The ftrace based kprobes are armed through ftrace as before, there's
no difference for them.
If any of the kprobes fails to get enabled, enable_kprobes returns
the error and leaves the kprobes enabled so far as they are, the
caller can find them with kprobe_disabled(). The sync is done also
in this case.
Time to enable disabled kprobes with the kprobe_many_example sample
module [1], enable_kprobe() in a loop against single enable_kprobes()
call, on bare metal AMD Ryzen 7 PRO 8840HS (16 CPUs), median of
6 runs, CONFIG_KPROBE_HASH_BITS=16:
probes enable_kprobe enable_kprobes speedup
1000 12.1 ms 0.36 ms 34x
5000 55.3 ms 1.70 ms 33x
10000 102 ms 3.50 ms 29x
20000 187 ms 7.30 ms 26x
50000 354 ms 21.4 ms 17x
The speedup depends on the kprobe hash table size, because arming
the kprobe does several get_kprobe() lookups. With
CONFIG_KPROBE_HASH_BITS=10 it is 33x for 1000 kprobes, but only
2.7x for 20000 and 1.3x for 50000, where the hash chain walks take
most of the time.
[1] https://lore.kernel.org/bpf/20261109195827.1091410-1-jolsa@kernel.org/
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/x86/kernel/kprobes/core.c | 13 +++++
include/linux/kprobes.h | 7 +++
kernel/kprobes.c | 90 +++++++++++++++++++++++++++++-----
3 files changed, 99 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 34d71907e6d1..02f27ca3db2b 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -793,6 +793,19 @@ void arch_arm_kprobe(struct kprobe *p)
perf_event_text_poke(p->addr, &p->opcode, 1, &int3, 1);
}
+void arch_arm_kprobe_nosync(struct kprobe *p)
+{
+ u8 int3 = INT3_INSN_OPCODE;
+
+ text_poke(p->addr, &int3, 1);
+ perf_event_text_poke(p->addr, &p->opcode, 1, &int3, 1);
+}
+
+void arch_arm_kprobes_sync(void)
+{
+ smp_text_poke_sync_each_cpu();
+}
+
void arch_disarm_kprobe(struct kprobe *p)
{
u8 int3 = INT3_INSN_OPCODE;
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index e6de7ae55bda..e1d30001da98 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -272,6 +272,8 @@ extern struct kretprobe_blackpoint kretprobe_blacklist[];
extern int arch_prepare_kprobe(struct kprobe *p);
extern void arch_arm_kprobe(struct kprobe *p);
+extern void arch_arm_kprobe_nosync(struct kprobe *p);
+extern void arch_arm_kprobes_sync(void);
extern void arch_disarm_kprobe(struct kprobe *p);
extern int arch_init_kprobes(void);
extern void kprobes_inc_nmissed_count(struct kprobe *p);
@@ -423,6 +425,7 @@ void kprobe_free_init_mem(void);
int disable_kprobe(struct kprobe *kp);
int enable_kprobe(struct kprobe *kp);
+int enable_kprobes(struct kprobe **kps, int num);
void dump_kprobe(struct kprobe *kp);
@@ -498,6 +501,10 @@ static inline int disable_kprobe(struct kprobe *kp)
{
return -EOPNOTSUPP;
}
+static inline int enable_kprobes(struct kprobe **kps, int num)
+{
+ return -EOPNOTSUPP;
+}
static inline int enable_kprobe(struct kprobe *kp)
{
return -EOPNOTSUPP;
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index eba446e8ae37..836924e99a76 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -417,6 +417,20 @@ static inline void copy_kprobe(struct kprobe *ap, struct kprobe *p)
memcpy(&p->ainsn, &ap->ainsn, sizeof(struct arch_specific_insn));
}
+/*
+ * Architectures can put the breakpoint without waiting for other CPUs
+ * in arch_arm_kprobe_nosync() and do the wait for all the breakpoints
+ * at once in arch_arm_kprobes_sync().
+ */
+void __weak arch_arm_kprobe_nosync(struct kprobe *p)
+{
+ arch_arm_kprobe(p);
+}
+
+void __weak arch_arm_kprobes_sync(void)
+{
+}
+
#ifdef CONFIG_OPTPROBES
/* NOTE: This is protected by 'kprobe_mutex'. */
static bool kprobes_allow_optimization;
@@ -1284,7 +1298,7 @@ static bool kprobe_queued_unopt(struct kprobe *p)
}
/* Put a breakpoint for a probe. */
-static void __arm_kprobe(struct kprobe *p)
+static void __arm_kprobe(struct kprobe *p, bool sync)
{
struct kprobe *_p;
@@ -1296,8 +1310,12 @@ static void __arm_kprobe(struct kprobe *p)
/* Fallback to unoptimized kprobe */
unoptimize_kprobe(_p, true);
- if (!kprobe_queued_unopt(p))
- arch_arm_kprobe(p);
+ if (!kprobe_queued_unopt(p)) {
+ if (sync)
+ arch_arm_kprobe(p);
+ else
+ arch_arm_kprobe_nosync(p);
+ }
optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */
if (unlikely(kprobe_queued_unopt(p)))
unoptimize_kprobe(p, true);
@@ -1354,7 +1372,8 @@ static void __init init_optprobe(void)
#define kill_optimized_kprobe(p) do {} while (0)
#define prepare_optimized_kprobe(p) do {} while (0)
#define try_to_optimize_kprobe(p) do {} while (0)
-#define __arm_kprobe(p) arch_arm_kprobe(p)
+#define __arm_kprobe(p, sync) \
+ ((sync) ? arch_arm_kprobe(p) : arch_arm_kprobe_nosync(p))
#define __disarm_kprobe(p, o) arch_disarm_kprobe(p)
#define kprobe_disarmed(p) kprobe_disabled(p)
#define wait_for_kprobe_optimizer_locked() \
@@ -1499,17 +1518,27 @@ static int prepare_kprobe(struct kprobe *p)
return arch_prepare_kprobe(p);
}
-static int arm_kprobe(struct kprobe *kp)
+/*
+ * Without 'sync' the breakpoint is installed without waiting for other
+ * CPUs and the caller needs to call arch_arm_kprobes_sync() afterwards.
+ * It makes no difference for ftrace based kprobes.
+ */
+static int arm_kprobe_sync(struct kprobe *kp, bool sync)
{
if (unlikely(kprobe_ftrace(kp)))
return arm_kprobe_ftrace(kp);
guard(cpus_read_lock)();
guard(mutex)(&text_mutex);
- __arm_kprobe(kp);
+ __arm_kprobe(kp, sync);
return 0;
}
+static int arm_kprobe(struct kprobe *kp)
+{
+ return arm_kprobe_sync(kp, true);
+}
+
static int disarm_kprobe(struct kprobe *kp, bool reopt)
{
if (unlikely(kprobe_ftrace(kp)))
@@ -2772,14 +2801,17 @@ int disable_kprobe(struct kprobe *kp)
}
EXPORT_SYMBOL_GPL(disable_kprobe);
-/* Enable one kprobe */
-int enable_kprobe(struct kprobe *kp)
+/*
+ * Enable 'kp' and arm its aggregator kprobe 'p' if needed.
+ *
+ * Without 'sync' the caller is responsible for calling
+ * arch_arm_kprobes_sync() when it's done with all the kprobes.
+ */
+static int __enable_kprobe(struct kprobe *kp, bool sync)
{
int ret = 0;
struct kprobe *p;
- guard(mutex)(&kprobe_mutex);
-
/* Check whether specified probe is valid. */
p = __get_valid_kprobe(kp);
if (unlikely(p == NULL))
@@ -2794,7 +2826,7 @@ int enable_kprobe(struct kprobe *kp)
if (!kprobes_all_disarmed && kprobe_disabled(p)) {
p->flags &= ~KPROBE_FLAG_DISABLED;
- ret = arm_kprobe(p);
+ ret = arm_kprobe_sync(p, sync);
if (ret) {
p->flags |= KPROBE_FLAG_DISABLED;
if (p != kp)
@@ -2803,8 +2835,44 @@ int enable_kprobe(struct kprobe *kp)
}
return ret;
}
+
+/* Enable one kprobe */
+int enable_kprobe(struct kprobe *kp)
+{
+ guard(mutex)(&kprobe_mutex);
+
+ return __enable_kprobe(kp, true);
+}
EXPORT_SYMBOL_GPL(enable_kprobe);
+/*
+ * Enable @num kprobes in @kps. The breakpoints are installed for all
+ * of them first and other CPUs are synced just once at the end, instead
+ * of once per kprobe as enable_kprobe() does.
+ *
+ * On error some of the kprobes might be already enabled.
+ */
+int enable_kprobes(struct kprobe **kps, int num)
+{
+ int i, ret = 0;
+
+ if (num <= 0)
+ return -EINVAL;
+
+ guard(mutex)(&kprobe_mutex);
+
+ for (i = 0; i < num; i++) {
+ ret = __enable_kprobe(kps[i], false);
+ if (ret)
+ break;
+ }
+
+ /* Sync also on error, some breakpoints might be already installed. */
+ arch_arm_kprobes_sync();
+ return ret;
+}
+EXPORT_SYMBOL_GPL(enable_kprobes);
+
/* Caller must NOT call this in usual path. This is only for critical case */
void dump_kprobe(struct kprobe *kp)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (2 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
` (26 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add module_sect_addr() that returns the runtime address of the loaded
module section with given name, or 0 if there's no such section or
the section attributes are not available (they need CONFIG_KALLSYMS
and CONFIG_SYSFS).
The caller needs to make sure the module is live and hold a reference
to it, which keeps the section attributes stable, so no other locking
is needed.
It will be used to resolve addresses of inlined instances in modules,
which are stored in inline BTF as section relative offsets.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/module.h | 9 +++++++++
kernel/module/sysfs.c | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/linux/module.h b/include/linux/module.h
index 76f4f3596477..e2209a8953f9 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -952,6 +952,15 @@ static inline bool module_sig_ok(struct module *module)
}
#endif /* CONFIG_MODULE_SIG */
+#if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
+unsigned long module_sect_addr(const struct module *mod, const char *name);
+#else
+static inline unsigned long module_sect_addr(const struct module *mod, const char *name)
+{
+ return 0;
+}
+#endif
+
#if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS)
int module_kallsyms_on_each_symbol(const char *modname,
int (*fn)(void *, const char *, unsigned long),
diff --git a/kernel/module/sysfs.c b/kernel/module/sysfs.c
index 01c65d608873..f6a08fad503e 100644
--- a/kernel/module/sysfs.c
+++ b/kernel/module/sysfs.c
@@ -133,6 +133,26 @@ static void remove_sect_attrs(struct module *mod)
}
}
+/*
+ * Returns address of the loaded section @name or 0 if there's no such
+ * section. The caller needs to make sure the module is live
+ * (MODULE_STATE_LIVE) and hold a reference to it, which keeps
+ * mod->sect_attrs stable; no other locking is needed.
+ */
+unsigned long module_sect_addr(const struct module *mod, const char *name)
+{
+ const struct bin_attribute *const *bin_attr;
+
+ if (!mod->sect_attrs)
+ return 0;
+
+ for (bin_attr = mod->sect_attrs->grp.bin_attrs; *bin_attr; bin_attr++) {
+ if (!strcmp((*bin_attr)->attr.name, name))
+ return (unsigned long)(*bin_attr)->private;
+ }
+ return 0;
+}
+
/*
* /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
*/
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (3 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
` (25 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add bpf_get_btf_vmlinux_inline() that returns parsed vmlinux inline
BTF (vmlinux.inline), the split BTF on top of vmlinux BTF that
describes inline sites of kernel functions.
The inline BTF is parsed on first use and stays cached, so there's no
cost unless something asks for it. The data comes from the BTF inline
section when CONFIG_DEBUG_INFO_BTF_INLINE is built in, otherwise from
the lazily loaded data behind the vmlinux.inline sysfs attribute,
exporting btf_sysfs_lazy_data() for that.
Make btf_parse_split() available also for CONFIG_DEBUG_INFO_BTF_INLINE
and keep btf_is_module() false for vmlinux.inline BTF.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 1 +
include/linux/btf.h | 6 +++
kernel/bpf/btf.c | 93 +++++++++++++++++++++++++++++++++++++++++-
kernel/bpf/sysfs_btf.c | 2 +-
4 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 4f9c2bf64643..94560bd9dccc 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3346,6 +3346,7 @@ static inline s32 bpf_call_args_imm(s16 idx)
#endif
struct btf *bpf_get_btf_vmlinux(void);
+struct btf *bpf_get_btf_vmlinux_inline(void);
/* Map specifics */
struct xdp_frame;
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 7bb3cc973c1f..9007da300ca0 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -646,6 +646,7 @@ int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx
struct bin_attribute *sysfs_btf_add(const char *name, void *data, size_t data_size,
bool mmap, const char *lazy_module_name);
bool sysfs_btf_update(struct bin_attribute *attr, void *data);
+void *btf_sysfs_lazy_data(const struct bin_attribute *attr);
void sysfs_btf_remove(struct bin_attribute *attr);
#else
static inline struct bin_attribute *
@@ -660,6 +661,11 @@ static inline bool sysfs_btf_update(struct bin_attribute *attr, void *data)
return false;
}
+static inline void *btf_sysfs_lazy_data(const struct bin_attribute *attr)
+{
+ return NULL;
+}
+
static inline void sysfs_btf_remove(struct bin_attribute *attr)
{
}
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 0e70ae5282ad..72eba56e9a5e 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7008,7 +7008,7 @@ __u32 btf_relocate_id(const struct btf *btf, __u32 id)
return btf->base_id_map[id];
}
-#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) || IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
static struct btf *btf_parse_split(struct btf_verifier_env *env,
const char *name, const void *data,
@@ -7059,6 +7059,9 @@ static struct btf *btf_parse_split(struct btf_verifier_env *env,
return ERR_PTR(err);
}
+#endif /* CONFIG_DEBUG_INFO_BTF_MODULES || CONFIG_DEBUG_INFO_BTF_INLINE */
+
+#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
static int btf_rebase_inline(struct btf *inline_btf,
const struct btf *module_btf,
const u32 *module_id_map,
@@ -9393,7 +9396,8 @@ bool btf_is_kernel(const struct btf *btf)
bool btf_is_module(const struct btf *btf)
{
- return btf->kernel_btf && strcmp(btf->name, "vmlinux") != 0;
+ return btf->kernel_btf && strcmp(btf->name, "vmlinux") != 0 &&
+ strcmp(btf->name, "vmlinux.inline") != 0;
}
enum {
@@ -9668,6 +9672,91 @@ static int __init btf_module_init(void)
fs_initcall(btf_module_init);
#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+static struct btf *btf_vmlinux_inline;
+static DEFINE_MUTEX(btf_vmlinux_inline_lock);
+
+#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)
+extern char __start_BTF_inline[];
+extern char __stop_BTF_inline[];
+
+static const void *btf_vmlinux_inline_data(u32 *size)
+{
+ *size = __stop_BTF_inline - __start_BTF_inline;
+ return *size ? __start_BTF_inline : NULL;
+}
+#else
+static const void *btf_vmlinux_inline_data(u32 *size)
+{
+ const void *data;
+
+ if (!vmlinux_inline_attr)
+ return ERR_PTR(-ENODEV);
+ data = btf_sysfs_lazy_data(vmlinux_inline_attr);
+ if (!data)
+ return ERR_PTR(-ENODEV);
+ *size = vmlinux_inline_attr->size;
+ return data;
+}
+#endif
+
+static struct btf *btf_parse_vmlinux_inline(const void *data, u32 data_size)
+{
+ struct btf_verifier_env *env;
+ struct btf *vmlinux_btf, *btf;
+
+ vmlinux_btf = bpf_get_btf_vmlinux();
+ if (IS_ERR(vmlinux_btf))
+ return vmlinux_btf;
+ if (!vmlinux_btf)
+ return ERR_PTR(-EINVAL);
+
+ env = kzalloc_obj(*env, GFP_KERNEL | __GFP_NOWARN);
+ if (!env)
+ return ERR_PTR(-ENOMEM);
+
+ env->log.level = BPF_LOG_KERNEL;
+ btf = btf_parse_split(env, "vmlinux.inline", data,
+ data_size, vmlinux_btf);
+ btf_verifier_env_free(env);
+ if (!IS_ERR(btf))
+ refcount_set(&btf->refcnt, 1);
+ return btf;
+}
+
+struct btf *bpf_get_btf_vmlinux_inline(void)
+{
+ /* Pairs with the release publication after a successful parse below. */
+ struct btf *btf = smp_load_acquire(&btf_vmlinux_inline);
+ const void *data;
+ u32 data_size;
+
+ if (btf)
+ return btf;
+
+ data = btf_vmlinux_inline_data(&data_size);
+ if (IS_ERR_OR_NULL(data))
+ return ERR_CAST(data);
+
+ mutex_lock(&btf_vmlinux_inline_lock);
+ btf = btf_vmlinux_inline;
+ if (!btf) {
+ btf = btf_parse_vmlinux_inline(data, data_size);
+ if (!IS_ERR(btf)) {
+ /* Pairs with the acquire load on the cached path above. */
+ smp_store_release(&btf_vmlinux_inline, btf);
+ }
+ }
+ mutex_unlock(&btf_vmlinux_inline_lock);
+ return btf;
+}
+#else
+struct btf *bpf_get_btf_vmlinux_inline(void)
+{
+ return NULL;
+}
+#endif /* IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE) */
+
struct module *btf_try_get_module(const struct btf *btf)
{
struct module *res = NULL;
diff --git a/kernel/bpf/sysfs_btf.c b/kernel/bpf/sysfs_btf.c
index 556fe92c3649..b2ebdf60cfda 100644
--- a/kernel/bpf/sysfs_btf.c
+++ b/kernel/bpf/sysfs_btf.c
@@ -74,7 +74,7 @@ struct btf_sysfs_entry {
char *module_name;
};
-static void *btf_sysfs_lazy_data(const struct bin_attribute *attr)
+void *btf_sysfs_lazy_data(const struct bin_attribute *attr)
{
struct btf_sysfs_entry *entry = container_of(attr, struct btf_sysfs_entry, attr);
void *data;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (4 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
` (24 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The error handling after the link is primed repeats the cleanup in
each failing branch. Use goto labels instead, so it's easier to add
another step that can fail in following changes.
There's no functional change intended.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/trace/bpf_trace.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 7b9bd6f560a5..c546e1d41be0 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2943,21 +2943,22 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
}
err = get_modules_for_addrs(&link->mods, addrs, cnt);
- if (err < 0) {
- bpf_link_cleanup(&link_primer);
- return err;
- }
+ if (err < 0)
+ goto error_cleanup;
link->mods_cnt = err;
err = register_fprobe_ips(&link->fp, addrs, cnt);
- if (err) {
- kprobe_multi_put_modules(link->mods, link->mods_cnt);
- bpf_link_cleanup(&link_primer);
- return err;
- }
+ if (err)
+ goto error_modules;
return bpf_link_settle(&link_primer);
+error_modules:
+ kprobe_multi_put_modules(link->mods, link->mods_cnt);
+error_cleanup:
+ bpf_link_cleanup(&link_primer);
+ return err;
+
error:
kfree(link);
kvfree(addrs);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (5 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
` (23 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The kprobe multi link attaches functions through fprobe, so it gets
only to the out-of-line copy of the function. The inlined instances
are not traced, and a function that is inlined in all its callers
can't be attached at all.
Adding BPF_F_KPROBE_MULTI_INLINE flag that makes the link attach also
the inlined instances of the functions provided in the syms array.
The instances are resolved by function name from the vmlinux inline
BTF (inline.text LOCSEC). Each of them gets its own kprobe and the
kprobes are enabled all at once with enable_kprobes. Instances of two
functions can share the same address, the program is executed for
both.
Each function needs to have either entry or at least one inlined
instance, otherwise the attach fails with -ESRCH.
Instances that kprobes refuse (jump label or static call site, bug
table entry, NOKPROBE_SYMBOL or noinstr caller) are skipped, and so
are instances inlined in functions without ftrace location (notrace),
which are likely not safe to probe. With all the attachable functions
in vmlinux that's 748 instances out of 20688. The attach fails if
a function has no entry and all its instances are skipped.
The program attached to inlined instance gets pt_regs of the probed
instruction, so the function arguments are not available in the
argument registers. The bpf_get_func_ip helper returns the address
of the inlined instance.
The flag can't be combined with BPF_F_KPROBE_MULTI_RETURN flag, session
program, the addrs array or program that uses bpf_override_return.
The number of inlined instances is limited to MAX_KPROBE_MULTI_CNT,
the attach fails with -E2BIG above that.
The support is x86_64 only for now, selected with the new
HAVE_KPROBE_MULTI_INLINE config option. The attach with the flag fails
with -EOPNOTSUPP on other architectures, on kernel without inline BTF
and without CONFIG_KPROBES.
The support for cookies and for inlined instances in modules is added
in following changes.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
arch/Kconfig | 6 +
arch/x86/Kconfig | 1 +
include/uapi/linux/bpf.h | 8 +-
kernel/trace/bpf_trace.c | 379 +++++++++++++++++++++++++++++++--
tools/include/uapi/linux/bpf.h | 8 +-
5 files changed, 384 insertions(+), 18 deletions(-)
diff --git a/arch/Kconfig b/arch/Kconfig
index 350144df6863..1824719263db 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -308,6 +308,12 @@ config HAVE_OPTPROBES
config HAVE_KPROBES_ON_FTRACE
bool
+config HAVE_KPROBE_MULTI_INLINE
+ bool
+ help
+ The architecture supports kprobe multi link attach to inlined
+ functions (BPF_F_KPROBE_MULTI_INLINE).
+
config ARCH_CORRECT_STACKTRACE_ON_KRETPROBE
bool
help
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 23889c2261e4..992756c0672d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -262,6 +262,7 @@ config X86
select HAVE_KERNEL_ZSTD
select HAVE_KPROBES
select HAVE_KPROBES_ON_FTRACE
+ select HAVE_KPROBE_MULTI_INLINE if X86_64
select HAVE_FUNCTION_ERROR_INJECTION
select HAVE_KRETPROBES
select HAVE_RETHOOK
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 28904c6f0787..96e6a629f0c0 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1365,10 +1365,14 @@ enum bpf_perf_event_type {
#define BPF_F_TEST_REG_INVARIANTS (1U << 7)
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
- * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
+ * BPF_TRACE_KPROBE_MULTI attach type.
*/
enum {
- BPF_F_KPROBE_MULTI_RETURN = (1U << 0)
+ /* Create return probe. */
+ BPF_F_KPROBE_MULTI_RETURN = (1U << 0),
+
+ /* Attach also to inlined function instances, skip those that fail. */
+ BPF_F_KPROBE_MULTI_INLINE = (1U << 1),
};
/* link_create.uprobe_multi.flags used in LINK_CREATE command for
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index c546e1d41be0..89388a140b48 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -30,6 +30,7 @@
#include <uapi/linux/bpf.h>
#include <uapi/linux/btf.h>
+#include <asm/sections.h>
#include <asm/tlb.h>
#include "trace_probe.h"
@@ -2365,6 +2366,27 @@ struct bpf_session_run_ctx {
};
#ifdef CONFIG_FPROBE
+struct bpf_kprobe_multi_link;
+
+struct inline_site {
+ struct kprobe kp;
+ struct bpf_kprobe_multi_link *link;
+ u32 sym_idx;
+ bool has_entry;
+ bool traceable;
+};
+
+/*
+ * @sites has @sites_cnt inlined instances found for the link, the ones
+ * that got registered are stored in @kps (@cnt), the rest was skipped.
+ */
+struct inline_sites {
+ struct inline_site *sites;
+ struct kprobe **kps;
+ u32 sites_cnt;
+ u32 cnt;
+};
+
struct bpf_kprobe_multi_link {
struct bpf_link link;
struct fprobe fp;
@@ -2373,6 +2395,7 @@ struct bpf_kprobe_multi_link {
u32 cnt;
u32 mods_cnt;
struct module **mods;
+ struct inline_sites inlines;
};
struct bpf_kprobe_multi_run_ctx {
@@ -2463,7 +2486,9 @@ static void bpf_kprobe_multi_link_release(struct bpf_link *link)
kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
/* Don't wait for RCU GP here. */
- unregister_fprobe_async(&kmulti_link->fp);
+ if (kmulti_link->cnt)
+ unregister_fprobe_async(&kmulti_link->fp);
+ unregister_kprobes(kmulti_link->inlines.kps, kmulti_link->inlines.cnt);
kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt);
}
@@ -2472,6 +2497,8 @@ static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link)
struct bpf_kprobe_multi_link *kmulti_link;
kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
+ kvfree(kmulti_link->inlines.sites);
+ kvfree(kmulti_link->inlines.kps);
kvfree(kmulti_link->addrs);
kvfree(kmulti_link->cookies);
kfree(kmulti_link->mods);
@@ -2626,7 +2653,7 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
static __always_inline int
kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
unsigned long entry_ip, struct ftrace_regs *fregs,
- bool is_return, void *data)
+ struct pt_regs *regs, bool is_return, void *data)
{
struct bpf_kprobe_multi_run_ctx run_ctx = {
.session_ctx = {
@@ -2637,13 +2664,12 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
.entry_ip = entry_ip,
};
struct bpf_run_ctx *old_run_ctx;
- struct pt_regs *regs;
int err;
/*
- * graph tracer framework ensures we won't migrate, so there is no need
- * to use migrate_disable for bpf_prog_run again. The check here just for
- * __this_cpu_inc_return.
+ * Both fprobe and kprobe handlers ensure we won't migrate, so there
+ * is no need to use migrate_disable for bpf_prog_run again. The check
+ * here just for __this_cpu_inc_return.
*/
cant_sleep();
@@ -2654,11 +2680,14 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
}
rcu_read_lock();
- regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
+ /* The caller provides either ftrace_regs or pt_regs. */
+ if (fregs)
+ regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
err = bpf_prog_run(link->link.prog, regs);
bpf_reset_run_ctx(old_run_ctx);
- ftrace_partial_regs_update(fregs, bpf_kprobe_multi_pt_regs_ptr());
+ if (fregs)
+ ftrace_partial_regs_update(fregs, bpf_kprobe_multi_pt_regs_ptr());
rcu_read_unlock();
out:
@@ -2676,7 +2705,7 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip,
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
err = kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip),
- fregs, false, data);
+ fregs, NULL, false, data);
return is_kprobe_session(link->link.prog) ? err : 0;
}
@@ -2689,9 +2718,21 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip,
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip),
- fregs, true, data);
+ fregs, NULL, true, data);
}
+static int
+kprobe_multi_inline_handler(struct kprobe *kp, struct pt_regs *regs)
+{
+ struct inline_site *site;
+
+ site = container_of(kp, struct inline_site, kp);
+ kprobe_multi_link_prog_run(site->link, (unsigned long)kp->addr,
+ NULL, regs, false, NULL);
+ return 0;
+}
+NOKPROBE_SYMBOL(kprobe_multi_inline_handler);
+
static int symbols_cmp_r(const void *a, const void *b, const void *priv)
{
const char **str_a = (const char **) a;
@@ -2700,6 +2741,11 @@ static int symbols_cmp_r(const void *a, const void *b, const void *priv)
return strcmp(*str_a, *str_b);
}
+static int symbols_cmp(const void *a, const void *b)
+{
+ return symbols_cmp_r(a, b, NULL);
+}
+
struct multi_symbols_sort {
const char **funcs;
u64 *cookies;
@@ -2809,8 +2855,262 @@ static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt)
return 0;
}
+static int inline_sym_idx(const struct btf *btf, const struct btf_loc *loc,
+ const char **syms, u32 cnt)
+{
+ const struct btf_type *t = btf_type_by_id(btf, loc->func);
+ const char *name, **sym;
+
+ if (!t)
+ return -1;
+ name = btf_name_by_offset(btf, t->name_off);
+ if (!name)
+ return -1;
+ sym = bsearch(&name, syms, cnt, sizeof(*syms), symbols_cmp);
+ return sym ? sym - syms : -1;
+}
+
+static int inlines_cmp(const void *a, const void *b)
+{
+ const struct inline_site *site_a = a, *site_b = b;
+
+ if (site_a->sym_idx != site_b->sym_idx)
+ return site_a->sym_idx < site_b->sym_idx ? -1 : 1;
+ if (site_a->kp.addr != site_b->kp.addr)
+ return site_a->kp.addr < site_b->kp.addr ? -1 : 1;
+ return 0;
+}
+
+struct inline_lookup {
+ /* Input: functions to look for, @syms is alphabetically sorted. */
+ const char **syms;
+ unsigned long *addrs;
+ u32 syms_cnt;
+
+ /* Output */
+ struct inline_sites *inlines;
+ u32 addrs_cnt;
+
+ /* Lookup state */
+ struct inline_site *sites;
+ u32 cnt;
+ u32 cap;
+};
+
+static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u32 sym_idx)
+{
+ struct inline_site *sites;
+ u32 cap;
+
+ if (lookup->cnt == MAX_KPROBE_MULTI_CNT)
+ return -E2BIG;
+
+ if (lookup->cnt == lookup->cap) {
+ cap = max(16, lookup->cap * 2);
+ sites = kvrealloc(lookup->sites, array_size(cap, sizeof(*sites)), GFP_KERNEL);
+ if (!sites)
+ return -ENOMEM;
+ lookup->sites = sites;
+ lookup->cap = cap;
+ }
+
+ lookup->sites[lookup->cnt++] = (struct inline_site) {
+ .kp.addr = (kprobe_opcode_t *)addr,
+ .sym_idx = sym_idx,
+ };
+ return 0;
+}
+
+/*
+ * Add inlined instances of the functions we look for from @locsec,
+ * the offsets of its locations are relative to @base address.
+ */
+static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *btf,
+ const struct btf_type *locsec, unsigned long base)
+{
+ struct btf_loc *loc;
+ int idx, err;
+ u32 i;
+
+ for_each_loc(i, locsec, loc) {
+ idx = inline_sym_idx(btf, loc, lookup->syms, lookup->syms_cnt);
+ if (idx < 0)
+ continue;
+ err = inline_lookup_add(lookup, base + loc->offset, idx);
+ if (err)
+ return err;
+ }
+ return 0;
+}
+
+/*
+ * Sort instances by symbol name and address, so instances of each
+ * symbol are next to each other, and get rid of duplicates.
+ */
+static void inline_lookup_sort(struct inline_lookup *lookup)
+{
+ struct inline_site *sites = lookup->sites;
+ u32 i, j;
+
+ sort(sites, lookup->cnt, sizeof(*sites), inlines_cmp, NULL);
+
+ for (i = 0, j = 0; i < lookup->cnt; i++) {
+ if (i && !inlines_cmp(&sites[i], &sites[i - 1]))
+ continue;
+ if (i != j)
+ sites[j] = sites[i];
+ j++;
+ }
+ lookup->cnt = j;
+}
+
+/*
+ * The inlined instance is attached inside the function it's inlined in,
+ * make sure that function is traceable (not notrace) and safe to probe.
+ */
+static bool inline_site_traceable(unsigned long addr)
+{
+ unsigned long size, offset;
+
+ if (!kallsyms_lookup_size_offset(addr, &size, &offset))
+ return false;
+ addr -= offset;
+ return ftrace_location_range(addr, addr + size - 1);
+}
+
+/*
+ * Find inlined instances for functions in @lookup->syms. Each function
+ * must have an entry address or at least one inlined instance, functions
+ * without an entry address are dropped from @lookup->addrs.
+ */
+static int inline_lookup_symbols(struct inline_lookup *lookup)
+{
+ struct inline_sites *inlines = lookup->inlines;
+ unsigned long *addrs = lookup->addrs;
+ u32 i, j, k, n, cnt = lookup->syms_cnt;
+ struct inline_site *sites;
+ struct btf *btf;
+ int err;
+ s32 id;
+
+ btf = bpf_get_btf_vmlinux_inline();
+ if (IS_ERR_OR_NULL(btf))
+ return -EOPNOTSUPP;
+
+ /* The offsets of inline.text locations are relative to .text section. */
+ id = btf_find_by_name_kind(btf, "inline.text", BTF_KIND_LOCSEC);
+ if (id < 0)
+ return -EOPNOTSUPP;
+
+ err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id), (unsigned long)_stext);
+ if (err)
+ goto error;
+
+ inline_lookup_sort(lookup);
+
+ sites = lookup->sites;
+ n = lookup->cnt;
+
+ for (i = 0; i < n; i++) {
+ sites[i].kp.pre_handler = kprobe_multi_inline_handler;
+ /* Registered disabled and enabled all at once. */
+ sites[i].kp.flags = KPROBE_FLAG_DISABLED;
+ sites[i].has_entry = !!addrs[sites[i].sym_idx];
+ sites[i].traceable = inline_site_traceable((unsigned long)sites[i].kp.addr);
+ }
+
+ /*
+ * Each symbol needs to have either entry or inlined instance,
+ * keep only symbols with entry in @addrs array.
+ * The instances are sorted by symbol name, so we walk them together.
+ */
+ for (i = 0, j = 0, k = 0; i < cnt; i++) {
+ while (k < n && sites[k].sym_idx < i)
+ k++;
+ if (!addrs[i]) {
+ if (k < n && sites[k].sym_idx == i)
+ continue;
+ err = -ESRCH;
+ goto error;
+ }
+ addrs[j] = addrs[i];
+ j++;
+ }
+
+ inlines->sites = sites;
+ inlines->sites_cnt = n;
+ lookup->addrs_cnt = j;
+ return 0;
+
+error:
+ kvfree(lookup->sites);
+ return err;
+}
+
+/*
+ * Register inlined instances of the @link and skip the ones that fail.
+ * Fail if function has no entry and none of its instances registered.
+ */
+static int inline_sites_register(struct bpf_kprobe_multi_link *link)
+{
+ struct inline_sites *inlines = &link->inlines;
+ struct inline_site *site, *first = NULL;
+ int err, first_err = 0;
+ bool attached = false;
+ u32 i, cnt = 0;
+
+ inlines->kps = kvmalloc_array(inlines->sites_cnt, sizeof(*inlines->kps), GFP_KERNEL);
+ if (!inlines->kps)
+ return -ENOMEM;
+
+ for (i = 0; i < inlines->sites_cnt; i++) {
+ site = &inlines->sites[i];
+ site->link = link;
+
+ /* First inlined instance of the function. */
+ if (!i || site->sym_idx != first->sym_idx) {
+ first = site;
+ first_err = 0;
+ attached = site->has_entry;
+ }
+
+ err = site->traceable ? register_kprobe(&site->kp) : -EINVAL;
+ if (err == -ENOMEM)
+ goto error;
+ if (err) {
+ first_err = first_err ?: err;
+ } else {
+ inlines->kps[cnt++] = &site->kp;
+ attached = true;
+ }
+
+ /* Last inlined instance of the function. */
+ if (i + 1 < inlines->sites_cnt && site[1].sym_idx == site->sym_idx)
+ continue;
+ if (!attached) {
+ err = first_err;
+ goto error;
+ }
+ }
+
+ /* Arm all the registered instances with single sync. */
+ if (cnt) {
+ err = enable_kprobes(inlines->kps, cnt);
+ if (err)
+ goto error;
+ }
+
+ inlines->cnt = cnt;
+ return 0;
+
+error:
+ unregister_kprobes(inlines->kps, cnt);
+ return err;
+}
+
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
{
+ struct inline_sites inlines = {};
struct bpf_kprobe_multi_link *link = NULL;
struct bpf_link_primer link_primer;
void __user *ucookies;
@@ -2840,7 +3140,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
return -EINVAL;
flags = attr->link_create.kprobe_multi.flags;
- if (flags & ~BPF_F_KPROBE_MULTI_RETURN)
+ if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE))
return -EINVAL;
uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs);
@@ -2848,6 +3148,24 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
if (!!uaddrs == !!usyms)
return -EINVAL;
+ if (flags & BPF_F_KPROBE_MULTI_INLINE) {
+ /*
+ * Inlined instances are resolved from function names and
+ * have just entry probe, so there's no return probe, session
+ * or override support.
+ */
+ if (flags & BPF_F_KPROBE_MULTI_RETURN)
+ return -EINVAL;
+ if (is_kprobe_session(prog) || prog->kprobe_override)
+ return -EINVAL;
+ if (uaddrs)
+ return -EINVAL;
+ if (!IS_ENABLED(CONFIG_KPROBES))
+ return -EOPNOTSUPP;
+ if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE))
+ return -EOPNOTSUPP;
+ }
+
cnt = attr->link_create.kprobe_multi.cnt;
if (!cnt)
return -EINVAL;
@@ -2894,6 +3212,26 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
symbols_swap_r, &data);
err = ftrace_lookup_symbols(us.syms, cnt, addrs);
+
+ /*
+ * With inline flag it's ok if the function is not found,
+ * as long as it has inlined instance. Unresolved functions
+ * have zero in addrs.
+ */
+ if ((flags & BPF_F_KPROBE_MULTI_INLINE) && (!err || err == -ESRCH)) {
+ struct inline_lookup lookup = {
+ .inlines = &inlines,
+ .syms = us.syms,
+ .syms_cnt = cnt,
+ .addrs = addrs,
+ };
+
+ err = inline_lookup_symbols(&lookup);
+ /* The cnt is changed to number of functions with entry. */
+ if (!err)
+ cnt = lookup.addrs_cnt;
+ }
+
free_user_syms(&us);
if (err)
goto error;
@@ -2928,6 +3266,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->cookies = cookies;
link->cnt = cnt;
link->link.flags = flags;
+ link->inlines = inlines;
if (cookies) {
/*
@@ -2947,12 +3286,23 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
goto error_cleanup;
link->mods_cnt = err;
- err = register_fprobe_ips(&link->fp, addrs, cnt);
- if (err)
- goto error_modules;
+ if (inlines.sites_cnt) {
+ err = inline_sites_register(link);
+ if (err)
+ goto error_modules;
+ }
+
+ /* All the functions might have just inlined instances. */
+ if (cnt) {
+ err = register_fprobe_ips(&link->fp, addrs, cnt);
+ if (err)
+ goto error_inlines;
+ }
return bpf_link_settle(&link_primer);
+error_inlines:
+ unregister_kprobes(link->inlines.kps, link->inlines.cnt);
error_modules:
kprobe_multi_put_modules(link->mods, link->mods_cnt);
error_cleanup:
@@ -2963,6 +3313,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
kfree(link);
kvfree(addrs);
kvfree(cookies);
+ kvfree(inlines.sites);
return err;
}
#else /* !CONFIG_FPROBE */
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 28904c6f0787..96e6a629f0c0 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1365,10 +1365,14 @@ enum bpf_perf_event_type {
#define BPF_F_TEST_REG_INVARIANTS (1U << 7)
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
- * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
+ * BPF_TRACE_KPROBE_MULTI attach type.
*/
enum {
- BPF_F_KPROBE_MULTI_RETURN = (1U << 0)
+ /* Create return probe. */
+ BPF_F_KPROBE_MULTI_RETURN = (1U << 0),
+
+ /* Attach also to inlined function instances, skip those that fail. */
+ BPF_F_KPROBE_MULTI_INLINE = (1U << 1),
};
/* link_create.uprobe_multi.flags used in LINK_CREATE command for
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (6 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
` (22 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add support to use cookies together with BPF_F_KPROBE_MULTI_INLINE
flag.
Each inlined instance carries the cookie configured for its function
and the instance is passed to the program through the run context,
so bpf_get_attach_cookie returns the cookie of the instance's function.
When instances of several functions share the same address (nested
inlines), the handler of each kprobe is called separately, so each
instance runs the program with its own cookie.
Functions without the entry are removed from the addrs array, so
remove them from the cookies array as well to keep both arrays
in sync.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/trace/bpf_trace.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 89388a140b48..15430d72c2a0 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2371,6 +2371,7 @@ struct bpf_kprobe_multi_link;
struct inline_site {
struct kprobe kp;
struct bpf_kprobe_multi_link *link;
+ u64 cookie;
u32 sym_idx;
bool has_entry;
bool traceable;
@@ -2402,6 +2403,7 @@ struct bpf_kprobe_multi_run_ctx {
struct bpf_session_run_ctx session_ctx;
struct bpf_kprobe_multi_link *link;
unsigned long entry_ip;
+ struct inline_site *site;
};
struct user_syms {
@@ -2629,6 +2631,8 @@ static u64 bpf_kprobe_multi_cookie(struct bpf_run_ctx *ctx)
return 0;
run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx,
session_ctx.run_ctx);
+ if (run_ctx->site)
+ return run_ctx->site->cookie;
link = run_ctx->link;
if (!link->cookies)
return 0;
@@ -2652,6 +2656,7 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
static __always_inline int
kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
+ struct inline_site *site,
unsigned long entry_ip, struct ftrace_regs *fregs,
struct pt_regs *regs, bool is_return, void *data)
{
@@ -2662,6 +2667,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
},
.link = link,
.entry_ip = entry_ip,
+ .site = site,
};
struct bpf_run_ctx *old_run_ctx;
int err;
@@ -2704,7 +2710,7 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip,
int err;
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
- err = kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip),
+ err = kprobe_multi_link_prog_run(link, NULL, ftrace_get_entry_ip(fentry_ip),
fregs, NULL, false, data);
return is_kprobe_session(link->link.prog) ? err : 0;
}
@@ -2717,7 +2723,7 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip,
struct bpf_kprobe_multi_link *link;
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
- kprobe_multi_link_prog_run(link, ftrace_get_entry_ip(fentry_ip),
+ kprobe_multi_link_prog_run(link, NULL, ftrace_get_entry_ip(fentry_ip),
fregs, NULL, true, data);
}
@@ -2727,7 +2733,7 @@ kprobe_multi_inline_handler(struct kprobe *kp, struct pt_regs *regs)
struct inline_site *site;
site = container_of(kp, struct inline_site, kp);
- kprobe_multi_link_prog_run(site->link, (unsigned long)kp->addr,
+ kprobe_multi_link_prog_run(site->link, site, (unsigned long)kp->addr,
NULL, regs, false, NULL);
return 0;
}
@@ -2885,6 +2891,7 @@ struct inline_lookup {
/* Input: functions to look for, @syms is alphabetically sorted. */
const char **syms;
unsigned long *addrs;
+ u64 *cookies;
u32 syms_cnt;
/* Output */
@@ -2988,6 +2995,7 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
struct inline_sites *inlines = lookup->inlines;
unsigned long *addrs = lookup->addrs;
u32 i, j, k, n, cnt = lookup->syms_cnt;
+ u64 *cookies = lookup->cookies;
struct inline_site *sites;
struct btf *btf;
int err;
@@ -3015,13 +3023,14 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
sites[i].kp.pre_handler = kprobe_multi_inline_handler;
/* Registered disabled and enabled all at once. */
sites[i].kp.flags = KPROBE_FLAG_DISABLED;
+ sites[i].cookie = cookies ? cookies[sites[i].sym_idx] : 0;
sites[i].has_entry = !!addrs[sites[i].sym_idx];
sites[i].traceable = inline_site_traceable((unsigned long)sites[i].kp.addr);
}
/*
* Each symbol needs to have either entry or inlined instance,
- * keep only symbols with entry in @addrs array.
+ * keep only symbols with entry in @addrs and @cookies arrays.
* The instances are sorted by symbol name, so we walk them together.
*/
for (i = 0, j = 0, k = 0; i < cnt; i++) {
@@ -3034,6 +3043,8 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
goto error;
}
addrs[j] = addrs[i];
+ if (cookies)
+ cookies[j] = cookies[i];
j++;
}
@@ -3224,6 +3235,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
.syms = us.syms,
.syms_cnt = cnt,
.addrs = addrs,
+ .cookies = cookies,
};
err = inline_lookup_symbols(&lookup);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 09/31] bpf: Add link info support for kprobe multi inlined functions
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (7 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
` (21 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The kprobe multi link info shows just the functions attached with
fprobe, the inlined instances are not visible.
Adding new fields to struct bpf_link_info for the attached inlined
instances:
inline_addrs - addresses of the inlined instances
inline_cookies - cookies of the inlined instances
inline_ids - BTF ids of the inlined functions
inline_count - number of the inlined instances
inline_skipped - number of instances that could not be attached
The BTF id is needed to get the function name, because instances of
two functions can share the same address.
The arrays have the same semantics as the addrs/cookies arrays, with
inline_count as in/out value.
Also adding the missed count of the inlined instances to the missed
value in the link info.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/uapi/linux/bpf.h | 5 +++
kernel/trace/bpf_trace.c | 70 ++++++++++++++++++++++++++++++++--
tools/include/uapi/linux/bpf.h | 5 +++
3 files changed, 76 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 96e6a629f0c0..eee02f62f98b 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -6979,6 +6979,11 @@ struct bpf_link_info {
__u32 flags;
__u64 missed;
__aligned_u64 cookies;
+ __aligned_u64 inline_addrs;
+ __aligned_u64 inline_cookies;
+ __aligned_u64 inline_ids;
+ __u32 inline_count; /* in/out: kprobe_multi inlined instances count */
+ __u32 inline_skipped;
} kprobe_multi;
struct {
__aligned_u64 path;
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 15430d72c2a0..2151ae84b18f 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2373,6 +2373,7 @@ struct inline_site {
struct bpf_kprobe_multi_link *link;
u64 cookie;
u32 sym_idx;
+ u32 func_id;
bool has_entry;
bool traceable;
};
@@ -2494,6 +2495,60 @@ static void bpf_kprobe_multi_link_release(struct bpf_link *link)
kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt);
}
+static unsigned long inline_sites_missed(const struct inline_sites *inlines)
+{
+ unsigned long missed = 0;
+ u32 i;
+
+ for (i = 0; i < inlines->cnt; i++)
+ missed += inlines->kps[i]->nmissed;
+ return missed;
+}
+
+/*
+ * Fill addresses, cookies and function BTF ids of attached inlined
+ * instances, with the same semantics as for the link functions.
+ */
+static int inline_sites_fill_link_info(const struct inline_sites *inlines,
+ struct bpf_link_info *info)
+{
+ u64 __user *ucookies = u64_to_user_ptr(info->kprobe_multi.inline_cookies);
+ u64 __user *uaddrs = u64_to_user_ptr(info->kprobe_multi.inline_addrs);
+ u32 __user *uids = u64_to_user_ptr(info->kprobe_multi.inline_ids);
+ bool show = kallsyms_show_value(current_cred());
+ u32 ucount = info->kprobe_multi.inline_count;
+ const struct inline_site *site;
+ int err = 0;
+ u32 i;
+
+ if (!uaddrs ^ !ucount)
+ return -EINVAL;
+ if ((ucookies || uids) && !ucount)
+ return -EINVAL;
+
+ info->kprobe_multi.inline_count = inlines->cnt;
+ info->kprobe_multi.inline_skipped = inlines->sites_cnt - inlines->cnt;
+
+ if (!uaddrs)
+ return 0;
+ if (ucount < inlines->cnt)
+ err = -ENOSPC;
+ else
+ ucount = inlines->cnt;
+
+ for (i = 0; i < ucount; i++) {
+ site = container_of(inlines->kps[i], struct inline_site, kp);
+
+ if (put_user(show ? (unsigned long)site->kp.addr : 0, uaddrs + i))
+ return -EFAULT;
+ if (ucookies && put_user(site->cookie, ucookies + i))
+ return -EFAULT;
+ if (uids && put_user(site->func_id, uids + i))
+ return -EFAULT;
+ }
+ return err;
+}
+
static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link)
{
struct bpf_kprobe_multi_link *kmulti_link;
@@ -2524,10 +2579,15 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link,
kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link);
info->kprobe_multi.count = kmulti_link->cnt;
info->kprobe_multi.flags = kmulti_link->link.flags;
- info->kprobe_multi.missed = kmulti_link->fp.nmissed;
+ info->kprobe_multi.missed = kmulti_link->fp.nmissed +
+ inline_sites_missed(&kmulti_link->inlines);
+
+ err = inline_sites_fill_link_info(&kmulti_link->inlines, info);
+ if (err && err != -ENOSPC)
+ return err;
if (!uaddrs)
- return 0;
+ return err;
if (ucount < kmulti_link->cnt)
err = -ENOSPC;
else
@@ -2904,7 +2964,8 @@ struct inline_lookup {
u32 cap;
};
-static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u32 sym_idx)
+static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr,
+ u32 sym_idx, u32 func_id)
{
struct inline_site *sites;
u32 cap;
@@ -2924,6 +2985,7 @@ static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr, u
lookup->sites[lookup->cnt++] = (struct inline_site) {
.kp.addr = (kprobe_opcode_t *)addr,
.sym_idx = sym_idx,
+ .func_id = func_id,
};
return 0;
}
@@ -2943,7 +3005,7 @@ static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *
idx = inline_sym_idx(btf, loc, lookup->syms, lookup->syms_cnt);
if (idx < 0)
continue;
- err = inline_lookup_add(lookup, base + loc->offset, idx);
+ err = inline_lookup_add(lookup, base + loc->offset, idx, loc->func);
if (err)
return err;
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 96e6a629f0c0..eee02f62f98b 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -6979,6 +6979,11 @@ struct bpf_link_info {
__u32 flags;
__u64 missed;
__aligned_u64 cookies;
+ __aligned_u64 inline_addrs;
+ __aligned_u64 inline_cookies;
+ __aligned_u64 inline_ids;
+ __u32 inline_count; /* in/out: kprobe_multi inlined instances count */
+ __u32 inline_skipped;
} kprobe_multi;
struct {
__aligned_u64 path;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 10/31] bpf: Add fdinfo support for kprobe multi inlined functions
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (8 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
` (20 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Display the number of registered inlined instances in link's fdinfo
as kprobe_inline_cnt and the number of skipped ones (the ones that
failed to register) as kprobe_inline_skipped.
Add the missed count of the inlined instances kprobes to the missed
value in the fdinfo.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/trace/bpf_trace.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2151ae84b18f..a3ac65f2e00c 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2629,9 +2629,13 @@ static void bpf_kprobe_multi_show_fdinfo(const struct bpf_link *link,
seq_printf(seq,
"kprobe_cnt:\t%u\n"
+ "kprobe_inline_cnt:\t%u\n"
+ "kprobe_inline_skipped:\t%u\n"
"missed:\t%lu\n",
kmulti_link->cnt,
- kmulti_link->fp.nmissed);
+ kmulti_link->inlines.cnt,
+ kmulti_link->inlines.sites_cnt - kmulti_link->inlines.cnt,
+ kmulti_link->fp.nmissed + inline_sites_missed(&kmulti_link->inlines));
seq_printf(seq, "%s\t %s\n", "cookie", "func");
for (int i = 0; i < kmulti_link->cnt; i++) {
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (9 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
` (19 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add btf_for_each_module_inline() that calls the provided callback for
each live module with inline BTF, the split BTF on top of module BTF
that describes inline sites in the module.
At the moment we keep just relocated inline BTF data for the module,
which is exposed in sysfs. Parse it on first use and keep the parsed
inline BTF cached until the module is gone, so there's no cost unless
something asks for it.
The module reference is held just for the callback, so the callback
needs to get its own reference to keep using the module.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/btf.h | 11 ++++++++
kernel/bpf/btf.c | 64 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 9007da300ca0..dcc1cb4a93bf 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -256,6 +256,17 @@ bool btf_type_is_arena_ptr(const struct btf *btf, const struct btf_type *t);
s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind);
s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p);
struct btf *btf_get_module_btf(const struct module *module);
+
+typedef int (*btf_module_inline_fn)(struct module *mod, const struct btf *btf, void *data);
+
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+int btf_for_each_module_inline(btf_module_inline_fn fn, void *data);
+#else
+static inline int btf_for_each_module_inline(btf_module_inline_fn fn, void *data)
+{
+ return 0;
+}
+#endif
__u32 btf_relocate_id(const struct btf *btf, __u32 id);
const struct btf_type *btf_type_skip_modifiers(const struct btf *btf,
u32 id, u32 *res_id);
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 72eba56e9a5e..683539f8ea6b 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -9412,6 +9412,9 @@ struct btf_module {
struct bin_attribute *sysfs_attr;
struct bin_attribute *sysfs_inline_attr;
void *btf_inline_data;
+ u32 btf_inline_data_size;
+ /* Parsed on first use, check btf_for_each_module_inline. */
+ struct btf *inline_btf;
int flags;
};
@@ -9587,6 +9590,7 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
btf_mod->module = module;
btf_mod->btf = btf;
btf_mod->btf_inline_data = relocated_inline_data;
+ btf_mod->btf_inline_data_size = inline_data_size;
list_add(&btf_mod->list, &btf_modules);
mutex_unlock(&btf_module_mutex);
@@ -9646,6 +9650,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
if (btf_mod->sysfs_inline_attr)
sysfs_btf_remove(btf_mod->sysfs_inline_attr);
kvfree(btf_mod->btf_inline_data);
+ if (btf_mod->inline_btf)
+ btf_free(btf_mod->inline_btf);
purge_cand_cache(btf_mod->btf);
btf_put(btf_mod->btf);
kfree(btf_mod);
@@ -9670,6 +9676,64 @@ static int __init btf_module_init(void)
}
fs_initcall(btf_module_init);
+
+#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
+static struct btf *btf_module_inline_btf(struct btf_module *btf_mod)
+{
+ struct btf_verifier_env *env;
+ struct btf *btf;
+
+ lockdep_assert_held(&btf_module_mutex);
+
+ if (btf_mod->inline_btf)
+ return btf_mod->inline_btf;
+
+ env = kzalloc_obj(*env, GFP_KERNEL | __GFP_NOWARN);
+ if (!env)
+ return ERR_PTR(-ENOMEM);
+
+ env->log.level = BPF_LOG_KERNEL;
+ btf = btf_parse_split(env, btf_mod->module->name, btf_mod->btf_inline_data,
+ btf_mod->btf_inline_data_size, btf_mod->btf);
+ btf_verifier_env_free(env);
+ if (!IS_ERR(btf))
+ btf_mod->inline_btf = btf;
+ return btf;
+}
+
+/*
+ * Call @fn for each live module with inline BTF, the split BTF on top
+ * of module BTF that describes inline sites in the module.
+ *
+ * The inline BTF is parsed on first use and stays cached until the
+ * module is gone. The module reference is held just for the @fn call,
+ * so @fn needs to get its own to keep using the module or its BTF.
+ *
+ * The iteration stops when @fn returns non zero value, which is then
+ * returned.
+ */
+int btf_for_each_module_inline(btf_module_inline_fn fn, void *data)
+{
+ struct btf_module *btf_mod;
+ struct btf *btf;
+ int err = 0;
+
+ mutex_lock(&btf_module_mutex);
+ list_for_each_entry(btf_mod, &btf_modules, list) {
+ if (!btf_mod->btf_inline_data || !(btf_mod->flags & BTF_MODULE_F_LIVE))
+ continue;
+ if (!try_module_get(btf_mod->module))
+ continue;
+ btf = btf_module_inline_btf(btf_mod);
+ err = IS_ERR(btf) ? PTR_ERR(btf) : fn(btf_mod->module, btf, data);
+ module_put(btf_mod->module);
+ if (err)
+ break;
+ }
+ mutex_unlock(&btf_module_mutex);
+ return err;
+}
+#endif /* IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE) */
#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */
#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (10 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
` (18 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Change get_modules_for_addrs to add modules to struct modules_array
object provided by the caller instead of using its own, and return
just zero or error. On error all the modules in the array are released.
It will be used to store modules with inlined instances together
with modules of the functions attached with fprobe in following
change. There's no functional change intended.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/trace/bpf_trace.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index a3ac65f2e00c..bd413d45ef2c 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2872,9 +2872,12 @@ static bool has_module(struct modules_array *arr, struct module *mod)
return false;
}
-static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u32 addrs_cnt)
+/*
+ * Add modules for @addrs to @arr. On error all the modules in @arr
+ * are released.
+ */
+static int get_modules_for_addrs(struct modules_array *arr, unsigned long *addrs, u32 addrs_cnt)
{
- struct modules_array arr = {};
u32 i, err = 0;
for (i = 0; i < addrs_cnt; i++) {
@@ -2884,7 +2887,7 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
scoped_guard(rcu) {
mod = __module_address(addrs[i]);
/* Either no module or it's already stored */
- if (!mod || has_module(&arr, mod)) {
+ if (!mod || has_module(arr, mod)) {
skip_add = true;
break; /* scoped_guard */
}
@@ -2895,23 +2898,19 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
continue;
if (err)
break;
- err = add_module(&arr, mod);
+ err = add_module(arr, mod);
if (err) {
module_put(mod);
break;
}
}
- /* We return either err < 0 in case of error, ... */
if (err) {
- kprobe_multi_put_modules(arr.mods, arr.mods_cnt);
- kfree(arr.mods);
- return err;
+ kprobe_multi_put_modules(arr->mods, arr->mods_cnt);
+ kfree(arr->mods);
+ memset(arr, 0, sizeof(*arr));
}
-
- /* or number of modules found if everything is ok. */
- *mods = arr.mods;
- return arr.mods_cnt;
+ return err;
}
static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt)
@@ -3188,6 +3187,7 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link)
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
{
struct inline_sites inlines = {};
+ struct modules_array mods = {};
struct bpf_kprobe_multi_link *link = NULL;
struct bpf_link_primer link_primer;
void __user *ucookies;
@@ -3359,10 +3359,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link);
}
- err = get_modules_for_addrs(&link->mods, addrs, cnt);
- if (err < 0)
+ err = get_modules_for_addrs(&mods, addrs, cnt);
+ if (err)
goto error_cleanup;
- link->mods_cnt = err;
+ link->mods = mods.mods;
+ link->mods_cnt = mods.mods_cnt;
if (inlines.sites_cnt) {
err = inline_sites_register(link);
@@ -3388,6 +3389,8 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
return err;
error:
+ kprobe_multi_put_modules(mods.mods, mods.mods_cnt);
+ kfree(mods.mods);
kfree(link);
kvfree(addrs);
kvfree(cookies);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (11 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
` (17 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The BPF_F_KPROBE_MULTI_INLINE flag attaches inlined instances found
in vmlinux inline BTF. Add support to attach also inlined instances
in kernel modules.
The module inline BTF has LOCSEC for each section with inlined
instances, named as inline<section>, with offsets relative to the
section start. Sections that are not in module text, like freed init
sections, are skipped.
The function is matched by name in module BTF and its base vmlinux
BTF, so kernel function inlined in module code is attached as well.
Modules with inlined instances are stored in the link, so they stay
loaded as long as the link exists.
The link info inline_ids value of instance in module is the BTF id
from the inline BTF of that module.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/trace/bpf_trace.c | 70 +++++++++++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index bd413d45ef2c..71da54a6ea20 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2873,8 +2873,8 @@ static bool has_module(struct modules_array *arr, struct module *mod)
}
/*
- * Add modules for @addrs to @arr. On error all the modules in @arr
- * are released.
+ * Add modules for @addrs to @arr, which might already have modules
+ * with inlined instances. On error all the modules in @arr are released.
*/
static int get_modules_for_addrs(struct modules_array *arr, unsigned long *addrs, u32 addrs_cnt)
{
@@ -2959,6 +2959,7 @@ struct inline_lookup {
/* Output */
struct inline_sites *inlines;
+ struct modules_array *mods;
u32 addrs_cnt;
/* Lookup state */
@@ -3015,6 +3016,58 @@ static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *
return 0;
}
+#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
+static int inline_lookup_module(struct module *mod, const struct btf *btf, void *data)
+{
+ u32 id, nr_types = btf_nr_types(btf);
+ struct inline_lookup *lookup = data;
+ const struct btf_type *t;
+ u32 cnt = lookup->cnt;
+ unsigned long base;
+ const char *name;
+ int err;
+
+ /*
+ * Each section with inlined instances has its own LOCSEC named
+ * as inline<section> with offsets relative to the section start.
+ */
+ for (id = btf_nr_types(btf_base_btf(btf)); id < nr_types; id++) {
+ t = btf_type_by_id(btf, id);
+ if (btf_kind(t) != BTF_KIND_LOCSEC)
+ continue;
+ name = btf_name_by_offset(btf, t->name_off);
+ if (!name || !str_has_prefix(name, "inline"))
+ continue;
+ /* Skip sections that are not loaded or are freed already (init). */
+ base = module_sect_addr(mod, name + strlen("inline"));
+ if (!base || !within_module_mem_type(base, mod, MOD_TEXT))
+ continue;
+ err = inline_lookup_locsec(lookup, btf, t, base);
+ if (err)
+ return err;
+ }
+
+ if (lookup->cnt == cnt)
+ return 0;
+
+ /* Keep the module we have inlined instances in. */
+ err = add_module(lookup->mods, mod);
+ if (!err)
+ __module_get(mod);
+ return err;
+}
+
+static int inline_lookup_modules(struct inline_lookup *lookup)
+{
+ return btf_for_each_module_inline(inline_lookup_module, lookup);
+}
+#else
+static int inline_lookup_modules(struct inline_lookup *lookup)
+{
+ return 0;
+}
+#endif
+
/*
* Sort instances by symbol name and address, so instances of each
* symbol are next to each other, and get rid of duplicates.
@@ -3051,9 +3104,11 @@ static bool inline_site_traceable(unsigned long addr)
}
/*
- * Find inlined instances for functions in @lookup->syms. Each function
- * must have an entry address or at least one inlined instance, functions
- * without an entry address are dropped from @lookup->addrs.
+ * Find inlined instances for functions in @lookup->syms in kernel and
+ * modules, modules with instances are stored in @lookup->mods with
+ * reference taken. Each function must have an entry address or at least
+ * one inlined instance, functions without an entry address are dropped
+ * from @lookup->addrs.
*/
static int inline_lookup_symbols(struct inline_lookup *lookup)
{
@@ -3075,6 +3130,10 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
if (id < 0)
return -EOPNOTSUPP;
+ err = inline_lookup_modules(lookup);
+ if (err)
+ goto error;
+
err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id), (unsigned long)_stext);
if (err)
goto error;
@@ -3298,6 +3357,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
if ((flags & BPF_F_KPROBE_MULTI_INLINE) && (!err || err == -ESRCH)) {
struct inline_lookup lookup = {
.inlines = &inlines,
+ .mods = &mods,
.syms = us.syms,
.syms_cnt = cnt,
.addrs = addrs,
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for kprobe multi link
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (12 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
` (16 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The kprobe multi link with BPF_F_KPROBE_MULTI_INLINE flag skips
inlined instances that fail to attach, so the link can end up
attached just to some of the inlined instances of the function.
Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for users that need all
the inlined instances attached. With the flag the attach fails on
the first inlined instance that fails to register and returns its
error.
The flag needs to be used together with BPF_F_KPROBE_MULTI_INLINE
flag, the attach fails with -EINVAL otherwise.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/uapi/linux/bpf.h | 3 +++
kernel/trace/bpf_trace.c | 17 +++++++++++++----
tools/include/uapi/linux/bpf.h | 3 +++
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index eee02f62f98b..3b97904851f4 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1373,6 +1373,9 @@ enum {
/* Attach also to inlined function instances, skip those that fail. */
BPF_F_KPROBE_MULTI_INLINE = (1U << 1),
+
+ /* With BPF_F_KPROBE_MULTI_INLINE, fail if inlined instance fails. */
+ BPF_F_KPROBE_MULTI_INLINE_STRICT = (1U << 2),
};
/* link_create.uprobe_multi.flags used in LINK_CREATE command for
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 71da54a6ea20..552a7420fb8c 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3184,9 +3184,10 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
/*
* Register inlined instances of the @link and skip the ones that fail.
- * Fail if function has no entry and none of its instances registered.
+ * Fail if function has no entry and none of its instances registered,
+ * with @strict fail on the first instance that fails to register.
*/
-static int inline_sites_register(struct bpf_kprobe_multi_link *link)
+static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict)
{
struct inline_sites *inlines = &link->inlines;
struct inline_site *site, *first = NULL;
@@ -3212,6 +3213,8 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link)
err = site->traceable ? register_kprobe(&site->kp) : -EINVAL;
if (err == -ENOMEM)
goto error;
+ if (err && strict)
+ goto error;
if (err) {
first_err = first_err ?: err;
} else {
@@ -3255,6 +3258,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
void __user *uaddrs;
u64 *cookies = NULL;
void __user *usyms;
+ bool strict;
int err;
/* no support for 32bit archs yet */
@@ -3276,14 +3280,19 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
return -EINVAL;
flags = attr->link_create.kprobe_multi.flags;
- if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE))
+ if (flags & ~(BPF_F_KPROBE_MULTI_RETURN | BPF_F_KPROBE_MULTI_INLINE |
+ BPF_F_KPROBE_MULTI_INLINE_STRICT))
return -EINVAL;
+ strict = flags & BPF_F_KPROBE_MULTI_INLINE_STRICT;
uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs);
usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms);
if (!!uaddrs == !!usyms)
return -EINVAL;
+ if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE))
+ return -EINVAL;
+
if (flags & BPF_F_KPROBE_MULTI_INLINE) {
/*
* Inlined instances are resolved from function names and
@@ -3426,7 +3435,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->mods_cnt = mods.mods_cnt;
if (inlines.sites_cnt) {
- err = inline_sites_register(link);
+ err = inline_sites_register(link, strict);
if (err)
goto error_modules;
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index eee02f62f98b..3b97904851f4 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1373,6 +1373,9 @@ enum {
/* Attach also to inlined function instances, skip those that fail. */
BPF_F_KPROBE_MULTI_INLINE = (1U << 1),
+
+ /* With BPF_F_KPROBE_MULTI_INLINE, fail if inlined instance fails. */
+ BPF_F_KPROBE_MULTI_INLINE_STRICT = (1U << 2),
};
/* link_create.uprobe_multi.flags used in LINK_CREATE command for
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (13 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
` (15 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Adding support for bpf_get_func_arg and bpf_get_func_arg_cnt helpers
in kprobe multi programs.
The number of arguments is read from function's BTF during the attach
and the argument value is read from ftrace_regs. The BTF lookup is done
only for programs that call the helpers.
The kprobe multi link does not need kernel BTF so far and that stays
the same for programs that do not call the helpers. For programs that
do, the number of arguments is zero for functions without BTF, the
attach does not fail.
The arguments are not available in return probe and for inlined
instances, the support for those is added in following change.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 10 ++
kernel/bpf/verifier.c | 3 +
kernel/trace/bpf_trace.c | 179 +++++++++++++++++++++++++++++++--
tools/include/uapi/linux/bpf.h | 10 ++
5 files changed, 192 insertions(+), 11 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 94560bd9dccc..0c700a08bb0c 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2073,6 +2073,7 @@ struct bpf_prog {
enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */
call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */
call_get_func_ip:1, /* Do we call get_func_ip() */
+ call_get_func_arg:1, /* Do we call get_func_arg[_cnt]() */
call_session_cookie:1, /* Do we call bpf_session_cookie() */
tstamp_type_access:1, /* Accessed __sk_buff->tstamp_type */
sleepable:1; /* BPF program is sleepable */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 3b97904851f4..863b911c4bc5 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5680,9 +5680,14 @@ union bpf_attr {
* Get **n**-th argument register (zero based) of the traced function (for tracing programs)
* returned in **value**.
*
+ * For kprobe multi programs get **n**-th argument (zero based) of
+ * the traced function.
+ *
* Return
* 0 on success.
* **-EINVAL** if n >= argument register count of traced function.
+ * **-EOPNOTSUPP** for kprobe multi programs executed in return
+ * probe or for inlined instances.
*
* long bpf_get_func_ret(void *ctx, u64 *value)
* Description
@@ -5698,8 +5703,13 @@ union bpf_attr {
* Get number of registers of the traced function (for tracing programs) where
* function arguments are stored in these registers.
*
+ * For kprobe multi programs get number of arguments of the traced
+ * function.
+ *
* Return
* The number of argument registers of the traced function.
+ * 0 for kprobe multi programs attached with
+ * **BPF_F_KPROBE_MULTI_RETURN** flag or for inlined instances.
*
* int bpf_get_retval(void)
* Description
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 18c59ae784eb..a2a8dffd44b6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -13479,6 +13479,9 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
env->prog->call_get_func_ip = true;
}
+ if (func_id == BPF_FUNC_get_func_arg || func_id == BPF_FUNC_get_func_arg_cnt)
+ env->prog->call_get_func_arg = true;
+
/* a call that only a speculative state reaches is dead code */
if (func_id == BPF_FUNC_override_return && !env->cur_state->speculative)
env->prog->kprobe_override = 1;
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 552a7420fb8c..f9b63cf5f66f 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1358,6 +1358,11 @@ static inline bool is_trace_fsession(const struct bpf_prog *prog)
prog->expected_attach_type == BPF_TRACE_FSESSION_MULTI);
}
+#ifdef CONFIG_FPROBE
+static const struct bpf_func_proto bpf_get_func_arg_proto_kprobe_multi;
+static const struct bpf_func_proto bpf_get_func_arg_cnt_proto_kprobe_multi;
+#endif
+
static const struct bpf_func_proto *
kprobe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
@@ -1384,6 +1389,12 @@ kprobe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
if (is_uprobe_multi(prog))
return &bpf_get_attach_cookie_proto_umulti;
return &bpf_get_attach_cookie_proto_trace;
+#ifdef CONFIG_FPROBE
+ case BPF_FUNC_get_func_arg:
+ return is_kprobe_multi(prog) ? &bpf_get_func_arg_proto_kprobe_multi : NULL;
+ case BPF_FUNC_get_func_arg_cnt:
+ return is_kprobe_multi(prog) ? &bpf_get_func_arg_cnt_proto_kprobe_multi : NULL;
+#endif
default:
return bpf_tracing_func_proto(func_id, prog);
}
@@ -2394,6 +2405,7 @@ struct bpf_kprobe_multi_link {
struct fprobe fp;
unsigned long *addrs;
u64 *cookies;
+ u8 *args_cnt;
u32 cnt;
u32 mods_cnt;
struct module **mods;
@@ -2405,6 +2417,7 @@ struct bpf_kprobe_multi_run_ctx {
struct bpf_kprobe_multi_link *link;
unsigned long entry_ip;
struct inline_site *site;
+ struct ftrace_regs *fregs;
};
struct user_syms {
@@ -2558,6 +2571,7 @@ static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link)
kvfree(kmulti_link->inlines.kps);
kvfree(kmulti_link->addrs);
kvfree(kmulti_link->cookies);
+ kvfree(kmulti_link->args_cnt);
kfree(kmulti_link->mods);
kfree(kmulti_link);
}
@@ -2660,14 +2674,15 @@ static void bpf_kprobe_multi_cookie_swap(void *a, void *b, int size, const void
{
const struct bpf_kprobe_multi_link *link = priv;
unsigned long *addr_a = a, *addr_b = b;
- u64 *cookie_a, *cookie_b;
-
- cookie_a = link->cookies + (addr_a - link->addrs);
- cookie_b = link->cookies + (addr_b - link->addrs);
+ u32 idx_a = addr_a - link->addrs;
+ u32 idx_b = addr_b - link->addrs;
- /* swap addr_a/addr_b and cookie_a/cookie_b values */
+ /* swap addr_a/addr_b and related cookie and args_cnt values */
swap(*addr_a, *addr_b);
- swap(*cookie_a, *cookie_b);
+ if (link->cookies)
+ swap(link->cookies[idx_a], link->cookies[idx_b]);
+ if (link->args_cnt)
+ swap(link->args_cnt[idx_a], link->args_cnt[idx_b]);
}
static int bpf_kprobe_multi_addrs_cmp(const void *a, const void *b)
@@ -2718,6 +2733,78 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
return run_ctx->entry_ip;
}
+/*
+ * Get number of arguments of the function we got executed for
+ * through its entry probe.
+ */
+static int kprobe_multi_entry_args_cnt(struct bpf_kprobe_multi_run_ctx *run_ctx)
+{
+ struct bpf_kprobe_multi_link *link = run_ctx->link;
+ unsigned long entry_ip = run_ctx->entry_ip;
+ unsigned long *addr;
+
+ if (!link->args_cnt)
+ return -EOPNOTSUPP;
+ addr = bsearch(&entry_ip, link->addrs, link->cnt, sizeof(entry_ip),
+ bpf_kprobe_multi_addrs_cmp);
+ if (!addr)
+ return -EOPNOTSUPP;
+ return link->args_cnt[addr - link->addrs];
+}
+
+BPF_CALL_3(bpf_get_func_arg_kprobe_multi, struct pt_regs *, regs, u32, n, u64 *, value)
+{
+ struct bpf_kprobe_multi_run_ctx *run_ctx;
+ int cnt;
+
+ run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx,
+ session_ctx.run_ctx);
+ /* Arguments of inlined instances are not supported. */
+ if (run_ctx->site)
+ return -EOPNOTSUPP;
+ /* The arguments are not available in return probe. */
+ if (run_ctx->session_ctx.is_return)
+ return -EOPNOTSUPP;
+
+ cnt = kprobe_multi_entry_args_cnt(run_ctx);
+ if (cnt < 0)
+ return cnt;
+ if (n >= cnt)
+ return -EINVAL;
+ *value = ftrace_regs_get_argument(run_ctx->fregs, n);
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_get_func_arg_proto_kprobe_multi = {
+ .func = bpf_get_func_arg_kprobe_multi,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+ .arg2_type = ARG_ANYTHING,
+ .arg3_type = ARG_PTR_TO_FIXED_SIZE_MEM | MEM_UNINIT | MEM_WRITE | MEM_ALIGNED,
+ .arg3_size = sizeof(u64),
+};
+
+BPF_CALL_1(bpf_get_func_arg_cnt_kprobe_multi, struct pt_regs *, regs)
+{
+ struct bpf_kprobe_multi_run_ctx *run_ctx;
+ int cnt;
+
+ run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx,
+ session_ctx.run_ctx);
+ /* Arguments of inlined instances are not supported. */
+ if (run_ctx->site)
+ return 0;
+
+ cnt = kprobe_multi_entry_args_cnt(run_ctx);
+ return cnt < 0 ? 0 : cnt;
+}
+
+static const struct bpf_func_proto bpf_get_func_arg_cnt_proto_kprobe_multi = {
+ .func = bpf_get_func_arg_cnt_kprobe_multi,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+};
+
static __always_inline int
kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
struct inline_site *site,
@@ -2732,6 +2819,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
.link = link,
.entry_ip = entry_ip,
.site = site,
+ .fregs = fregs,
};
struct bpf_run_ctx *old_run_ctx;
int err;
@@ -2955,6 +3043,7 @@ struct inline_lookup {
const char **syms;
unsigned long *addrs;
u64 *cookies;
+ u8 *args_cnt;
u32 syms_cnt;
/* Output */
@@ -3068,6 +3157,49 @@ static int inline_lookup_modules(struct inline_lookup *lookup)
}
#endif
+/* Get number of arguments of the function from its BTF, zero if there's none. */
+static u8 func_args_cnt(const char *name)
+{
+ const struct btf_type *t;
+ struct btf *btf;
+ u32 cnt = 0;
+ s32 id;
+
+ id = bpf_find_btf_id(name, BTF_KIND_FUNC, &btf);
+ if (id < 0)
+ return 0;
+ t = btf_type_by_id(btf, btf_type_by_id(btf, id)->type);
+ if (btf_type_is_func_proto(t))
+ cnt = btf_type_vlen(t);
+ /* Do not count variable arguments. */
+ if (cnt && !btf_params(t)[cnt - 1].type)
+ cnt--;
+ btf_put(btf);
+ return min(cnt, U8_MAX);
+}
+
+/*
+ * Get number of arguments for @cnt functions in @addrs, the function
+ * name is taken from @syms if it's provided, otherwise it's resolved
+ * from the function address.
+ */
+static void kprobe_multi_args_cnt(u8 *args_cnt, const char **syms,
+ unsigned long *addrs, u32 cnt)
+{
+ char buf[KSYM_NAME_LEN];
+ const char *name;
+ u32 i;
+
+ for (i = 0; i < cnt; i++) {
+ /* Function that has only inlined instances. */
+ if (!addrs[i])
+ continue;
+ name = syms ? syms[i] : kallsyms_lookup(addrs[i], NULL, NULL, NULL, buf);
+ if (name)
+ args_cnt[i] = func_args_cnt(name);
+ }
+}
+
/*
* Sort instances by symbol name and address, so instances of each
* symbol are next to each other, and get rid of duplicates.
@@ -3169,6 +3301,8 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
addrs[j] = addrs[i];
if (cookies)
cookies[j] = cookies[i];
+ if (lookup->args_cnt)
+ lookup->args_cnt[j] = lookup->args_cnt[i];
j++;
}
@@ -3257,6 +3391,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
u32 flags, cnt, size;
void __user *uaddrs;
u64 *cookies = NULL;
+ u8 *args_cnt = NULL;
void __user *usyms;
bool strict;
int err;
@@ -3335,11 +3470,26 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
}
}
+ /*
+ * The number of arguments is needed only for programs that call
+ * bpf_get_func_arg[_cnt] helpers, the arguments are not available
+ * in return probe.
+ */
+ if (prog->call_get_func_arg && !(flags & BPF_F_KPROBE_MULTI_RETURN)) {
+ args_cnt = kvcalloc(cnt, sizeof(*args_cnt), GFP_KERNEL);
+ if (!args_cnt) {
+ err = -ENOMEM;
+ goto error;
+ }
+ }
+
if (uaddrs) {
if (copy_from_user(addrs, uaddrs, size)) {
err = -EFAULT;
goto error;
}
+ if (args_cnt)
+ kprobe_multi_args_cnt(args_cnt, NULL, addrs, cnt);
} else {
struct multi_symbols_sort data = {
.cookies = cookies,
@@ -3358,6 +3508,9 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
err = ftrace_lookup_symbols(us.syms, cnt, addrs);
+ if (args_cnt && (!err || err == -ESRCH))
+ kprobe_multi_args_cnt(args_cnt, us.syms, addrs, cnt);
+
/*
* With inline flag it's ok if the function is not found,
* as long as it has inlined instance. Unresolved functions
@@ -3371,6 +3524,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
.syms_cnt = cnt,
.addrs = addrs,
.cookies = cookies,
+ .args_cnt = args_cnt,
};
err = inline_lookup_symbols(&lookup);
@@ -3411,16 +3565,18 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->addrs = addrs;
link->cookies = cookies;
+ link->args_cnt = args_cnt;
link->cnt = cnt;
link->link.flags = flags;
link->inlines = inlines;
- if (cookies) {
+ if (cookies || args_cnt) {
/*
- * Sorting addresses will trigger sorting cookies as well
- * (check bpf_kprobe_multi_cookie_swap). This way we can
- * find cookie based on the address in bpf_get_attach_cookie
- * helper.
+ * Sorting addresses will trigger sorting cookies and
+ * args_cnt as well (check bpf_kprobe_multi_cookie_swap).
+ * This way we can find cookie based on the address in
+ * bpf_get_attach_cookie helper and number of arguments
+ * in bpf_get_func_arg[_cnt] helpers.
*/
sort_r(addrs, cnt, sizeof(*addrs),
bpf_kprobe_multi_cookie_cmp,
@@ -3463,6 +3619,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
kfree(link);
kvfree(addrs);
kvfree(cookies);
+ kvfree(args_cnt);
kvfree(inlines.sites);
return err;
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 3b97904851f4..863b911c4bc5 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -5680,9 +5680,14 @@ union bpf_attr {
* Get **n**-th argument register (zero based) of the traced function (for tracing programs)
* returned in **value**.
*
+ * For kprobe multi programs get **n**-th argument (zero based) of
+ * the traced function.
+ *
* Return
* 0 on success.
* **-EINVAL** if n >= argument register count of traced function.
+ * **-EOPNOTSUPP** for kprobe multi programs executed in return
+ * probe or for inlined instances.
*
* long bpf_get_func_ret(void *ctx, u64 *value)
* Description
@@ -5698,8 +5703,13 @@ union bpf_attr {
* Get number of registers of the traced function (for tracing programs) where
* function arguments are stored in these registers.
*
+ * For kprobe multi programs get number of arguments of the traced
+ * function.
+ *
* Return
* The number of argument registers of the traced function.
+ * 0 for kprobe multi programs attached with
+ * **BPF_F_KPROBE_MULTI_RETURN** flag or for inlined instances.
*
* int bpf_get_retval(void)
* Description
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (14 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
` (14 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Adding bpf_get_func_arg and bpf_get_func_arg_cnt helpers support for
inlined instances attached with BPF_F_KPROBE_MULTI_INLINE flag.
The program attached to inlined instance gets pt_regs of the probed
instruction, where the arguments are not in the argument registers.
Their locations are described in inline BTF, so store the location
prototype of each instance and use it in the helpers.
The register value is read with regs_get_dwarf_register function, so
the support is at the moment limited to x86_64.
The bpf_get_func_arg helper fails with:
-EINVAL for argument index out of the number of arguments
-ENOENT for argument without location (likely optimized out)
-EFAULT if the argument can't be read from its location
-EOPNOTSUPP for unsupported location
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/uapi/linux/bpf.h | 13 ++--
kernel/trace/bpf_trace.c | 132 ++++++++++++++++++++++++++++++---
tools/include/uapi/linux/bpf.h | 13 ++--
3 files changed, 137 insertions(+), 21 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 863b911c4bc5..eab777547afd 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5681,13 +5681,16 @@ union bpf_attr {
* returned in **value**.
*
* For kprobe multi programs get **n**-th argument (zero based) of
- * the traced function.
+ * the traced function or of its inlined instance.
*
* Return
* 0 on success.
* **-EINVAL** if n >= argument register count of traced function.
- * **-EOPNOTSUPP** for kprobe multi programs executed in return
- * probe or for inlined instances.
+ * **-ENOENT** if the argument of inlined instance has no location.
+ * **-EFAULT** if the argument of inlined instance can't be read.
+ * **-EOPNOTSUPP** if the location of inlined instance argument is
+ * not supported or for kprobe multi programs executed in return
+ * probe.
*
* long bpf_get_func_ret(void *ctx, u64 *value)
* Description
@@ -5704,12 +5707,12 @@ union bpf_attr {
* function arguments are stored in these registers.
*
* For kprobe multi programs get number of arguments of the traced
- * function.
+ * function or of its inlined instance.
*
* Return
* The number of argument registers of the traced function.
* 0 for kprobe multi programs attached with
- * **BPF_F_KPROBE_MULTI_RETURN** flag or for inlined instances.
+ * **BPF_F_KPROBE_MULTI_RETURN** flag.
*
* int bpf_get_retval(void)
* Description
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index f9b63cf5f66f..af7d258d7357 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2382,10 +2382,13 @@ struct bpf_kprobe_multi_link;
struct inline_site {
struct kprobe kp;
struct bpf_kprobe_multi_link *link;
+ const struct btf *btf;
+ const struct btf_type *loc_proto;
u64 cookie;
u32 sym_idx;
u32 func_id;
bool has_entry;
+ bool is_vmlinux;
bool traceable;
};
@@ -2733,6 +2736,109 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
return run_ctx->entry_ip;
}
+/*
+ * Get @n-th argument of the inlined instance @site from its location
+ * described in inline BTF, @regs are registers of the probed instruction.
+ */
+static int inline_site_arg(const struct inline_site *site, struct pt_regs *regs,
+ u32 n, u64 *value)
+{
+ const struct btf_loc_param *p;
+ const struct btf_type *t;
+ u32 id, flags, vlen;
+ unsigned long regval;
+ u64 val, mem = 0;
+ int err;
+
+ if (n >= btf_type_vlen(site->loc_proto))
+ return -EINVAL;
+
+ /* There's no location for the argument, it's likely optimized out. */
+ id = btf_loc_proto_params(site->loc_proto)[n];
+ if (!id)
+ return -ENOENT;
+
+ /*
+ * The location is BTF_KIND_LOC_PARAM type, its size is the size
+ * of the argument and its flags say how to get the argument value
+ * from the vlen number of 32-bit values that follow.
+ */
+ t = btf_type_by_id(site->btf, id);
+ p = btf_loc_param(t);
+ vlen = btf_type_vlen(t);
+ flags = p->flags;
+
+ /* The value needs to fit in u64. */
+ if (t->size > sizeof(u64))
+ return -EOPNOTSUPP;
+
+ /*
+ * The argument is constant, stored in the first value, 64-bit
+ * constant is stored in two values in {lo, hi} order.
+ */
+ if (flags & BTF_LOC_PARAM_CONST) {
+ val = p->values[0];
+ if (vlen > 1)
+ val |= (u64)p->values[1] << 32;
+ if (flags & BTF_LOC_PARAM_ADDR) {
+ /* The address is relative to the kernel image start. */
+ if (!site->is_vmlinux)
+ return -EOPNOTSUPP;
+ val += (unsigned long)_text;
+ } else if (flags & BTF_LOC_PARAM_SIGNED) {
+ /* Sign extend the constant from the argument size. */
+ val = sign_extend64(val, t->size * 8 - 1);
+ }
+ *value = val;
+ return 0;
+ }
+
+ /*
+ * The rest of the locations is based on register, the first value
+ * is its DWARF number.
+ */
+
+ /* Value stored in two registers. */
+ if (flags == BTF_LOC_PARAM_REG && vlen > 1)
+ return -EOPNOTSUPP;
+
+ /*
+ * Fails for registers we don't have value for, which includes
+ * frame base register (BTF_LOC_PARAM_FBREG).
+ */
+ err = regs_get_dwarf_register(regs, p->values[0], ®val);
+ if (err)
+ return err;
+ val = regval;
+
+ /*
+ * The offset follows the register number, it's either signed
+ * 32-bit value or 64-bit value in {lo, hi} order.
+ */
+ if (flags & BTF_LOC_PARAM_OFFSET) {
+ if (vlen > 2)
+ val += (u64)p->values[2] << 32 | p->values[1];
+ else
+ val += (s32)p->values[1];
+ }
+
+ /*
+ * Without dereference the argument is the register value (plus
+ * offset) itself, otherwise it's address the argument is read from.
+ */
+ if (flags & BTF_LOC_PARAM_DEREF) {
+ if (copy_from_kernel_nofault(&mem, (void *)(unsigned long)val, t->size))
+ return -EFAULT;
+ /* On big endian the argument was read to the high bytes of mem. */
+ if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+ mem >>= (sizeof(mem) - t->size) * 8;
+ val = mem;
+ }
+
+ *value = val;
+ return 0;
+}
+
/*
* Get number of arguments of the function we got executed for
* through its entry probe.
@@ -2759,9 +2865,8 @@ BPF_CALL_3(bpf_get_func_arg_kprobe_multi, struct pt_regs *, regs, u32, n, u64 *,
run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx,
session_ctx.run_ctx);
- /* Arguments of inlined instances are not supported. */
if (run_ctx->site)
- return -EOPNOTSUPP;
+ return inline_site_arg(run_ctx->site, regs, n, value);
/* The arguments are not available in return probe. */
if (run_ctx->session_ctx.is_return)
return -EOPNOTSUPP;
@@ -2791,9 +2896,8 @@ BPF_CALL_1(bpf_get_func_arg_cnt_kprobe_multi, struct pt_regs *, regs)
run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx,
session_ctx.run_ctx);
- /* Arguments of inlined instances are not supported. */
if (run_ctx->site)
- return 0;
+ return btf_type_vlen(run_ctx->site->loc_proto);
cnt = kprobe_multi_entry_args_cnt(run_ctx);
return cnt < 0 ? 0 : cnt;
@@ -3057,8 +3161,9 @@ struct inline_lookup {
u32 cap;
};
-static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr,
- u32 sym_idx, u32 func_id)
+static int inline_lookup_add(struct inline_lookup *lookup, const struct btf *btf,
+ const struct btf_loc *loc, unsigned long addr,
+ u32 sym_idx, bool is_vmlinux)
{
struct inline_site *sites;
u32 cap;
@@ -3077,8 +3182,11 @@ static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr,
lookup->sites[lookup->cnt++] = (struct inline_site) {
.kp.addr = (kprobe_opcode_t *)addr,
+ .btf = btf,
+ .loc_proto = btf_type_by_id(btf, loc->loc_proto),
.sym_idx = sym_idx,
- .func_id = func_id,
+ .func_id = loc->func,
+ .is_vmlinux = is_vmlinux,
};
return 0;
}
@@ -3088,7 +3196,8 @@ static int inline_lookup_add(struct inline_lookup *lookup, unsigned long addr,
* the offsets of its locations are relative to @base address.
*/
static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *btf,
- const struct btf_type *locsec, unsigned long base)
+ const struct btf_type *locsec, unsigned long base,
+ bool is_vmlinux)
{
struct btf_loc *loc;
int idx, err;
@@ -3098,7 +3207,7 @@ static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf *
idx = inline_sym_idx(btf, loc, lookup->syms, lookup->syms_cnt);
if (idx < 0)
continue;
- err = inline_lookup_add(lookup, base + loc->offset, idx, loc->func);
+ err = inline_lookup_add(lookup, btf, loc, base + loc->offset, idx, is_vmlinux);
if (err)
return err;
}
@@ -3131,7 +3240,7 @@ static int inline_lookup_module(struct module *mod, const struct btf *btf, void
base = module_sect_addr(mod, name + strlen("inline"));
if (!base || !within_module_mem_type(base, mod, MOD_TEXT))
continue;
- err = inline_lookup_locsec(lookup, btf, t, base);
+ err = inline_lookup_locsec(lookup, btf, t, base, false);
if (err)
return err;
}
@@ -3266,7 +3375,8 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
if (err)
goto error;
- err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id), (unsigned long)_stext);
+ err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id),
+ (unsigned long)_stext, true);
if (err)
goto error;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 863b911c4bc5..eab777547afd 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -5681,13 +5681,16 @@ union bpf_attr {
* returned in **value**.
*
* For kprobe multi programs get **n**-th argument (zero based) of
- * the traced function.
+ * the traced function or of its inlined instance.
*
* Return
* 0 on success.
* **-EINVAL** if n >= argument register count of traced function.
- * **-EOPNOTSUPP** for kprobe multi programs executed in return
- * probe or for inlined instances.
+ * **-ENOENT** if the argument of inlined instance has no location.
+ * **-EFAULT** if the argument of inlined instance can't be read.
+ * **-EOPNOTSUPP** if the location of inlined instance argument is
+ * not supported or for kprobe multi programs executed in return
+ * probe.
*
* long bpf_get_func_ret(void *ctx, u64 *value)
* Description
@@ -5704,12 +5707,12 @@ union bpf_attr {
* function arguments are stored in these registers.
*
* For kprobe multi programs get number of arguments of the traced
- * function.
+ * function or of its inlined instance.
*
* Return
* The number of argument registers of the traced function.
* 0 for kprobe multi programs attached with
- * **BPF_F_KPROBE_MULTI_RETURN** flag or for inlined instances.
+ * **BPF_F_KPROBE_MULTI_RETURN** flag.
*
* int bpf_get_retval(void)
* Description
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (15 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
` (13 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The attach of kprobe multi link with BPF_F_KPROBE_MULTI_INLINE flag
fails for several reasons with the same error.
Pass the link_create log to bpf_kprobe_multi_link_attach and use it
to explain the failure, including the function and the inlined
instance that can't be attached.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/trace_events.h | 7 +++-
kernel/bpf/syscall.c | 2 +-
kernel/trace/bpf_trace.c | 78 ++++++++++++++++++++++++++++--------
3 files changed, 68 insertions(+), 19 deletions(-)
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index dff8a209875c..a6bd86be8ef5 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -15,6 +15,7 @@ struct array_buffer;
struct tracer;
struct dentry;
struct bpf_prog;
+struct bpf_verifier_log;
union bpf_attr;
struct bpf_verifier_log;
@@ -795,7 +796,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
u32 *fd_type, const char **buf,
u64 *probe_offset, u64 *probe_addr,
unsigned long *missed);
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log);
int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
struct bpf_verifier_log *log);
@@ -847,7 +849,8 @@ static inline int bpf_get_perf_event_info(const struct perf_event *event,
return -EOPNOTSUPP;
}
static inline int
-bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log)
{
return -EOPNOTSUPP;
}
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0bdb4288beb2..28797c5fd9d2 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -6017,7 +6017,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a
ret = bpf_perf_link_attach(attr, prog);
else if (attr->link_create.attach_type == BPF_TRACE_KPROBE_MULTI ||
attr->link_create.attach_type == BPF_TRACE_KPROBE_SESSION)
- ret = bpf_kprobe_multi_link_attach(attr, prog);
+ ret = bpf_kprobe_multi_link_attach(attr, prog, log);
else if (attr->link_create.attach_type == BPF_TRACE_UPROBE_MULTI ||
attr->link_create.attach_type == BPF_TRACE_UPROBE_SESSION)
ret = bpf_uprobe_multi_link_attach(attr, prog);
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index af7d258d7357..7c0a22971d7a 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3149,6 +3149,7 @@ struct inline_lookup {
u64 *cookies;
u8 *args_cnt;
u32 syms_cnt;
+ struct bpf_verifier_log *log;
/* Output */
struct inline_sites *inlines;
@@ -3168,8 +3169,11 @@ static int inline_lookup_add(struct inline_lookup *lookup, const struct btf *btf
struct inline_site *sites;
u32 cap;
- if (lookup->cnt == MAX_KPROBE_MULTI_CNT)
+ if (lookup->cnt == MAX_KPROBE_MULTI_CNT) {
+ bpf_log(lookup->log, "Number of inlined instances is above the limit %u.\n",
+ MAX_KPROBE_MULTI_CNT);
return -E2BIG;
+ }
if (lookup->cnt == lookup->cap) {
cap = max(16, lookup->cap * 2);
@@ -3354,6 +3358,7 @@ static bool inline_site_traceable(unsigned long addr)
static int inline_lookup_symbols(struct inline_lookup *lookup)
{
struct inline_sites *inlines = lookup->inlines;
+ struct bpf_verifier_log *log = lookup->log;
unsigned long *addrs = lookup->addrs;
u32 i, j, k, n, cnt = lookup->syms_cnt;
u64 *cookies = lookup->cookies;
@@ -3363,13 +3368,17 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
s32 id;
btf = bpf_get_btf_vmlinux_inline();
- if (IS_ERR_OR_NULL(btf))
+ if (IS_ERR_OR_NULL(btf)) {
+ bpf_log(log, "Kernel inline BTF is not available.\n");
return -EOPNOTSUPP;
+ }
/* The offsets of inline.text locations are relative to .text section. */
id = btf_find_by_name_kind(btf, "inline.text", BTF_KIND_LOCSEC);
- if (id < 0)
+ if (id < 0) {
+ bpf_log(log, "Kernel inline BTF has no inline.text section.\n");
return -EOPNOTSUPP;
+ }
err = inline_lookup_modules(lookup);
if (err)
@@ -3405,6 +3414,8 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
if (!addrs[i]) {
if (k < n && sites[k].sym_idx == i)
continue;
+ bpf_log(log, "Function %s has no entry and no inlined instance.\n",
+ lookup->syms[i]);
err = -ESRCH;
goto error;
}
@@ -3430,8 +3441,10 @@ static int inline_lookup_symbols(struct inline_lookup *lookup)
* Register inlined instances of the @link and skip the ones that fail.
* Fail if function has no entry and none of its instances registered,
* with @strict fail on the first instance that fails to register.
+ * The instance that failed is returned in *@failed.
*/
-static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict)
+static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict,
+ struct inline_site **failed)
{
struct inline_sites *inlines = &link->inlines;
struct inline_site *site, *first = NULL;
@@ -3457,8 +3470,10 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
err = site->traceable ? register_kprobe(&site->kp) : -EINVAL;
if (err == -ENOMEM)
goto error;
- if (err && strict)
+ if (err && strict) {
+ *failed = site;
goto error;
+ }
if (err) {
first_err = first_err ?: err;
} else {
@@ -3470,6 +3485,7 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
if (i + 1 < inlines->sites_cnt && site[1].sym_idx == site->sym_idx)
continue;
if (!attached) {
+ *failed = first;
err = first_err;
goto error;
}
@@ -3490,9 +3506,12 @@ static int inline_sites_register(struct bpf_kprobe_multi_link *link, bool strict
return err;
}
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log)
{
struct inline_sites inlines = {};
+ struct inline_site *failed = NULL;
+ struct user_syms us = {};
struct modules_array mods = {};
struct bpf_kprobe_multi_link *link = NULL;
struct bpf_link_primer link_primer;
@@ -3535,8 +3554,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
if (!!uaddrs == !!usyms)
return -EINVAL;
- if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE))
+ if (strict && !(flags & BPF_F_KPROBE_MULTI_INLINE)) {
+ bpf_log(log, "Strict flag needs to be used with inline flag.\n");
return -EINVAL;
+ }
if (flags & BPF_F_KPROBE_MULTI_INLINE) {
/*
@@ -3544,16 +3565,28 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
* have just entry probe, so there's no return probe, session
* or override support.
*/
- if (flags & BPF_F_KPROBE_MULTI_RETURN)
+ if (flags & BPF_F_KPROBE_MULTI_RETURN) {
+ bpf_log(log, "Inlined functions can't be attached with return probe.\n");
return -EINVAL;
- if (is_kprobe_session(prog) || prog->kprobe_override)
+ }
+ if (is_kprobe_session(prog) || prog->kprobe_override) {
+ bpf_log(log,
+ "Inlined functions can't be attached with session or override program.\n");
return -EINVAL;
- if (uaddrs)
+ }
+ if (uaddrs) {
+ bpf_log(log,
+ "Inlined functions need to be specified with kprobe_multi.syms.\n");
return -EINVAL;
- if (!IS_ENABLED(CONFIG_KPROBES))
+ }
+ if (!IS_ENABLED(CONFIG_KPROBES)) {
+ bpf_log(log, "Inlined functions need kprobes support.\n");
return -EOPNOTSUPP;
- if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE))
+ }
+ if (!IS_ENABLED(CONFIG_HAVE_KPROBE_MULTI_INLINE)) {
+ bpf_log(log, "Inlined functions are not supported on this architecture.\n");
return -EOPNOTSUPP;
+ }
}
cnt = attr->link_create.kprobe_multi.cnt;
@@ -3604,7 +3637,6 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
struct multi_symbols_sort data = {
.cookies = cookies,
};
- struct user_syms us;
err = copy_user_syms(&us, usyms, cnt);
if (err)
@@ -3635,6 +3667,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
.addrs = addrs,
.cookies = cookies,
.args_cnt = args_cnt,
+ .log = log,
};
err = inline_lookup_symbols(&lookup);
@@ -3643,7 +3676,6 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
cnt = lookup.addrs_cnt;
}
- free_user_syms(&us);
if (err)
goto error;
}
@@ -3701,7 +3733,16 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
link->mods_cnt = mods.mods_cnt;
if (inlines.sites_cnt) {
- err = inline_sites_register(link, strict);
+ err = inline_sites_register(link, strict, &failed);
+ if (failed && strict) {
+ bpf_log(log,
+ "Function %s has inlined instance that can't be attached, %pS failed with %d.\n",
+ us.syms[failed->sym_idx], failed->kp.addr, err);
+ } else if (failed) {
+ bpf_log(log,
+ "Function %s has no entry and none of its inlined instances can be attached, %pS failed with %d.\n",
+ us.syms[failed->sym_idx], failed->kp.addr, err);
+ }
if (err)
goto error_modules;
}
@@ -3713,6 +3754,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
goto error_inlines;
}
+ free_user_syms(&us);
return bpf_link_settle(&link_primer);
error_inlines:
@@ -3721,9 +3763,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
kprobe_multi_put_modules(link->mods, link->mods_cnt);
error_cleanup:
bpf_link_cleanup(&link_primer);
+ free_user_syms(&us);
return err;
error:
+ free_user_syms(&us);
kprobe_multi_put_modules(mods.mods, mods.mods_cnt);
kfree(mods.mods);
kfree(link);
@@ -3734,8 +3778,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
return err;
}
#else /* !CONFIG_FPROBE */
-int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log)
{
+ bpf_log(log, "This kernel does not support kprobe multi link.\n");
return -EOPNOTSUPP;
}
static u64 bpf_kprobe_multi_cookie(struct bpf_run_ctx *ctx)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (16 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
` (12 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add always inlined functions and their callers for kprobe multi
inline tests, the callers are triggered through the tracing test_run.
The bpf_kprobe_multi_inline_test4 caller is marked with
NOKPROBE_SYMBOL, so inlined instances in it can't be attached.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
net/bpf/test_run.c | 83 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 1 deletion(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index cc3236e3c0c4..4a5077590412 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -6,6 +6,7 @@
#include <linux/btf_ids.h>
#include <linux/slab.h>
#include <linux/init.h>
+#include <linux/kprobes.h>
#include <linux/vmalloc.h>
#include <linux/etherdevice.h>
#include <linux/filter.h>
@@ -558,6 +559,81 @@ noinline int bpf_fentry_test10(const void *a)
return (long)a;
}
+/*
+ * Inlined functions for kprobe multi inline tests, the outer function
+ * starts with the inner one, so their inlined instances in
+ * bpf_kprobe_multi_inline_test1 share the address.
+ */
+static __always_inline int bpf_kprobe_multi_inline_inner(int a)
+{
+ /*
+ * Keep an instruction in the inline site, there's no argument
+ * setup, so it's the first instruction of the outer function
+ * inline site as well.
+ */
+ asm volatile("nop");
+ return a + 1;
+}
+
+static __always_inline int bpf_kprobe_multi_inline_outer(int a)
+{
+ return bpf_kprobe_multi_inline_inner(a) + 1;
+}
+
+noinline int bpf_kprobe_multi_inline_test1(int a)
+{
+ return bpf_kprobe_multi_inline_outer(a);
+}
+
+noinline int bpf_kprobe_multi_inline_test2(int a)
+{
+ return bpf_kprobe_multi_inline_inner(a);
+}
+
+/*
+ * Inlined functions with instances that can't be attached, because
+ * kprobes are not allowed in bpf_kprobe_multi_inline_test4:
+ *
+ * bpf_kprobe_multi_inline_partial - one instance can be attached
+ * (test3) and one can't (test4)
+ * bpf_kprobe_multi_inline_nokprobe - no instance can be attached
+ */
+static __always_inline int bpf_kprobe_multi_inline_partial(int a)
+{
+ asm volatile("nop");
+ return a + 1;
+}
+
+static __always_inline int bpf_kprobe_multi_inline_nokprobe(int a)
+{
+ asm volatile("nop");
+ return a + 2;
+}
+
+noinline int bpf_kprobe_multi_inline_test3(int a)
+{
+ return bpf_kprobe_multi_inline_partial(a);
+}
+
+noinline int bpf_kprobe_multi_inline_test4(int a)
+{
+ return bpf_kprobe_multi_inline_partial(a) +
+ bpf_kprobe_multi_inline_nokprobe(a);
+}
+NOKPROBE_SYMBOL(bpf_kprobe_multi_inline_test4);
+
+/* Inlined function with arguments for kprobe multi inline args test. */
+static __always_inline long bpf_kprobe_multi_inline_args(int a, long b, void *c)
+{
+ asm volatile("nop");
+ return a + b + (long)c;
+}
+
+noinline long bpf_kprobe_multi_inline_test5(int a, long b, void *c)
+{
+ return bpf_kprobe_multi_inline_args(a, b, c);
+}
+
noinline void bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
{
}
@@ -710,7 +786,12 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
bpf_fentry_test8(&arg) != 0 ||
bpf_fentry_test9(&retval) != 0 ||
- bpf_fentry_test10((void *)0) != 0)
+ bpf_fentry_test10((void *)0) != 0 ||
+ bpf_kprobe_multi_inline_test1(1) != 3 ||
+ bpf_kprobe_multi_inline_test2(1) != 2 ||
+ bpf_kprobe_multi_inline_test3(1) != 2 ||
+ bpf_kprobe_multi_inline_test4(1) != 5 ||
+ bpf_kprobe_multi_inline_test5(1, 2, (void *)3) != 6)
goto out;
break;
case BPF_MODIFY_RETURN:
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (17 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
` (11 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inlined and inlined_strict options to struct bpf_kprobe_multi_opts
to attach the link with BPF_F_KPROBE_MULTI_INLINE[_STRICT] flags.
The inlined instances are resolved by kernel from function names,
so the options work only with syms array or with pattern without
wildcards.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/lib/bpf/libbpf.c | 18 +++++++++++++++++-
tools/lib/bpf/libbpf.h | 6 +++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 61a388868373..885383def114 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -13159,7 +13159,7 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
struct bpf_link *link = NULL;
const unsigned long *addrs;
int err, link_fd, prog_fd;
- bool retprobe, session, unique_match;
+ bool retprobe, session, unique_match, inlined, inlined_strict;
const __u64 *cookies;
const char **syms;
size_t cnt;
@@ -13179,6 +13179,8 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
cnt = OPTS_GET(opts, cnt, false);
cookies = OPTS_GET(opts, cookies, false);
unique_match = OPTS_GET(opts, unique_match, false);
+ inlined = OPTS_GET(opts, inlined, false);
+ inlined_strict = OPTS_GET(opts, inlined_strict, false);
if (!pattern && !addrs && !syms)
return libbpf_err_ptr(-EINVAL);
@@ -13190,6 +13192,14 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
return libbpf_err_ptr(-EINVAL);
if (addrs && syms)
return libbpf_err_ptr(-EINVAL);
+ /*
+ * Inlined instances are resolved by kernel from function names,
+ * so we can't use addresses or pattern resolved to addresses.
+ */
+ if (inlined && (addrs || unique_match || (pattern && strpbrk(pattern, "*?"))))
+ return libbpf_err_ptr(-EINVAL);
+ if (inlined_strict && !inlined)
+ return libbpf_err_ptr(-EINVAL);
/*
* Exact function name (no wildcards) without unique_match:
@@ -13224,6 +13234,8 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
if (retprobe && session)
return libbpf_err_ptr(-EINVAL);
+ if (inlined && (retprobe || session))
+ return libbpf_err_ptr(-EINVAL);
attach_type = session ? BPF_TRACE_KPROBE_SESSION : BPF_TRACE_KPROBE_MULTI;
@@ -13232,6 +13244,10 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
lopts.kprobe_multi.cookies = cookies;
lopts.kprobe_multi.cnt = cnt;
lopts.kprobe_multi.flags = retprobe ? BPF_F_KPROBE_MULTI_RETURN : 0;
+ if (inlined)
+ lopts.kprobe_multi.flags |= BPF_F_KPROBE_MULTI_INLINE;
+ if (inlined_strict)
+ lopts.kprobe_multi.flags |= BPF_F_KPROBE_MULTI_INLINE_STRICT;
link = calloc(1, sizeof(*link));
if (!link) {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 56300be81016..286512037a68 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -648,10 +648,14 @@ struct bpf_kprobe_multi_opts {
bool session;
/* enforce unique match */
bool unique_match;
+ /* attach also to inlined instances of functions */
+ bool inlined;
+ /* fail if any inlined instance can't be attached, needs inlined */
+ bool inlined_strict;
size_t :0;
};
-#define bpf_kprobe_multi_opts__last_field unique_match
+#define bpf_kprobe_multi_opts__last_field inlined_strict
LIBBPF_API struct bpf_link *
bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (18 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
` (10 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
The kernel explains the failure of kprobe multi link attach in the
link_create log, but libbpf does not ask for it, so the user gets
just the error code.
Pass the log buffer to bpf_link_create in
bpf_program__attach_kprobe_multi_opts and print the kernel message
when the attach fails, like:
libbpf: prog 'test': failed to attach: -ENOENT
libbpf: prog 'test': Function foo has no entry and no inlined instance.
The log is passed only if kernel supports the syscall common
attributes, so there's no change for older kernels.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/lib/bpf/libbpf.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 885383def114..cc6898e97337 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -13160,8 +13160,10 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
const unsigned long *addrs;
int err, link_fd, prog_fd;
bool retprobe, session, unique_match, inlined, inlined_strict;
+ LIBBPF_OPTS(bpf_log_opts, log_opts);
const __u64 *cookies;
const char **syms;
+ char log_buf[4096];
size_t cnt;
if (!OPTS_VALID(opts, bpf_kprobe_multi_opts))
@@ -13249,6 +13251,13 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
if (inlined_strict)
lopts.kprobe_multi.flags |= BPF_F_KPROBE_MULTI_INLINE_STRICT;
+ /* Get the reason of the attach failure from kernel if it's supported. */
+ log_buf[0] = '\0';
+ log_opts.buf = log_buf;
+ log_opts.size = sizeof(log_buf);
+ log_opts.level = 1;
+ lopts.log_opts = &log_opts;
+
link = calloc(1, sizeof(*link));
if (!link) {
err = -ENOMEM;
@@ -13269,6 +13278,8 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
err = -ENOENT;
pr_warn("prog '%s': failed to attach: %s\n",
prog->name, errstr(err));
+ if (log_buf[0])
+ pr_warn("prog '%s': %s\n", prog->name, log_buf);
goto error;
}
link->fd = link_fd;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (19 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
` (9 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Display the inline flags and the attached inlined instances of the
kprobe multi link.
For each inlined instance display its address, cookie, name of the
inlined function and the function it is inlined in:
# bpftool link
3: kprobe_multi prog 10
kprobe.multi inline func_cnt 1 inline_cnt 2
addr cookie func [module]
ffffffff825e9110 5 bpf_fentry_test1
addr cookie func, inlined in [module]
ffffffff825eb4b9 6 bpf_kprobe_multi_inline_inner, bpf_kprobe_multi_inline_test1+0x9
ffffffff825eb4c9 6 bpf_kprobe_multi_inline_inner, bpf_kprobe_multi_inline_test2+0x9
The function the instance is inlined in is the kallsyms symbol
covering the instance address.
The name of the inlined function is resolved from the BTF type id
returned in inline_ids, because several inlined functions can have
their instance on the same address.
In json output the instances are displayed in "inlines" array,
together with "inline", "inline_strict", "inline_cnt" and
"inline_skipped" fields.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/bpf/bpftool/link.c | 348 ++++++++++++++++++++++++++++++++++-----
1 file changed, 303 insertions(+), 45 deletions(-)
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 5cffa2d283b4..19daac789a4c 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <bpf/bpf.h>
+#include <bpf/btf.h>
#include <bpf/hashmap.h>
#include "json_writer.h"
@@ -254,6 +255,12 @@ struct addr_cookie {
__u64 cookie;
};
+struct addr_cookie_id {
+ __u64 addr;
+ __u64 cookie;
+ __u32 id;
+};
+
static int cmp_addr_cookie(const void *A, const void *B)
{
const struct addr_cookie *a = A, *b = B;
@@ -263,6 +270,15 @@ static int cmp_addr_cookie(const void *A, const void *B)
return a->addr < b->addr ? -1 : 1;
}
+static int cmp_addr_cookie_id(const void *A, const void *B)
+{
+ const struct addr_cookie_id *a = A, *b = B;
+
+ if (a->addr == b->addr)
+ return 0;
+ return a->addr < b->addr ? -1 : 1;
+}
+
static struct addr_cookie *
get_addr_cookie_array(__u64 *addrs, __u64 *cookies, __u32 count)
{
@@ -282,6 +298,29 @@ get_addr_cookie_array(__u64 *addrs, __u64 *cookies, __u32 count)
return data;
}
+static struct addr_cookie_id *get_addr_cookie_id_array(struct bpf_link_info *info)
+{
+ __u64 *cookies = u64_to_ptr(info->kprobe_multi.inline_cookies);
+ __u64 *addrs = u64_to_ptr(info->kprobe_multi.inline_addrs);
+ __u32 *ids = u64_to_ptr(info->kprobe_multi.inline_ids);
+ __u32 count = info->kprobe_multi.inline_count;
+ struct addr_cookie_id *data;
+ __u32 i;
+
+ data = calloc(count, sizeof(data[0]));
+ if (!data) {
+ p_err("mem alloc failed");
+ return NULL;
+ }
+ for (i = 0; i < count; i++) {
+ data[i].addr = addrs[i];
+ data[i].cookie = cookies[i];
+ data[i].id = ids[i];
+ }
+ qsort(data, count, sizeof(data[0]), cmp_addr_cookie_id);
+ return data;
+}
+
static bool is_x86_ibt_enabled(void)
{
#if defined(__x86_64__)
@@ -322,33 +361,156 @@ symbol_matches_target(__u64 sym_addr, __u64 target_addr, bool is_ibt_enabled)
return false;
}
+/* Inlined instances are placed inside functions, find the one covering @addr. */
+static struct kernel_sym *find_kernel_sym_by_range(__u64 addr)
+{
+ __u32 lo = 0, hi = dd.sym_count, mid;
+
+ if (!addr)
+ return NULL;
+
+ while (lo < hi) {
+ mid = lo + (hi - lo) / 2;
+ if (dd.sym_mapping[mid].address <= addr)
+ lo = mid + 1;
+ else
+ hi = mid;
+ }
+ return lo ? &dd.sym_mapping[lo - 1] : NULL;
+}
+
+/*
+ * Inline BTF used to get names of inlined functions. The vmlinux one is
+ * loaded once on first use, for modules we keep the last used one.
+ */
+static struct {
+ struct btf *vmlinux;
+ struct btf *vmlinux_inline;
+ struct btf *mod;
+ struct btf *mod_inline;
+ char mod_name[MODULE_MAX_NAME];
+ bool vmlinux_loaded;
+} inline_btf;
+
+static struct btf *parse_sysfs_btf(const char *name, const char *suffix, struct btf *base)
+{
+ char path[PATH_MAX];
+ struct btf *btf;
+
+ snprintf(path, sizeof(path), "/sys/kernel/btf/%s%s", name, suffix);
+ btf = btf__parse_split(path, base);
+ return IS_ERR_OR_NULL(btf) ? NULL : btf;
+}
+
+/* Get inline BTF for vmlinux or for @module, NULL if it's not available. */
+static struct btf *get_inline_btf(const char *module)
+{
+ if (!inline_btf.vmlinux_loaded) {
+ inline_btf.vmlinux_loaded = true;
+ inline_btf.vmlinux = libbpf_find_kernel_btf();
+ if (IS_ERR_OR_NULL(inline_btf.vmlinux))
+ inline_btf.vmlinux = NULL;
+ else
+ inline_btf.vmlinux_inline = parse_sysfs_btf("vmlinux", ".inline",
+ inline_btf.vmlinux);
+ }
+ if (!inline_btf.vmlinux)
+ return NULL;
+ if (module[0] == '\0')
+ return inline_btf.vmlinux_inline;
+
+ if (strcmp(inline_btf.mod_name, module)) {
+ btf__free(inline_btf.mod_inline);
+ btf__free(inline_btf.mod);
+ inline_btf.mod_inline = NULL;
+
+ /* Module inline BTF is split BTF on top of the module BTF. */
+ snprintf(inline_btf.mod_name, sizeof(inline_btf.mod_name), "%s", module);
+ inline_btf.mod = parse_sysfs_btf(module, "", inline_btf.vmlinux);
+ if (inline_btf.mod)
+ inline_btf.mod_inline = parse_sysfs_btf(module, ".inline",
+ inline_btf.mod);
+ }
+ return inline_btf.mod_inline;
+}
+
+static void free_inline_btf(void)
+{
+ /* The caller checks errno of the last link lookup, keep it. */
+ int saved_errno = errno;
+
+ btf__free(inline_btf.mod_inline);
+ btf__free(inline_btf.mod);
+ btf__free(inline_btf.vmlinux_inline);
+ btf__free(inline_btf.vmlinux);
+ memset(&inline_btf, 0, sizeof(inline_btf));
+ errno = saved_errno;
+}
+
+/*
+ * Get name of the inlined function with BTF type @id, the id is from
+ * inline BTF of the object the inlined instance is located in, which
+ * we get from @sym. Returns NULL if the name is not available.
+ */
+static const char *inline_func_name(const struct kernel_sym *sym, __u32 id)
+{
+ const struct btf_type *t;
+ const char *name;
+ struct btf *btf;
+
+ if (!sym || !id)
+ return NULL;
+ btf = get_inline_btf(sym->module);
+ if (!btf)
+ return NULL;
+ t = btf__type_by_id(btf, id);
+ if (!t)
+ return NULL;
+ name = btf__name_by_offset(btf, t->name_off);
+ return name && name[0] ? name : NULL;
+}
+
static void
show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
{
- struct addr_cookie *data;
+ __u32 inline_count = info->kprobe_multi.inline_count;
+ __u32 count = info->kprobe_multi.count;
+ struct addr_cookie_id *inlines = NULL;
+ struct addr_cookie *data = NULL;
+ struct kernel_sym *sym;
+ const char *name;
__u32 i, j = 0;
bool is_ibt_enabled;
jsonw_bool_field(json_wtr, "retprobe",
info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_RETURN);
- jsonw_uint_field(json_wtr, "func_cnt", info->kprobe_multi.count);
+ jsonw_bool_field(json_wtr, "inline",
+ info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_INLINE);
+ jsonw_bool_field(json_wtr, "inline_strict",
+ info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_INLINE_STRICT);
+ jsonw_uint_field(json_wtr, "func_cnt", count);
jsonw_uint_field(json_wtr, "missed", info->kprobe_multi.missed);
- jsonw_name(json_wtr, "funcs");
- jsonw_start_array(json_wtr);
- data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
- u64_to_ptr(info->kprobe_multi.cookies),
- info->kprobe_multi.count);
- if (!data)
- return;
+
+ if (count)
+ data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
+ u64_to_ptr(info->kprobe_multi.cookies),
+ count);
+ if (inline_count)
+ inlines = get_addr_cookie_id_array(info);
/* Load it once for all. */
- if (!dd.sym_count)
+ if ((data || inlines) && !dd.sym_count)
kernel_syms_load(&dd);
- if (!dd.sym_count)
- goto error;
+ /* The array is empty if we don't have its data or symbols. */
+ if (!data || !dd.sym_count)
+ count = 0;
+ if (!inlines || !dd.sym_count)
+ inline_count = 0;
is_ibt_enabled = is_x86_ibt_enabled();
- for (i = 0; i < dd.sym_count; i++) {
+ jsonw_name(json_wtr, "funcs");
+ jsonw_start_array(json_wtr);
+ for (i = 0; count && i < dd.sym_count; i++) {
if (!symbol_matches_target(dd.sym_mapping[i].address,
data[j].addr, is_ibt_enabled))
continue;
@@ -364,12 +526,50 @@ show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
}
jsonw_uint_field(json_wtr, "cookie", data[j].cookie);
jsonw_end_object(json_wtr);
- if (++j == info->kprobe_multi.count)
+ if (++j == count)
break;
}
jsonw_end_array(json_wtr);
-error:
+
+ jsonw_uint_field(json_wtr, "inline_cnt", info->kprobe_multi.inline_count);
+ jsonw_uint_field(json_wtr, "inline_skipped", info->kprobe_multi.inline_skipped);
+ jsonw_name(json_wtr, "inlines");
+ jsonw_start_array(json_wtr);
+ for (i = 0; i < inline_count; i++) {
+ sym = find_kernel_sym_by_range(inlines[i].addr);
+ name = inline_func_name(sym, inlines[i].id);
+
+ jsonw_start_object(json_wtr);
+ jsonw_uint_field(json_wtr, "addr", (unsigned long)inlines[i].addr);
+ /* Name of the inlined function. */
+ if (name) {
+ jsonw_string_field(json_wtr, "func", name);
+ } else {
+ jsonw_name(json_wtr, "func");
+ jsonw_null(json_wtr);
+ }
+ /* The function it is inlined in. */
+ if (sym) {
+ jsonw_string_field(json_wtr, "caller", sym->name);
+ jsonw_uint_field(json_wtr, "offset", inlines[i].addr - sym->address);
+ } else {
+ jsonw_name(json_wtr, "caller");
+ jsonw_null(json_wtr);
+ jsonw_uint_field(json_wtr, "offset", 0);
+ }
+ /* Print null if it is vmlinux */
+ if (!sym || sym->module[0] == '\0') {
+ jsonw_name(json_wtr, "module");
+ jsonw_null(json_wtr);
+ } else {
+ jsonw_string_field(json_wtr, "module", sym->module);
+ }
+ jsonw_uint_field(json_wtr, "cookie", inlines[i].cookie);
+ jsonw_end_object(json_wtr);
+ }
+ jsonw_end_array(json_wtr);
free(data);
+ free(inlines);
}
static __u64 *u64_to_arr(__u64 val)
@@ -828,35 +1028,57 @@ void netfilter_dump_plain(const struct bpf_link_info *info)
static void show_kprobe_multi_plain(struct bpf_link_info *info)
{
- struct addr_cookie *data;
+ __u32 inline_count = info->kprobe_multi.inline_count;
+ bool is_ibt_enabled, is_inline, is_inline_strict;
+ __u32 count = info->kprobe_multi.count;
+ struct addr_cookie_id *inlines = NULL;
+ struct addr_cookie *data = NULL;
+ struct kernel_sym *sym;
+ const char *name;
__u32 i, j = 0;
- bool is_ibt_enabled;
- if (!info->kprobe_multi.count)
+ is_inline_strict = info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_INLINE_STRICT;
+ is_inline = info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_INLINE;
+
+ /* Link with inline flag can have only inlined instances attached. */
+ if (!count && !is_inline)
return;
if (info->kprobe_multi.flags & BPF_F_KPROBE_MULTI_RETURN)
printf("\n\tkretprobe.multi ");
else
printf("\n\tkprobe.multi ");
- printf("func_cnt %u ", info->kprobe_multi.count);
+ if (is_inline_strict)
+ printf("inline_strict ");
+ else if (is_inline)
+ printf("inline ");
+ printf("func_cnt %u ", count);
+ if (is_inline)
+ printf("inline_cnt %u ", inline_count);
+ if (info->kprobe_multi.inline_skipped)
+ printf("inline_skipped %u ", info->kprobe_multi.inline_skipped);
if (info->kprobe_multi.missed)
printf("missed %llu ", info->kprobe_multi.missed);
- data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
- u64_to_ptr(info->kprobe_multi.cookies),
- info->kprobe_multi.count);
- if (!data)
- return;
+ if (count)
+ data = get_addr_cookie_array(u64_to_ptr(info->kprobe_multi.addrs),
+ u64_to_ptr(info->kprobe_multi.cookies),
+ count);
+ if (inline_count)
+ inlines = get_addr_cookie_id_array(info);
/* Load it once for all. */
- if (!dd.sym_count)
+ if ((data || inlines) && !dd.sym_count)
kernel_syms_load(&dd);
- if (!dd.sym_count)
- goto error;
+ /* The array is empty if we don't have its data or symbols. */
+ if (!data || !dd.sym_count)
+ count = 0;
+ if (!inlines || !dd.sym_count)
+ inline_count = 0;
is_ibt_enabled = is_x86_ibt_enabled();
- printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
- for (i = 0; i < dd.sym_count; i++) {
+ if (count)
+ printf("\n\t%-16s %-16s %s", "addr", "cookie", "func [module]");
+ for (i = 0; count && i < dd.sym_count; i++) {
if (!symbol_matches_target(dd.sym_mapping[i].address,
data[j].addr, is_ibt_enabled))
continue;
@@ -867,11 +1089,30 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)
else
printf(" ");
- if (++j == info->kprobe_multi.count)
+ if (++j == count)
break;
}
-error:
+
+ if (inline_count)
+ printf("\n\t%-16s %-16s %s", "addr", "cookie", "func, inlined in [module]");
+ for (i = 0; i < inline_count; i++) {
+ sym = find_kernel_sym_by_range(inlines[i].addr);
+
+ printf("\n\t%016lx %-16llx ",
+ (unsigned long)inlines[i].addr, inlines[i].cookie);
+ if (!sym)
+ continue;
+ name = inline_func_name(sym, inlines[i].id);
+ if (name)
+ printf("%s, ", name);
+ printf("%s+0x%lx", sym->name,
+ (unsigned long)inlines[i].addr - sym->address);
+ if (sym->module[0] != '\0')
+ printf(" [%s]", sym->module);
+ printf(" ");
+ }
free(data);
+ free(inlines);
}
static void show_uprobe_multi_plain(struct bpf_link_info *info)
@@ -1140,7 +1381,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
static int do_show_link(int fd)
{
__u64 *ref_ctr_offsets = NULL, *offsets = NULL, *cookies = NULL;
- __u32 *ids = NULL;
+ __u64 *inline_addrs = NULL, *inline_cookies = NULL;
+ __u32 *ids = NULL, *inline_ids = NULL;
struct bpf_link_info info;
__u32 len = sizeof(info);
char path_buf[PATH_MAX];
@@ -1172,24 +1414,36 @@ static int do_show_link(int fd)
goto again;
}
if (info.type == BPF_LINK_TYPE_KPROBE_MULTI &&
- !info.kprobe_multi.addrs) {
+ !info.kprobe_multi.addrs && !info.kprobe_multi.inline_addrs) {
+ __u32 inline_count = info.kprobe_multi.inline_count;
+
count = info.kprobe_multi.count;
if (count) {
addrs = calloc(count, sizeof(__u64));
- if (!addrs) {
- p_err("mem alloc failed");
- close(fd);
- return -ENOMEM;
- }
- info.kprobe_multi.addrs = ptr_to_u64(addrs);
cookies = calloc(count, sizeof(__u64));
- if (!cookies) {
- p_err("mem alloc failed");
- free(addrs);
- close(fd);
- return -ENOMEM;
- }
+ }
+ if (inline_count) {
+ inline_addrs = calloc(inline_count, sizeof(__u64));
+ inline_cookies = calloc(inline_count, sizeof(__u64));
+ inline_ids = calloc(inline_count, sizeof(__u32));
+ }
+ if ((count && (!addrs || !cookies)) ||
+ (inline_count && (!inline_addrs || !inline_cookies || !inline_ids))) {
+ p_err("mem alloc failed");
+ free(inline_ids);
+ free(inline_cookies);
+ free(inline_addrs);
+ free(cookies);
+ free(addrs);
+ close(fd);
+ return -ENOMEM;
+ }
+ if (count || inline_count) {
+ info.kprobe_multi.addrs = ptr_to_u64(addrs);
info.kprobe_multi.cookies = ptr_to_u64(cookies);
+ info.kprobe_multi.inline_addrs = ptr_to_u64(inline_addrs);
+ info.kprobe_multi.inline_cookies = ptr_to_u64(inline_cookies);
+ info.kprobe_multi.inline_ids = ptr_to_u64(inline_ids);
goto again;
}
}
@@ -1282,6 +1536,9 @@ static int do_show_link(int fd)
show_link_close_plain(fd, &info);
free(ref_ctr_offsets);
+ free(inline_ids);
+ free(inline_cookies);
+ free(inline_addrs);
free(cookies);
free(offsets);
free(addrs);
@@ -1353,6 +1610,7 @@ static int do_show(int argc, char **argv)
out:
if (dd.sym_count)
kernel_syms_destroy(&dd);
+ free_inline_btf();
return errno == ENOENT ? 0 : -1;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (20 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
` (8 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add always inlined functions and their callers to bpf_testmod module
for kprobe multi inline tests, the callers are triggered through
bpf_testmod_test_read:
bpf_testmod_kprobe_multi_inline_test - calls inline
bpf_testmod_kprobe_multi_inline_args_test - calls inline_args
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/test_kmods/bpf_testmod.c | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 86d25638a727..8a0a8ee83703 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -166,6 +166,31 @@ bpf_testmod_test_union_arg_2(int a, union bpf_testmod_union_arg_2 b)
return bpf_testmod_test_struct_arg_result;
}
+/* Inlined function for kprobe multi inline tests. */
+static __always_inline int bpf_testmod_kprobe_multi_inline(int a)
+{
+ /* Keep an instruction in the inline site. */
+ asm volatile("nop");
+ return a + 1;
+}
+
+noinline int bpf_testmod_kprobe_multi_inline_test(int a)
+{
+ return bpf_testmod_kprobe_multi_inline(a);
+}
+
+/* Inlined function with arguments for kprobe multi inline args test. */
+static __always_inline long bpf_testmod_kprobe_multi_inline_args(int a, long b, void *c)
+{
+ asm volatile("nop");
+ return a + b + (long)c;
+}
+
+noinline long bpf_testmod_kprobe_multi_inline_args_test(int a, long b, void *c)
+{
+ return bpf_testmod_kprobe_multi_inline_args(a, b, c);
+}
+
noinline int
bpf_testmod_test_arg_ptr_to_struct(struct bpf_testmod_struct_arg_1 *a) {
bpf_testmod_test_struct_arg_result = a->a;
@@ -828,6 +853,9 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
(void)bpf_testmod_test_arg_ptr_to_struct(&struct_arg1_2);
+ (void)bpf_testmod_kprobe_multi_inline_test(1);
+ (void)bpf_testmod_kprobe_multi_inline_args_test(1, 2, (void *)3);
+
#ifdef __SIZEOF_INT128__
(void)bpf_testmod_test_int128_ret(i);
(void)bpf_testmod_test_int128_arg((__int128)1, 2, 3);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (21 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
` (7 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_attach test that attaches inlined functions with
BPF_F_KPROBE_MULTI_INLINE flag and checks each inlined instance is
hit once with its function cookie, including instances sharing the
same address, and that the probes are gone after detach.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 213 ++++++++++++++++++
.../selftests/bpf/progs/kprobe_multi_inline.c | 41 ++++
2 files changed, 254 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 651123cd8602..e54db60427c3 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -11,6 +11,7 @@
#include "kprobe_multi_verifier.skel.h"
#include "kprobe_write_ctx.skel.h"
#include "kprobe_multi_sleepable.skel.h"
+#include "kprobe_multi_inline.skel.h"
#include "bpf/libbpf_internal.h"
#include "bpf/hashmap.h"
@@ -536,6 +537,16 @@ static void test_kprobe_multi_bench_attach(bool kernel)
free_kallsyms_local(ksyms);
}
+/* Attaching to inlined functions is supported only on x86_64. */
+static bool inline_attach_supported(void)
+{
+#ifdef __x86_64__
+ return true;
+#else
+ return false;
+#endif
+}
+
static void test_kprobe_multi_bench_attach_addr(bool kernel)
{
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
@@ -703,6 +714,207 @@ static void test_attach_probe_dup_sym(void)
kprobe_multi__destroy(skel);
}
+#define INLINE_MAX 8
+
+/*
+ * Get addresses of inlined instances of @func from inline.text LOCSEC
+ * of @inline_btf, the offsets are relative to @base. Returns number of
+ * instances or -ENOENT if there's no such LOCSEC.
+ */
+static int find_inline_sites(struct btf *inline_btf, unsigned long base, const char *func,
+ unsigned long *addrs, int max)
+{
+ const struct btf_type *t, *ft;
+ struct btf_loc *l;
+ int id, i, n, cnt = 0;
+
+ id = btf__find_by_name_kind(inline_btf, "inline.text", BTF_KIND_LOCSEC);
+ if (id < 0)
+ return -ENOENT;
+
+ t = btf__type_by_id(inline_btf, id);
+ n = btf_vlen(t);
+ for (i = 0, l = btf_locsec_locs(t); i < n; i++, l++) {
+ ft = btf__type_by_id(inline_btf, l->func);
+ if (!ft || strcmp(btf__name_by_offset(inline_btf, ft->name_off), func))
+ continue;
+ if (!ASSERT_LT(cnt, max, "inline_sites_max"))
+ return -EINVAL;
+ addrs[cnt++] = base + l->offset;
+ }
+ return cnt;
+}
+
+/* BTF used to find inlined instances, loaded once on first use. */
+static struct btf *vmlinux_btf;
+static struct btf *vmlinux_inline_btf;
+
+static struct btf *get_vmlinux_btf(void)
+{
+ if (!vmlinux_btf)
+ vmlinux_btf = btf__load_vmlinux_btf();
+ return vmlinux_btf;
+}
+
+/*
+ * Get split BTF from @path on top of @base, it's parsed just once and
+ * stored in @cache. Returns 0 on success or negative error.
+ */
+static int get_split_btf(struct btf **cache, const char *path, struct btf *base)
+{
+ struct btf *btf;
+ int err;
+
+ if (*cache)
+ return 0;
+
+ btf = btf__parse_split(path, base);
+ err = libbpf_get_error(btf);
+ if (err)
+ return err;
+ *cache = btf;
+ return 0;
+}
+
+static void free_inline_btf(void)
+{
+ btf__free(vmlinux_inline_btf);
+ btf__free(vmlinux_btf);
+ vmlinux_inline_btf = vmlinux_btf = NULL;
+}
+
+/*
+ * Get addresses of inlined instances of @func from vmlinux inline BTF.
+ * Returns number of instances or -ENOENT if there's no inline BTF.
+ */
+static int get_inline_sites(const char *func, unsigned long *addrs, int max)
+{
+ static unsigned long base;
+ int err;
+
+ /* LOCSEC offsets are relative to the .text section base. */
+ if (!base)
+ base = ksym_get_addr("_stext");
+ if (!ASSERT_NEQ(base, 0, "stext_addr"))
+ return -EINVAL;
+
+ if (!ASSERT_OK_PTR(get_vmlinux_btf(), "vmlinux_btf"))
+ return -EINVAL;
+
+ err = get_split_btf(&vmlinux_inline_btf, "/sys/kernel/btf/vmlinux.inline", vmlinux_btf);
+ if (err) {
+ /* pahole may not have inline BTF feature support. */
+ if (err != -ENOENT)
+ ASSERT_OK(err, "parse_inline_btf");
+ return err;
+ }
+
+ return find_inline_sites(vmlinux_inline_btf, base, func, addrs, max);
+}
+
+static int inline_hits(struct kprobe_multi_inline *skel, unsigned long ip, __u64 cookie)
+{
+ int i, cnt = 0;
+
+ for (i = 0; i < skel->bss->hits_cnt; i++) {
+ if (skel->bss->hits_ip[i] == ip && skel->bss->hits_cookie[i] == cookie)
+ cnt++;
+ }
+ return cnt;
+}
+
+static void inline_trigger(struct kprobe_multi_inline *skel)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ int err;
+
+ skel->bss->hits_cnt = 0;
+ err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.trigger), &topts);
+ ASSERT_OK(err, "test_run");
+ ASSERT_EQ(topts.retval, 0, "test_run");
+}
+
+/* Each inlined instance must be hit just once with its function cookie. */
+static void inline_check_sites(struct kprobe_multi_inline *skel, unsigned long *addrs,
+ int cnt, __u64 cookie)
+{
+ int i;
+
+ for (i = 0; i < cnt; i++)
+ ASSERT_EQ(inline_hits(skel, addrs[i], cookie), 1, "inline_site_hit");
+}
+
+static void test_inline_attach(void)
+{
+ const char *syms[2] = { "bpf_kprobe_multi_inline_outer",
+ "bpf_kprobe_multi_inline_inner" };
+ unsigned long inner[INLINE_MAX], outer[INLINE_MAX];
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ struct kprobe_multi_inline *skel = NULL;
+ __u64 cookies[2] = { 2, 1 };
+ int inner_cnt, outer_cnt;
+
+ inner_cnt = get_inline_sites(syms[1], inner, INLINE_MAX);
+ outer_cnt = get_inline_sites(syms[0], outer, INLINE_MAX);
+ if (inner_cnt == -ENOENT || outer_cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+
+ /* inner is inlined in both callers, outer just in the first one */
+ if (!ASSERT_EQ(inner_cnt, 2, "inner_cnt") || !ASSERT_EQ(outer_cnt, 1, "outer_cnt"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cookies = cookies;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ /*
+ * The outer instance is usually on the same address as one of
+ * the inner instances, each of them needs to get its own cookie.
+ */
+ ASSERT_EQ(skel->bss->hits_cnt, inner_cnt + outer_cnt, "hits_cnt");
+ inline_check_sites(skel, inner, inner_cnt, 1);
+ inline_check_sites(skel, outer, outer_cnt, 2);
+
+ /* Make sure the probes are gone after detach. */
+ kprobe_multi_inline__detach(skel);
+
+ inline_trigger(skel);
+ ASSERT_EQ(skel->bss->hits_cnt, 0, "hits_cnt_detached");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
+/* Run all the tests for attaching to inlined functions. */
+static void test_inline_subtests(void)
+{
+ if (!inline_attach_supported()) {
+ test__skip();
+ return;
+ }
+
+ if (test__start_subtest("inline_attach"))
+ test_inline_attach();
+
+ free_inline_btf();
+}
+
void serial_test_kprobe_multi_bench_attach(void)
{
if (test__start_subtest("kernel"))
@@ -748,5 +960,6 @@ void test_kprobe_multi_test(void)
test_attach_write_ctx();
if (test__start_subtest("dup_sym"))
test_attach_probe_dup_sym();
+ test_inline_subtests();
RUN_TESTS(kprobe_multi_verifier);
}
diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
new file mode 100644
index 000000000000..f23f79f540fd
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+#define MAX_HITS 16
+
+int pid = 0;
+
+__u64 hits_ip[MAX_HITS];
+__u64 hits_cookie[MAX_HITS];
+__u32 hits_cnt = 0;
+
+/*
+ * No tests in here, just to trigger 'bpf_kprobe_multi_inline_test*'
+ * through tracing test_run
+ */
+SEC("fentry/bpf_modify_return_test")
+int BPF_PROG(trigger)
+{
+ return 0;
+}
+
+SEC("kprobe.multi")
+int test_kprobe_inline(struct pt_regs *ctx)
+{
+ __u32 idx = hits_cnt;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ if (idx >= MAX_HITS)
+ return 0;
+
+ hits_ip[idx] = bpf_get_func_ip(ctx);
+ hits_cookie[idx] = bpf_get_attach_cookie(ctx);
+ hits_cnt = idx + 1;
+ return 0;
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (22 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
` (6 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_mixed test that attaches function with entry probe and
inlined function in single kprobe multi link, and checks that both
the function entry and the inlined instances are hit once with
their cookies.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index e54db60427c3..1ff918dd100f 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -901,6 +901,54 @@ static void test_inline_attach(void)
kprobe_multi_inline__destroy(skel);
}
+/* Attach function with entry probe and inlined function in single link. */
+static void test_inline_mixed(void)
+{
+ const char *syms[2] = { "bpf_kprobe_multi_inline_inner", "bpf_fentry_test1" };
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ struct kprobe_multi_inline *skel = NULL;
+ unsigned long inner[INLINE_MAX], addr;
+ __u64 cookies[2] = { 6, 5 };
+ int inner_cnt;
+
+ inner_cnt = get_inline_sites(syms[0], inner, INLINE_MAX);
+ if (inner_cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(inner_cnt, 2, "inner_cnt"))
+ return;
+
+ addr = ksym_get_addr("bpf_fentry_test1");
+ if (!ASSERT_NEQ(addr, 0, "bpf_fentry_test1_addr"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cookies = cookies;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ ASSERT_EQ(skel->bss->hits_cnt, inner_cnt + 1, "hits_cnt");
+ ASSERT_EQ(inline_hits(skel, addr, 5), 1, "entry_hit");
+ inline_check_sites(skel, inner, inner_cnt, 6);
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/* Run all the tests for attaching to inlined functions. */
static void test_inline_subtests(void)
{
@@ -911,6 +959,8 @@ static void test_inline_subtests(void)
if (test__start_subtest("inline_attach"))
test_inline_attach();
+ if (test__start_subtest("inline_mixed"))
+ test_inline_mixed();
free_inline_btf();
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (23 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
` (5 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_skip test that attaches function with one inlined
instance that can be attached and one that can't, and checks the
second one is skipped.
Also check the attach fails for function that has no entry and its
only inlined instance can't be attached.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 102 ++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 1ff918dd100f..f6556bd9f2d0 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -487,6 +487,33 @@ static void test_unique_match(void)
kprobe_multi__destroy(skel);
}
+/*
+ * Get value of the @name counter from fdinfo of kprobe multi link.
+ *
+ * The same counters are available also in link info, but we want to
+ * have fdinfo tested as well and link info has its own test in
+ * fill_link_info.c.
+ */
+static long get_fdinfo_cnt(int link_fd, const char *name)
+{
+ char path[64], buf[256], fmt[64];
+ long cnt = -1;
+ FILE *f;
+
+ snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", link_fd);
+ f = fopen(path, "r");
+ if (!ASSERT_OK_PTR(f, "open_fdinfo"))
+ return -1;
+
+ snprintf(fmt, sizeof(fmt), "%s:\t%%ld", name);
+ while (fgets(buf, sizeof(buf), f)) {
+ if (sscanf(buf, fmt, &cnt) == 1)
+ break;
+ }
+ fclose(f);
+ return cnt;
+}
+
static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_multi_opts *opts)
{
long attach_start_ns, attach_end_ns;
@@ -949,6 +976,79 @@ static void test_inline_mixed(void)
kprobe_multi_inline__destroy(skel);
}
+/* Inlined instances that can't be attached are skipped. */
+static void test_inline_skip(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ const char *syms[1] = { "bpf_kprobe_multi_inline_partial" };
+ const char *nosyms[1] = { "bpf_kprobe_multi_inline_nokprobe" };
+ struct kprobe_multi_inline *skel = NULL;
+ unsigned long sites[INLINE_MAX];
+ __u64 cookies[1] = { 8 };
+ int cnt, i, saved_error, link_fd;
+ struct ksym *ksym;
+ bool attached;
+
+ cnt = get_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+
+ /* One instance in function that kprobes can attach and one that can't. */
+ if (!ASSERT_EQ(cnt, 2, "inline_sites_cnt"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cookies = cookies;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ link_fd = bpf_link__fd(skel->links.test_kprobe_inline);
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_cnt"), 1, "kprobe_inline_cnt");
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_skipped"), 1, "kprobe_inline_skipped");
+
+ inline_trigger(skel);
+
+ /* Only the instance outside of the nokprobe function is hit. */
+ ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+
+ for (i = 0; i < cnt; i++) {
+ ksym = ksym_search(sites[i]);
+ if (!ASSERT_OK_PTR(ksym, "ksym_search"))
+ continue;
+ attached = !strcmp(ksym->name, "bpf_kprobe_multi_inline_test3");
+ ASSERT_EQ(inline_hits(skel, sites[i], 8), attached ? 1 : 0, "inline_site_hit");
+ }
+
+ kprobe_multi_inline__detach(skel);
+
+ /* Function with no entry and all inlined instances skipped fails to attach. */
+ opts.syms = nosyms;
+ opts.cookies = NULL;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "attach_nokprobe"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "attach_nokprobe_error");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/* Run all the tests for attaching to inlined functions. */
static void test_inline_subtests(void)
{
@@ -961,6 +1061,8 @@ static void test_inline_subtests(void)
test_inline_attach();
if (test__start_subtest("inline_mixed"))
test_inline_mixed();
+ if (test__start_subtest("inline_skip"))
+ test_inline_skip();
free_inline_btf();
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (24 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
` (4 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_fails test for attach failures of kprobe multi link with
BPF_F_KPROBE_MULTI_INLINE flag: used with addrs, with return probe,
with session program, with wildcard pattern and for function that
has nothing to attach.
Most of the setups are rejected by libbpf already, so they are
tested also through bpf_link_create to check the kernel error and
the message in the link_create log.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 168 ++++++++++++++++++
.../selftests/bpf/progs/kprobe_multi_inline.c | 6 +
2 files changed, 174 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index f6556bd9f2d0..3f5d5b5198e6 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1049,6 +1049,172 @@ static void test_inline_skip(void)
kprobe_multi_inline__destroy(skel);
}
+/*
+ * Make sure the link create fails with @error and kernel explains
+ * the failure with @msg in the log.
+ */
+static bool inline_link_fails(int prog_fd, enum bpf_attach_type type,
+ struct bpf_link_create_opts *lopts,
+ int error, const char *msg)
+{
+ LIBBPF_OPTS(bpf_log_opts, log_opts);
+ char log_buf[4096] = {};
+ int saved_error, link_fd;
+
+ log_opts.buf = log_buf;
+ log_opts.size = sizeof(log_buf);
+ log_opts.level = 1;
+ lopts->log_opts = &log_opts;
+
+ link_fd = bpf_link_create(prog_fd, 0, type, lopts);
+ saved_error = -errno;
+ if (!ASSERT_LT(link_fd, 0, "link_create")) {
+ close(link_fd);
+ return false;
+ }
+ ASSERT_EQ(saved_error, error, "link_create_error");
+ ASSERT_HAS_SUBSTR(log_buf, msg, "link_create_log");
+ return true;
+}
+
+/*
+ * Most of the invalid inline setups are rejected by libbpf before
+ * it gets to the kernel, so each setup is tested twice:
+ *
+ * - through bpf_program__attach_kprobe_multi_opts to test the libbpf check,
+ * - through bpf_link_create (inline_link_fails) to test the kernel check
+ * together with the failure message in the kernel log, which libbpf
+ * does not pass to the caller.
+ */
+static void test_inline_fails(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ LIBBPF_OPTS(bpf_link_create_opts, lopts);
+ struct kprobe_multi_inline *skel = NULL;
+ const char *syms[1] = { "bpf_kprobe_multi_inline_inner" };
+ const char *nosyms[1] = { "bpf_kprobe_multi_inline_nonexistent" };
+ const char *nokprobe[1] = { "bpf_kprobe_multi_inline_nokprobe" };
+ unsigned long inner[INLINE_MAX], addrs[1];
+ int saved_error, prog_fd;
+
+ if (get_inline_sites(syms[0], inner, INLINE_MAX) == -ENOENT) {
+ test__skip();
+ return;
+ }
+
+ addrs[0] = ksym_get_addr("bpf_fentry_test1");
+ if (!ASSERT_NEQ(addrs[0], 0, "bpf_fentry_test1_addr"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ prog_fd = bpf_program__fd(skel->progs.test_kprobe_inline);
+
+ /* fail_1 - inlined with addrs */
+ opts.addrs = addrs;
+ opts.cnt = 1;
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "fail_1"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "fail_1_error");
+
+ lopts.kprobe_multi.addrs = addrs;
+ lopts.kprobe_multi.cnt = 1;
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE;
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Inlined functions need to be specified with kprobe_multi.syms."))
+ goto cleanup;
+
+ /* fail_2 - inlined with return probe */
+ LIBBPF_OPTS_RESET(opts,
+ .syms = syms,
+ .cnt = 1,
+ .inlined = true,
+ .retprobe = true,
+ );
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "fail_2"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "fail_2_error");
+
+ LIBBPF_OPTS_RESET(lopts,
+ .kprobe_multi.syms = syms,
+ .kprobe_multi.cnt = 1,
+ .kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE | BPF_F_KPROBE_MULTI_RETURN,
+ );
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Inlined functions can't be attached with return probe."))
+ goto cleanup;
+
+ /* fail_3 - inlined with session program */
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE;
+
+ if (!inline_link_fails(bpf_program__fd(skel->progs.test_session_inline),
+ BPF_TRACE_KPROBE_SESSION, &lopts, -EINVAL,
+ "Inlined functions can't be attached with session or override "
+ "program."))
+ goto cleanup;
+
+ /* fail_4 - inlined with wildcard pattern */
+ LIBBPF_OPTS_RESET(opts,
+ .inlined = true,
+ );
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline,
+ "bpf_kprobe_multi_inline_*", &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "fail_4"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "fail_4_error");
+
+ /* fail_5 - function with no entry and no inlined instance */
+ LIBBPF_OPTS_RESET(opts,
+ .syms = nosyms,
+ .cnt = 1,
+ .inlined = true,
+ );
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "fail_5"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -ENOENT, "fail_5_error");
+
+ LIBBPF_OPTS_RESET(lopts,
+ .kprobe_multi.syms = nosyms,
+ .kprobe_multi.cnt = 1,
+ .kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE,
+ );
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -ESRCH,
+ "Function bpf_kprobe_multi_inline_nonexistent has no entry and "
+ "no inlined instance."))
+ goto cleanup;
+
+ /* fail_6 - function with no entry and no inlined instance that can be attached */
+ lopts.kprobe_multi.syms = nokprobe;
+
+ inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Function bpf_kprobe_multi_inline_nokprobe has no entry and none of its "
+ "inlined instances can be attached, bpf_kprobe_multi_inline_test4+");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/* Run all the tests for attaching to inlined functions. */
static void test_inline_subtests(void)
{
@@ -1063,6 +1229,8 @@ static void test_inline_subtests(void)
test_inline_mixed();
if (test__start_subtest("inline_skip"))
test_inline_skip();
+ if (test__start_subtest("inline_fails"))
+ test_inline_fails();
free_inline_btf();
}
diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
index f23f79f540fd..f2b428292544 100644
--- a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
+++ b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
@@ -39,3 +39,9 @@ int test_kprobe_inline(struct pt_regs *ctx)
hits_cnt = idx + 1;
return 0;
}
+
+SEC("kprobe.session")
+int test_session_inline(struct pt_regs *ctx)
+{
+ return 0;
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (25 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
` (3 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_module test that attaches function inlined in bpf_testmod
module with BPF_F_KPROBE_MULTI_INLINE flag and checks its inlined
instance is hit once with the function cookie and that the probe
is gone after detach.
The expected address of the inlined instance is read from bpf_testmod
inline BTF, the test is skipped if it's not available.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 115 +++++++++++++++++-
1 file changed, 114 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 3f5d5b5198e6..761cd7fe63ac 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -775,6 +775,8 @@ static int find_inline_sites(struct btf *inline_btf, unsigned long base, const c
/* BTF used to find inlined instances, loaded once on first use. */
static struct btf *vmlinux_btf;
static struct btf *vmlinux_inline_btf;
+static struct btf *testmod_btf;
+static struct btf *testmod_inline_btf;
static struct btf *get_vmlinux_btf(void)
{
@@ -805,9 +807,11 @@ static int get_split_btf(struct btf **cache, const char *path, struct btf *base)
static void free_inline_btf(void)
{
+ btf__free(testmod_inline_btf);
+ btf__free(testmod_btf);
btf__free(vmlinux_inline_btf);
btf__free(vmlinux_btf);
- vmlinux_inline_btf = vmlinux_btf = NULL;
+ testmod_inline_btf = testmod_btf = vmlinux_inline_btf = vmlinux_btf = NULL;
}
/*
@@ -839,6 +843,56 @@ static int get_inline_sites(const char *func, unsigned long *addrs, int max)
return find_inline_sites(vmlinux_inline_btf, base, func, addrs, max);
}
+/* Get address of bpf_testmod .text section, zero if it's not available. */
+static unsigned long get_testmod_text_addr(void)
+{
+ static unsigned long addr;
+ FILE *f;
+
+ if (addr)
+ return addr;
+
+ f = fopen("/sys/module/bpf_testmod/sections/.text", "r");
+ if (!f)
+ return 0;
+ if (fscanf(f, "%lx", &addr) != 1)
+ addr = 0;
+ fclose(f);
+ return addr;
+}
+
+/*
+ * Get addresses of inlined instances of @func from bpf_testmod inline BTF.
+ * Returns number of instances or -ENOENT if there's no inline BTF.
+ */
+static int get_testmod_inline_sites(const char *func, unsigned long *addrs, int max)
+{
+ unsigned long base;
+ int err;
+
+ /* LOCSEC offsets are relative to the module .text section base. */
+ base = get_testmod_text_addr();
+ if (!ASSERT_NEQ(base, 0, "testmod_text_addr"))
+ return -EINVAL;
+
+ if (!ASSERT_OK_PTR(get_vmlinux_btf(), "vmlinux_btf"))
+ return -EINVAL;
+
+ err = get_split_btf(&testmod_btf, "/sys/kernel/btf/bpf_testmod", vmlinux_btf);
+ if (!ASSERT_OK(err, "testmod_btf"))
+ return -EINVAL;
+
+ err = get_split_btf(&testmod_inline_btf, "/sys/kernel/btf/bpf_testmod.inline", testmod_btf);
+ if (err) {
+ /* pahole may not have inline BTF feature support. */
+ if (err != -ENOENT)
+ ASSERT_OK(err, "parse_testmod_inline_btf");
+ return err;
+ }
+
+ return find_inline_sites(testmod_inline_btf, base, func, addrs, max);
+}
+
static int inline_hits(struct kprobe_multi_inline *skel, unsigned long ip, __u64 cookie)
{
int i, cnt = 0;
@@ -1049,6 +1103,63 @@ static void test_inline_skip(void)
kprobe_multi_inline__destroy(skel);
}
+/* Attach inlined function in kernel module. */
+static void test_inline_module(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ const char *syms[1] = { "bpf_testmod_kprobe_multi_inline" };
+ struct kprobe_multi_inline *skel = NULL;
+ unsigned long sites[INLINE_MAX];
+ __u64 cookies[1] = { 7 };
+ struct ksym *ksym;
+ int cnt;
+
+ cnt = get_testmod_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(cnt, 1, "sites_cnt"))
+ return;
+
+ ksym = ksym_search(sites[0]);
+ if (!ASSERT_OK_PTR(ksym, "ksym_search"))
+ return;
+ ASSERT_STREQ(ksym->name, "bpf_testmod_kprobe_multi_inline_test", "inline_site_caller");
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cookies = cookies;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ skel->bss->hits_cnt = 0;
+ ASSERT_OK(trigger_module_test_read(1), "trigger_read");
+
+ ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+ ASSERT_EQ(inline_hits(skel, sites[0], 7), 1, "inline_site_hit");
+
+ /* Make sure the probe is gone after detach. */
+ kprobe_multi_inline__detach(skel);
+
+ skel->bss->hits_cnt = 0;
+ ASSERT_OK(trigger_module_test_read(1), "trigger_read");
+ ASSERT_EQ(skel->bss->hits_cnt, 0, "hits_cnt_detached");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/*
* Make sure the link create fails with @error and kernel explains
* the failure with @msg in the log.
@@ -1231,6 +1342,8 @@ static void test_inline_subtests(void)
test_inline_skip();
if (test__start_subtest("inline_fails"))
test_inline_fails();
+ if (test__start_subtest("inline_module"))
+ test_inline_module();
free_inline_btf();
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (26 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test Jiri Olsa
` (2 subsequent siblings)
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_strict test for kprobe multi link with
BPF_F_KPROBE_MULTI_INLINE_STRICT flag:
- the attach fails when the flag is used without
BPF_F_KPROBE_MULTI_INLINE flag
- the attach fails for function with inlined instance that can't
be attached, and the log names the function and the instance
- the attach succeeds for function with all the inlined instances
attached and link's fdinfo shows no skipped instance
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 82 +++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 761cd7fe63ac..f3eb95261c7a 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1326,6 +1326,86 @@ static void test_inline_fails(void)
kprobe_multi_inline__destroy(skel);
}
+/* With strict flag all the inlined instances need to be attached. */
+static void test_inline_strict(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ LIBBPF_OPTS(bpf_link_create_opts, lopts);
+ const char *partial[1] = { "bpf_kprobe_multi_inline_partial" };
+ const char *syms[1] = { "bpf_kprobe_multi_inline_inner" };
+ struct kprobe_multi_inline *skel = NULL;
+ unsigned long sites[INLINE_MAX];
+ int cnt, saved_error, prog_fd, link_fd;
+
+ cnt = get_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(cnt, 2, "inline_sites_cnt"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ prog_fd = bpf_program__fd(skel->progs.test_kprobe_inline);
+
+ /* strict without inlined */
+ opts.syms = syms;
+ opts.cnt = 1;
+ opts.inlined_strict = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "strict_no_inlined"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "strict_no_inlined_error");
+
+ lopts.kprobe_multi.syms = syms;
+ lopts.kprobe_multi.cnt = 1;
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE_STRICT;
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Strict flag needs to be used with inline flag."))
+ goto cleanup;
+
+ /* function with inlined instance that can't be attached */
+ opts.syms = partial;
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "strict_partial"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "strict_partial_error");
+
+ lopts.kprobe_multi.syms = partial;
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE | BPF_F_KPROBE_MULTI_INLINE_STRICT;
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Function bpf_kprobe_multi_inline_partial has inlined instance "
+ "that can't be attached, bpf_kprobe_multi_inline_test4+"))
+ goto cleanup;
+
+ /* function with all the inlined instances attached */
+ opts.syms = syms;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "strict_attach"))
+ goto cleanup;
+
+ link_fd = bpf_link__fd(skel->links.test_kprobe_inline);
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_cnt"), cnt, "kprobe_inline_cnt");
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_skipped"), 0, "kprobe_inline_skipped");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/* Run all the tests for attaching to inlined functions. */
static void test_inline_subtests(void)
{
@@ -1344,6 +1424,8 @@ static void test_inline_subtests(void)
test_inline_fails();
if (test__start_subtest("inline_module"))
test_inline_module();
+ if (test__start_subtest("inline_strict"))
+ test_inline_strict();
free_inline_btf();
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (27 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add inline_args and inline_args_module tests for bpf_get_func_arg
and bpf_get_func_arg_cnt helpers used in kprobe multi program, for
inlined function in kernel and module and for function with entry
probe.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 185 ++++++++++++++++++
.../selftests/bpf/progs/kprobe_multi_inline.c | 32 +++
2 files changed, 217 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index f3eb95261c7a..6ae5bfaa81ba 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1160,6 +1160,187 @@ static void test_inline_module(void)
kprobe_multi_inline__destroy(skel);
}
+#define INLINE_ARGS_CNT 3
+
+/*
+ * The probe on @ip must be hit just once and see @exp arguments,
+ * anything above that needs to fail.
+ */
+static void inline_check_args(struct kprobe_multi_inline *skel, unsigned long ip,
+ const __u64 *exp)
+{
+ int i, idx = -1;
+
+ if (!ASSERT_EQ(inline_hits(skel, ip, 0), 1, "args_hit"))
+ return;
+
+ for (i = 0; i < skel->bss->hits_cnt; i++) {
+ if (skel->bss->hits_ip[i] == ip)
+ idx = i;
+ }
+
+ ASSERT_EQ(skel->bss->args_cnt[idx], INLINE_ARGS_CNT, "args_cnt");
+
+ for (i = 0; i < INLINE_ARGS_CNT; i++) {
+ ASSERT_OK(skel->bss->args_err[idx][i], "args_err");
+ /* The arguments have different sizes, check the lower part. */
+ ASSERT_EQ((__u32)skel->bss->args_val[idx][i], (__u32)exp[i], "args_val");
+ }
+
+ ASSERT_EQ(skel->bss->args_err[idx][i], -EINVAL, "args_err_last");
+}
+
+/*
+ * Get arguments of inlined function and of function with entry probe
+ * in single link. The arguments of function with entry probe work also
+ * for link without inline flag, but not for return probe.
+ */
+static void test_inline_args(void)
+{
+ const char *syms[2] = { "bpf_kprobe_multi_inline_args", "bpf_fentry_test3" };
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ struct kprobe_multi_inline *skel = NULL;
+ __u64 exp_entry[INLINE_ARGS_CNT] = { 4, 5, 6 };
+ __u64 exp[INLINE_ARGS_CNT] = { 1, 2, 3 };
+ unsigned long sites[INLINE_MAX], addr;
+ int cnt, i;
+
+ cnt = get_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(cnt, 1, "sites_cnt"))
+ return;
+
+ addr = ksym_get_addr("bpf_fentry_test3");
+ if (!ASSERT_NEQ(addr, 0, "bpf_fentry_test3_addr"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline_args =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ ASSERT_EQ(skel->bss->hits_cnt, 2, "hits_cnt");
+ inline_check_args(skel, sites[0], exp);
+ inline_check_args(skel, addr, exp_entry);
+
+ kprobe_multi_inline__detach(skel);
+
+ /* Function with entry probe has arguments also without inline flag. */
+ opts.syms = &syms[1];
+ opts.cnt = 1;
+ opts.inlined = false;
+
+ skel->links.test_kprobe_inline_args =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+ inline_check_args(skel, addr, exp_entry);
+
+ kprobe_multi_inline__detach(skel);
+
+ /* The same for function specified by address. */
+ opts.syms = NULL;
+ opts.addrs = &addr;
+
+ skel->links.test_kprobe_inline_args =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+ inline_check_args(skel, addr, exp_entry);
+
+ kprobe_multi_inline__detach(skel);
+
+ /* There are no arguments in return probe. */
+ opts.retprobe = true;
+
+ skel->links.test_kprobe_inline_args =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ inline_trigger(skel);
+
+ if (!ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt"))
+ goto cleanup;
+ ASSERT_EQ(skel->bss->args_cnt[0], 0, "args_cnt");
+ for (i = 0; i < INLINE_ARGS_CNT; i++)
+ ASSERT_EQ(skel->bss->args_err[0][i], -EOPNOTSUPP, "args_err");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
+/* Get arguments of function inlined in module. */
+static void test_inline_args_module(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ const char *syms[1] = { "bpf_testmod_kprobe_multi_inline_args" };
+ struct kprobe_multi_inline *skel = NULL;
+ __u64 exp[INLINE_ARGS_CNT] = { 1, 2, 3 };
+ unsigned long sites[INLINE_MAX];
+ int cnt;
+
+ cnt = get_testmod_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(cnt, 1, "sites_cnt"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ skel->bss->pid = getpid();
+
+ opts.syms = syms;
+ opts.cnt = ARRAY_SIZE(syms);
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline_args =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+ NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+ goto cleanup;
+
+ skel->bss->hits_cnt = 0;
+ ASSERT_OK(trigger_module_test_read(1), "trigger_read");
+
+ ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+ inline_check_args(skel, sites[0], exp);
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/*
* Make sure the link create fails with @error and kernel explains
* the failure with @msg in the log.
@@ -1426,6 +1607,10 @@ static void test_inline_subtests(void)
test_inline_module();
if (test__start_subtest("inline_strict"))
test_inline_strict();
+ if (test__start_subtest("inline_args"))
+ test_inline_args();
+ if (test__start_subtest("inline_args_module"))
+ test_inline_args_module();
free_inline_btf();
}
diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
index f2b428292544..a57e79f7c640 100644
--- a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
+++ b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
@@ -6,6 +6,7 @@
char _license[] SEC("license") = "GPL";
#define MAX_HITS 16
+#define MAX_ARGS 4
int pid = 0;
@@ -13,6 +14,10 @@ __u64 hits_ip[MAX_HITS];
__u64 hits_cookie[MAX_HITS];
__u32 hits_cnt = 0;
+__u64 args_cnt[MAX_HITS];
+__u64 args_val[MAX_HITS][MAX_ARGS];
+long args_err[MAX_HITS][MAX_ARGS];
+
/*
* No tests in here, just to trigger 'bpf_kprobe_multi_inline_test*'
* through tracing test_run
@@ -40,6 +45,33 @@ int test_kprobe_inline(struct pt_regs *ctx)
return 0;
}
+SEC("kprobe.multi")
+int test_kprobe_inline_args(struct pt_regs *ctx)
+{
+ __u32 idx = hits_cnt;
+ __u64 val;
+ int i;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ if (idx >= MAX_HITS)
+ return 0;
+
+ hits_ip[idx] = bpf_get_func_ip(ctx);
+ hits_cookie[idx] = bpf_get_attach_cookie(ctx);
+ args_cnt[idx] = bpf_get_func_arg_cnt(ctx);
+
+ for (i = 0; i < MAX_ARGS; i++) {
+ val = 0;
+ args_err[idx][i] = bpf_get_func_arg(ctx, i, &val);
+ args_val[idx][i] = val;
+ }
+
+ hits_cnt = idx + 1;
+ return 0;
+}
+
SEC("kprobe.session")
int test_session_inline(struct pt_regs *ctx)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (28 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Add kernel_inline and modules_inline subtests to the
kprobe_multi_bench_attach test that attach all attachable functions
with BPF_F_KPROBE_MULTI_INLINE flag, so the link is attached also to
all their inlined instances.
On top of the attach/detach times the test prints the number of
attached and skipped inlined instances from the link's fdinfo.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/kprobe_multi_test.c | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 6ae5bfaa81ba..c403d1cb9d9e 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -520,6 +520,7 @@ static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_mul
long detach_start_ns, detach_end_ns;
double attach_delta, detach_delta;
struct bpf_link *link = NULL;
+ long inline_cnt = 0, inline_skipped = 0;
attach_start_ns = get_time_ns();
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_empty,
@@ -529,6 +530,11 @@ static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_mul
if (!ASSERT_OK_PTR(link, "bpf_program__attach_kprobe_multi_opts"))
return;
+ if (opts->inlined) {
+ inline_cnt = get_fdinfo_cnt(bpf_link__fd(link), "kprobe_inline_cnt");
+ inline_skipped = get_fdinfo_cnt(bpf_link__fd(link), "kprobe_inline_skipped");
+ }
+
detach_start_ns = get_time_ns();
bpf_link__destroy(link);
detach_end_ns = get_time_ns();
@@ -537,6 +543,10 @@ static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_mul
detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
printf("%s: found %lu functions\n", __func__, opts->cnt);
+ if (opts->inlined) {
+ printf("%s: attached %ld inlined instances, skipped %ld\n", __func__,
+ inline_cnt, inline_skipped);
+ }
printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
}
@@ -574,6 +584,42 @@ static bool inline_attach_supported(void)
#endif
}
+/* Attach all attachable functions together with their inlined instances. */
+static void test_kprobe_multi_bench_attach_inline(bool kernel)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ struct kprobe_multi_empty *skel = NULL;
+ struct ksyms *ksyms = NULL;
+
+ if (!inline_attach_supported()) {
+ test__skip();
+ return;
+ }
+
+ /* pahole may not have inline BTF feature support. */
+ if (access("/sys/kernel/btf/vmlinux.inline", F_OK)) {
+ test__skip();
+ return;
+ }
+
+ if (!ASSERT_OK(bpf_get_ksyms(&ksyms, kernel), "bpf_get_ksyms"))
+ return;
+
+ skel = kprobe_multi_empty__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_empty__open_and_load"))
+ goto cleanup;
+
+ opts.syms = (const char **)ksyms->filtered_syms;
+ opts.cnt = ksyms->filtered_cnt;
+ opts.inlined = true;
+
+ do_bench_test(skel, &opts);
+
+cleanup:
+ kprobe_multi_empty__destroy(skel);
+ free_kallsyms_local(ksyms);
+}
+
static void test_kprobe_multi_bench_attach_addr(bool kernel)
{
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
@@ -1625,6 +1671,10 @@ void serial_test_kprobe_multi_bench_attach(void)
test_kprobe_multi_bench_attach_addr(true);
if (test__start_subtest("modules"))
test_kprobe_multi_bench_attach_addr(false);
+ if (test__start_subtest("kernel_inline"))
+ test_kprobe_multi_bench_attach_inline(true);
+ if (test__start_subtest("modules_inline"))
+ test_kprobe_multi_bench_attach_inline(false);
}
void test_kprobe_multi_test(void)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
* [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
` (29 preceding siblings ...)
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
@ 2026-12-02 12:30 ` Jiri Olsa
30 siblings, 0 replies; 32+ messages in thread
From: Jiri Olsa @ 2026-12-02 12:30 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Masami Hiramatsu
Cc: bpf, linux-trace-kernel, linux-kernel, x86, Song Liu,
Yonghong Song, Quentin Monnet, Alan Maguire
Adding fill_link_info tests for kprobe multi link with inlined
instances attached:
- kprobe_multi_inline_link_info checks the addresses, cookies and
BTF ids of the inlined instances and the number of attached and
skipped instances
- kprobe_multi_inline_invalid_ubuff checks the errors returned for
wrong setup of the inline link info fields
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../selftests/bpf/prog_tests/fill_link_info.c | 251 ++++++++++++++++++
1 file changed, 251 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index 0918321c8e63..e4ad210b40b8 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -413,6 +413,253 @@ static void test_kprobe_multi_fill_link_info(struct test_fill_link_info *skel,
bpf_link__destroy(link);
}
+/*
+ * The first function is attached on its entry, the rest through inlined
+ * instances: outer is inlined in one caller, inner in two and partial has
+ * one instance that is attached and one that can't be attached and is
+ * skipped.
+ */
+static const char *kmulti_inline_syms[] = {
+ "bpf_fentry_test1",
+ "bpf_kprobe_multi_inline_outer",
+ "bpf_kprobe_multi_inline_inner",
+ "bpf_kprobe_multi_inline_partial",
+};
+static __u64 kmulti_inline_cookies[] = { 1, 2, 3, 4 };
+static int kmulti_inline_cnts[] = { 0, 1, 2, 1 };
+#define KMULTI_INLINE_CNT 4
+
+/*
+ * Check the inline.text LOCSEC of @btf has inlined instance of function
+ * with BTF id @id on address @addr.
+ */
+static bool kmulti_inline_has_loc(const struct btf *btf, __u32 id, __u64 addr)
+{
+ /* LOCSEC offsets are relative to the .text section base. */
+ __u64 base = ksym_get_addr("_stext");
+ const struct btf_type *t;
+ struct btf_loc *loc;
+ int i, n, locsec;
+
+ locsec = btf__find_by_name_kind(btf, "inline.text", BTF_KIND_LOCSEC);
+ if (!ASSERT_GT(locsec, 0, "inline_locsec"))
+ return false;
+
+ t = btf__type_by_id(btf, locsec);
+ n = btf_vlen(t);
+ for (i = 0, loc = btf_locsec_locs(t); i < n; i++, loc++) {
+ if (loc->func == id && base + loc->offset == addr)
+ return true;
+ }
+ return false;
+}
+
+static int verify_kmulti_inline_link_info(int fd, const struct btf *btf)
+{
+ __u64 inline_addrs[KMULTI_INLINE_CNT], inline_cookies[KMULTI_INLINE_CNT];
+ int cnts[ARRAY_SIZE(kmulti_inline_syms)] = {}, i, j, err;
+ __u32 inline_ids[KMULTI_INLINE_CNT];
+ const struct btf_type *t;
+ struct bpf_link_info info;
+ __u32 len = sizeof(info);
+ __u64 addr = 0, cookie = 0;
+ struct ksym *ksym;
+ const char *name;
+
+ memset(&info, 0, sizeof(info));
+
+again:
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ if (!ASSERT_OK(err, "get_link_info"))
+ return -1;
+
+ if (!ASSERT_EQ(info.type, BPF_LINK_TYPE_KPROBE_MULTI, "kmulti_type"))
+ return -1;
+
+ ASSERT_EQ(info.kprobe_multi.flags, BPF_F_KPROBE_MULTI_INLINE, "kmulti_flags");
+
+ /* Function with entry probe is not counted in inlined instances. */
+ if (!ASSERT_EQ(info.kprobe_multi.count, 1, "func_cnt") ||
+ !ASSERT_EQ(info.kprobe_multi.inline_count, KMULTI_INLINE_CNT, "inline_cnt"))
+ return -1;
+
+ /* Instances that could not be attached are counted as skipped. */
+ ASSERT_EQ(info.kprobe_multi.inline_skipped, 1, "inline_skipped");
+
+ if (!info.kprobe_multi.addrs) {
+ info.kprobe_multi.addrs = ptr_to_u64(&addr);
+ info.kprobe_multi.cookies = ptr_to_u64(&cookie);
+ info.kprobe_multi.inline_addrs = ptr_to_u64(inline_addrs);
+ info.kprobe_multi.inline_cookies = ptr_to_u64(inline_cookies);
+ info.kprobe_multi.inline_ids = ptr_to_u64(inline_ids);
+ goto again;
+ }
+
+ ASSERT_EQ(addr, ksym_get_addr(kmulti_inline_syms[0]), "kmulti_addr");
+ ASSERT_EQ(cookie, kmulti_inline_cookies[0], "kmulti_cookie");
+
+ for (i = 0; i < KMULTI_INLINE_CNT; i++) {
+ /* The id is BTF id of the inlined function .. */
+ t = btf__type_by_id(btf, inline_ids[i]);
+ if (!ASSERT_OK_PTR(t, "inline_id"))
+ continue;
+ name = btf__name_by_offset(btf, t->name_off);
+
+ /* .. the instance has cookie of that function .. */
+ for (j = 0; j < ARRAY_SIZE(kmulti_inline_syms); j++) {
+ if (!strcmp(name, kmulti_inline_syms[j]))
+ break;
+ }
+ if (!ASSERT_LT(j, ARRAY_SIZE(kmulti_inline_syms), "inline_func"))
+ continue;
+ ASSERT_EQ(inline_cookies[i], kmulti_inline_cookies[j], "inline_cookie");
+ cnts[j]++;
+
+ /* .. and its address is the one from inline BTF, inside the caller. */
+ ASSERT_TRUE(kmulti_inline_has_loc(btf, inline_ids[i], inline_addrs[i]),
+ "inline_addr");
+ ksym = ksym_search(inline_addrs[i]);
+ if (!ASSERT_OK_PTR(ksym, "ksym_search"))
+ continue;
+ ASSERT_OK(strncmp(ksym->name, "bpf_kprobe_multi_inline_test", 28), "inline_caller");
+ }
+
+ for (j = 0; j < ARRAY_SIZE(kmulti_inline_syms); j++)
+ ASSERT_EQ(cnts[j], kmulti_inline_cnts[j], "inline_func_cnt");
+ return 0;
+}
+
+static void verify_kmulti_inline_invalid_user_buffer(int fd)
+{
+ __u64 addrs[KMULTI_INLINE_CNT + 1], cookies[KMULTI_INLINE_CNT];
+ __u32 ids[KMULTI_INLINE_CNT];
+ struct bpf_link_info info;
+ __u32 len = sizeof(info);
+ int err, i;
+
+ /* Wrong info setup (inline_addrs == NULL and inline_count != 0) -> EINVAL */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EINVAL, "no_addr");
+
+ /* Wrong info setup (inline_addrs != NULL and inline_count == 0) -> EINVAL */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_addrs = ptr_to_u64(addrs);
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EINVAL, "no_cnt");
+
+ /* Wrong info setup (inline_cookies != NULL and inline_count == 0) -> EINVAL */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_cookies = ptr_to_u64(cookies);
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EINVAL, "cookies_no_cnt");
+
+ /* Wrong info setup (inline_ids != NULL and inline_count == 0) -> EINVAL */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_ids = ptr_to_u64(ids);
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EINVAL, "ids_no_cnt");
+
+ /* Smaller than actual count provided -> ENOSPC */
+ memset(&info, 0, sizeof(info));
+ memset(addrs, 0, sizeof(addrs));
+ info.kprobe_multi.inline_addrs = ptr_to_u64(addrs);
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT - 1;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -ENOSPC, "smaller_cnt");
+ for (i = 0; i < KMULTI_INLINE_CNT - 1; i++)
+ ASSERT_NEQ(addrs[i], 0, "inline_addrs");
+ /* check that the last entry is not populated */
+ ASSERT_EQ(addrs[i], 0, "inline_addrs");
+
+ /* Bigger than actual count provided -> OK */
+ memset(&info, 0, sizeof(info));
+ memset(addrs, 0, sizeof(addrs));
+ info.kprobe_multi.inline_addrs = ptr_to_u64(addrs);
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT + 1;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, 0, "bigger_cnt");
+ ASSERT_EQ(info.kprobe_multi.inline_count, KMULTI_INLINE_CNT, "bigger_cnt_inline_cnt");
+ for (i = 0; i < KMULTI_INLINE_CNT; i++)
+ ASSERT_NEQ(addrs[i], 0, "inline_addrs");
+ ASSERT_EQ(addrs[i], 0, "inline_addrs");
+
+ /* Invalid inline_addrs pointer -> EFAULT */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_addrs = 0x1;
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EFAULT, "invalid_buff_addrs");
+
+ /* Invalid inline_cookies pointer -> EFAULT */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_addrs = ptr_to_u64(addrs);
+ info.kprobe_multi.inline_cookies = 0x1;
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EFAULT, "invalid_buff_cookies");
+
+ /* Invalid inline_ids pointer -> EFAULT */
+ memset(&info, 0, sizeof(info));
+ info.kprobe_multi.inline_addrs = ptr_to_u64(addrs);
+ info.kprobe_multi.inline_ids = 0x1;
+ info.kprobe_multi.inline_count = KMULTI_INLINE_CNT;
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ ASSERT_EQ(err, -EFAULT, "invalid_buff_ids");
+}
+
+static void test_kprobe_multi_inline_fill_link_info(struct test_fill_link_info *skel,
+ bool invalid)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ struct btf *vmlinux_btf, *inline_btf = NULL;
+ struct bpf_link *link;
+ int link_fd, err;
+
+ /* Attaching to inlined functions is supported only on x86_64. */
+#ifndef __x86_64__
+ test__skip();
+ return;
+#endif
+
+ vmlinux_btf = btf__load_vmlinux_btf();
+ if (!ASSERT_OK_PTR(vmlinux_btf, "vmlinux_btf"))
+ return;
+
+ inline_btf = btf__parse_split("/sys/kernel/btf/vmlinux.inline", vmlinux_btf);
+ err = libbpf_get_error(inline_btf);
+ if (err) {
+ inline_btf = NULL;
+ /* pahole may not have inline BTF feature support. */
+ if (err == -ENOENT)
+ test__skip();
+ else
+ ASSERT_OK(err, "parse_inline_btf");
+ goto out;
+ }
+
+ opts.syms = kmulti_inline_syms;
+ opts.cookies = kmulti_inline_cookies;
+ opts.cnt = ARRAY_SIZE(kmulti_inline_syms);
+ opts.inlined = true;
+ link = bpf_program__attach_kprobe_multi_opts(skel->progs.kmulti_run, NULL, &opts);
+ if (!ASSERT_OK_PTR(link, "attach_kprobe_multi_inline"))
+ goto out;
+
+ link_fd = bpf_link__fd(link);
+ if (!invalid) {
+ err = verify_kmulti_inline_link_info(link_fd, inline_btf);
+ ASSERT_OK(err, "verify_kmulti_inline_link_info");
+ } else {
+ verify_kmulti_inline_invalid_user_buffer(link_fd);
+ }
+ bpf_link__destroy(link);
+out:
+ btf__free(inline_btf);
+ btf__free(vmlinux_btf);
+}
+
static int tmulti_target_cmp(const void *a, const void *b)
{
const struct tmulti_target *ta = a;
@@ -874,6 +1121,10 @@ void test_fill_link_info(void)
}
if (test__start_subtest("kprobe_multi_invalid_ubuff"))
test_kprobe_multi_fill_link_info(skel, true, true, true);
+ if (test__start_subtest("kprobe_multi_inline_link_info"))
+ test_kprobe_multi_inline_fill_link_info(skel, false);
+ if (test__start_subtest("kprobe_multi_inline_invalid_ubuff"))
+ test_kprobe_multi_inline_fill_link_info(skel, true);
if (test__start_subtest("tracing_multi_link_info")) {
test_tracing_multi_fill_link_info(skel, false, false);
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread
end of thread, other threads:[~2026-12-02 12:35 UTC | newest]
Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.