Re: [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions

From: Jiri Olsa

Date: Thu Dec 03 2026 - 09:21:01 EST


On Thu, Dec 03, 2026 at 01:57:14AM +0000, Alexei Starovoitov wrote:
> On Wed, Dec 02, 2026 at 04:30 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> > 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.
>
> I like the idea. kprobes behind the kprobe multi link is the piece
> that was missing.
> But the lookup by name in the kernel is kinda heavy.
>
> In Alan's RFC thread I leaned towards the kernel doing the whole thing.
> The reason: kprobe multi could not attach to arbitrary IPs.
> Patch 7 shows that it can. That changes the trade off.
>
> Lets start with the mechanism only.
> addrs[] takes any address that kprobes accept.
> fprobe gets the ftrace locations. Every other address gets a kprobe.
> Such addrs fail with -ENOENT in fprobe_init() today, so no need for
> a flag.
> User space reads vmlinux.inline from sysfs and passes the sites.

ok, makes sense, more comments below

>
> libbpf works this way already. It resolves "tcp_*" in user space and
> passes addrs. In this series wildcards can't use inline (patch 19).
> To match fully inlined functions libbpf has to read vmlinux.inline
> anyway.
>
> this series addrs[]
> ----------------- ----------------------- -------------------------
> name -> sites kernel, exact names user space, wildcards too
> subset of sites no yes
> vmlinux.inline 2nd copy, ~10 Mbytes, mmap in user space
> never freed
> cookie per function per site
> args bpf_get_func_arg() cookie -> arg spec, like
> usdt.bpf.h
> arch x86-64 any with kprobes
> link info 5 new fields as is
> fdinfo 2 new lines as is, %pS
> bpftool new table, BTF lookup print sym+off
> new flags 2 0
>
> Your use case from Alan's v2 thread works too: trace foo() only where
> it is inlined in bar(). User space picks the sites.
>
> Then there is no need for BTF parsing in the kernel, module_sect_addr(),
> regs_get_dwarf_register(), inline_* in bpf_link_info, STRICT, etc.
> Patches 2 and 3 stay.
>
> If tracers show that the lookup has to be in the kernel we add it
> on top of addrs[]. uapi doesn't go the other way.

initially I thought that doing the lookup in user space might be a
security concern for shirudo, but it's probably just more work for
the loader, not a security risk

>
> What the diff doesn't do:
> It is all or none. imo that's the right default.
> It doesn't say which address kprobes refuse. The link_create log can
> name it. A flag to skip such addresses can come later. link info shows
> what is attached.

I think we need the skip flag. kprobes refuse some of the inlined
sites (jump label, static call, bug table, NOKPROBE_SYMBOL, noinstr)
and finding those in user space would need vmlinux and a copy of
the kprobe checks, which seems too much

I changed the bench test to print out the stats:

inlined instances 20695
attached 19947
skipped, notrace function 563
skipped, refused by kprobes 185

it's the worst case, normal attach with just a few functions would
hit much less, but it's still inconvenient, because user space has
to retry the attach for each address the log names

> It calls register_kprobes(). enable_kprobes() goes on top.

ok

> Two functions inlined at one address share one cookie.

I think we can still allow same addresses having their own cookie,
if we keep the cookie in the kprobe struct and pass it through the
run context instead of looking it up by the address

it's probably needed for the arg specs too, two inline functions
on the same address would otherwise end up with the same spec

thanks,
jirka