Skip to content

Commit 885827b

Browse files
clementlegergregkh
authored andcommitted
riscv: stacktrace: fix backtracing through exceptions
commit 51356ce upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8fa7f51 commit 885827b

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
@@ -174,6 +174,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
174174
#else
175175
sret
176176
#endif
177+
SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
177178
SYM_CODE_END(ret_from_exception)
178179
ASM_NOKPROBE(ret_from_exception)
179180

arch/riscv/kernel/stacktrace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
})
3434

3535
extern asmlinkage void handle_exception(void);
36+
extern unsigned long ret_from_exception_end;
3637

3738
static inline int fp_is_valid(unsigned long fp, unsigned long sp)
3839
{
@@ -88,7 +89,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
8889
pc = READ_ONCE_TASK_STACK(task, frame->ra);
8990
pc = ftrace_graph_ret_addr(current, &graph_idx, pc,
9091
&frame->ra);
91-
if (pc == (unsigned long)handle_exception) {
92+
if (pc >= (unsigned long)handle_exception &&
93+
pc < (unsigned long)&ret_from_exception_end) {
9294
if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
9395
break;
9496

0 commit comments

Comments
 (0)