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 11/31] bpf: Add btf_for_each_module_inline function
Date: Wed, 2 Dec 2026 13:30:15 +0100 [thread overview]
Message-ID: <20261202123035.10335-12-jolsa@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org>
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
next prev parent reply other threads:[~2026-12-02 12:32 UTC|newest]
Thread overview: 34+ 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 ` [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 ` Jiri Olsa [this message]
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:51 ` sashiko-bot
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:50 ` sashiko-bot
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-12-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