mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Quentin Monnet <qmo@kernel.org>,
	Alan Maguire <almagui@kernel.org>
Subject: [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions
Date: Wed,  2 Dec 2026 13:30:04 +0100	[thread overview]
Message-ID: <20261202123035.10335-1-jolsa@kernel.org> (raw)

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

             reply	other threads:[~2026-12-02 12:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:30 Jiri Olsa [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202123035.10335-1-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=qmo@kernel.org \
    --cc=song@kernel.org \
    --cc=x86@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®