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=FO6nmLHviAScpHtmck8hnrlANfRoBO8bcWQxfLVBjBAziBJXZt576roQ1bEiYjWLRDOw MvSe3yLGyAvb5yBch6FtVbnqP/nIrAX6Tj107s9ZE8NjraGxEkCHZ7fzs5WEcL93Z1vdU nlm4VPPju62rhonRalFiD+Tppct2uIBxpQ6fpHZN0YzUKRA5xqB/6r5s0JCusb9HOAD8m J+LW3dzuAbJSD/x/OTp7uVv4irZpswk4u+QPJZMbLhsSn6kkqwUTEmzrl7Bhh6ovG2Ro3 u08x+N4YCEYtBQ+YoV17kcYcTw5pJvFPToEaF0HEwmNt7XVb4DGAm7SCD8xm0MUBkeQ== 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=jhtGI3fgFAQKyAyPEoeT5genSuhBTyhMOoDZGtNvz/41VDMQlNbK/xUYHkMWX9+Es9OV FlJ3s9UPBo5MQwtSHiFcAarcCsZoFzYo3OIwqu2NLY7shgrM4QCZSTTaKOnrwiZSLm9Hi PEupAif8kMPOL5tNqn3GouWSq4HumuyU+1Dzbc7FhnwinlcZ4WmxH08pMAbAMRmejsoy6 eqeyUlCPJ+bRIkCHMZRAkcfchU3uoP0ZkyScPwQwvE/C4DO5NYEKfXgyOj+lw9W02jz8V C15e+Yrq1khXxfCLtY+8rGE3PTuYczqo3F6H/6SuageLzvpy3kITKNyv3UyA+/GktYA== 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 DE8E7606A31A for ; Wed, 2 Dec 2026 00:15:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE8E7606A31A 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-4ab8b4887d4so8721241b6e.1 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=xSppVNO2VB3vBPLbhQC2J1/2pRX6FoI8IzT946XNA74rsljkDVFTvnEJkIjEbGnIiG ufk5MtqP4/VrmOCNhOIFqNLga8g8nJ5/POyM+2SIIQBPRzfqfIqer6znJXL2OnkUeg0g XeUUUhaGq/mHMIzfVmr5bJtqChx7I0rg9WP58fjTa6yOx7PHUSshljLBX1MHPs7UaIe1 ERooqMX672bK79mSqeyP/DaHxb4kQUipOpRFM9k66Mrk5cymphy8hh8s83kYggVzI5E1 LaBkO4AAtgVeeFSFsOfwa8HJOo/XaYJ2hWEBrafdhBUSH1ivMztf3v9/qx3NotbiPwR1 vsKA== X-Forwarded-Encrypted: i=1; AL+hErFE27YVOB0oDMIiEN6VSO9JfJnQkvGzfbovIJrQ1Jqw0ekQig8ryFuXXdjZfTp81q5PDGZhjNbmuQMIKY4=@vger.kernel.org X-Gm-Message-State: APuU4Z+EGLyyng13ZERBsoHDd3yk5BlsEK4R8+aYMVX08Dt1ZLazMumQ WngqZniwPnayaI0+57fliuzbkG072tPxf7JxTa6AoyDtYg+nPJIX2q8rGGeaO9SUY7agt5XEb8n kstvbVJeisIZbSg== 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-kernel@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