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=1796214694; b=XKVmJphcA4SWAQcGkqMz15ZOH24lNTy3QeK3xfe2I4dMZ4IPEs4M5XJSq89lYFkIM0Ll PFvmt6M366So82gFD3UDOdSk+AyvK6I81510fJNIgwNIkaqSKhGEAb+Url44dNNh++Rkt yJwKVevaE+v4euWhziItw00VMF8XN4cIfr5HnAGDLYPbX4S7+gN/xsb0v4WOkTTD2AGey d5l0esVeqjOMZyu8KOlqKIL+HyEbdxn9KITDV19jiEEY+aH5Wkl8mX5h7DKLXVQ+7BLvR Fzeqq5P0uXoJbfW2zbD18lSv6GxUk3RurnDZUpF5m3cLNaCUqtP0cWBOty/ulAgkEzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214694; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=kzD6ETdTttXHZ+Ax/5zolCxOO4hNIcEIYwOWplGqfy0=; b=1eif0p4qeBIzXjJO2BREFMB76pAk4GrAevY8DuuVPsw/G1uWbbDX2AGfe8WNHendYSix NkcQXu94oNUTyI6YfLwqiUVyR9oGrA8evUEMvqDBYjPDsL7v4SAuLw/Oz+dLnPn/hB1XG F67AQoLQHvSkTPyotzGnU5ALG/3cNRnG2c9u8Lei7dtDEDKWgBujnUDr2abU0/1fzJCAy hIioBk2Yc64DZ5Gf9Ux+IhGopYb4y2CKpUQ8EsujdsMTf/MV5DbPa3ipQelV4jJQ1tZj1 /UNWI8uXynOAYkRAcmtwLELp9+5YA0bKhT22q+el28JvO2P1Q+GmG5dudmsWk2DMrGA== 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=RPfjG1Lv; 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 ED981606A31A; Wed, 2 Dec 2026 12:31:33 +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=RPfjG1Lv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69B6D1F00897; Wed, 2 Dec 2026 12:31:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214693; bh=kzD6ETdTttXHZ+Ax/5zolCxOO4hNIcEIYwOWplGqfy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RPfjG1LvDAwfBOD52vFvRzuKcX+g/OlmNCQLHiDKZNyXjb83Vsq2qJHYm9KWrS2bh qrIw6e8GSknOzD2aVc3JbSagvc8Gj2AJHlwoC9JIp7iyzd1w2g1hiosAeYiAMyyVH1 iKeLUUNouYdksC6AS08glSMfi994PCnr58RG4qbFcPWSB/oJ73Lbr4PFm/ySzcK4hh b0YhgmygsDxq27OEJf3f6AF9XZZg7VDI/kG8qsjfbAhpsFwEklrYZ2znM/Pk0hBH8d qEng59WxLludKlGSr6Uy7NE8as8M8ZXlQEC6cFsWZKTP4el3PQU63FCia/JqHvxB5I 5IGyn/d8g/pig== 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 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Date: Wed, 2 Dec 2026 13:30:09 +0100 Message-ID: <20261202123035.10335-6-jolsa@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org> References: <20261202123035.10335-1-jolsa@kernel.org> X-Mailing-List: linux-kernel@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 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 --- 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