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=1796214683; b=CnxRjdqvIwuumQWqtdQqP3AgIH3kY8caboVOUjZ/6SCl6ys596Rn8MzXaUapmPhnPpzO +uXwbMCSoUYpsspOkXHPhdAXfcV4iRiJfpiwp7Lp75ZqEuX8uPi+PD/29x32EVEncQG1X 1PCwNO9Ju4DT9qL4idRIx1mzVxHN4X7f2stpQlJBkaU2hJfHX4OyCd8vVUoRZqPdFwlyW BwX6n2sReAbww+ytl2h4xTyCY+YYSG2/SDtVKg7AZn/eV6ZE91zlDYB+vq5HgCUc/VWyN xNa6XtOti5qEPrTRguO4OpQF8C817FIb6I7U9SYB01h1aCRoMfHWmt79N24BoAbjhOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214683; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=G9G27cn/FcyhUlYHg8E2vLIEE4321tKc8wfrHQ+TTMI=; b=gWGNpRGNnG1V0AUhTk2kRpyQIoGcfOAeikRd8kRRxjrpOtOWhS4hAFeVS9RNSd357ldO h63KKj/MGE2moKWQRHTSWmGMui7SxzJFZLrmTfr0GfVaqpep6I+W1HDIIjVVKBmd8cvf0 yfE01eVA2mCY1DTic2WvlCGeJ/+itGR8ZVIojuHP0bTYCoqywARZjJArb9UqRRlpdS+Yg fbune3fAZWBfV1DB1U4L1gclPD+5nowBN4/cSClWF3+G40O9FgsVZQjVT6myzksm/RGvP 8+rKduZKjS/5OrXkLqMws972KLW4RyIyyt8psmyl+pBpbBXzM40HTS6u0a4MYnD48Cw== 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=dDGl1T4H; 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 A27F4606A323; Wed, 2 Dec 2026 12:31:23 +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=dDGl1T4H Received: by smtp.kernel.org (Postfix) with ESMTPSA id 376681F00924; Wed, 2 Dec 2026 12:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796214683; bh=G9G27cn/FcyhUlYHg8E2vLIEE4321tKc8wfrHQ+TTMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dDGl1T4HYFty3A+Q/+Um3tOCxAMbQ3Hr97NLKvQoAOlGtfvqKHgO6E5Y35/DEz8WU p7WEizB09XmGj/1ktaHJixTjXV+h5xziaW9pD8U6Jf7f+WxD7FW0npOPWeV2DJbIXM 5N2Jd52LE2jRrKmOxYQLGdBB21x0i+oTuSpK/hwOw/n/DWnxlQ8HVYJb4s6wElBxht dXds+ApPTJemhoAIVjXE04+z1wQNEvicvsWssa4VW2DMR3zMdv/pFsK5rCipShhuOd 8LQ8jYAVULvS7f8JEJH6hSF+vjjk7X/Uv/R6ZejCcaKJQ9wcbY+KuI+MIhIF82KvOg Xxz+fd5NOYUuA== 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 04/31] module: Add module_sect_addr function Date: Wed, 2 Dec 2026 13:30:08 +0100 Message-ID: <20261202123035.10335-5-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 Add module_sect_addr() that returns the runtime address of the loaded module section with given name, or 0 if there's no such section or the section attributes are not available (they need CONFIG_KALLSYMS and CONFIG_SYSFS). The caller needs to make sure the module is live and hold a reference to it, which keeps the section attributes stable, so no other locking is needed. It will be used to resolve addresses of inlined instances in modules, which are stored in inline BTF as section relative offsets. Signed-off-by: Jiri Olsa --- include/linux/module.h | 9 +++++++++ kernel/module/sysfs.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/module.h b/include/linux/module.h index 76f4f3596477..e2209a8953f9 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -952,6 +952,15 @@ static inline bool module_sig_ok(struct module *module) } #endif /* CONFIG_MODULE_SIG */ +#if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) +unsigned long module_sect_addr(const struct module *mod, const char *name); +#else +static inline unsigned long module_sect_addr(const struct module *mod, const char *name) +{ + return 0; +} +#endif + #if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS) int module_kallsyms_on_each_symbol(const char *modname, int (*fn)(void *, const char *, unsigned long), diff --git a/kernel/module/sysfs.c b/kernel/module/sysfs.c index 01c65d608873..f6a08fad503e 100644 --- a/kernel/module/sysfs.c +++ b/kernel/module/sysfs.c @@ -133,6 +133,26 @@ static void remove_sect_attrs(struct module *mod) } } +/* + * Returns address of the loaded section @name or 0 if there's no such + * section. The caller needs to make sure the module is live + * (MODULE_STATE_LIVE) and hold a reference to it, which keeps + * mod->sect_attrs stable; no other locking is needed. + */ +unsigned long module_sect_addr(const struct module *mod, const char *name) +{ + const struct bin_attribute *const *bin_attr; + + if (!mod->sect_attrs) + return 0; + + for (bin_attr = mod->sect_attrs->grp.bin_attrs; *bin_attr; bin_attr++) { + if (!strcmp((*bin_attr)->attr.name, name)) + return (unsigned long)(*bin_attr)->private; + } + return 0; +} + /* * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections. */ -- 2.56.1