mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Samuel Wu <wusamuel@google.com>
To: Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	 Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	 Luis Chamberlain <mcgrof@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	 Daniel Gomez <da.gomez@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	 Aaron Tomlin <atomlin@atomlin.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Nathan Chancellor <nathan@kernel.org>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	 Justin Stitt <justinstitt@google.com>
Cc: david.laight.linux@gmail.com, akpm@linux-foundation.org,
	pmladek@suse.com,  Samuel Wu <wusamuel@google.com>,
	kernel-team@android.com, linux-kernel@vger.kernel.org,
	 linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org,
	bpf@vger.kernel.org,  linux-modules@vger.kernel.org,
	linux-kselftest@vger.kernel.org,  llvm@lists.linux.dev
Subject: [PATCH bpf-next v4 03/10] bpf: Add bpf_kallsyms_query_name()
Date: Tue,  1 Dec 2026 16:13:44 -0800	[thread overview]
Message-ID: <20261202001344.2721429-15-wusamuel@google.com> (raw)
In-Reply-To: <20261202001344.2721429-12-wusamuel@google.com>

KALLSYMS_QUERY_BY_NAME, added later in this series, needs to find a
symbol name or prefix across BPF JIT symbols in one pass.
bpf_get_kallsym() walks bpf_kallsyms from the head on each call, which
is O(N^2) and can trigger rcu_tasks stalls and timeouts.

Add bpf_kallsyms_query_name() to scan bpf_kallsyms in a single O(N) RCU
pass, matching existing kallsyms linear scans.

Signed-off-by: Samuel Wu <wusamuel@google.com>
---
 include/linux/filter.h | 11 +++++++++++
 kernel/bpf/core.c      | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 06f128632d5c..70ecce4f1a8b 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -39,6 +39,7 @@ struct xdp_buff;
 struct sock_reuseport;
 struct ctl_table;
 struct ctl_table_header;
+struct kallsyms_name_query;
 
 /* ArgX, context and stack frame pointer register positions. Note,
  * Arg1, Arg2, Arg3, etc are used as argument mappings of function
@@ -1684,6 +1685,9 @@ int bpf_address_lookup(unsigned long addr, unsigned long *size,
 bool is_bpf_text_address(unsigned long addr);
 int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 		    char *sym);
+int bpf_kallsyms_query_name(unsigned int *symnum,
+			    const struct kallsyms_name_query *q,
+			    unsigned long *value, char *sym);
 struct bpf_prog *bpf_prog_ksym_find(unsigned long addr);
 
 void bpf_prog_kallsyms_add(struct bpf_prog *fp);
@@ -1741,6 +1745,13 @@ static inline int bpf_get_kallsym(unsigned int symnum, unsigned long *value,
 	return -ERANGE;
 }
 
+static inline int bpf_kallsyms_query_name(unsigned int *symnum,
+					  const struct kallsyms_name_query *q,
+					  unsigned long *value, char *sym)
+{
+	return -ENOENT;
+}
+
 static inline struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
 {
 	return NULL;
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index facb0d6d2e8d..9f7ad6597d89 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1113,6 +1113,31 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 	return ret;
 }
 
+int bpf_kallsyms_query_name(unsigned int *symnum,
+			    const struct kallsyms_name_query *q,
+			    unsigned long *value, char *sym)
+{
+	struct bpf_ksym *ksym;
+	unsigned int it = 0;
+
+	if (!bpf_jit_kallsyms_enabled())
+		return -ENOENT;
+
+	guard(rcu)();
+	list_for_each_entry_rcu(ksym, &bpf_kallsyms, lnode) {
+		if (it < *symnum || strncmp(ksym->name, q->name, q->cmp_len)) {
+			it++;
+			continue;
+		}
+
+		strscpy(sym, ksym->name, KSYM_NAME_LEN);
+		*value = ksym->start;
+		*symnum = it;
+		return 0;
+	}
+	return -ENOENT;
+}
+
 int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
 				struct bpf_jit_poke_descriptor *poke)
 {
-- 
2.56.1.911.g883d8bcb20-goog


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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:13 [PATCH bpf-next v4 00/10] kallsyms: Add KALLSYMS_QUERY_BY_NAME and KALLSYMS_QUERY_BY_ADDR ioctls Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 01/10] Documentation: ioctl-number: Add PROCFS_IOCTL_MAGIC range 0x10-0x11 Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 02/10] module: Add module_kallsyms_query_name() Samuel Wu
2026-12-02  0:13 ` Samuel Wu [this message]
2026-12-02  0:13 ` [PATCH bpf-next v4 04/10] kallsyms: Add KALLSYMS_QUERY_BY_NAME ioctl to /proc/kallsyms Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 05/10] kallsyms: Add KALLSYMS_QUERY_BY_ADDR " Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 06/10] docs/procfs: Document KALLSYMS_QUERY_* ioctls on /proc/kallsyms Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 07/10] tools: Copy KALLSYMS_QUERY_* definitions to linux/fs.h Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 08/10] selftests/proc: Add KALLSYMS_QUERY_* ioctl tests Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 09/10] libbpf: Resolve typeless ksyms via KALLSYMS_QUERY_BY_NAME ioctl Samuel Wu
2026-12-02  0:59   ` bot+bpf-ci
2026-12-02  0:13 ` [PATCH bpf-next v4 10/10] selftests/bpf: Test typeless module ksym resolution Samuel Wu

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=20261202001344.2721429-15-wusamuel@google.com \
    --to=wusamuel@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=atomlin@atomlin.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=da.gomez@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=david.laight.linux@gmail.com \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jack@suse.cz \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=mcgrof@kernel.org \
    --cc=memxor@gmail.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=samitolvanen@google.com \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --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

all inboxes | Powered by JetHome®