From: bot+bpf-ci@kernel.org
To: irogers@google.com,linux-kernel@vger.kernel.org,linux-trace-kernel@vger.kernel.org,linux-arch@vger.kernel.org
Cc: jpoimboe@kernel.org,rostedt@goodmis.org,peterz@infradead.org,mingo@redhat.com,tglx@kernel.org,bp@alien8.de,dave.hansen@linux.intel.com,x86@kernel.org,catalin.marinas@arm.com,will@kernel.org,mark.rutland@arm.com,linux-arm-kernel@lists.infradead.org,pjw@kernel.org,palmer@dabbelt.com,aou@eecs.berkeley.edu,alex@ghiti.fr,linux-riscv@lists.infradead.org,acme@kernel.org,namhyung@kernel.org,linux-perf-users@vger.kernel.org,mhiramat@kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,bpf@vger.kernel.org,nathan@kernel.org,nsc@kernel.org,linux-kbuild@vger.kernel.org,ojeda@kernel.org,rust-for-linux@vger.kernel.org,ardb@kernel.org,linux-efi@vger.kernel.org,maz@kernel.org,oupton@kernel.org,kvmarm@lists.linux.dev,shuah@kernel.org,linux-kselftest@vger.kernel.org,indu.bhagat@oracle.com,jremus@linux.ibm.com,wnliu@google.com,dylanbhatch@google.com,irogers@google.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mas
on@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [RFC PATCH v1 09/11] riscv/unwind: Add Minimal DWARF CFI kernel unwinder
Date: Mon, 23 Nov 2026 00:56:54 +0000 (UTC) [thread overview]
Message-ID: <446a1b870b63e07c6456e140f4fc260d09bd33cbc94fe9dbed4126be9c1e9844@mail.kernel.org> (raw)
In-Reply-To: <20261122235757.3456048-10-irogers@google.com>
[-- Attachment #1: Type: text/plain, Size: 7134 bytes --]
> riscv/unwind: Add Minimal DWARF CFI kernel unwinder
TL;DR:
- struct mod_arch_specific may be redefined (build error) with
CONFIG_MODULES=n
- Stack walk may stop at IRQ stack top, losing frames
- return_address(n) may be off by one frame (unverified)
- fprobe comment nit
> diff --git a/arch/riscv/include/asm/module.h b/arch/riscv/include/asm/module.h
> --- a/arch/riscv/include/asm/module.h
> +++ b/arch/riscv/include/asm/module.h
[ ... ]
> +#if defined(CONFIG_MODULE_SECTIONS) || defined(CONFIG_UNWINDER_DWARF_CFI)
> struct mod_arch_specific {
> +#ifdef CONFIG_MODULE_SECTIONS
> struct mod_section got;
> struct mod_section plt;
> struct mod_section got_plt;
> +#endif
> +#ifdef CONFIG_UNWINDER_DWARF_CFI
> + struct mod_dwarf_cfi_index __rcu *dwarf_cfi_index;
> +#endif
> };
> +#endif
Can this define struct mod_arch_specific twice when CONFIG_MODULES=n?
UNWINDER_DWARF_CFI only does 'select HAVE_MOD_ARCH_SPECIFIC if MODULES', and
MODULE_SECTIONS is selected by RELOCATABLE only 'if MODULES'. With
CONFIG_MODULES=n and CONFIG_UNWINDER_DWARF_CFI=y, CONFIG_HAVE_MOD_ARCH_SPECIFIC
is unset, so include/asm-generic/module.h (included first) already provides:
#ifndef CONFIG_HAVE_MOD_ARCH_SPECIFIC
struct mod_arch_specific
{
};
#endif
include/linux/module.h includes <asm/module.h> even with CONFIG_MODULES=n, so
the block above would then fail with a redefinition of struct
mod_arch_specific.
Before this patch, MODULE_SECTIONS guarded the struct and also selected
HAVE_MOD_ARCH_SPECIFIC, so the two always agreed.
Would guarding the struct with CONFIG_HAVE_MOD_ARCH_SPECIFIC, adding
'&& defined(CONFIG_MODULES)' to the UNWINDER_DWARF_CFI half of the condition,
or selecting HAVE_MOD_ARCH_SPECIFIC unconditionally from UNWINDER_DWARF_CFI
be better?
> diff --git a/arch/riscv/kernel/probes/rethook_trampoline.S b/arch/riscv/kernel/probes/rethook_trampoline.S
> --- a/arch/riscv/kernel/probes/rethook_trampoline.S
> +++ b/arch/riscv/kernel/probes/rethook_trampoline.S
[ ... ]
> +/*
> + * Under CONFIG_UNWINDER_DWARF_CFI, PT_EPC(sp) is seeded with
> + * &arch_rethook_trampoline before rethook_trampoline_handler() overwrites
> + * regs->epc with the restored caller PC prior to running rethook handlers,
> + * enabling reliable CFI unwinding across kretprobe and fprobe return hooks.
> + */
> SYM_CODE_START(arch_rethook_trampoline)
This isn't a bug, but does fprobe use rethook in this tree?
FPROBE selects FUNCTION_GRAPH_TRACER and kernel/trace/fprobe.c has no rethook
references; the only rethook_hook() caller is pre_handler_kretprobe() in
kernel/kprobes.c. So fprobe exits run through return_to_handler() in
mcount.S rather than arch_rethook_trampoline().
Should the comment mention only kretprobes, or point fprobe readers at
return_to_handler?
> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
> --- a/arch/riscv/kernel/stacktrace.c
> +++ b/arch/riscv/kernel/stacktrace.c
[ ... ]
> + if ((sp & (sizeof(long) - 1)) ||
> + !riscv_stack_bounds(task, sp, /*size=*/0, &cur_low,
> + &cur_high))
> + return -EINVAL;
Can this reject a valid sp at the top of the IRQ stack?
The CFA check only rejects values above the top:
if ((cfa & (sizeof(long) - 1)) || cfa < cur_low || cfa > cur_high)
and the call_on_irq_stack() transition accepts the top:
sp <= irq_low + IRQ_STACK_SIZE &&
but riscv_stack_bounds(task, sp, /*size=*/0, ...) only matches when
'addr < high'.
When the walker reaches the function that call_on_irq_stack() called while it
is still at its entry, sp is irq_stack_ptr + IRQ_STACK_SIZE, and the walk
returns -EINVAL before it can use the entry row.
One way to reach it:
local_bh_enable()
do_softirq()
do_softirq_own_stack()
call_on_irq_stack(NULL, ___do_softirq)
If an ftrace callback on ___do_softirq takes a stack trace (func_stack_trace,
or an fprobe event with a stacktrace trigger), the ftrace_caller branch sets
sp to the IRQ stack top, and riscv_stack_bounds() then matches none of the
task, IRQ or overflow stacks. The same happens for walks starting from
ftrace_partial_regs() pt_regs where regs->sp is the top, for example
fprobe/kprobe_multi BPF programs calling bpf_get_stackid()
-> perf_callchain_kernel() -> walk_stackframe(NULL, regs). It also happens to
__do_softirq() when ___do_softirq() tail-calls it.
The trace then stops at ___do_softirq and loses call_on_irq_stack(),
do_softirq_own_stack() and every frame on the task stack. There is no
memory-safety impact, and the old frame-pointer unwinder could not cross the
IRQ stack either, but this defeats the call_on_irq_stack() transition support
the commit message describes.
Should riscv_stack_bounds() accept addr == high when size == 0, or should the
IRQ stack top be special-cased here?
[ ... ]
> +noinline void notrace walk_stackframe(struct task_struct *task,
> + struct pt_regs *regs,
> + bool (*fn)(void *, unsigned long),
> + void *arg)
> +{
> + walk_stackframe_cfi(task, regs, fn, arg, /*require_reliable=*/false);
> +}
Does return_address(n) now return an address one frame too far up with
CONFIG_UNWINDER_DWARF_CFI=y?
return_address() in arch/riscv/kernel/return_address.c does:
data.level = level + 3;
...
arch_stack_walk(save_return_addr, &data, current, NULL);
The three skipped entries are arch_stack_walk, return_address and the caller
of return_address, which assumes arch_stack_walk() has its own frame. That
held because CONFIG_FRAME_POINTER builds pass -fno-optimize-sibling-calls
(top-level Makefile). This patch makes FRAME_POINTER unavailable under
UNWINDER_DWARF_CFI and adds -fomit-frame-pointer, so sibling-call
optimisation is back on at -O2.
arch_stack_walk() is a single forwarding call:
noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,
void *cookie,
struct task_struct *task,
struct pt_regs *regs)
{
walk_stackframe(task, regs, consume_entry, cookie);
}
which is a candidate for 'tail walk_stackframe', leaving no frame of its own.
The walk would then report return_address, F, G, H instead of arch_stack_walk,
return_address, F, G, so return_address(n) yields __builtin_return_address(n+1)
of F.
That affects get_lock_parent_ip() (current->preempt_disable_ip, shown as
"Preemption disabled at:") and the preemptirq tracepoints and the
irqsoff/preemptoff tracers that use CALLER_ADDR1. s390, which also unwinds
without frame pointers, adds CFLAGS_stacktrace.o += -fno-optimize-sibling-calls
in arch/s390/kernel/Makefile for this reason.
I haven't verified this by compiling for RISC-V, so it is inferred from the
compiler rules and the s390 precedent. Would adding -fno-optimize-sibling-calls
for stacktrace.o under UNWINDER_DWARF_CFI, having arch_stack_walk() call an
always-inline walker directly, or adjusting the skip count in return_address()
be appropriate?
---
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/45087188604
next prev parent reply other threads:[~2026-11-23 0:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 23:57 [RFC PATCH v1 00/11] unwind: Minimal DWARF CFI stack unwinding for x86, arm64, and riscv Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 01/11] unwind: Add Minimal DWARF CFI bytecode interpreter and KUnit tests Ian Rogers
2026-11-23 0:40 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 02/11] unwind_user: Support Minimal DWARF CFI user-space unwinding Ian Rogers
2026-11-23 0:39 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 03/11] scripts, unwind: Add build-time .eh_frame minifier Ian Rogers
2026-11-23 0:40 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 04/11] objtool/ibt: Ignore .eh_frame relocations during ENDBR validation Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 05/11] x86/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23 0:56 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 06/11] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23 0:56 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 08/11] riscv: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-23 0:39 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 09/11] riscv/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23 0:56 ` bot+bpf-ci [this message]
2026-11-22 23:57 ` [RFC PATCH v1 10/11] selftests/perf_events: Add Minimal DWARF CFI deferred user unwind test Ian Rogers
2026-11-23 0:40 ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 11/11] scripts: Add eh_frame_min.py .eh_frame coverage and size analyzer Ian Rogers
2026-11-23 0:39 ` bot+bpf-ci
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=446a1b870b63e07c6456e140f4fc260d09bd33cbc94fe9dbed4126be9c1e9844@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=acme@kernel.org \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=dylanbhatch@google.com \
--cc=eddyz87@gmail.com \
--cc=indu.bhagat@oracle.com \
--cc=irogers@google.com \
--cc=jpoimboe@kernel.org \
--cc=jremus@linux.ibm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=martin.lau@kernel.org \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=oupton@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=rostedt@goodmis.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=wnliu@google.com \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®