riscv: improve the stacktrace report
cover riscv: improve the stacktrace report
Make show_regs() to dump the stack to improve riscv crash report, and also fix the wrong value when stack unwind if FRAME_POINTER enabled.
Chen Huang (1):
riscv/stacktrace: Fix stack output without ra on the stack top
Kefeng Wang (2):
riscv: Add dump stack in show_regs
riscv: Improve __show_regs
arch/riscv/include/asm/bug.h | 1 + arch/riscv/include/asm/stacktrace.h | 2 ++ arch/riscv/kernel/process.c | 16 ++++++++++++++-- arch/riscv/kernel/stacktrace.c | 22 +++++++++++++++++----- arch/riscv/kernel/traps.c | 3 ++- 5 files changed, 36 insertions(+), 8 deletions(-)
Signature · 7 lines
2.26.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH RESEND 1/3 riscv: Add dump stack in show_regs
Like commit 1149aad10b1e ("arm64: Add dump_backtrace() in show_regs"), dump the stack in riscv show_regs as common code expects.
--- arch/riscv/include/asm/bug.h | 1 + arch/riscv/include/asm/stacktrace.h | 2 ++ arch/riscv/kernel/process.c | 9 ++++++++- arch/riscv/kernel/stacktrace.c | 10 ++++++++-- arch/riscv/kernel/traps.c | 3 ++- 5 files changed, 21 insertions(+), 4 deletions(-)
arch/riscv/include/asm/bug.h +1 -0
@@ -85,6 +85,7 @@ do { \struct pt_regs ;struct task_struct ; +void __show_regs (struct pt_regs *regs);void die (struct pt_regs *regs,const char *str);void do_trap (struct pt_regs *regs,int signo,int code,unsigned long addr);
arch/riscv/include/asm/stacktrace.h +2 -0
@@ -13,5 +13,7 @@ struct stackframe { extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,bool (*fn)(void *,unsigned long ),void *arg); +extern void dump_backtrace (struct pt_regs *regs,struct task_struct *task, +const char *loglvl);#endif /* _ASM_RISCV_STACKTRACE_H */
arch/riscv/kernel/process.c +8 -1
@@ -18,6 +18,7 @@#include <asm/unistd.h> #include <asm/processor.h> #include <asm/csr.h> +#include <asm/stacktrace.h> #include <asm/string.h> #include <asm/switch_to.h> #include <asm/thread_info.h>
@@ -39,7 +40,7 @@ void arch_cpu_idle(void)raw_local_irq_enable (); } -void show_regs (struct pt_regs *regs) +void __show_regs (struct pt_regs *regs) {show_regs_print_info (KERN_DEFAULT );
@@ -69,6 +70,12 @@ void show_regs(struct pt_regs *regs)pr_cont ("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n" , regs->status, regs->badaddr, regs->cause); } +void show_regs (struct pt_regs *regs) +{ +__show_regs (regs); +if (!user_mode (regs)) +dump_backtrace (regs,NULL ,KERN_DEFAULT ); +}void start_thread (struct pt_regs *regs,unsigned long pc,unsigned long sp)
arch/riscv/kernel/stacktrace.c +8 -2
@@ -101,10 +101,16 @@ static bool print_trace_address(void *arg, unsigned long pc)return true; } +void dump_backtrace (struct pt_regs *regs,struct task_struct *task, +const char *loglvl) +{ +pr_cont ("%sCall Trace:\n" , loglvl); +walk_stackframe (task, regs, print_trace_address, (void *)loglvl); +} +void show_stack (struct task_struct *task,unsigned long *sp,const char *loglvl) { -pr_cont ("Call Trace:\n" ); -walk_stackframe (task,NULL , print_trace_address, (void *)loglvl); +dump_backtrace (NULL , task, loglvl); }static bool save_wchan (void *arg,unsigned long pc)
arch/riscv/kernel/traps.c +2 -1
@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/irq.h> +#include <asm/bug.h> #include <asm/processor.h> #include <asm/ptrace.h> #include <asm/csr.h>
@@ -66,7 +67,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr) tsk->comm, task_pid_nr(tsk), signo, code, addr);print_vma_addr (KERN_CONT " in " ,instruction_pointer (regs));pr_cont ("\n" ); -show_regs (regs); +__show_regs (regs); }force_sig_fault (signo, code, (void __user *)addr);
Signature · 7 lines
2.26.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH RESEND 2/3 riscv: Improve __show_regs
In reply to Kefeng WangShow the function symbols of epc and ra to improve the readability of crash reports, and align the printing formats about the raw epc value.
--- arch/riscv/kernel/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/riscv/kernel/process.c +6 -1
@@ -44,7 +44,12 @@ void __show_regs(struct pt_regs *regs) {show_regs_print_info (KERN_DEFAULT ); -pr_cont ("epc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n" , +if (!user_mode (regs)) { +pr_cont ("epc : %pS\n" , (void *)regs->epc); +pr_cont (" ra : %pS\n" , (void *)regs->ra); + } + +pr_cont ("epc : " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n" , regs->epc, regs->ra, regs->sp);pr_cont (" gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n" , regs->gp, regs->tp, regs->t0);
Signature · 7 lines
2.26.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH RESEND 3/3 riscv/stacktrace: Fix stack output without ra on the stack top
In reply to Kefeng WangFrom: Chen Huang <[email protected]>
When a function doesn't have a callee, then it will not push ra into the stack, such as lkdtm_BUG() function,
addi sp,sp,-16
sd s0,8(sp)
addi s0,sp,16
ebreak
The struct stackframe use {fp,ra} to get information from stack, if walk_stackframe() with pr_regs, we will obtain wrong value and bad stacktrace,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 ---[ end trace 18da3fbdf08e25d5 ]---
Correct the next fp and pc, after that, full stacktrace shown as expects,
[<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8 [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c [<ffffffe00066c372>] direct_entry+0xc0/0x10a [<ffffffe000439f86>] full_proxy_write+0x42/0x6a [<ffffffe000309626>] vfs_write+0x7e/0x214 [<ffffffe00030992a>] ksys_write+0x98/0xc0 [<ffffffe000309960>] sys_write+0xe/0x16 [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2 ---[ end trace 61917f3d9a9fadcd ]---
--- arch/riscv/kernel/stacktrace.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/stacktrace.c +9 -3
@@ -54,9 +54,15 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,/* Unwind stack frame */ frame = (struct stackframe *)fp -1 ; sp = fp; - fp = frame->fp; - pc =ftrace_graph_ret_addr (current,NULL , frame->ra, - (unsigned long *)(fp -8 )); +if (regs && (regs->epc == pc) && (frame->fp &0x7 )) { + fp = frame->ra; + pc = regs->ra; + }else { + fp = frame->fp; + pc =ftrace_graph_ret_addr (current,NULL , frame->ra, + (unsigned long *)(fp -8 )); + } + } }
Signature · 7 lines
2.26.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
maintainerQuoted 11 lines · On Mon, 11 Jan 2021 04:40:11 PST (-0800), [email protected] wrote:
Make
show_regs()to dump the stack to improve riscv crash report, and also fix the wrong value when stack unwind ifFRAME_POINTERenabled.Chen Huang (1):
riscv/stacktrace: Fix stack output without ra on the stack topKefeng Wang (2):
riscv: Add dump stack inshow_regs
riscv: Improve__show_regs
Quoted 6 lines
arch/riscv/include/asm/bug.h | 1 + arch/riscv/include/asm/stacktrace.h | 2 ++ arch/riscv/kernel/process.c | 16 ++++++++++++++-- arch/riscv/kernel/stacktrace.c | 22 +++++++++++++++++----- arch/riscv/kernel/traps.c | 3 ++- 5 files changed, 36 insertions(+), 8 deletions(-)
Thanks, these are on for-next.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv