kallsyms: show typed function parameters in oops/WARN dumps
Subsystems (6)
cover kallsyms: show typed function parameters in oops/WARN dumps
Building on the lineinfo series, this adds typed function parameter display to oops and WARN dumps. A build-time tool extracts parameter names and types from DWARF, and the kernel maps pt_regs to the calling convention at crash time. When BTF is available, struct pointer parameters are dereferenced and their members displayed.
Example output from a WARN in a function receiving struct new_utsname * (kernel version info) and struct file * parameters:
------------[ cut here ]------------ WARNING: drivers/tty/sysrq.c:1209 at demo_crash+0xf/0x20 (drivers/tty/sysrq.c:1209) CPU: 2 UID: 0 PID: 323 Comm: bash RIP: 0010:demo_crash+0xf/0x20 (drivers/tty/sysrq.c:1209) ... RDI: ffffffffb8ca8d00 RSI: ffffa0a3c250acc0 ... Function parameters (paraminfo_demo_crash): uts (struct new_utsname *) = 0xffffffffb8ca8d00 .sysname = "Linux" .nodename = "localhost" .release = "7.0.0-rc2-00006-g3190..." .version = "#45 SMP PRE" file (struct file * ) = 0xffffa0a3c250acc0 .f_mode = (fmode_t)67993630 .f_op = (struct file_operations *)0xffffffffb7237620 .f_flags = (unsigned int)32769 .f_cred = (struct cred *)0xffffa0a3c2e06a80 .dentry = (struct dentry *)0xffffa0a3c0978cc0 .prev_pos = (loff_t)-1 Call Trace: <TASK> write_sysrq_trigger+0x96/0xb0 (drivers/tty/sysrq.c:1222) proc_reg_write+0x54/0xa0 (fs/proc/inode.c:330) vfs_write+0xc9/0x480 (fs/read_write.c:686) ksys_write+0x6e/0xe0 (fs/read_write.c:738) do_syscall_64+0xe2/0x570 (arch/x86/entry/syscall_64.c:62) entry_SYSCALL_64_after_hwframe+0x77/0x7f (arch/x86/entry/entry_64.S:121)
Patch 1 adds the core paraminfo infrastructure (DWARF extraction, kernel-side lookup, register-to-parameter mapping, ~1-2 MB overhead). Patch 2 adds optional BTF-based struct rendering, gated behind CONFIG_KALLSYMS_PARAMINFO_BTF.
Sasha Levin (2):
kallsyms: show function parameter info in oops/WARN dumps
kallsyms: add BTF-based deep parameter rendering in oops dumps
.../admin-guide/kallsyms-lineinfo.rst | 31 + arch/x86/kernel/dumpstack.c | 6 +- include/linux/kallsyms.h | 9 + init/Kconfig | 40 ++ kernel/Makefile | 1 + kernel/kallsyms.c | 182 ++++++ kernel/kallsyms_internal.h | 6 + kernel/kallsyms_paraminfo_btf.c | 199 ++++++ lib/Kconfig.debug | 11 + lib/tests/Makefile | 3 + lib/tests/paraminfo_kunit.c | 249 ++++++++ scripts/Makefile | 3 + scripts/empty_paraminfo.S | 18 + scripts/gen_paraminfo.c | 597 ++++++++++++++++++ scripts/link-vmlinux.sh | 44 +- 15 files changed, 1393 insertions(+), 6 deletions(-) create mode 100644 kernel/kallsyms_paraminfo_btf.c create mode 100644 lib/tests/paraminfo_kunit.c create mode 100644 scripts/empty_paraminfo.S create mode 100644 scripts/gen_paraminfo.c
--
2.51.0
PATCH 1/2 kallsyms: show function parameter info in oops/WARN dumps
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (scripts/gen_paraminfo.c) parses DW_TAG_subprogram and DW_TAG_formal_parameter entries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.
At runtime, kallsyms_show_paraminfo() performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value from pt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".
Integration at show_regs() means this works for both oops and WARN() automatically, since both paths provide full pt_regs at the exception point.
Example output:
Function parameters (ext4_readdir):
file (struct file *) = 0xffff888123456000
ctx (struct dir_context *) = 0x0000000000001234 <-- fault addressGated behind CONFIG_KALLSYMS_PARAMINFO (depends on CONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.
--- .../admin-guide/kallsyms-lineinfo.rst | 31 + arch/x86/kernel/dumpstack.c | 6 +- include/linux/kallsyms.h | 9 + init/Kconfig | 21 + kernel/kallsyms.c | 168 ++++++ kernel/kallsyms_internal.h | 6 + lib/Kconfig.debug | 11 + lib/tests/Makefile | 3 + lib/tests/paraminfo_kunit.c | 256 ++++++++ scripts/Makefile | 3 + scripts/empty_paraminfo.S | 18 + scripts/gen_paraminfo.c | 549 ++++++++++++++++++ scripts/link-vmlinux.sh | 44 +- 13 files changed, 1119 insertions(+), 6 deletions(-) create mode 100644 lib/tests/paraminfo_kunit.c create mode 100644 scripts/empty_paraminfo.S create mode 100644 scripts/gen_paraminfo.c
Documentation/admin-guide/kallsyms-lineinfo.rst +31 -0
@@ -83,6 +83,37 @@ compression). Per-module lineinfo adds approximately 2-3 bytes per DWARF line entry to each ``.ko`` file. +Function Parameter Info +====================== + +``CONFIG_KALLSYMS_PARAMINFO`` extends the debugging information by embedding +function parameter names and types in the kernel image. When an oops or WARN +occurs, the faulting function's register-passed arguments are displayed with +their names, types, and values from the saved registers. + +Enable in addition to the lineinfo options:: + + CONFIG_KALLSYMS_PARAMINFO=y + +Example oops output with paraminfo:: + + RIP: 0010:ext4_readdir+0x1a3/0x5b0 (fs/ext4/dir.c:421) + ... + Function parameters (ext4_readdir): + file (struct file *) = 0xffff888123456000 + ctx (struct dir_context *) = 0x0000000000001234 <-- fault address + +The ``<-- fault address`` annotation appears when a parameter value matches +the page fault address (CR2 on x86), helping quickly identify which argument +caused the crash. + +This feature works for both oops and WARN() on x86-64. Only register-passed +parameters (up to 6 on x86-64: RDI, RSI, RDX, RCX, R8, R9) are displayed. +The parameter info is only shown for the faulting/warning frame where full +register state is available. + +The paraminfo tables add approximately 1-2 MiB to the kernel image. + Known Limitations =================
arch/x86/kernel/dumpstack.c +4 -2
@@ -483,8 +483,10 @@ void show_regs(struct pt_regs *regs)__show_regs (regs, print_kernel_regs,KERN_DEFAULT );/* -* When in-kernel, we also print out the stack at the time of the fault.. +* When in-kernel, show function parameter info and stack trace. */ -if (!user_mode (regs)) +if (!user_mode (regs)) { +kallsyms_show_paraminfo (regs);show_trace_log_lvl (current, regs,NULL ,KERN_DEFAULT ); + } }
include/linux/kallsyms.h +9 -0
@@ -104,6 +104,13 @@ int lookup_symbol_name(unsigned long addr, char *symname);bool kallsyms_lookup_lineinfo (unsigned long addr,const char **file,unsigned int *line); +#ifdef CONFIG_KALLSYMS_PARAMINFO +struct pt_regs ; +void kallsyms_show_paraminfo (struct pt_regs *regs); +#else +static inline void kallsyms_show_paraminfo (struct pt_regs *regs) {} +#endif +#else /* !CONFIG_KALLSYMS */ static inline unsigned long kallsyms_lookup_name (const char *name)
@@ -179,6 +186,8 @@ static inline bool kallsyms_lookup_lineinfo(unsigned long addr, {return false; } + +static inline void kallsyms_show_paraminfo (struct pt_regs *regs) {}#endif /*CONFIG_KALLSYMS*/ static inline void print_ip_sym (const char *loglvl,unsigned long ip)
init/Kconfig +21 -0
@@ -2085,6 +2085,27 @@ config KALLSYMS_LINEINFO_MODULES If unsure, say N. +config KALLSYMS_PARAMINFO + bool "Show function parameter info in oops/WARN dumps" + depends on KALLSYMS_LINEINFO + help + Embeds function parameter name and type information in the kernel + image, extracted from DWARF debug info at build time. When an + oops or WARN occurs, the crashing/warning function's register- + passed arguments are displayed with their names, types, and + values from pt_regs. + + When enabled, oops/WARN dumps include lines like: + + Function parameters (ext4_readdir): + file (struct file *) = 0xffff888123456000 + ctx (struct dir_context *) = 0x0000000000001234 + + Requires elfutils (libdw-dev/elfutils-devel) on the build host. + Adds approximately 1-2 MB to the kernel image. + + If unsure, say N. + # end of the "standard kernel features (expert users)" menu config ARCH_HAS_MEMBARRIER_CALLBACKS
kernel/kallsyms.c +168 -0
174 lines not on this page · raw message
kernel/kallsyms_internal.h +6 -0
@@ -26,4 +26,10 @@ extern const u32 lineinfo_file_offsets[];extern const u32 lineinfo_filenames_size;extern const char lineinfo_filenames[]; +extern const u32 paraminfo_num_funcs; +extern const u32 paraminfo_func_addrs[]; +extern const u32 paraminfo_func_offsets[]; +extern const u8 paraminfo_func_data[]; +extern const char paraminfo_strings[]; +#endif // LINUX_KALLSYMS_INTERNAL_H_
lib/Kconfig.debug +11 -0
@@ -3058,6 +3058,17 @@ config LINEINFO_KUNIT_TEST If unsure, say N. +config PARAMINFO_KUNIT_TEST + tristate "KUnit tests for kallsyms paraminfo" if !KUNIT_ALL_TESTS + depends on KUNIT && KALLSYMS_PARAMINFO + default KUNIT_ALL_TESTS + help + KUnit tests for the kallsyms function parameter info feature. + Verifies that paraminfo tables correctly map functions to their + parameter names and types. + + If unsure, say N. + config HW_BREAKPOINT_KUNIT_TEST bool "Test hw_breakpoint constraints accounting" if !KUNIT_ALL_TESTS depends on HAVE_HW_BREAKPOINT
lib/tests/Makefile +3 -0
@@ -39,6 +39,9 @@ obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) += longest_symbol_kunit.o CFLAGS_lineinfo_kunit.o += $(call cc-option,-fno-inline-functions-called-once) obj-$(CONFIG_LINEINFO_KUNIT_TEST) += lineinfo_kunit.o +CFLAGS_paraminfo_kunit.o += $(call cc-option,-fno-inline-functions-called-once) +obj-$(CONFIG_PARAMINFO_KUNIT_TEST) += paraminfo_kunit.o + obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o obj-$(CONFIG_MIN_HEAP_KUNIT_TEST) += min_heap_kunit.o CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
lib/tests/paraminfo_kunit.c new file +256 -0
256 lines not on this page · raw message
scripts/Makefile +3 -0
@@ -5,6 +5,7 @@ hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms hostprogs-always-$(CONFIG_KALLSYMS_LINEINFO) += gen_lineinfo +hostprogs-always-$(CONFIG_KALLSYMS_PARAMINFO) += gen_paraminfo hostprogs-always-$(BUILD_C_RECORDMCOUNT) += recordmcount hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
@@ -39,6 +40,8 @@ HOSTCFLAGS_sign-file.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/nu HOSTLDLIBS_sign-file = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) HOSTCFLAGS_gen_lineinfo.o = $(shell $(HOSTPKG_CONFIG) --cflags libdw 2> /dev/null) HOSTLDLIBS_gen_lineinfo = $(shell $(HOSTPKG_CONFIG) --libs libdw 2> /dev/null || echo -ldw -lelf -lz) +HOSTCFLAGS_gen_paraminfo.o = $(shell $(HOSTPKG_CONFIG) --cflags libdw 2> /dev/null) +HOSTLDLIBS_gen_paraminfo = $(shell $(HOSTPKG_CONFIG) --libs libdw 2> /dev/null || echo -ldw -lelf -lz) ifdef CONFIG_UNWINDER_ORC ifeq ($(ARCH),x86_64)
scripts/empty_paraminfo.S new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Empty paraminfo stub for the initial vmlinux link. + * The real paraminfo is generated from .tmp_vmlinux1 by gen_paraminfo. + */ + .section .rodata, "a" + .globl paraminfo_num_funcs + .balign 4 +paraminfo_num_funcs: + .long 0 + .globl paraminfo_func_addrs +paraminfo_func_addrs: + .globl paraminfo_func_offsets +paraminfo_func_offsets: + .globl paraminfo_func_data +paraminfo_func_data: + .globl paraminfo_strings +paraminfo_strings:
scripts/gen_paraminfo.c new file +549 -0
549 lines not on this page · raw message
scripts/link-vmlinux.sh +40 -4
83 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH 2/2 kallsyms: add BTF-based deep parameter rendering in oops dumps
In reply to Sasha LevinWhen CONFIG_KALLSYMS_PARAMINFO_BTF is enabled and a function parameter is a pointer to a kernel struct, use BTF type information to safely dereference the pointer and display struct member values in oops/WARN dumps.
The rendering uses btf_type_snprintf_show() which internally uses copy_from_kernel_nofault() for safe memory access, making it safe to call in oops/panic context. Struct members are printed in a compact two-column layout for readability.
Example output:
Function parameters (paraminfo_demo_crash):
file (struct file *) = 0xffff8bc043cb36c0
.f_mode = (fmode_t)67993630 .f_flags = (unsigned int)32769
.f_mapping = (struct address_space *)0x.. .f_inode = (struct inode *)0x..
.f_cred = (struct cred *)0x... .prev_pos = (loff_t)-1Gated behind CONFIG_KALLSYMS_PARAMINFO_BTF which depends on both CONFIG_KALLSYMS_PARAMINFO and CONFIG_DEBUG_INFO_BTF. No additional kernel image size beyond BTF itself.
--- init/Kconfig | 19 +++ kernel/Makefile | 1 + kernel/kallsyms.c | 47 ++++-- kernel/kallsyms_paraminfo_btf.c | 267 ++++++++++++++++++++++++++++++++ lib/tests/paraminfo_kunit.c | 13 +- scripts/gen_paraminfo.c | 80 ++++++++-- 6 files changed, 384 insertions(+), 43 deletions(-) create mode 100644 kernel/kallsyms_paraminfo_btf.c
init/Kconfig +19 -0
@@ -2106,6 +2106,25 @@ config KALLSYMS_PARAMINFO If unsure, say N. +config KALLSYMS_PARAMINFO_BTF + bool "Render struct contents for pointer parameters in oops dumps" + depends on KALLSYMS_PARAMINFO && DEBUG_INFO_BTF + help + When a function parameter is a pointer to a kernel struct and BTF + type information is available, dereference the pointer and display + key struct members (1 level deep) in oops/WARN dumps. + + When enabled, oops dumps may include additional indented lines + showing struct member values in a two-column layout: + + file (struct file *) = 0xffff888123456000 + .f_flags = (unsigned int)32769 .f_mode = (fmode_t)29 + + Requires CONFIG_DEBUG_INFO_BTF. + No additional kernel image size beyond BTF itself. + + If unsure, say N. + # end of the "standard kernel features (expert users)" menu config ARCH_HAS_MEMBARRIER_CALLBACKS
kernel/Makefile +1 -0
@@ -75,6 +75,7 @@ obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o +obj-$(CONFIG_KALLSYMS_PARAMINFO_BTF) += kallsyms_paraminfo_btf.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o elfcorehdr.o obj-$(CONFIG_CRASH_RESERVE) += crash_reserve.o
kernel/kallsyms.c +30 -17
100 lines not on this page · raw message
kernel/kallsyms_paraminfo_btf.c new file +267 -0
267 lines not on this page · raw message
lib/tests/paraminfo_kunit.c +3 -10
@@ -7,7 +7,8 @@* Verifies that the paraminfo tables correctly map function addresses * to their parameter names and types. * -* Build with: CONFIG_PARAMINFO_KUNIT_TEST=m (or =y) +* Build with: CONFIG_PARAMINFO_KUNIT_TEST=y (must be built-in; paraminfo +* tables are vmlinux-only, so module test functions won't be found) */ #include <kunit/test.h>
@@ -45,15 +46,7 @@ static noinline void paraminfo_test_no_args(void)/* ---- Helpers to query paraminfo tables directly ---- */ -/* -* These access the raw paraminfo tables to verify correctness. -* The tables are defined in kernel/kallsyms_internal.h. -*/ -extern const u32 paraminfo_num_funcs; -extern const u32 paraminfo_func_addrs[]; -extern const u32 paraminfo_func_offsets[]; -extern const u8 paraminfo_func_data[]; -extern const char paraminfo_strings[]; +#include "../../kernel/kallsyms_internal.h" struct param_result {unsigned int num_params;
scripts/gen_paraminfo.c +64 -16
185 lines not on this page · raw message
Signature · 1 line
2.51.0
Quoted 8 lines · Sasha Levin
Function parameters (
paraminfo_demo_crash):
uts (structnew_utsname*) =0xffffffffb8ca8d00
.sysname = "Linux" .nodename = "localhost"
.release = "7.0.0-rc2-00006-g3190..." .version = "#45 SMP PRE"
file (struct file * ) =0xffffa0a3c250acc0
.f_mode = (fmode_t)67993630 .f_op = (structfile_operations*)0xffffffffb7237620
.f_flags = (unsigned int)32769 .f_cred = (struct cred *)0xffffa0a3c2e06a80
.dentry = (struct dentry *)0xffffa0a3c0978cc0
Should this be in crash's format?
struct dentry ffffffffffff0000
Andrew Morton
maintainerQuoted 5 lines · On Mon, 23 Mar 2026 12:48:55 -0400 Sasha Levin <[email protected]> wrote:
Building on the lineinfo series, this adds typed function parameter display to oops and WARN dumps. A build-time tool extracts parameter names and types from DWARF, and the kernel maps
pt_regsto the calling convention at crash time. When BTF is available, struct pointer parameters are dereferenced and their members displayed.
mm.git is full and I'm seriously looking at loadshedded. Can we please leave this until next cycle, give your "kallsyms: embed source file:line info in kernel stack traces", v4 time to settle in?
Quoted 10 lines · Alexey Dobriyan
Quoted 8 lines · Sasha Levin
Function parameters (
paraminfo_demo_crash):
uts (structnew_utsname*) =0xffffffffb8ca8d00
.sysname = "Linux" .nodename = "localhost"
.release = "7.0.0-rc2-00006-g3190..." .version = "#45 SMP PRE"
file (struct file * ) =0xffffa0a3c250acc0
.f_mode = (fmode_t)67993630 .f_op = (structfile_operations*)0xffffffffb7237620
.f_flags = (unsigned int)32769 .f_cred = (struct cred *)0xffffa0a3c2e06a80
.dentry = (struct dentry *)0xffffa0a3c0978cc0
Quoted 3 lines
Should this be in crash's format?
struct dentry
ffffffffffff0000
The format currently used comes from the kernel's own BTF show infrastructure.
crash's struct dentry ffffffffffff0000 syntax is specific to crash. drgn, GDB, bpftool, and the kernel's own BTF rendering all use the (struct type *)0xaddr notation we're already using. Adopting crash's format would make this output inconsistent with all other BTF-based output in the kernel, and would also lose the member name context (.dentry).
Signature · 2 lines
Thanks, Sasha
Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Mon, 23 Mar 2026 12:48:55 -0400 Sasha Levin <[email protected]> wrote:
Building on the lineinfo series, this adds typed function parameter display to oops and WARN dumps. A build-time tool extracts parameter names and types from DWARF, and the kernel maps
pt_regsto the calling convention at crash time. When BTF is available, struct pointer parameters are dereferenced and their members displayed.mm.git is full and I'm seriously looking at loadshedded. Can we please leave this until next cycle, give your "kallsyms: embed source file:line info in kernel stack traces", v4 time to settle in?
Definitely.
If you want to ignore these, and related patches that might appear in the next couple of weeks, I'll plan to send them to you in an organized series after -rc1.
Signature · 2 lines
Thanks, Sasha
Quoted 1 line · Sasha Levin
Building on the lineinfo series, this adds typed function parameter
hi,
could you please specify the exact tree/commit and point to the series this patchset is based on?
thanks,
jirka
Quoted 68 lines
display to oops and WARN dumps. A build-time tool extracts parameter names and types from DWARF, and the kernel maps
pt_regsto the calling convention at crash time. When BTF is available, struct pointer parameters are dereferenced and their members displayed.Example output from a WARN in a function receiving struct
new_utsname* (kernel version info) and struct file * parameters:------------[ cut here ]------------ WARNING: drivers/tty/sysrq.c:1209 at demo_crash+0xf/0x20 (drivers/tty/sysrq.c:1209) CPU: 2 UID: 0 PID: 323 Comm: bash RIP: 0010:demo_crash+0xf/0x20 (drivers/tty/sysrq.c:1209) ... RDI: ffffffffb8ca8d00 RSI: ffffa0a3c250acc0 ... Function parameters (paraminfo_demo_crash): uts (struct new_utsname *) = 0xffffffffb8ca8d00 .sysname = "Linux" .nodename = "localhost" .release = "7.0.0-rc2-00006-g3190..." .version = "#45 SMP PRE" file (struct file * ) = 0xffffa0a3c250acc0 .f_mode = (fmode_t)67993630 .f_op = (struct file_operations *)0xffffffffb7237620 .f_flags = (unsigned int)32769 .f_cred = (struct cred *)0xffffa0a3c2e06a80 .dentry = (struct dentry *)0xffffa0a3c0978cc0 .prev_pos = (loff_t)-1 Call Trace: <TASK> write_sysrq_trigger+0x96/0xb0 (drivers/tty/sysrq.c:1222) proc_reg_write+0x54/0xa0 (fs/proc/inode.c:330) vfs_write+0xc9/0x480 (fs/read_write.c:686) ksys_write+0x6e/0xe0 (fs/read_write.c:738) do_syscall_64+0xe2/0x570 (arch/x86/entry/syscall_64.c:62) entry_SYSCALL_64_after_hwframe+0x77/0x7f (arch/x86/entry/entry_64.S:121)Patch 1 adds the core paraminfo infrastructure (DWARF extraction, kernel-side lookup, register-to-parameter mapping, ~1-2 MB overhead). Patch 2 adds optional BTF-based struct rendering, gated behind
CONFIG_KALLSYMS_PARAMINFO_BTF.Sasha Levin (2):
kallsyms: show function parameter info in oops/WARN dumps
kallsyms: add BTF-based deep parameter rendering in oops dumps.../admin-guide/kallsyms-lineinfo.rst | 31 + arch/x86/kernel/dumpstack.c | 6 +- include/linux/kallsyms.h | 9 + init/Kconfig | 40 ++ kernel/Makefile | 1 + kernel/kallsyms.c | 182 ++++++ kernel/kallsyms_internal.h | 6 + kernel/kallsyms_paraminfo_btf.c | 199 ++++++ lib/Kconfig.debug | 11 + lib/tests/Makefile | 3 + lib/tests/paraminfo_kunit.c | 249 ++++++++ scripts/Makefile | 3 + scripts/empty_paraminfo.S | 18 + scripts/gen_paraminfo.c | 597 ++++++++++++++++++ scripts/link-vmlinux.sh | 44 +- 15 files changed, 1393 insertions(+), 6 deletions(-) create mode 100644 kernel/kallsyms_paraminfo_btf.c create mode 100644 lib/tests/paraminfo_kunit.c create mode 100644 scripts/empty_paraminfo.S create mode 100644 scripts/gen_paraminfo.c--
2.51.0
Quoted 6 lines · Jiri Olsa
Quoted 1 line · Sasha Levin
Building on the lineinfo series, this adds typed function parameter
hi,
could you please specify the exact tree/commit and point to the series this patchset is based on?
Yup, sorry, I should have noted that. This series is based on Andrew Morton's mm-nonmm-unstable branch (git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
mm-nonmm-unstable) since he took the base lineinfo patches and these build on code adjacent to it.
There's no direct dependency between the two, but they touch the same parts of the code.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Sasha LevinQuoted 23 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):
Quoted 8 lines
file (struct file *) = 0xffff888123456000 ctx (struct dir_context *) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>
Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does. dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures from BTF that are not accurate. This work is still ongoing. For example see this set:
https://lore.kernel.org/bpf/[email protected]/
pahole isn't perfect, but what you attempted to do here is just broken.
Re: [PATCH 2/2] kallsyms: add BTF-based deep parameter rendering in oops dumps
In reply to Sasha LevinQuoted 23 lines · Sasha Levin
kernel/kallsyms_paraminfo_btf.c new file +22
-0+static const char *extract_struct_name (const char *type_str,bool *is_union, +char *name_buf,size_t bufsz) +{ +const char *p, *end; + + *is_union = false; + +/* Must end with " *" to be a pointer */ + end = type_str +strlen (type_str); +if (end - type_str <3 || end[-1 ] !='*' || end[-2 ] !=' ' ) +return NULL ; + +if (!strncmp (type_str,"struct " ,7 )) { + p = type_str +7 ; + }else if (!strncmp (type_str,"union " ,6 )) { + p = type_str +6 ; + *is_union = true; + }else { +return NULL ; + } + +/* Copy name up to the " *" */
kernel/kallsyms_paraminfo_btf.c line 71
Quoted 10 lines
kernel/kallsyms_paraminfo_btf.c new file +10
-0+ { +size_t len = (end -2 ) - p; + +if (len ==0 || len >= bufsz) +return NULL ; +memcpy (name_buf, p, len); + name_buf[len] ='\0' ; + } + +return name_buf;
Nack. This is just awful.
You didn't even bother to reformat what claude spat out. Which means you didn't think it through.
It prints something that looks plausible
which is the opposite of what kernel crash dump should be. crash output should be accurate and not a guess work.
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Alexei StarovoitovQuoted 30 lines · Alexei Starovoitov
Quoted 29 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):file (struct file *) = 0xffff888123456000 ctx (struct dir_context *) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.
Quoted 7 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does.
Let's keep this on the technical side please.
Quoted 2 lines
dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures
Fair point about pahole and optimized-out args. The problem is that BTF depends on BPF_SYSCALL, and the environments I care about can't enable either. Automotive, robotics, and safety configs all have DWARF and KALLSYMS but no path to BTF.
Quoted 3 lines
from BTF that are not accurate. This work is still ongoing. For example see this set:
https://lore.kernel.org/bpf/[email protected]/
Ack. I wasn't familiar with this, and looks like it makes the 2nd patch in this series unnecessary.
Quoted 2 lines
pahole isn't perfect, but what you attempted to do here is just broken.
I hear you that raw DWARF isn't perfect with optimized code, but I'd rather show best-effort info than nothing. Happy to mark it as such in the output. Open to suggestions on improving accuracy without the BTF dependency.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
Quoted 40 lines · Sasha Levin
Quoted 30 lines · Alexei Starovoitov
Quoted 29 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):file (struct file *) = 0xffff888123456000 ctx (struct dir_context *) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.Quoted 7 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does.
Quoted 7 lines
Let's keep this on the technical side please.
Quoted 2 lines
dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures
Fair point about pahole and optimized-out args. The problem is that BTF depends on
BPF_SYSCALL, and the environments I care about can't enable either.
This is trivially fixable without reinventing pahole.
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Sasha LevinQuoted 41 lines · Sasha Levin
Quoted 30 lines · Alexei Starovoitov
Quoted 29 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):
file (struct file *) =0xffff888123456000
ctx (structdir_context*) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.Quoted 7 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does.
Let's keep this on the technical side please.
Quoted 8 lines
Quoted 2 lines
dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures
Fair point about pahole and optimized-out args. The problem is that BTF depends on
BPF_SYSCALL, and the environments I care about can't enable either. Automotive, robotics, and safety configs all have DWARF and KALLSYMS but no path to BTF.
Curious what the blockers are to BTF adoption? Hopefully we can tackle some of these or get them on a roadmap at least. I know some embedded folks want vmlinux BTF as a module instead of directly contained in the vmlinux binary to minimize vmlinux size; is this the problem you run into? Are there other issues? Any info you could provide would be great as the aim is to make BTF feasible in as many environments as possible. Thanks!
Alan
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Alexei StarovoitovQuoted 43 lines · Alexei Starovoitov
Quoted 42 lines · Sasha Levin
Quoted 30 lines · Alexei Starovoitov
Quoted 29 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):file (struct file *) = 0xffff888123456000 ctx (struct dir_context *) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.Quoted 7 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does.
Let's keep this on the technical side please.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures
Fair point about pahole and optimized-out args. The problem is that BTF depends on
BPF_SYSCALL, and the environments I care about can't enable either.This is trivially fixable without reinventing pahole.
Hmm...
Looking at the code, I'd need to:
- Split BTF parsing from kernel/bpf/btf.c to somewhere outside of kernel/bpf/.
- New init path for btf_vmlinux outside BPF verifier.
- Refactor btf_parse_vmlinux() BPF-specific bits.
- Remove BPF_SYSCALL dependency from DEBUG_INFO_BTF.
- Somehow make BTF work with DEBUG_INFO_REDUCED.
I suppose that the first 4 are straightforward, but I don't have an idea about DEBUG_INFO_REDUCED. Though we can probably tackle it later.
Does that make sense? Did I miss anything?
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Alan MaguireQuoted 51 lines · Alan Maguire
Quoted 41 lines · Sasha Levin
Quoted 30 lines · Alexei Starovoitov
Quoted 29 lines · Sasha Levin
Embed DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments with their names, types, and values.
A new build-time tool (
scripts/gen_paraminfo.c) parsesDW_TAG_subprogramandDW_TAG_formal_parameterentries from DWARF .debug_info, extracting parameter names and human-readable type strings. The resulting tables are stored in .rodata using the same two-phase link approach as lineinfo.At runtime,
kallsyms_show_paraminfo()performs a binary search on the paraminfo tables, maps parameters to x86-64 calling convention registers (RDI, RSI, RDX, RCX, R8, R9), and prints each parameter's name, type, and value frompt_regs. If a parameter value matches the page fault address (CR2), it is highlighted with "<-- fault address".Integration at
show_regs()means this works for both oops andWARN()automatically, since both paths provide fullpt_regsat the exception point.Example output:
Function parameters (
ext4_readdir):
file (struct file *) =0xffff888123456000
ctx (structdir_context*) = 0x0000000000001234 <-- fault addressGated behind
CONFIG_KALLSYMS_PARAMINFO(depends onCONFIG_KALLSYMS_LINEINFO). Adds approximately 1-2 MB to the kernel image for ~58K functions.Quoted 7 lines
Quoted 2 lines
Assisted-by Claude:claude-opus-4-6Signed-off-by Sasha Levin <[email protected]>Nack.
You asked claude to reinvent pahole and BTF and it did it completely missing years of fine tuning that pahole does.
Let's keep this on the technical side please.
Quoted 8 lines
Quoted 2 lines
dwarf cannot be trusted as-is. pahole converts it carefully by analyzing optimized out arguments and dropping signatures
Fair point about pahole and optimized-out args. The problem is that BTF depends on
BPF_SYSCALL, and the environments I care about can't enable either. Automotive, robotics, and safety configs all have DWARF and KALLSYMS but no path to BTF.
Quoted 6 lines
Curious what the blockers are to BTF adoption? Hopefully we can tackle some of these or get them on a roadmap at least. I know some embedded folks want vmlinux BTF as a module instead of directly contained in the vmlinux binary to minimize vmlinux size; is this the problem you run into? Are there other issues? Any info you could provide would be great as the aim is to make BTF feasible in as many environments as possible. Thanks!
So the biggest reason I'm aware of is that those systems do not want to enable BPF, and BTF is hidden behind BPF.
Other than that:
1. Toolchain qualifications for safety uses (we'd need to get pahole safety
certified).
2. On the ecosystem side, from what I saw, BTF isn't part of most BSPs that
vendors produce.
3. I saw concerns in the past about interactions with PREEMPT_RT, but I'm not
sure if it's still a thing.
Signature · 2 lines
Thanks, Sasha
RFC 1/1 btf: split core BTF parsing out of BPF subsystem into kernel/btf/
In reply to Sasha LevinMove BTF type format parsing and inspection code out of the BPF subsystem into its own kernel/btf/ directory, separating core BTF functionality from BPF-specific extensions.
CONFIG_DEBUG_INFO_BTF currently depends on CONFIG_BPF_SYSCALL, which prevents embedded, automotive, and safety-critical environments from using BTF. These platforms often disable BPF for security and size reasons but would benefit from BTF type information for crash diagnostics and debugging.
Introduce CONFIG_BTF for the core BTF runtime support (type parsing, lookup, and display) which can be enabled independently of CONFIG_BPF_SYSCALL, and remove the BPF_SYSCALL dependency from CONFIG_DEBUG_INFO_BTF. The code is split into:
kernel/btf/btf.c - Core BTF: parsing, verification, type lookup,
display infrastructure. No BPF dependencies.
kernel/btf/bpf.c - BPF extensions: kfunc registration, struct_ops,
verifier integration, FD interface, module BTF.
kernel/btf/btf.h - Internal shared header.
When CONFIG_BPF_SYSCALL=n, only btf.c is compiled, providing the minimal BTF API. When CONFIG_BPF_SYSCALL=y, both files are compiled and bpf.c overrides weak symbols in btf.c for BPF-specific cleanup (IDR management, RCU-deferred freeing, kfunc/struct_ops tab cleanup).
No functional change when CONFIG_BPF_SYSCALL=y.
---
include/linux/btf.h | 80 +-
kernel/Makefile | 1 +
kernel/bpf/Makefile | 2 +-
kernel/btf/Makefile | 4 +
kernel/{bpf/btf.c => btf/bpf.c} | 6386 ++++---------------------------
kernel/btf/btf.c | 4803 +++++++++++++++++++++++
kernel/btf/btf.h | 135 +
lib/Kconfig.debug | 15 +-
8 files changed, 5796 insertions(+), 5630 deletions(-)
create mode 100644 kernel/btf/Makefile
rename kernel/{bpf/btf.c => btf/bpf.c} (50%)
create mode 100644 kernel/btf/btf.c
create mode 100644 kernel/btf/btf.hinclude/linux/btf.h +43 -37
@@ -139,17 +139,11 @@ struct btf_struct_metas {struct btf_struct_meta types[]; }; -extern const struct file_operations btf_fops; -const char *btf_get_name (const struct btf *btf);void btf_get (struct btf *btf);void btf_put (struct btf *btf);const struct btf_header *btf_header (const struct btf *btf); -int btf_new_fd (const union bpf_attr *attr,bpfptr_t uattr,u32 uattr_sz); -struct btf *btf_get_by_fd (int fd); -int btf_get_info_by_fd (const struct btf *btf, -const union bpf_attr *attr, -union bpf_attr __user *uattr); +/* Figure out the size of a type_id. If type_id is a modifier * (e.g. const), it will be resolved to find out the type with size. *
@@ -213,12 +207,9 @@ int btf_type_seq_show_flags(const struct btf *btf, u32 type_id, void *obj,int btf_type_snprintf_show (const struct btf *btf,u32 type_id,void *obj,char *buf,int len,u64 flags); -int btf_get_fd_by_id (u32 id); -u32 btf_obj_id (const struct btf *btf);bool btf_is_kernel (const struct btf *btf);bool btf_is_module (const struct btf *btf);bool btf_is_vmlinux (const struct btf *btf); -struct module *btf_try_get_module (const struct btf *btf);u32 btf_nr_types (const struct btf *btf);u32 btf_named_start_id (const struct btf *btf,bool own);struct btf *btf_base_btf (const struct btf *btf);
@@ -228,12 +219,8 @@ bool btf_type_is_primitive(const struct btf_type *t);bool btf_member_is_reg_int (const struct btf *btf,const struct btf_type *s,const struct btf_member *m,u32 expected_offset,u32 expected_size); -struct btf_record *btf_parse_fields (const struct btf *btf,const struct btf_type *t, -u32 field_mask,u32 value_size); -int btf_check_and_fixup_fields (const struct btf *btf,struct btf_record *rec);bool btf_type_is_void (const struct btf_type *t);s32 btf_find_by_name_kind (const struct btf *btf,const char *name,u8 kind); -s32 bpf_find_btf_id (const char *name,u32 kind,struct btf **btf_p);const struct btf_type *btf_type_skip_modifiers (const struct btf *btf,u32 id,u32 *res_id); const struct btf_type *btf_type_resolve_ptr(const struct btf *btf,
@@ -245,6 +232,20 @@ btf_resolve_size(const struct btf *btf, const struct btf_type *type, u32 *type_size);const char *btf_type_str (const struct btf_type *t); +/* BPF-specific declarations */ +extern const struct file_operations btf_fops; +int btf_new_fd (const union bpf_attr *attr,bpfptr_t uattr,u32 uattr_sz); +struct btf *btf_get_by_fd (int fd); +int btf_get_info_by_fd (const struct btf *btf, +const union bpf_attr *attr, +union bpf_attr __user *uattr); +int btf_get_fd_by_id (u32 id); +u32 btf_obj_id (const struct btf *btf); +struct btf_record *btf_parse_fields (const struct btf *btf,const struct btf_type *t, +u32 field_mask,u32 value_size); +int btf_check_and_fixup_fields (const struct btf *btf,struct btf_record *rec); +s32 bpf_find_btf_id (const char *name,u32 kind,struct btf **btf_p); +#define for_each_member (i, struct_type, member) \ for (i = 0, member = btf_type_member(struct_type); \ i < btf_type_vlen(struct_type); \
@@ -524,9 +525,6 @@ static inline void *btf_id_set8_contains(const struct btf_id_set8 *set, u32 id)bool btf_param_match_suffix (const struct btf *btf,const struct btf_param *arg,const char *suffix); -int btf_ctx_arg_offset (const struct btf *btf,const struct btf_type *func_proto, -u32 arg_no); -u32 btf_ctx_arg_idx (struct btf *btf,const struct btf_type *func_proto,int off);struct bpf_verifier_log ;
@@ -564,16 +562,39 @@ struct btf_field_iter {int vlen; }; -#ifdef CONFIG_BPF_SYSCALL +#ifdef CONFIG_BTF const struct btf_type *btf_type_by_id (const struct btf *btf,u32 type_id);void btf_set_base_btf (struct btf *btf,const struct btf *base_btf); +const char *btf_name_by_offset (const struct btf *btf,u32 offset); +const char *btf_str_by_offset (const struct btf *btf,u32 offset); +#else +static inline const struct btf_type *btf_type_by_id (const struct btf *btf, +u32 type_id) +{ +return NULL ; +} + +static inline void btf_set_base_btf (struct btf *btf,const struct btf *base_btf) +{ +} + +static inline const char *btf_name_by_offset (const struct btf *btf, +u32 offset) +{ +return NULL ; +} +#endif /* CONFIG_BTF */ + +#ifdef CONFIG_BPF_SYSCALL +struct module *btf_try_get_module (const struct btf *btf);int btf_relocate (struct btf *btf,const struct btf *base_btf,__u32 **map_ids);int btf_field_iter_init (struct btf_field_iter *it,struct btf_type *t,enum btf_field_iter_kind iter_kind);__u32 *btf_field_iter_next (struct btf_field_iter *it); -const char *btf_name_by_offset (const struct btf *btf,u32 offset); -const char *btf_str_by_offset (const struct btf *btf,u32 offset); +int btf_ctx_arg_offset (const struct btf *btf,const struct btf_type *func_proto, +u32 arg_no); +u32 btf_ctx_arg_idx (struct btf *btf,const struct btf_type *func_proto,int off);struct btf *btf_parse_vmlinux (void );struct btf *bpf_prog_get_target_btf (const struct bpf_prog *prog);u32 *btf_kfunc_flags (const struct btf *btf,u32 kfunc_btf_id,const struct bpf_prog *prog);
@@ -606,17 +627,7 @@ static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type return btf_type_is_struct(t); }#else -static inline const struct btf_type *btf_type_by_id (const struct btf *btf, -u32 type_id) -{ -return NULL ; -} - -static inline void btf_set_base_btf (struct btf *btf,const struct btf *base_btf) -{ -} - -static inline int btf_relocate (void *log,struct btf *btf,const struct btf *base_btf, +static inline int btf_relocate (struct btf *btf,const struct btf *base_btf,__u32 **map_ids) {return -EOPNOTSUPP ;
@@ -633,11 +644,6 @@ static inline __u32 *btf_field_iter_next(struct btf_field_iter *it)return NULL ; } -static inline const char *btf_name_by_offset (const struct btf *btf, -u32 offset) -{ -return NULL ; -}static inline u32 *btf_kfunc_id_set_contains (const struct btf *btf,u32 kfunc_btf_id,struct bpf_prog *prog)
@@ -683,5 +689,5 @@ static inline int btf_check_iter_arg(struct btf *btf, const struct btf_type *fun {return -EOPNOTSUPP ; } -#endif +#endif /* CONFIG_BPF_SYSCALL */ #endif
kernel/Makefile +1 -0
@@ -121,6 +121,7 @@ obj-$(CONFIG_RETHOOK) += trace/ obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-$(CONFIG_CPU_PM) += cpu_pm.o obj-$(CONFIG_BPF) += bpf/ +obj-$(CONFIG_BTF) += btf/ obj-$(CONFIG_KCSAN) += kcsan/ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
kernel/bpf/Makefile +1 -1
@@ -14,7 +14,7 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o obj-${CONFIG_BPF_LSM} += bpf_inode_storage.o obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o obj-$(CONFIG_BPF_JIT) += trampoline.o -obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o +obj-$(CONFIG_BPF_SYSCALL) += memalloc.o rqspinlock.o stream.o ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy) obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o endif
kernel/btf/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_BTF) += btf.o +obj-$(CONFIG_BPF_SYSCALL) += bpf.o
kernel/btf/bpf.c renamed from kernel/bpf/btf.c +797 -5589
2,833 lines not on this page · raw message
kernel/btf/btf.c new file +4803 -0
4,803 lines not on this page · raw message
kernel/btf/btf.h new file +135 -0
135 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.51.0
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewRe: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
These six declarations between the closing brace of struct btf_struct_ops_tab and bpf_find_btf_id() appear to be orphaned fields from the original struct btf definition that were left behind during…
Quoted 5 lines
kernel/btf/bpf.c new file +0
-0
[ ... ]
kernel/btf/bpf.c
Quoted 12 lines
kernel/btf/bpf.c new file +12
-0+struct btf_struct_ops_tab { +u32 cnt; +u32 capacity; +struct bpf_struct_ops_desc ops[]; +}; +u32 id; +struct rcu_head rcu; +struct btf_kfunc_set_tab *kfunc_set_tab; +struct btf_id_dtor_kfunc_tab *dtor_kfunc_tab; +struct btf_struct_metas *struct_meta_tab; +struct btf_struct_ops_tab *struct_ops_tab; +s32 bpf_find_btf_id (const char *name,u32 kind,struct btf **btf_p)
These six declarations between the closing brace of struct btf_struct_ops_tab and bpf_find_btf_id() appear to be orphaned fields from the original struct btf definition that were left behind during the split.
They are parsed as file-scope global variable definitions. With -fno-common, the name "id" in particular is likely to collide at link time. Were these meant to be removed here, given that they already appear correctly inside struct btf in kernel/btf/btf.h under the CONFIG_BPF_SYSCALL guard?
Quoted 5 lines
lib/Kconfig.debug +0
-0@@ -395,14 +395,23 @@ config DEBUG_INFO_SPLIT
[ ... ]
Quoted 7 lines
lib/Kconfig.debug +7
-0+config BTF + bool "BTF type information support" + depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED + depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST + depends on PAHOLE_VERSION >= 122 + # pahole uses elfutils, which does not have support for Hexagon relocations + depends on !HEXAGON
[ ... ]
lib/Kconfig.debug config DEBUG_INFO_SPLIT · line 414
Quoted 3 lines
lib/Kconfig.debug +3
-0+config DEBUG_INFO_BTF + bool "Generate BTF type information" + select BTF
The old DEBUG_INFO_BTF had its own depends on lines:
depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST depends on BPF_SYSCALL
depends on PAHOLE_VERSION >= 122
depends on !HEXAGON
Those constraints now live only on CONFIG_BTF, and DEBUG_INFO_BTF uses "select BTF" with no depends of its own. Since select bypasses the selected symbol's depends-on checks, DEBUG_INFO_BTF is now visible and selectable even when BTF's dependencies are not met (e.g. on Hexagon, or with PAHOLE_VERSION < 122).
Should DEBUG_INFO_BTF use "depends on BTF" instead of (or in addition to) "select BTF", so that it inherits the same constraints?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/23520643445
kernel test robot
build botRe: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
In reply to Sasha Levinkernel test robot noticed the following build warnings:
Hi Sasha,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on bpf/master akpm-mm/mm-nonmm-unstable linus/master v7.0-rc5] [cannot apply to bpf-next/net next-20260327]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sasha-Levin/btf-split-core-BTF-parsing-out-of-BPF-subsystem-into-kernel-btf/20260327-005818 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20260325011853.657295-1-sashal%40kernel.org patch subject: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/ config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20260329/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260329/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
kernel/bpf/verifier.c: In function 'map_kptr_match_type':
>> kernel/bpf/verifier.c:6070:34: warning: '%s' directive argument is null [-Wformat-overflow=]
6070 | verbose(env, "expected=%s%s", reg_type_str(env, PTR_TO_BTF_ID), targ_name);
| ^~
kernel/bpf/verifier.c:6072:37: warning: '%s' directive argument is null [-Wformat-overflow=]
6072 | verbose(env, " or %s%s\n", reg_type_str(env, PTR_TO_BTF_ID | PTR_UNTRUSTED),
| ^~
kernel/bpf/verifier.c: In function 'check_reg_type':
kernel/bpf/verifier.c:9610:62: warning: '%s' directive argument is null [-Wformat-overflow=]
9610 | verbose(env, "R%d is of type %s but %s is expected\n",
| ^~
kernel/bpf/verifier.c: In function 'check_ptr_to_map_access':
kernel/bpf/verifier.c:7617:46: warning: '%s' directive argument is null [-Wformat-overflow=]
7617 | verbose(env, "only read from %s is supported\n", tname);
| ^~ kernel/bpf/verifier.c:7611:38: warning: '%s' directive argument is null [-Wformat-overflow=]
7611 | verbose(env, "R%d is %s invalid negative access: off=%d\n",
| ^~
kernel/bpf/verifier.c:7605:34: warning: '%s' directive argument is null [-Wformat-overflow=]
7605 | "'struct %s' access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN\n",
| ^~
kernel/bpf/verifier.c: In function 'check_ptr_to_btf_access':
kernel/bpf/verifier.c:7439:55: warning: '%s' directive argument is null [-Wformat-overflow=]
7439 | "Cannot access kernel 'struct %s' from non-GPL compatible program\n",
| ^~
kernel/bpf/verifier.c:7472:37: warning: '%s' directive argument is null [-Wformat-overflow=]
7472 | "R%d is ptr_%s access percpu memory: off=%d\n",
| ^~
kernel/bpf/verifier.c:7465:37: warning: '%s' directive argument is null [-Wformat-overflow=]
7465 | "R%d is ptr_%s access user memory: off=%d\n",
| ^~
kernel/bpf/verifier.c:7458:37: warning: '%s' directive argument is null [-Wformat-overflow=]
7458 | "R%d is ptr_%s invalid negative access: off=%d\n",
| ^~
kernel/bpf/verifier.c:7449:37: warning: '%s' directive argument is null [-Wformat-overflow=]
7449 | "R%d is ptr_%s invalid variable offset: off=%d, var_off=%s\n",
| ^~
kernel/bpf/verifier.c:7433:34: warning: '%s' directive argument is null [-Wformat-overflow=]
7433 | "'struct %s' access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN\n",
| ^~
kernel/bpf/verifier.c: In function 'check_helper_call.isra':
kernel/bpf/verifier.c:12067:83: warning: '%s' directive argument is null [-Wformat-overflow=]
12067 | verbose(env, "unable to resolve the size of type '%s': %ld\n",
| ^~
--
kernel/bpf/log.c: In function 'print_reg_state':
>> kernel/bpf/log.c:702:30: warning: '%s' directive argument is null [-Wformat-overflow=]
702 | verbose(env, "%s", btf_type_name(reg->btf, reg->btf_id));
| ^~~~
kernel/bpf/log.c:14:64: note: in definition of macro 'verbose'
14 | #define verbose(env, fmt, args...) bpf_verifier_log_write(env, fmt, ##args)
| ^~~
kernel/bpf/log.c:702:31: note: format string is defined here
702 | verbose(env, "%s", btf_type_name(reg->btf, reg->btf_id));
| ^~--
In file included from kernel/bpf/btf_relocate.c:2:
kernel/bpf/../../tools/lib/bpf/btf_relocate.c: In function 'btf_relocate_rewrite_strs':
kernel/bpf/../../tools/lib/bpf/btf_relocate.c:20:49: error: implicit declaration of function 'btf_str_by_offset'; did you mean 'btf__str_by_offset'? [-Wimplicit-function-declaration]
20 | #define btf__str_by_offset btf_str_by_offset
| ^~~~~~~~~~~~~~~~~
include/linux/printk.h:483:33: note: in expansion of macro 'btf__str_by_offset'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/printk.h:511:26: note: in expansion of macro 'printk_index_wrap'
511 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
kernel/bpf/../../tools/lib/bpf/btf_relocate.c:431:33: note: in expansion of macro 'pr_warn'
431 | pr_warn("string '%s' [offset %u] is not mapped to base BTF\n",
| ^~~~~~~
In file included from include/asm-generic/bug.h:31,
from arch/sh/include/asm/bug.h:112,
from include/linux/bug.h:5,
from include/linux/alloc_tag.h:8,
from include/linux/workqueue.h:9,
from include/linux/bpf.h:11,
from kernel/bpf/../../tools/lib/bpf/btf_relocate.c:9:
>> include/linux/kern_levels.h:5:25: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/../../tools/lib/bpf/btf_relocate.c:431:33: note: in expansion of macro 'pr_warn'
431 | pr_warn("string '%s' [offset %u] is not mapped to base BTF\n",
| ^~~~~~~vim +6070 kernel/bpf/verifier.c
e9147b4422e1f3 Kumar Kartikeya Dwivedi 2022-04-15 6002
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6003 static int map_kptr_match_type(struct bpf_verifier_env *env,
aa3496accc412b Kumar Kartikeya Dwivedi 2022-11-04 6004 struct btf_field *kptr_field,
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6005 struct bpf_reg_state *reg, u32 regno)
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6006 {
b32a5dae44cc73 Dave Marchevsky 2023-03-09 6007 const char *targ_name = btf_type_name(kptr_field->kptr.btf, kptr_field->kptr.btf_id);
ab6c637ad0276e Yonghong Song 2023-08-21 6008 int perm_flags;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6009 const char *reg_name = "";
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6010
ab6c637ad0276e Yonghong Song 2023-08-21 6011 if (btf_is_kernel(reg->btf)) {
ab6c637ad0276e Yonghong Song 2023-08-21 6012 perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED | MEM_RCU;
ab6c637ad0276e Yonghong Song 2023-08-21 6013
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6014 /* Only unreferenced case accepts untrusted pointers */
aa3496accc412b Kumar Kartikeya Dwivedi 2022-11-04 6015 if (kptr_field->type == BPF_KPTR_UNREF)
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6016 perm_flags |= PTR_UNTRUSTED;
ab6c637ad0276e Yonghong Song 2023-08-21 6017 } else {
ab6c637ad0276e Yonghong Song 2023-08-21 6018 perm_flags = PTR_MAYBE_NULL | MEM_ALLOC;
36d8bdf75a9319 Yonghong Song 2023-08-27 6019 if (kptr_field->type == BPF_KPTR_PERCPU)
36d8bdf75a9319 Yonghong Song 2023-08-27 6020 perm_flags |= MEM_PERCPU;
ab6c637ad0276e Yonghong Song 2023-08-21 6021 }
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6022
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6023 if (base_type(reg->type) != PTR_TO_BTF_ID || (type_flag(reg->type) & ~perm_flags))
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6024 goto bad_type;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6025
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6026 /* We need to verify reg->type and reg->btf, before accessing reg->btf */
b32a5dae44cc73 Dave Marchevsky 2023-03-09 6027 reg_name = btf_type_name(reg->btf, reg->btf_id);
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6028
c0a5a21c25f37c Kumar Kartikeya Dwivedi 2022-04-25 6029 /* For ref_ptr case, release function check should ensure we get one
c0a5a21c25f37c Kumar Kartikeya Dwivedi 2022-04-25 6030 * referenced PTR_TO_BTF_ID, and that its fixed offset is 0. For the
c0a5a21c25f37c Kumar Kartikeya Dwivedi 2022-04-25 6031 * normal store of unreferenced kptr, we must ensure var_off is zero.
022ac075088366 Eduard Zingerman 2026-02-12 6032 * Since ref_ptr cannot be accessed directly by BPF insns, check for
022ac075088366 Eduard Zingerman 2026-02-12 6033 * reg->ref_obj_id is not needed here.
c0a5a21c25f37c Kumar Kartikeya Dwivedi 2022-04-25 6034 */
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6035 if (__check_ptr_off_reg(env, reg, regno, true))
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6036 return -EACCES;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6037
ab6c637ad0276e Yonghong Song 2023-08-21 6038 /* A full type match is needed, as BTF can be vmlinux, module or prog BTF, and
022ac075088366 Eduard Zingerman 2026-02-12 6039 * we also need to take into account the reg->var_off.
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6040 *
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6041 * We want to support cases like:
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6042 *
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6043 * struct foo {
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6044 * struct bar br;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6045 * struct baz bz;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6046 * };
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6047 *
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6048 * struct foo *v;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6049 * v = func(); // PTR_TO_BTF_ID
022ac075088366 Eduard Zingerman 2026-02-12 6050 * val->foo = v; // reg->var_off is zero, btf and btf_id match type
022ac075088366 Eduard Zingerman 2026-02-12 6051 * val->bar = &v->br; // reg->var_off is still zero, but we need to retry with
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6052 * // first member type of struct after comparison fails
022ac075088366 Eduard Zingerman 2026-02-12 6053 * val->baz = &v->bz; // reg->var_off is non-zero, so struct needs to be walked
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6054 * // to match type
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6055 *
022ac075088366 Eduard Zingerman 2026-02-12 6056 * In the kptr_ref case, check_func_arg_reg_off already ensures reg->var_off
2ab3b3808eb17f Kumar Kartikeya Dwivedi 2022-04-25 6057 * is zero. We must also ensure that btf_struct_ids_match does not walk
2ab3b3808eb17f Kumar Kartikeya Dwivedi 2022-04-25 6058 * the struct to match type against first member of struct, i.e. reject
2ab3b3808eb17f Kumar Kartikeya Dwivedi 2022-04-25 6059 * second case from above. Hence, when type is BPF_KPTR_REF, we set
2ab3b3808eb17f Kumar Kartikeya Dwivedi 2022-04-25 6060 * strict mode to true for type match.
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6061 */
022ac075088366 Eduard Zingerman 2026-02-12 6062 if (!btf_struct_ids_match(&env->log, reg->btf, reg->btf_id, reg->var_off.value,
aa3496accc412b Kumar Kartikeya Dwivedi 2022-11-04 6063 kptr_field->kptr.btf, kptr_field->kptr.btf_id,
36d8bdf75a9319 Yonghong Song 2023-08-27 6064 kptr_field->type != BPF_KPTR_UNREF))
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6065 goto bad_type;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6066 return 0;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6067 bad_type:
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6068 verbose(env, "invalid kptr access, R%d type=%s%s ", regno,
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6069 reg_type_str(env, reg->type), reg_name);
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 @6070 verbose(env, "expected=%s%s", reg_type_str(env, PTR_TO_BTF_ID), targ_name);
aa3496accc412b Kumar Kartikeya Dwivedi 2022-11-04 6071 if (kptr_field->type == BPF_KPTR_UNREF)
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6072 verbose(env, " or %s%s\n", reg_type_str(env, PTR_TO_BTF_ID | PTR_UNTRUSTED),
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6073 targ_name);
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6074 else
6efe152d4061a8 Kumar Kartikeya Dwivedi 2022-04-25 6075 verbose(env, "\n");
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6076 return -EINVAL;
61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6077 }61df10c7799e27 Kumar Kartikeya Dwivedi 2022-04-25 6078
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
In reply to Sasha Levinkernel test robot noticed the following build warnings:
Hi Sasha,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on bpf/master akpm-mm/mm-nonmm-unstable linus/master v7.0-rc5] [cannot apply to bpf-next/net next-20260327]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sasha-Levin/btf-split-core-BTF-parsing-out-of-BPF-subsystem-into-kernel-btf/20260327-005818 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20260325011853.657295-1-sashal%40kernel.org patch subject: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/ config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20260329/[email protected]/config) compiler: hppa-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260329/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
kernel/bpf/core.c: In function 'bpf_prog_kallsyms_add':
kernel/bpf/core.c:589:54: warning: '%s' directive argument is null [-Wformat-truncation=]
589 | snprintf(sym, (size_t)(end - sym), "_%s", func_name);
| ^~
In file included from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14,
from arch/parisc/include/asm/hardware.h:5,
from arch/parisc/include/asm/processor.h:18,
from arch/parisc/include/asm/spinlock.h:7,
from arch/parisc/include/asm/atomic.h:22,
from include/linux/atomic.h:7,
from include/linux/filter.h:8,
from kernel/bpf/core.c:21:
In function 'kbasename',
inlined from 'bpf_prog_get_file_line' at kernel/bpf/core.c:3352:11:
>> include/linux/string.h:381:28: warning: argument 1 null where non-null expected [-Wnonnull]
381 | const char *tail = strrchr(path, '/');
| ^~~~~~~~~~~~~~~~~~
include/linux/string.h: In function 'bpf_prog_get_file_line':
include/linux/string.h:183:15: note: in a call to function 'strrchr' declared 'nonnull'
183 | extern char * strrchr(const char *,int);
| ^~~~~~~
--
kernel/bpf/log.c: In function 'verbose_linfo':
>> kernel/bpf/log.c:423:17: warning: argument 1 null where non-null expected [-Wnonnull]
423 | fname = strrchr(s, '/');
| ^~~~~~~~~~~~~~~
In file included from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14,
from arch/parisc/include/asm/hardware.h:5,
from arch/parisc/include/asm/processor.h:18,
from arch/parisc/include/asm/spinlock.h:7,
from arch/parisc/include/asm/atomic.h:22,
from include/linux/atomic.h:7,
from arch/parisc/include/asm/bitops.h:13,
from include/linux/bitops.h:67,
from include/linux/kernel.h:23,
from kernel/bpf/log.c:7:
include/linux/string.h:183:15: note: in a call to function 'strrchr' declared 'nonnull'
183 | extern char * strrchr(const char *,int);
| ^~~~~~~
kernel/bpf/log.c: In function 'print_reg_state':
kernel/bpf/log.c:702:30: warning: '%s' directive argument is null [-Wformat-overflow=]
702 | verbose(env, "%s", btf_type_name(reg->btf, reg->btf_id));
| ^~~~
kernel/bpf/log.c:14:64: note: in definition of macro 'verbose'
14 | #define verbose(env, fmt, args...) bpf_verifier_log_write(env, fmt, ##args)
| ^~~
kernel/bpf/log.c:702:31: note: format string is defined here
702 | verbose(env, "%s", btf_type_name(reg->btf, reg->btf_id));
| ^~--
In file included from include/asm-generic/bug.h:31,
from arch/parisc/include/asm/bug.h:97,
from include/linux/bug.h:5,
from include/linux/alloc_tag.h:8,
from include/linux/workqueue.h:9,
from include/linux/bpf.h:11,
from kernel/bpf/bpf_struct_ops.c:4:
kernel/bpf/bpf_struct_ops.c: In function 'prepare_arg_info.constprop':
include/linux/kern_levels.h:5:25: warning: '%s' directive argument is null [-Wformat-overflow=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/bpf_struct_ops.c:210:17: note: in expansion of macro 'pr_warn'
210 | pr_warn("the number of arguments of the stub function %s does not match the number of arguments of the member %s of struct %s\n",
| ^~~~~~~
include/linux/kern_levels.h:5:25: warning: '%s' directive argument is null [-Wformat-overflow=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/bpf_struct_ops.c:191:17: note: in expansion of macro 'pr_warn'
191 | pr_warn("Cannot find the stub function name for the %s in struct %s\n",
| ^~~~~~~
In function 'is_module_member',
inlined from 'bpf_struct_ops_desc_init' at kernel/bpf/bpf_struct_ops.c:412:37:
>> kernel/bpf/bpf_struct_ops.c:321:17: warning: argument 1 null where non-null expected [-Wnonnull]
321 | return !strcmp(btf_name_by_offset(btf, t->name_off), "module");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14,
from arch/parisc/include/asm/hardware.h:5,
from arch/parisc/include/asm/processor.h:18,
from arch/parisc/include/asm/spinlock.h:7,
from arch/parisc/include/asm/atomic.h:22,
from include/linux/atomic.h:7,
from arch/parisc/include/asm/bitops.h:13,
from include/linux/bitops.h:67,
from include/linux/log2.h:12,
from include/asm-generic/div64.h:55,
from ./arch/parisc/include/generated/asm/div64.h:1,
from include/linux/math.h:6,
from include/linux/math64.h:6,
from include/linux/time64.h:5,
from include/linux/restart_block.h:9,
from include/linux/thread_info.h:14,
from include/asm-generic/preempt.h:5,
from ./arch/parisc/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:79,
from include/linux/alloc_tag.h:11:
include/linux/string.h: In function 'bpf_struct_ops_desc_init':
include/linux/string.h:161:12: note: in a call to function 'strcmp' declared 'nonnull'
161 | extern int strcmp(const char *,const char *);
| ^~~~~~
include/linux/kern_levels.h:5:25: warning: '%s' directive argument is null [-Wformat-overflow=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/bpf_struct_ops.c:406:25: note: in expansion of macro 'pr_warn'
406 | pr_warn("bit field member %s in struct %s is not supported\n",
| ^~~~~~~
include/linux/kern_levels.h:5:25: warning: '%s' directive argument is null [-Wformat-overflow=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/bpf_struct_ops.c:432:33: note: in expansion of macro 'pr_warn'
432 | pr_warn("func ptr %s in struct %s returns non-struct pointer, which is not supported\n",
| ^~~~~~~
include/linux/kern_levels.h:5:25: warning: '%s' directive argument is null [-Wformat-overflow=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/bpf_struct_ops.c:442:25: note: in expansion of macro 'pr_warn'
442 | pr_warn("Error in parsing func ptr %s in struct %s\n",
| ^~~~~~~
kernel/bpf/bpf_struct_ops.c: In function 'bpf_struct_ops_map_update_elem':
>> kernel/bpf/bpf_struct_ops.c:647:51: warning: '%s' directive argument is null [-Wformat-truncation=]
647 | snprintf(ksym->name, KSYM_NAME_LEN, "bpf__%s_%s", tname, mname);
| ^~vim +381 include/linux/string.h
639b9e34f15e4b Akinobu Mita 2012-07-30 369
b18888ab256f05 Andy Shevchenko 2012-12-17 370 /**
b18888ab256f05 Andy Shevchenko 2012-12-17 371 * kbasename - return the last part of a pathname.
b18888ab256f05 Andy Shevchenko 2012-12-17 372 *
b18888ab256f05 Andy Shevchenko 2012-12-17 373 * @path: path to extract the filename from.
645b9ad2dc6b2d Kriish Sharma 2025-11-18 374 *
645b9ad2dc6b2d Kriish Sharma 2025-11-18 375 * Returns:
645b9ad2dc6b2d Kriish Sharma 2025-11-18 376 * Pointer to the filename portion inside @path. If no '/' exists,
645b9ad2dc6b2d Kriish Sharma 2025-11-18 377 * returns @path unchanged.
b18888ab256f05 Andy Shevchenko 2012-12-17 378 */
b18888ab256f05 Andy Shevchenko 2012-12-17 379 static inline const char *kbasename(const char *path)
b18888ab256f05 Andy Shevchenko 2012-12-17 380 {
b18888ab256f05 Andy Shevchenko 2012-12-17 @381 const char *tail = strrchr(path, '/');
b18888ab256f05 Andy Shevchenko 2012-12-17 382 return tail ? tail + 1 : path;
b18888ab256f05 Andy Shevchenko 2012-12-17 383 }b18888ab256f05 Andy Shevchenko 2012-12-17 384
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
In reply to Sasha Levinkernel test robot noticed the following build errors:
Hi Sasha,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
[also build test ERROR on bpf/master akpm-mm/mm-nonmm-unstable linus/master v7.0-rc5] [cannot apply to bpf-next/net next-20260327]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sasha-Levin/btf-split-core-BTF-parsing-out-of-BPF-subsystem-into-kernel-btf/20260327-005818 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20260325011853.657295-1-sashal%40kernel.org patch subject: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/ config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20260329/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260329/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from kernel/bpf/btf_relocate.c:2:
kernel/bpf/../../tools/lib/bpf/btf_relocate.c: In function 'btf_relocate_rewrite_strs':
>> kernel/bpf/../../tools/lib/bpf/btf_relocate.c:20:49: error: implicit declaration of function 'btf_str_by_offset'; did you mean 'btf__str_by_offset'? [-Wimplicit-function-declaration]
20 | #define btf__str_by_offset btf_str_by_offset
| ^~~~~~~~~~~~~~~~~
include/linux/printk.h:483:33: note: in expansion of macro 'btf__str_by_offset'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/printk.h:511:26: note: in expansion of macro 'printk_index_wrap'
511 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
kernel/bpf/../../tools/lib/bpf/btf_relocate.c:431:33: note: in expansion of macro 'pr_warn'
431 | pr_warn("string '%s' [offset %u] is not mapped to base BTF\n",
| ^~~~~~~
In file included from include/asm-generic/bug.h:31,
from arch/sh/include/asm/bug.h:112,
from include/linux/bug.h:5,
from include/linux/alloc_tag.h:8,
from include/linux/workqueue.h:9,
from include/linux/bpf.h:11,
from kernel/bpf/../../tools/lib/bpf/btf_relocate.c:9:
include/linux/kern_levels.h:5:25: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:483:25: note: in definition of macro 'printk_index_wrap'
483 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:564:9: note: in expansion of macro 'printk'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:564:16: note: in expansion of macro 'KERN_WARNING'
564 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
kernel/bpf/../../tools/lib/bpf/btf_relocate.c:431:33: note: in expansion of macro 'pr_warn'
431 | pr_warn("string '%s' [offset %u] is not mapped to base BTF\n",
| ^~~~~~~vim +20 kernel/bpf/../../tools/lib/bpf/btf_relocate.c
8646db238997df3 Alan Maguire 2024-06-20 15 8646db238997df3 Alan Maguire 2024-06-20 16 #define btf_type_by_id (struct btf_type *)btf_type_by_id 8646db238997df3 Alan Maguire 2024-06-20 17 #define btf__type_cnt btf_nr_types 8646db238997df3 Alan Maguire 2024-06-20 18 #define btf__base_btf btf_base_btf 8646db238997df3 Alan Maguire 2024-06-20 19 #define btf__name_by_offset btf_name_by_offset
8646db238997df3 Alan Maguire 2024-06-20 @20 #define btf__str_by_offset btf_str_by_offset8646db238997df3 Alan Maguire 2024-06-20 21 #define btf_kflag btf_type_kflag8646db238997df3 Alan Maguire 2024-06-20 22
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
In reply to Sasha LevinQuoted 10 lines · Sasha Levin
Move BTF type format parsing and inspection code out of the BPF subsystem into its own
kernel/bf/directory, separating core BTF functionality from BPF-specific extensions.
CONFIG_DEBUG_INFO_BTFcurrently depends onCONFIG_BPF_SYSCALL, which prevents embedded, automotive, and safety-critical environments from using BTF. These platforms often disable BPF for security and size reasons but would benefit from BTF type information for crash diagnostics and debugging.
I had a go at a refactor in this area too, and it's pretty tricky. How about we start with a smaller goal; making /sys/kernel/btf available to userspace on systems without CONFIG_BPF_SYSCALL? This would just involve a small refactor of the BTF module-related stuff in kernel/bpf/btf.c, moving it to btf_module.c or similar say. No need to split out BTF parsing APIs from those actively used in validating BPF etc, since a non-BPF_SYSCALL system would not need to parse BTF in the kernel (just make it available in sysfs.
Re: [RFC] btf: split core BTF parsing out of BPF subsystem into kernel/btf/
Quoted 13 lines · Alan Maguire
Quoted 10 lines · Sasha Levin
Move BTF type format parsing and inspection code out of the BPF subsystem into its own
kernel/bf/directory, separating core BTF functionality from BPF-specific extensions.
CONFIG_DEBUG_INFO_BTFcurrently depends onCONFIG_BPF_SYSCALL, which prevents embedded, automotive, and safety-critical environments from using BTF. These platforms often disable BPF for security and size reasons but would benefit from BTF type information for crash diagnostics and debugging.
Quoted 7 lines
I had a go at a refactor in this area too, and it's pretty tricky. How about we start with a smaller goal; making
/sys/kernel/btfavailable to userspace on systems withoutCONFIG_BPF_SYSCALL? This would just involve a small refactor of the BTF module-related stuff inkernel/bpf/btf.c, moving it tobtf_module.cor similar say. No need to split out BTF parsing APIs from those actively used in validating BPF etc, since a non-BPF_SYSCALL system would not need to parse BTF in the kernel (just make it available in sysfs.
Small refactor is ok, but in general I'm not interested in complicating code for systems without CONFIG_BPF_SYSCALL.
[email protected]
AI reviewRe: [PATCH 1/2] kallsyms: show function parameter info in oops/WARN dumps
In reply to Sasha LevinSashiko AI review found 8 potential issue(s): - [High] Build Tool Infinite Loop / Hash Table Exhaustion - [Medium] Incorrect Parameter Attribution due to Missing Validation - [Medium] Missing…
Sashiko AI review found 8 potential issue(s):
- [High] Build Tool Infinite Loop / Hash Table Exhaustion
- [Medium] Incorrect Parameter Attribution due to Missing Validation
- [Medium] Missing Architecture Dependency in Kconfig
- [Medium] Misleading Fault Address Highlighting for Non-Page-Fault Exceptions
- [Medium] Conceptual Flaw: Statically Mapping Parameters to Clobbered Registers
- [Low] Build Error on x86_64 due to Incorrect pt_regs Fields
- [Low] KUnit Test Module Linkage Failure
- [Low] Unused Static Variable Causes Build Warning/Error
--
commit dc18a113b4058bc5d9640e6245bce2e390eeb331
Author: Sasha Levin <[email protected]>
kallsyms: show function parameter info in oops/WARN dumps
This commit embeds DWARF-derived function parameter name and type information in the kernel image so that oops and WARN dumps display the crashing function's register-passed arguments. It adds a build tool to parse DWARF and stores it in .rodata, gated behind CONFIG_KALLSYMS_PARAMINFO.
init/Kconfig config KALLSYMS_LINEINFO_MODULES · line 2110
Quoted 11 lines
init/Kconfig +3
-0@@ -2105,6 +2105,27 @@ config KALLSYMS_LINEINFO_MODULES If unsure, say N. +config KALLSYMS_PARAMINFO + bool "Show function parameter info in oops/WARN dumps" + depends on KALLSYMS_LINEINFO
Should this have an architecture dependency (e.g., depends on X86_64)?
The feature appears to be heavily x86-64 specific, hardcoding x86-64 registers and exclusively hooking into arch/x86/kernel/dumpstack.c. Enabling it on unsupported architectures could inflate the kernel image with unused tables.
[ ... ]
Quoted 16 lines
kernel/kallsyms.c +8
-0@@ -501,6 +501,174 @@ bool kallsyms_lookup_lineinfo(unsigned long addr,return lineinfo_search (&tbl, (unsigned int )raw_offset, file, line); } +#ifdef CONFIG_KALLSYMS_PARAMINFO + +#include <linux/ptrace.h> +#ifdef CONFIG_X86 +#include <asm/special_insns.h> +#endif + +#define MAX_PARAMINFO_PARAMS 6
kernel/kallsyms.c bool kallsyms_lookup_lineinfo(unsigned long addr, · line 521
Quoted 10 lines
kernel/kallsyms.c +10
-0+ +/* +* x86-64 calling convention: arguments are passed in registers +* RDI, RSI, RDX, RCX, R8, R9 (in that order). +*/ +#ifdef CONFIG_X86_64 + +static const char *const paraminfo_reg_names[] = { +"RDI" ,"RSI" ,"RDX" ,"RCX" ,"R8" ,"R9" +};
Is this variable used anywhere? It doesn't seem to be referenced in the file, which could trigger a -Wunused-variable compiler warning.
kernel/kallsyms.c bool kallsyms_lookup_lineinfo(unsigned long addr, · line 529
Quoted 8 lines
kernel/kallsyms.c +8
-0+ +static unsigned long paraminfo_get_reg (const struct pt_regs *regs, +unsigned int idx) +{ +switch (idx) { +case 0 :return regs->di; +case 1 :return regs->si; +case 2 :return regs->dx;
Will this cause a build error on x86_64? In the 64-bit kernel, the struct pt_regs defines these fields as rdi, rsi, rdx, etc. rather than di, si, dx.
[ ... ]
kernel/kallsyms.c bool kallsyms_lookup_lineinfo(unsigned long addr, · line 620
Quoted 12 lines
kernel/kallsyms.c +12
-0+ func_idx =paraminfo_find_func (offset); +if (func_idx <0 ) +return ; + +/* +* Verify the IP is within a reasonable range of the function +* start. paraminfo_func_addrs[] contains function start offsets; +* check that we're not too far past the start. Use kallsyms to +* verify we're in the right function. +*/ +if (!kallsyms_lookup_size_offset (ip, &sym_size, &sym_offset)) +return ;
Does this code verify that the matched paraminfo function actually aligns with the faulting function?
If the fault occurs in a function without parameters, func_idx will point to the closest preceding function with parameter data. Should there be a check such as offset - sym_offset == paraminfo_func_addrs[func_idx] to prevent printing parameters of the preceding function?
[ ... ]
kernel/kallsyms.c bool kallsyms_lookup_lineinfo(unsigned long addr, · line 640
Quoted 12 lines
kernel/kallsyms.c +12
-0+/* Look up function name for the header */ +if (lookup_symbol_name (ip - sym_offset, sym_name)) +return ; + +/* +* Read the fault address for highlighting. On x86, CR2 holds +* the page fault linear address. On other architectures this +* would need a different mechanism. +*/ +#ifdef CONFIG_X86 + fault_addr =read_cr2 (); +#else
Can this produce misleading highlighting for non-page-fault exceptions?
The x86 CPU updates the CR2 register during a Page Fault, but for other exceptions such as WARN() or General Protection Faults, CR2 retains the stale address from the last unrelated page fault.
[ ... ]
Quoted 4 lines
kernel/kallsyms.c +4
-0+for (i =0 ; i < num_params; i++) { +u32 name_off, type_off; +const char *pname, *ptype; +unsigned long val;
kernel/kallsyms.c bool kallsyms_lookup_lineinfo(unsigned long addr, · line 659
Quoted 10 lines
kernel/kallsyms.c +10
-0+bool is_fault_addr; + +memcpy (&name_off, data,sizeof (u32)); + data +=sizeof (u32); +memcpy (&type_off, data,sizeof (u32)); + data +=sizeof (u32); + + pname = paraminfo_strings + name_off; + ptype = paraminfo_strings + type_off; + val =paraminfo_get_reg (regs, i);
Could these caller-saved registers contain clobbered values?
Since exceptions typically occur mid-function, the compiler might have freely clobbered these registers to hold local variables or intermediate state, which could lead to garbage values being displayed instead of the original parameters.
[ ... ]
Quoted 7 lines
lib/tests/paraminfo_kunit.c new file +1
-0@@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0
[ ... ]
lib/tests/paraminfo_kunit.c line 56
Quoted 9 lines
lib/tests/paraminfo_kunit.c new file +9
-0+/* +* These access the raw paraminfo tables to verify correctness. +* The tables are defined in kernel/kallsyms_internal.h. +*/ +extern const u32 paraminfo_num_funcs; +extern const u32 paraminfo_func_addrs[]; +extern const u32 paraminfo_func_offsets[]; +extern const u8 paraminfo_func_data[]; +extern const char paraminfo_strings[];
Can this test be built as a loadable module?
CONFIG_PARAMINFO_KUNIT_TEST is a tristate config, but the test directly references internal unexported tables. Building it as a module might fail with undefined symbol errors during the modpost stage.
[ ... ]
Quoted 5 lines
scripts/gen_paraminfo.c new file +0
-0
[ ... ]
scripts/gen_paraminfo.c line 88
Quoted 9 lines
scripts/gen_paraminfo.c new file +9
-0+static unsigned int find_or_add_string (const char *s) +{ +unsigned int h =hash_str (s); + +while (str_hash[h].str) { +if (!strcmp (str_hash[h].str, s)) +return str_hash[h].idx; + h = (h +1 ) & (STR_HASH_SIZE -1 ); + }
Could this loop permanently hang the kernel build process?
The STR_HASH_SIZE is 16,384, but a typical kernel has around 58k functions. If the number of unique parameter names and types exceeds 16,384, the hash table will become completely full and this while loop will never find an empty slot.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH 2/2] kallsyms: add BTF-based deep parameter rendering in oops dumps
In reply to Sasha LevinSashiko AI review found 7 potential issue(s): - [High] Unsynchronized static buffers cause data corruption and KASAN out-of-bounds reads in concurrent WARN() context. - [High] `dwarf_attr_integrate`…
Sashiko AI review found 7 potential issue(s):
- [High] Unsynchronized static buffers cause data corruption and KASAN out-of-bounds reads in concurrent WARN() context.
- [High] dwarf_attr_integrate incorrectly skips function definitions, breaking paraminfo generation.
- [High] Out-of-bounds array read in BTF string coalescing logic.
- [High] Stack buffer overflow risk due to truncated sym_name buffer.
- [Medium] extract_struct_name silently fails on const and volatile qualified struct pointers.
- [Medium] Spurious parameter info shown for module functions due to 32-bit truncation hash collisions.
- [Low] Unresolved symbol link errors if KUnit test is built as a module.
--
commit dc1b9fb23e8dd955bb821b603ed59ecf1ae219f5
Author: Sasha Levin <[email protected]>
kallsyms: add BTF-based deep parameter rendering in oops dumps
This patch adds BTF-based deep rendering for struct pointer parameters in oops and WARN dumps. It introduces paraminfo_btf_show_ptr() to safely format BPF data and updates the kallsyms logic to invoke this rendering for pointer types.
kernel/kallsyms.c void kallsyms_show_paraminfo(struct pt_regs *regs) · line 590
Quoted 10 lines
kernel/kallsyms.c +1
-1@@ -586,13 +586,13 @@ void kallsyms_show_paraminfo(struct pt_regs *regs)const u8 *data;unsigned int num_params, i;unsigned long ip, fault_addr; -char sym_name[KSYM_NAME_LEN ]; +char sym_name[128 ];unsigned long sym_size, sym_offset;
KSYM_NAME_LEN can be configured to larger values than 128 (e.g., 512 for Rust symbol support via CONFIG_KALLSYMS_MAX_NAME_LEN). If this buffer is passed to kallsyms APIs that write up to KSYM_NAME_LEN bytes, could this cause a stack buffer overflow during an oops dump?
[ ... ]
Quoted 15 lines
kernel/kallsyms.c +4
-4@@ -611,14 +611,23 @@ void kallsyms_show_paraminfo(struct pt_regs *regs)return ;/* -* Verify the IP is within a reasonable range of the function -* start. paraminfo_func_addrs[] contains function start offsets; -* check that we're not too far past the start. Use kallsyms to -* verify we're in the right function. +* Verify the paraminfo entry actually matches the function +* containing the IP. Without this, if the faulting function +* has no paraminfo, the binary search silently returns the +* preceding function's entry — showing wrong parameter info. */ if (!kallsyms_lookup_size_offset (ip, &sym_size, &sym_offset))return ;
kernel/kallsyms.c void kallsyms_show_paraminfo(struct pt_regs *regs) · line 630
Quoted 10 lines
kernel/kallsyms.c +9
-0+ { +unsigned int func_start_offset; + + func_start_offset = (unsigned int )(ip - sym_offset - + (unsigned long )_text); +if (paraminfo_func_addrs[func_idx] != func_start_offset) +return ; + } +
For an instruction pointer within a kernel module, the memory distance from the core _text section can exceed 4GB on 64-bit architectures where modules reside in vmalloc space.
Will casting this distance to a 32-bit integer truncate the upper bits? If the truncated value coincidentally matches a valid entry in paraminfo_func_addrs, could this incorrectly display parameter info for a completely unrelated vmlinux function?
Quoted 4 lines
kernel/kallsyms_paraminfo_btf.c new file +0
-0@@ -0,0 +1,267 @@
[ ... ]
Quoted 5 lines
kernel/kallsyms_paraminfo_btf.c new file +5
-0+static const char *extract_struct_name (const char *type_str,bool *is_union, +char *name_buf,size_t bufsz) +{ +const char *p, *end; +
kernel/kallsyms_paraminfo_btf.c line 54
Quoted 10 lines
kernel/kallsyms_paraminfo_btf.c new file +10
-0+ *is_union = false; + +/* Must end with " *" to be a pointer */ + end = type_str +strlen (type_str); +if (end - type_str <3 || end[-1 ] !='*' || end[-2 ] !=' ' ) +return NULL ; + +if (!strncmp (type_str,"struct " ,7 )) { + p = type_str +7 ; + }else if (!strncmp (type_str,"union " ,6 )) {
The extract_struct_name() function checks for "struct " at the very beginning of the string. Since gen_paraminfo.c generates strings with qualifiers for pointers like "const struct file *", won't this strict comparison fail on qualified strings and silently bypass BTF rendering?
[ ... ]
Quoted 4 lines
kernel/kallsyms_paraminfo_btf.c new file +4
-0+void paraminfo_btf_show_ptr (unsigned long ptr_val,const char *type_str) +{ +static char buf[BTF_SHOW_BUF_LEN ]; +char sname[64 ];
[ ... ]
kernel/kallsyms_paraminfo_btf.c line 198
Quoted 4 lines
kernel/kallsyms_paraminfo_btf.c new file +4
-0+#define MAX_COALESCED 8 + { +static char coalesced[MAX_COALESCED ][128 ]; +int ci =0 , i;
The comment states this is safe because oops context is effectively single-threaded. However, since this function is also invoked during WARN() dumps, and WARN() does not stop other CPUs, couldn't multiple CPUs hit warnings and execute this code simultaneously?
Will concurrent lockless modifications to these static arrays cause data races, garbled output, and potential out-of-bounds memory accesses if null terminators are overwritten mid-read?
[ ... ]
kernel/kallsyms_paraminfo_btf.c line 230
Quoted 9 lines
kernel/kallsyms_paraminfo_btf.c new file +9
-0+/* Gather chars from subsequent lines */ +for (j = i +1 ; j < nlines && + spos < (int )sizeof (coalesced[0 ]) -2 ; j++) { +char *s = lines[j]; + +if (s[0 ] =='\'' && s[2 ] =='\'' && + (s[3 ] =='\0' || s[3 ] ==',' )) { + coalesced[ci][spos++] = s[1 ]; + lines[j] ="" ;
This evaluates s[2] and s[3] without validating the string's length. If the parsed string is a single character (e.g., s[0] == '\'' and s[1] == '\0'), won't this read past the null terminator?
If this short string is located at the very end of the buf array, will evaluating s[2] read past the global array's bounds and trigger a KASAN out-of-bounds read?
lib/tests/paraminfo_kunit.c line 12
Quoted 11 lines
lib/tests/paraminfo_kunit.c +2
-1@@ -7,7 +7,8 @@* Verifies that the paraminfo tables correctly map function addresses * to their parameter names and types. * -* Build with: CONFIG_PARAMINFO_KUNIT_TEST=m (or =y) +* Build with: CONFIG_PARAMINFO_KUNIT_TEST=y (must be built-in; paraminfo +* tables are vmlinux-only, so module test functions won't be found) */
This isn't a bug, but the comment notes this test must be built-in because it relies on unexported vmlinux-only symbols.
If there is no corresponding Kconfig dependency enforced, could configuring the test as a module cause the build to fail with undefined reference errors during modpost?
Quoted 4 lines
scripts/gen_paraminfo.c +0
-0@@ -341,6 +384,12 @@ static void process_dwarf(Dwarf *dwarf, unsigned long long text_addr)
[ ... ]
scripts/gen_paraminfo.c static void process_dwarf(Dwarf *dwarf, unsigned long long text_addr) · line 353
Quoted 4 lines
scripts/gen_paraminfo.c +1
-1/* Skip declarations (no body) */ -if (dwarf_attr (&child, DW_AT_declaration, &attr)) +if (dwarf_attr_integrate (&child, DW_AT_declaration, &attr))continue ;
For a function definition that was prototyped elsewhere, the definition DIE contains a DW_AT_specification attribute pointing to its declaration DIE.
Because dwarf_attr_integrate resolves attributes through the specification chain, won't it locate DW_AT_declaration on the declaration DIE and evaluate to true?
Could this inadvertently cause the script to skip almost all exported kernel function definitions?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2