Re: [PATCH v1 2/2] riscv: stacktrace: Use %pB for backtrace display

From: Paul Walmsley

Date: Thu Jun 04 2026 - 20:33:41 EST


On Wed, 3 Jun 2026, Rui Qi wrote:

> The print_trace_address callback uses print_ip_sym which formats
> addresses with %pS. This does not adjust the address before symbol
> lookup, so when a noreturn function (e.g. panic, do_exit) is the last
> call in a function, the saved return address can point to the start of
> the next function, and kallsyms resolves it to the wrong symbol.
>
> The kernel provides %pB (sprint_backtrace) specifically for this
> purpose: it subtracts 1 from the address before symbol lookup, which
> is sufficient to fall back into the calling function range. x86 uses
> %pB in its printk_stack_address for the same reason.
>
> Replace print_ip_sym with a direct printk using %pB, matching the
> pattern used by x86.
>
> Signed-off-by: Rui Qi <qirui.001@xxxxxxxxxxxxx>

The Sashiko review mentions that the x86 backtrace code uses %pS for exact
instruction pointers coming from registers (show_regs_if_on_stack()), vs.
%pB for return addresses on the stack (printk_stack_address()):

https://sashiko.dev/#/patchset/20260603115329.791603-1-qirui.001%40bytedance.com

Do we need to incorporate similar logic?


- Paul