From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214641; b=S+iO3+Jz/xnTuz5xagY+R2xM8gV1S12MG+LY6QU4Tx7MN3P6840Ti77SZOVKCFOu9i9H FqRsII1u22qwfhyc8Bu29qfrmr0EZnMfurugNn5c9T02aTqKkDRoM8qsEizsTsgHZUGCR 4u/mr8XHxui4VdTBJ+/Fb9umu0DDwxifDJryUyerRbavBq/5jVOlROI2rp0xVEKIJI/zU UXeGToCWqDt17WXArwMRP6jSqFXX5YgVE0EbynG35pdktNV8Xdilhe0RjAt32P9TmvbR5 FRAiIw8tMwz0HCpBuTIeyu4Zc5N9TzkOfjx5sRkML9prSueHD4G2ASlWSxce4n4MC8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214641; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=tPZgUp1gEplow464PDDZ5sX32iZTVLvv6PDwXY3l2RU=; b=QwTVsVpfHWJ1LxVSD5q2FainZQ3tTPzdMkpQDcX8pwWPhKSelAMRBpdsle1WFuYb7R0L 9PPPqMBCIIKJtFAPL1ik6LrxbFuGK/Pn67okXPPvFP5j5GNSMZabZ9SYotesnppe56QH1 OV1G9H+BNrD+X+F3J9OgOH6GG/7WZxFUqnS19Gtr6qGMMi5HIRzgseKekNv9RvuFTYsVx 2EY72pKHQCz5G16NQ662fH5LV3CN5QCAADlwqW4p8sUwDBoxUT1hSumHXPSzkm68KpI59 eK9wBcQn825n+38yAtkFFp6Bl2dKEzGs9LXy8//+VlehilCGl+s3b5yaSwsXF4HuDGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SuxwAKCs; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82F50606A32D; Wed, 2 Dec 2026 12:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SuxwAKCs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 335931F00924; Wed, 2 Dec 2026 12:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214641; bh=tPZgUp1gEplow464PDDZ5sX32iZTVLvv6PDwXY3l2RU=; h=From:To:Cc:Subject:Date; b=SuxwAKCsR3YFH/ftkDgc74/itK5BWYaa/fV6khnHB7IRF4kvBMcRwGt9wr1ZjXGgK hEAaiVW1m1SBxCcefs5dJ401o5W8fh5M8Lr9jj/QXVUvQzlj7PhbfMs9dcbUc90xRD tE0C/i5g+M2G1vtl9WYcOx1UBFGtqhTVkbYa5q+QDcaiNvTHS28EGO0lQJ9Te1A1fv IL3H5mG8kGLacaisryzFbLkhODAB5Fg5LSlCW5zBWA6BRmBtnCMmJrTXr3nS7Lfl3u iCf6UjOM15z9C65QHKI6OFCoxHHYUiRUBlQY11eBzSRdkRtQru0gwkUHTm3jyP7TgM QrdNIcmqyuwqg== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , Quentin Monnet , Alan Maguire Subject: [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Date: Wed, 2 Dec 2026 13:30:04 +0100 Message-ID: <20261202123035.10335-1-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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