From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796170534; b=b+lg/w38LljVswINmuDSuUisVWzLPPFk+/UxYOmj/FdzCNFXshiW7j8IKI0YR3Bcnmvn ZbP81RRE06DwC4f5lr2vnEhF2VwPeXDKjdp5X7/48RFuOTjsSeXueq31Zc8Lu5ZHcFPv7 5ymikbAvHzS0uKoDXSuvgJzbrj02c6Lszb0W0KtykDuSVkY1grNBA6v2CODW1Y03kQXnP 3cN4trVEzFactTPk7UII9LtxW2+c0XSrvYuyjHAx1FMgU3jBkWNYEihAgJ9/I6u9BRLIA yvvwdTQFs2uqr8Ab85uvCxsMyrdGCVB6OJb082HSZ+xGQlDalSqrHq2xNoBHxmpxVFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170534; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=6yHHQ/qAd9xPpsIcSo0PfHdr8Pud1p9W/05R5Y36cpU=; b=IAgj+N8pqp1HNFoLTKIoR7ay6avOGEEowa7IFC0L3KhoL6g37pRpvILBUtelVz+JZMoT DeOnJgReAucEcQ4c/zsh6LIjLkk7LOUUj05oH0FCztrkucOtPCE7h86QE+n1uwNyq58wL C1uOqipKmq6TMsZ7WxGun3Lb2zO8ovaSajb7uzbI4eQqxxwcz6LFoBw2I4MrzFBcy4WQ3 8oyUNSCTQSgnxbyAAFhr6grfCcMyTnb0FRvX3Rn18LCJgw2PiRBT76w8jfBVCKcnSCjFT b214K+doanqine+phXro0s5PX/xG4seLHUx5IAb1sHoSAhPwGh0Rh+RnYfahuvL0BvQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lmbcQ+Th; arc=none smtp.remote-ip=209.85.167.197 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE96D606A320 for ; Wed, 2 Dec 2026 00:15:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE96D606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lmbcQ+Th Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-4cbf700ddccso9185154b6e.0 for ; Tue, 01 Dec 2026 16:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796170533; x=1796775333; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6yHHQ/qAd9xPpsIcSo0PfHdr8Pud1p9W/05R5Y36cpU=; b=lmbcQ+ThdUgYG5nn+aH91KvVfNZX1bK4GRcTQ0dmt0nB8lUbbku0mGEeiYb6gfKHi8 Ru/NIdKpwo1m1wY/rENdE6frOwC58KRDPI2iGyTj5eue1d1JOudVd91G6r2nSgrvKiZr 2H0MTwfhFRvhpHR9z0A2dTsJnSxb1DQQYO+3hX0aF2gIitFo5yS9RY+rF6TZ1EjtA8BY MZENDE9tEpObQekiE1zSlQ3HSZJdNqPmBF8Shi1339FCToggJ0DrzANyFZRxV/girokd lasR3ceaUiah77j/oX/hb9N2N0bvL2h6H8KrVoAnftZukDLfB31UxI6HFWLWozuByAaq oolw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796170533; x=1796775333; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6yHHQ/qAd9xPpsIcSo0PfHdr8Pud1p9W/05R5Y36cpU=; b=DP98L4KSqEx6pS4gZYSX5Oy9bGQwAnCt+WKEulu2uWvGvL4k5UH2lYIO1ulCi7AxVE ZRBN09o6m1Mx4mU+kRc0iaHOyD/ITqAaBtJhgd7DrRwmvhZNa5HqjB6e8KVHf0Vc3ikN 0AlImMcCyGk+OV5q7zXJiq8TgtcO0sRjYRgfmjnaWibV31jibhB2b8C07vVnZnEVTS1/ Td4QyLmd4qeBLYXec1KW2hq3Sm46Pk5ANdoCcsGmSbm2G4cEhyFFi9MSdZvzsdgG8sYw DAMgKXSRsS1aiFvmglxcielU3o9Sx+es2r363vPNm7SK4Gx0ElYCyVVUKjz5QLPqEoGJ K4IA== X-Forwarded-Encrypted: i=1; AL+hErFSia7N5fFLfO0Q+/DVvWnSDQ0A2sl4/GpNvSG7sKVudZ1soRCb+k+yff+pSnvHx0v48UtMf3xAc0NO5LGv@vger.kernel.org X-Gm-Message-State: APuU4Z/r4TFETYtpn/2B56FLlssL7u9j6izg2ftI0nPKzCNxkf0F1NFI E22zLrGzmtE8S2E2cQR0cySk847jvMQZgrpSY4bLvgNn/81N/9HyPT9TJ7ipMauGiYHP7n5O2fy j9gZjTmWsq0yLaw== X-Received: from oibkm20-n1.prod.google.com ([2002:a05:6808:6694:10b0:4f5:3dd:a0bd]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:c3eb:b0:4b9:e5fa:8a17 with SMTP id 5614622812f47-57a0a913526mr37746696b6e.28.1796170532544; Tue, 01 Dec 2026 16:15:32 -0800 (PST) Date: Tue, 1 Dec 2026 16:13:44 -0800 In-Reply-To: <20261202001344.2721429-12-wusamuel@google.com> X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202001344.2721429-12-wusamuel@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202001344.2721429-15-wusamuel@google.com> Subject: [PATCH bpf-next v4 03/10] bpf: Add bpf_kallsyms_query_name() From: Samuel Wu To: Jonathan Corbet , Shuah Khan , Randy Dunlap , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Alexander Viro , Christian Brauner , Jan Kara , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: david.laight.linux@gmail.com, akpm@linux-foundation.org, pmladek@suse.com, Samuel Wu , 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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