Skip to content

Commit 2db3373

Browse files
clementlegeropsiff
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 <cleger@rivosinc.com> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20241209155714.1239665-1-cleger@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 885827bc1518fbc96deac6c821ffe7b3fa35649b) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent c8dc56f commit 2db3373

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

arch/riscv/kernel/entry.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
183183
#else
184184
sret
185185
#endif
186+
SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
186187
SYM_CODE_END(ret_from_exception)
187188
ASM_NOKPROBE(ret_from_exception)
188189

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)