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=1796214776; b=zLSk/dujulq/RvCOlCxrLwH8KsAI244V3MgYsME3mQS9DkhazgRWr+mzqG5FZBqPn0ed zhnjP2PuBEvr9bE8GxosLAVEwoL2M75XUUiFn653HaqIiijgyayLdvpUzevgT/1cKKHNd wkZqvkllemgh/amXvOAF3Qmb7WP/X0ud7oqS2PXp+7Do5u/bBOeDWPH/oHDX/x7xmHb1F jRxNgZ/XQHJvV4HJ4BSXqWJ9Pm4HVjsnvU+L0Kz7nA+rT+ZppHHvcaw10OUF/CAvtlsuI 31+pVHXyoFwxHoH23wY9KmgPLBVGIYP+s9xtooDys/fDRSb/ujH/FDvVNsk6ZuGsspA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214776; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=GCYArgQl2NpvMJsJnolrYP0ilo8UOcRTWBZ1cbY8CeY=; b=r1CvXwLiZgXl1vcypFBHrAmealiPUGZgACFzNJX4FXlf9WVj291606FaOL3h6yOAl27c YrgpS2og52wbkMO81mlEBKIjFK8CSW6gKiR+H07bb4rZyQzZBDmdeIC5uK7WYGkIUS+DU 58ehQNwo3C3RK7Rykt8fJiTAzgqnOyCuHJqctxPA8AThQ9KGdBV62uuWyJ5vWhkcdUFK+ qDhg8lEKgDorw+UTckUaJ5M5Ll7uoK/Cy8w3afXYAgw1MzouP/BaNvTHmoj+zCIAkKaO9 TOUfnISP1+6O8iWUzGK7tfndWH/iXSzHnIbmzvQG+DHDYnr0Dl2Pr3xKYFJ+JqhTErw== 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=Ir8qa9Eo; 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 AFC3F606A323; Wed, 2 Dec 2026 12:32:56 +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=Ir8qa9Eo Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDCB31F00897; Wed, 2 Dec 2026 12:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214776; bh=GCYArgQl2NpvMJsJnolrYP0ilo8UOcRTWBZ1cbY8CeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ir8qa9Eo5O19nJSSrI8ZWgES+ed7/FhJE4X4Aww+l6foDrtHtY/sVSK9nb0Bw0eAj NTle3QxvStPmeW6EZn0Jr1oRCYzJ+sryGsqjQFVLXou2zfKjKCmDzx1Ug6OG1nl4Mn +Qohd3Dj5UOSukEqnajHhTWCUB+ufHcvFgqy3NvFji6mOMM5L9fMIPJr1tns75kEiI NunOjNfHZrXDFwD01USDOPus3PEJsSUrgzcBLgrUnCqS4BUIILumMbZKEtb21bUN/P w5esl/tmi0tfDwYpm/Ny2QkJmmV+F0nh+W5GbinWgDrYov2CCvtcxsGsp5+QNwrOml NOOGly0rLBzgQ== 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 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Date: Wed, 2 Dec 2026 13:30:17 +0100 Message-ID: <20261202123035.10335-14-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-trace-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 The BPF_F_KPROBE_MULTI_INLINE flag attaches inlined instances found in vmlinux inline BTF. Add support to attach also inlined instances in kernel modules. The module inline BTF has LOCSEC for each section with inlined instances, named as inline
, with offsets relative to the section start. Sections that are not in module text, like freed init sections, are skipped. The function is matched by name in module BTF and its base vmlinux BTF, so kernel function inlined in module code is attached as well. Modules with inlined instances are stored in the link, so they stay loaded as long as the link exists. The link info inline_ids value of instance in module is the BTF id from the inline BTF of that module. Signed-off-by: Jiri Olsa --- kernel/trace/bpf_trace.c | 70 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index bd413d45ef2c..71da54a6ea20 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2873,8 +2873,8 @@ static bool has_module(struct modules_array *arr, struct module *mod) } /* - * Add modules for @addrs to @arr. On error all the modules in @arr - * are released. + * Add modules for @addrs to @arr, which might already have modules + * with inlined instances. On error all the modules in @arr are released. */ static int get_modules_for_addrs(struct modules_array *arr, unsigned long *addrs, u32 addrs_cnt) { @@ -2959,6 +2959,7 @@ struct inline_lookup { /* Output */ struct inline_sites *inlines; + struct modules_array *mods; u32 addrs_cnt; /* Lookup state */ @@ -3015,6 +3016,58 @@ static int inline_lookup_locsec(struct inline_lookup *lookup, const struct btf * return 0; } +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES +static int inline_lookup_module(struct module *mod, const struct btf *btf, void *data) +{ + u32 id, nr_types = btf_nr_types(btf); + struct inline_lookup *lookup = data; + const struct btf_type *t; + u32 cnt = lookup->cnt; + unsigned long base; + const char *name; + int err; + + /* + * Each section with inlined instances has its own LOCSEC named + * as inline
with offsets relative to the section start. + */ + for (id = btf_nr_types(btf_base_btf(btf)); id < nr_types; id++) { + t = btf_type_by_id(btf, id); + if (btf_kind(t) != BTF_KIND_LOCSEC) + continue; + name = btf_name_by_offset(btf, t->name_off); + if (!name || !str_has_prefix(name, "inline")) + continue; + /* Skip sections that are not loaded or are freed already (init). */ + base = module_sect_addr(mod, name + strlen("inline")); + if (!base || !within_module_mem_type(base, mod, MOD_TEXT)) + continue; + err = inline_lookup_locsec(lookup, btf, t, base); + if (err) + return err; + } + + if (lookup->cnt == cnt) + return 0; + + /* Keep the module we have inlined instances in. */ + err = add_module(lookup->mods, mod); + if (!err) + __module_get(mod); + return err; +} + +static int inline_lookup_modules(struct inline_lookup *lookup) +{ + return btf_for_each_module_inline(inline_lookup_module, lookup); +} +#else +static int inline_lookup_modules(struct inline_lookup *lookup) +{ + return 0; +} +#endif + /* * Sort instances by symbol name and address, so instances of each * symbol are next to each other, and get rid of duplicates. @@ -3051,9 +3104,11 @@ static bool inline_site_traceable(unsigned long addr) } /* - * Find inlined instances for functions in @lookup->syms. Each function - * must have an entry address or at least one inlined instance, functions - * without an entry address are dropped from @lookup->addrs. + * Find inlined instances for functions in @lookup->syms in kernel and + * modules, modules with instances are stored in @lookup->mods with + * reference taken. Each function must have an entry address or at least + * one inlined instance, functions without an entry address are dropped + * from @lookup->addrs. */ static int inline_lookup_symbols(struct inline_lookup *lookup) { @@ -3075,6 +3130,10 @@ static int inline_lookup_symbols(struct inline_lookup *lookup) if (id < 0) return -EOPNOTSUPP; + err = inline_lookup_modules(lookup); + if (err) + goto error; + err = inline_lookup_locsec(lookup, btf, btf_type_by_id(btf, id), (unsigned long)_stext); if (err) goto error; @@ -3298,6 +3357,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if ((flags & BPF_F_KPROBE_MULTI_INLINE) && (!err || err == -ESRCH)) { struct inline_lookup lookup = { .inlines = &inlines, + .mods = &mods, .syms = us.syms, .syms_cnt = cnt, .addrs = addrs, -- 2.56.1