Skip to content

Commit 51356ce

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: stacktrace: fix backtracing through exceptions
Prior to commit 5d5fc33 ("riscv: Improve exception and system call latency"), backtrace through exception worked since ra was filled with ret_from_exception symbol address and the stacktrace code checked 'pc' to be equal to that symbol. Now that handle_exception uses regular 'call' instructions, this isn't working anymore and backtrace stops at handle_exception(). Since there are multiple call site to C code in the exception handling path, rather than checking multiple potential return addresses, add a new symbol at the end of exception handling and check pc to be in that range. Fixes: 5d5fc33 ("riscv: Improve exception and system call latency") Signed-off-by: Clément Léger <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent f754f27 commit 51356ce

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

arch/riscv/kernel/entry.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
278278
#else
279279
sret
280280
#endif
281+
SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
281282
SYM_CODE_END(ret_from_exception)
282283
ASM_NOKPROBE(ret_from_exception)
283284

arch/riscv/kernel/stacktrace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifdef CONFIG_FRAME_POINTER
1818

1919
extern asmlinkage void handle_exception(void);
20+
extern unsigned long ret_from_exception_end;
2021

2122
static inline int fp_is_valid(unsigned long fp, unsigned long sp)
2223
{
@@ -71,7 +72,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
7172
fp = frame->fp;
7273
pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra,
7374
&frame->ra);
74-
if (pc == (unsigned long)handle_exception) {
75+
if (pc >= (unsigned long)handle_exception &&
76+
pc < (unsigned long)&ret_from_exception_end) {
7577
if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
7678
break;
7779

0 commit comments

Comments
 (0)