All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND 0/3] riscv: improve the stacktrace report
@ 2021-01-11 12:40 Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 1/3] riscv: Add dump stack in show_regs Kefeng Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kefeng Wang @ 2021-01-11 12:40 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv, Paul Walmsley, Palmer Dabbelt
  Cc: Kefeng Wang, Albert Ou, Chen Huang

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(-)

-- 
2.26.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH RESEND 1/3] riscv: Add dump stack in show_regs
  2021-01-11 12:40 [PATCH RESEND 0/3] riscv: improve the stacktrace report Kefeng Wang
@ 2021-01-11 12:40 ` Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 2/3] riscv: Improve __show_regs Kefeng Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2021-01-11 12:40 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv, Paul Walmsley, Palmer Dabbelt
  Cc: Atish Patra, Kefeng Wang, Albert Ou, Chen Huang

Like commit 1149aad10b1e ("arm64: Add dump_backtrace() in show_regs"),
dump the stack in riscv show_regs as common code expects.

Reviewed-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 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(-)

diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
index d6f1ec08d97b..d3804a2f9aad 100644
--- a/arch/riscv/include/asm/bug.h
+++ b/arch/riscv/include/asm/bug.h
@@ -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);
 
diff --git a/arch/riscv/include/asm/stacktrace.h b/arch/riscv/include/asm/stacktrace.h
index 470a65c4ccdc..3450c1912afd 100644
--- a/arch/riscv/include/asm/stacktrace.h
+++ b/arch/riscv/include/asm/stacktrace.h
@@ -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 */
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index dd5f985b1f40..78bb3a00d249 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -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)
diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 48b870a685b3..76dadf6d396b 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -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)
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index ad14f4466d92..570eb078b1e1 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -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);
-- 
2.26.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH RESEND 2/3] riscv: Improve __show_regs
  2021-01-11 12:40 [PATCH RESEND 0/3] riscv: improve the stacktrace report Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 1/3] riscv: Add dump stack in show_regs Kefeng Wang
@ 2021-01-11 12:40 ` Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 3/3] riscv/stacktrace: Fix stack output without ra on the stack top Kefeng Wang
  2021-01-14  5:17 ` [PATCH RESEND 0/3] riscv: improve the stacktrace report Palmer Dabbelt
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2021-01-11 12:40 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv, Paul Walmsley, Palmer Dabbelt
  Cc: Kefeng Wang, Albert Ou, Chen Huang

Show the function symbols of epc and ra to improve the
readability of crash reports, and align the printing
formats about the raw epc value.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/riscv/kernel/process.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 78bb3a00d249..d8c099aa1337 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -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);
-- 
2.26.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH RESEND 3/3] riscv/stacktrace: Fix stack output without ra on the stack top
  2021-01-11 12:40 [PATCH RESEND 0/3] riscv: improve the stacktrace report Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 1/3] riscv: Add dump stack in show_regs Kefeng Wang
  2021-01-11 12:40 ` [PATCH RESEND 2/3] riscv: Improve __show_regs Kefeng Wang
@ 2021-01-11 12:40 ` Kefeng Wang
  2021-01-14  5:17 ` [PATCH RESEND 0/3] riscv: improve the stacktrace report Palmer Dabbelt
  3 siblings, 0 replies; 5+ messages in thread
From: Kefeng Wang @ 2021-01-11 12:40 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv, Paul Walmsley, Palmer Dabbelt
  Cc: Kefeng Wang, Albert Ou, Chen Huang

From: Chen Huang <chenhuang5@huawei.com>

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 ]---

Signed-off-by: Chen Huang <chenhuang5@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/riscv/kernel/stacktrace.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 76dadf6d396b..51ce3620ac1f 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -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));
+		}
+
 	}
 }
 
-- 
2.26.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND 0/3] riscv: improve the stacktrace report
  2021-01-11 12:40 [PATCH RESEND 0/3] riscv: improve the stacktrace report Kefeng Wang
                   ` (2 preceding siblings ...)
  2021-01-11 12:40 ` [PATCH RESEND 3/3] riscv/stacktrace: Fix stack output without ra on the stack top Kefeng Wang
@ 2021-01-14  5:17 ` Palmer Dabbelt
  3 siblings, 0 replies; 5+ messages in thread
From: Palmer Dabbelt @ 2021-01-14  5:17 UTC (permalink / raw)
  To: wangkefeng.wang
  Cc: linux-riscv, aou, wangkefeng.wang, chenhuang5, Paul Walmsley

On Mon, 11 Jan 2021 04:40:11 PST (-0800), wangkefeng.wang@huawei.com wrote:
> 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(-)

Thanks, these are on for-next.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-14  5:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 12:40 [PATCH RESEND 0/3] riscv: improve the stacktrace report Kefeng Wang
2021-01-11 12:40 ` [PATCH RESEND 1/3] riscv: Add dump stack in show_regs Kefeng Wang
2021-01-11 12:40 ` [PATCH RESEND 2/3] riscv: Improve __show_regs Kefeng Wang
2021-01-11 12:40 ` [PATCH RESEND 3/3] riscv/stacktrace: Fix stack output without ra on the stack top Kefeng Wang
2021-01-14  5:17 ` [PATCH RESEND 0/3] riscv: improve the stacktrace report Palmer Dabbelt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.