Skip to content

Commit 43ccbaa

Browse files
clementlegermehmetb0
authored andcommitted
riscv: stacktrace: fix backtracing through exceptions
BugLink: https://bugs.launchpad.net/bugs/2098165 [ Upstream commit 51356ce ] 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: Sasha Levin <[email protected]> Signed-off-by: Koichiro Den <[email protected]>
1 parent c081384 commit 43ccbaa

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
@@ -191,6 +191,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
191191
#else
192192
sret
193193
#endif
194+
SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
194195
SYM_CODE_END(ret_from_exception)
195196
ASM_NOKPROBE(ret_from_exception)
196197

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)