Skip to content

Commit eac2f30

Browse files
Chen Huangpalmer-dabbelt
Chen Huang
authored andcommitted
riscv: stacktrace: fix the riscv stacktrace when CONFIG_FRAME_POINTER enabled
As [1] and [2] said, the arch_stack_walk should not to trace itself, or it will leave the trace unexpectedly when called. The example is when we do "cat /sys/kernel/debug/page_owner", all pages' stack is the same. arch_stack_walk+0x18/0x20 stack_trace_save+0x40/0x60 register_dummy_stack+0x24/0x5e init_page_owner+0x2e So we use __builtin_frame_address(1) as the first frame to be walked. And mark the arch_stack_walk() noinline. We found that pr_cont will affact pages' stack whose task state is RUNNING when testing "echo t > /proc/sysrq-trigger". So move the place of pr_cont and mark the function dump_backtrace() noinline. Also we move the case when task == NULL into else branch, and test for it in "echo c > /proc/sysrq-trigger". [1] https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Chen Huang <[email protected]> Fixes: 5d8544e ("RISC-V: Generic library routines and assembly") Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6efb943 commit eac2f30

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

arch/riscv/kernel/stacktrace.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
2727
fp = frame_pointer(regs);
2828
sp = user_stack_pointer(regs);
2929
pc = instruction_pointer(regs);
30-
} else if (task == NULL || task == current) {
31-
fp = (unsigned long)__builtin_frame_address(0);
32-
sp = sp_in_global;
33-
pc = (unsigned long)walk_stackframe;
30+
} else if (task == current) {
31+
fp = (unsigned long)__builtin_frame_address(1);
32+
sp = (unsigned long)__builtin_frame_address(0);
33+
pc = (unsigned long)__builtin_return_address(0);
3434
} else {
3535
/* task blocked in __switch_to */
3636
fp = task->thread.s[0];
@@ -106,15 +106,15 @@ static bool print_trace_address(void *arg, unsigned long pc)
106106
return true;
107107
}
108108

109-
void dump_backtrace(struct pt_regs *regs, struct task_struct *task,
109+
noinline void dump_backtrace(struct pt_regs *regs, struct task_struct *task,
110110
const char *loglvl)
111111
{
112-
pr_cont("%sCall Trace:\n", loglvl);
113112
walk_stackframe(task, regs, print_trace_address, (void *)loglvl);
114113
}
115114

116115
void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
117116
{
117+
pr_cont("%sCall Trace:\n", loglvl);
118118
dump_backtrace(NULL, task, loglvl);
119119
}
120120

@@ -139,7 +139,7 @@ unsigned long get_wchan(struct task_struct *task)
139139

140140
#ifdef CONFIG_STACKTRACE
141141

142-
void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
142+
noinline void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
143143
struct task_struct *task, struct pt_regs *regs)
144144
{
145145
walk_stackframe(task, regs, consume_entry, cookie);

0 commit comments

Comments
 (0)