From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796170514; b=FZ/iWm9odSP8sNaRrEo/h8/L4LTJNZrneYW4OwAimoflWY1ImDXPPBQFCC5uQbIZUOh2 i7Q3DsoDVK7qIRhUAP9J+FaH6+EbkJqC5kSezx3Vju5ZNrDB6kX+8fOwEj/N/qKjQh9w/ 2HMzwPXxY55xXREMQzS27pENWRduCMm3+P5NQyBEvt6joHRlLwqrSQv3NTags3QwaAyIa 6kx3yCL9jIH9igsRga9aFr/aFcvreCwap/ac/6DNRNV2r0xVR8bxOR+unlkxB5QczhP3k aoIlJlfz2/VsI3nwu0TQqEO/++YJLq15AfM0H7pWsh58jhYD7fxfFqAIraYhPpHTWqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170514; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Qm9VDfZMkDq6ROtGuFwnAC6vZffIKur/W9T4kXarLSI=; b=iwMiJLbbvzTZa+D5QqZmufuHi26Kp1i6gJK5xxpSbWGfE6ecvL+QSR8O5wd3alQlqNov /rDwXwdU/RApqIckzYHaEEHP14LTbNqyQtAv5DPgSUJr7P+Ib663fzec7dlkMaRkVzxK9 eUycnfXdgFN1aFeurHMk8jMFEP7IdBlDynZ+Btjk3RiZzpIkFsCKM3GwAUINTFJDL0IYP pxU0otgC9bLvr362sXaHWIIussi7L61hXo/a5vG83YQ/7wvF5cpr1AoZJcxOoTfvWggYN EPFbxCzxwbFQ3CDG54zsIUdZdWNQsgsvuTPVuJckcwYoxLPHsYBDz4IS0tQXo6Z2jlg== 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=pywPCH2d; arc=none smtp.remote-ip=74.125.82.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.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 3294A606A32F for ; Wed, 2 Dec 2026 00:15:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3294A606A32F 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=pywPCH2d Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-3869accaac2so8041672eec.1 for ; Tue, 01 Dec 2026 16:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796170513; x=1796775313; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Qm9VDfZMkDq6ROtGuFwnAC6vZffIKur/W9T4kXarLSI=; b=pywPCH2dKd31cJVrfsZRjcU9vTap1rimC2901MqbYduddzUEukHQ6vykZJ8D/ztHsH 7G2aYvxIG3d+0IZiKu4w04Owu9jGevt/WwSUOOfLTkn2b0BTyWzFOwELdoBF13GHLmYN jFBGyKebSbnPGpsL1gNNHtVI6Gyo/qDjCfOwhpqx6208Kc1+1Oe+5Y57Y7s2m9YJpdrP YPA0NsJAAvgU1KmtfjVnUr1t9bBFaOUeLvsMKO/yxwoEhSAHQoYx/vLjfcg1nlSoyQUm +Zu1DPZsKEi668vJyjA9pnKvmlXlWb4tmPWxFNhuQbJvRBqIsb7s2DtwC3KmUhOC5ROt Fzmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796170513; x=1796775313; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Qm9VDfZMkDq6ROtGuFwnAC6vZffIKur/W9T4kXarLSI=; b=dilBbqj+kaY/carSTRWw6+BGDjB0ghZXnVy5jFaDjCYZvxmttNuRSUPVvB/HHw0Mb4 oJZdWcyv42BgQApxeh/roScOlS7EBf4Sx1Sdb93jvdkii5fg//g76UksnkEaL5B5GF+r 7BhoadyB9+qvoCni+hUpDMNH1JN/1hf32eanlkCmwDUHqkhqeFE6/FlK6lziXZqLmpHx w7WisB7Dvso+sF/vK43ZY905KVy4FVqoSBivFBZk9HOEfmAxjsleazUY0XPx8Ur4ww53 OuF+k2I1BA0eXD25rQbeQ+1u8uKyL9y1sCd/L+GMFzBj/CExLKzdqNLpwye2mlrF2VZX 8lpQ== X-Forwarded-Encrypted: i=1; AL+hErEbFw5fR1nxAFEoJdvh2jYOilCR/yfmERijrCck8h+ymD/6KHAlWm81dueU76TF3kODpKdPTVzTBns6Ntw=@vger.kernel.org X-Gm-Message-State: APuU4Z9jWt878ozhinQhcNZ21toWraaRCcVQFVyUD67kN/32vZLwmj1J jVdtkTXKz69vYsSWhTInas3l+enwu8mdRFEK6dEH2/3/2E33N6um4GCwuapFdtx1+RflxcIhpsY m+R7urJpUDk3yfg== X-Received: from dycmv4.prod.google.com ([2002:a05:693c:2804:b0:387:16a9:be02]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:a0b:b0:386:a416:6c91 with SMTP id 5a478bee46e88-386a4166fdemr32045205eec.20.1796170512820; Tue, 01 Dec 2026 16:15:12 -0800 (PST) Date: Tue, 1 Dec 2026 16:13:41 -0800 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 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202001344.2721429-12-wusamuel@google.com> Subject: [PATCH bpf-next v4 00/10] kallsyms: Add KALLSYMS_QUERY_BY_NAME and KALLSYMS_QUERY_BY_ADDR ioctls 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" /proc/kallsyms is the primary interface for userspace to query the kernel symbol table. However, resolving even a handful of symbols or addresses requires reading and parsing the entire text file, which is often several megabytes and takes thousands of read() syscalls. This patchseries adds two ioctl() commands to interface /proc/kallsyms: 1. KALLSYMS_QUERY_BY_NAME: Finds a symbol by name, or by prefix with the KALLSYMS_QUERY_NAME_PREFIX flag. The default is to search vmlinux followed by modules, but userspace can specify a specific section with the optional query_module. Each call returns one match along with the match position, such that subsequent ioctl() calls can continue with a (position + 1) call. 2. KALLSYMS_QUERY_BY_ADDR: Finds the symbol that covers query_addr. A caller that needs an exact match can compare input, query_addr, with the output, sym_addr. Both commands fill a shared struct kallsyms_query_sym, with fields: address, size, and optional name and module buffers. Buffer lengths are in/out; on -ENAMETOOLONG the required sizes are still returned. As with the text file, return values adhere to the same permissions (such as at open() time), otherwise the ioctls fails with -EPERM. For version compatibility, each struct carries its own size, so the command values do not change when the structs grow. libbpf uses KALLSYMS_QUERY_BY_NAME to resolve typeless ksyms. It matches exact names plus ".llvm." prefixes, as well as indicates if there is name ambiguity; this keeps the semantics identical, while still getting the performance benefit. 1. libbpf typeless ksym (8CPU Cuttlefish VM, BPF): Metric Text parse KALLSYMS_QUERY Change -------------------------- ---------- --------------- ------------ Resolve 11 typeless ksyms 152.6 ms 4.41 ms ~35x 2. Perfetto symbolization (8CPU x86-64 VM, 175k-line): Metric Text parse KALLSYMS_QUERY Change -------------------------- ---------- --------------- ------- Init 131.0 ms 0.04 ms ~3000x 50k symbolizations 28.6 ms 3.5 ms ~8x traced_probes VmRSS 15.0 MB 4.5 MB -70% traced_probes VmHWM 23.7 MB 4.5 MB -81% Note: Main reason v4 numbers are slower than v2 is that ambiguity resolution in libbpf requires extra ioctl() calls. Patch overview: - Patch 1: register existing PROCFS_IOCTL range in ioctl-number.rst - Patch 2-3: Add linear scan for modules and BPF JIT symbols - Patch 4-5: Add ioctls to QUERY_BY_NAME and QUERY_BY_ADDR - Patch 6: Document new ioctls - Patch 7: Sync new ioctl UAPI definitions into tools - Patch 8: Add proc selftest for both ioctls - Patch 9-10: Use QUERY_BY_NAME in libbpf and add BPF selftest Changes in v4: - Added linear scan in bpf_kallsyms_query_name() and cond_resched() in kprobe loop (per bpf-ci) - Renaming few functions and variables for consistency with existing convention (per Andrii and Petr) - Return first error in kallsyms_copy_sym_to_user() (per Andrii) - libbpf: dropped the local #ifndef (per Andrii) - Rebase patchseries on bpf-next - v3 link: https://lore.kernel.org/all/20261113221248.3535369-11-wusamuel@google.com/ Changes in v3: - Add new and missing ioctls in ioctl-number.rst (Randy) - Split into two ioctls() BY_NAME and BY_ADDR (Andrii, David) - Add shared struct for both commands (Andrii) - Add optional name and module inputs (Andrii) - Encode size 0 in commands and keep the sizes in structs (Andrii) - Add an optional module_filter (Andrii) - BY_NAME searches vmlinux, modules, ftrace, BPF JIT and kprobes (Andrii) - Add one-by-one pagination for BY_NAME (Andrii, David) - Add prefix matching (David) - Do not return hidden BPF JIT symbols (bpf-ci) - libbpf: retain semantics (match ".llvm", fail on ambiguous matches) and fall back to text parser on error (bpf-ci, Andrii) - Added module_kallsyms_find_name() as a separate patch - Selftests: report skips with a reason (sashiko) - v2 link: https://lore.kernel.org/all/20261023001603.560210-8-wusamuel@google.com/ Changes in v2: - Replaced the BPF syscall approach in libbpf with the more generalizable KALLSYMS_QUERY ioctl() on /proc/kallsyms, per Andrii - Added KALLSYMS_QUERY_BY_ADDR for address-to-symbol lookup - Added proc and bpf selftests and procfs documentation - v1 link: https://lore.kernel.org/all/20261009130708.1370675-1-wusamuel@google.com/ Samuel Wu (10): Documentation: ioctl-number: Add PROCFS_IOCTL_MAGIC range 0x10-0x11 module: Add module_kallsyms_query_name() bpf: Add bpf_kallsyms_query_name() kallsyms: Add KALLSYMS_QUERY_BY_NAME ioctl to /proc/kallsyms kallsyms: Add KALLSYMS_QUERY_BY_ADDR ioctl to /proc/kallsyms docs/procfs: Document KALLSYMS_QUERY_* ioctls on /proc/kallsyms tools: Copy KALLSYMS_QUERY_* definitions to linux/fs.h selftests/proc: Add KALLSYMS_QUERY_* ioctl tests libbpf: Resolve typeless ksyms via KALLSYMS_QUERY_BY_NAME ioctl selftests/bpf: Test typeless module ksym resolution Documentation/filesystems/proc.rst | 9 + .../userspace-api/ioctl/ioctl-number.rst | 2 + include/linux/filter.h | 11 + include/linux/kallsyms.h | 10 + include/linux/module.h | 13 + include/uapi/linux/fs.h | 58 +++ kernel/bpf/core.c | 25 ++ kernel/kallsyms.c | 357 ++++++++++++++++++ kernel/module/kallsyms.c | 57 +++ tools/include/uapi/linux/fs.h | 58 +++ tools/lib/bpf/libbpf.c | 69 +++- .../testing/selftests/bpf/prog_tests/ksyms.c | 9 + .../testing/selftests/bpf/progs/test_ksyms.c | 4 + tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + .../selftests/proc/proc-kallsyms-query.c | 248 ++++++++++++ 16 files changed, 930 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/proc/proc-kallsyms-query.c base-commit: 595782f6799a3eeed50b3dd1fb954cc8ce3689ac -- 2.56.1.911.g883d8bcb20-goog