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

From: Rui Qi

Date: Wed Jun 03 2026 - 08:07:35 EST


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>
---
arch/riscv/kernel/stacktrace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index c7555447149b..f4eb65bf53ef 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -139,7 +139,7 @@ static bool print_trace_address(void *arg, unsigned long pc)
{
const char *loglvl = arg;

- print_ip_sym(loglvl, pc);
+ printk("%s[<%px>] %pB\n", loglvl, (void *)pc, (void *)pc);
return true;
}

--
2.20.1