The Linux Kernel Mailing List
 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 05/31] bpf: Add bpf_get_btf_vmlinux_inline function
Date: Wed,  2 Dec 2026 13:30:09 +0100	[thread overview]
Message-ID: <20261202123035.10335-6-jolsa@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org>

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


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

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