Skip to contentSkip to conversation

riscv: cover to ARCH_STACKWALK

PATCH In review Kefeng Wang 5 participants 21 messages Nov 13, 2020 – Jan 11, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover riscv: cover to ARCH_STACKWALK

Use the newer common infrastructure and simpler arch_stack_walk() interface for stack walk.

Kefeng Wang (3):
riscv: Cleanup stacktrace
riscv: Make stack walk callback consistent with generic code
riscv: Enable ARCH_STACKWALK

 arch/riscv/Kconfig                  |  1 +
 arch/riscv/include/asm/stacktrace.h | 17 ++++++++
 arch/riscv/kernel/perf_callchain.c  | 10 +----
 arch/riscv/kernel/stacktrace.c      | 62 +++++++----------------------
 4 files changed, 34 insertions(+), 56 deletions(-)
 create mode 100644 arch/riscv/include/asm/stacktrace.h
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH 1/3 riscv: Cleanup stacktrace

1. add asm/stacktrace.h for walk_stackframe and struct stackframe
2. remove unnecessary blank lines in stacktrace.c
3. fix warning "no previous prototype for ‘fill_callchain’"

---
 arch/riscv/include/asm/stacktrace.h | 17 +++++++++++++++++
 arch/riscv/kernel/perf_callchain.c  | 10 ++--------
 arch/riscv/kernel/stacktrace.c      |  9 ++-------
 3 files changed, 21 insertions(+), 15 deletions(-)
 create mode 100644 arch/riscv/include/asm/stacktrace.h
arch/riscv/include/asm/stacktrace.h new file +17 -0
new file mode 100644
index 000000000000..f09c1e31bde9
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_RISCV_STACKTRACE_H
+#define _ASM_RISCV_STACKTRACE_H
+
+#include <linux/sched.h>
+#include <asm/ptrace.h>
+
+struct stackframe {
+	unsigned long fp;
+	unsigned long ra;
+};
+
+extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
+				    bool (*fn)(unsigned long, void *), void *arg);
+
+#endif /* _ASM_RISCV_STACKTRACE_H */
arch/riscv/kernel/perf_callchain.c +2 -8
index cf190197a22f..623ecd36a720 100644
@@ -4,11 +4,7 @@
 #include <linux/perf_event.h>
 #include <linux/uaccess.h>
 
-/* Kernel callchain */
-struct stackframe {
-	unsigned long fp;
-	unsigned long ra;
-};
+#include <asm/stacktrace.h>
 
 /*
  * Get the return address for a single stackframe and return a pointer to the
@@ -74,13 +70,11 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
 		fp = user_backtrace(entry, fp, 0);
 }
 
-bool fill_callchain(unsigned long pc, void *entry)
+static bool fill_callchain(unsigned long pc, void *entry)
 {
 	return perf_callchain_store(entry, pc);
 }
 
-void notrace walk_stackframe(struct task_struct *task,
-	struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg);
 void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
 			   struct pt_regs *regs)
 {
arch/riscv/kernel/stacktrace.c +2 -7
index 595342910c3f..345a202c92bb 100644
@@ -12,15 +12,12 @@
 #include <linux/stacktrace.h>
 #include <linux/ftrace.h>
 
+#include <asm/stacktrace.h>
+
 register unsigned long sp_in_global __asm__("sp");
 
 #ifdef CONFIG_FRAME_POINTER
 
-struct stackframe {
-	unsigned long fp;
-	unsigned long ra;
-};
-
 void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 			     bool (*fn)(unsigned long, void *), void *arg)
 {
@@ -96,7 +93,6 @@ void notrace walk_stackframe(struct task_struct *task,
 
 #endif /* CONFIG_FRAME_POINTER */
 
-
 static bool print_trace_address(unsigned long pc, void *arg)
 {
 	const char *loglvl = arg;
@@ -130,7 +126,6 @@ unsigned long get_wchan(struct task_struct *task)
 	return pc;
 }
 
-
 #ifdef CONFIG_STACKTRACE
 
 static bool __save_trace(unsigned long pc, void *arg, bool nosched)
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw

PATCH 2/3 riscv: Make stack walk callback consistent with generic code

In reply to Kefeng Wang

In order to use generic arch_stack_walk() code, make stack walk callback consistent with it.

---
 arch/riscv/include/asm/stacktrace.h |  2 +-
 arch/riscv/kernel/perf_callchain.c  |  2 +-
 arch/riscv/kernel/stacktrace.c      | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)
arch/riscv/include/asm/stacktrace.h +1 -1
index f09c1e31bde9..470a65c4ccdc 100644
@@ -12,6 +12,6 @@ struct stackframe {
 };
 
 extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
-				    bool (*fn)(unsigned long, void *), void *arg);
+				    bool (*fn)(void *, unsigned long), void *arg);
 
 #endif /* _ASM_RISCV_STACKTRACE_H */
arch/riscv/kernel/perf_callchain.c +1 -1
index 623ecd36a720..0bb1854dce83 100644
@@ -70,7 +70,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
 		fp = user_backtrace(entry, fp, 0);
 }
 
-static bool fill_callchain(unsigned long pc, void *entry)
+static bool fill_callchain(void *entry, unsigned long pc)
 {
 	return perf_callchain_store(entry, pc);
 }
arch/riscv/kernel/stacktrace.c +5 -5
index 345a202c92bb..81c48144c504 100644
@@ -43,7 +43,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 		unsigned long low, high;
 		struct stackframe *frame;
 
-		if (unlikely(!__kernel_text_address(pc) || fn(pc, arg)))
+		if (unlikely(!__kernel_text_address(pc) || fn(arg, pc)))
 			break;
 
 		/* Validate frame pointer */
@@ -63,7 +63,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 #else /* !CONFIG_FRAME_POINTER */
 
 void notrace walk_stackframe(struct task_struct *task,
-	struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
+	struct pt_regs *regs, bool (*fn)(void *, unsigned long), void *arg)
 {
 	unsigned long sp, pc;
 	unsigned long *ksp;
@@ -85,7 +85,7 @@ void notrace walk_stackframe(struct task_struct *task,
 
 	ksp = (unsigned long *)sp;
 	while (!kstack_end(ksp)) {
-		if (__kernel_text_address(pc) && unlikely(fn(pc, arg)))
+		if (__kernel_text_address(pc) && unlikely(fn(arg, pc)))
 			break;
 		pc = (*ksp++) - 0x4;
 	}
@@ -107,7 +107,7 @@ void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
 	walk_stackframe(task, NULL, print_trace_address, (void *)loglvl);
 }
 
-static bool save_wchan(unsigned long pc, void *arg)
+static bool save_wchan(void *arg, unsigned long pc)
 {
 	if (!in_sched_functions(pc)) {
 		unsigned long *p = arg;
@@ -143,7 +143,7 @@ static bool __save_trace(unsigned long pc, void *arg, bool nosched)
 	return (trace->nr_entries >= trace->max_entries);
 }
 
-static bool save_trace(unsigned long pc, void *arg)
+static bool save_trace(void *arg, unsigned long pc)
 {
 	return __save_trace(pc, arg, false);
 }
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

PATCH 3/3 riscv: Enable ARCH_STACKWALK

In reply to Kefeng Wang

Convert to ARCH_STACKWALK to reduce duplicated code in stack trace.

---
 arch/riscv/Kconfig             |  1 +
 arch/riscv/kernel/stacktrace.c | 49 +++++++---------------------------
 2 files changed, 11 insertions(+), 39 deletions(-)
arch/riscv/Kconfig +1 -0
index dfbc1351ee62..d9da5d92e40d 100644
@@ -14,6 +14,7 @@ config RISCV
 	def_bool y
 	select ARCH_CLOCKSOURCE_INIT
 	select ARCH_SUPPORTS_ATOMIC_RMW
+	select ARCH_STACKWALK
 	select ARCH_HAS_BINFMT_FLAT
 	select ARCH_HAS_DEBUG_VM_PGTABLE
 	select ARCH_HAS_DEBUG_VIRTUAL if MMU
arch/riscv/kernel/stacktrace.c +10 -39

91 lines not on this page · raw message

Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#4 lore raw
In reply to Kefeng Wang
Quoted 8 lines · On Thu, 12 Nov 2020 22:42:20 PST (-0800), [email protected] wrote:

Use the newer common infrastructure and simpler arch_stack_walk() interface for stack walk.

Kefeng Wang (3):
riscv: Cleanup stacktrace
riscv: Make stack walk callback consistent with generic code
riscv: Enable ARCH_STACKWALK

Quoted 6 lines
 arch/riscv/Kconfig                  |  1 +
 arch/riscv/include/asm/stacktrace.h | 17 ++++++++
 arch/riscv/kernel/perf_callchain.c  | 10 +----
 arch/riscv/kernel/stacktrace.c      | 62 +++++++----------------------
 4 files changed, 34 insertions(+), 56 deletions(-)
 create mode 100644 arch/riscv/include/asm/stacktrace.h

Thanks, these are on for-next.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw

PATCH 1/2 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.

---
NOTE: The patches based on
https://patchwork.kernel.org/project/linux-riscv/list/?series=383349

 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
index d6f1ec08d97b..d3804a2f9aad 100644
@@ -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
index 470a65c4ccdc..3450c1912afd 100644
@@ -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
index 19225ec65db6..e41b733abeaa 100644
@@ -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)
 	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
index 48b870a685b3..76dadf6d396b 100644
@@ -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
index ad14f4466d92..570eb078b1e1 100644
@@ -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
#6 lore raw

PATCH 2/2 riscv: Fix __show_regs printing formats

Using printk directly and align the printing formats.

Before:
epc: ffffffe0008dc23a ra : ffffffe0008dc238 sp : ffffffe081ddbd80 gp : ffffffe0010e2c70 tp : ffffffe0800d47c0 t0 : ffffffe001018620
t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe081ddbda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baaf90 a2 : 0000000000000010 a3 : 0000000000000001 a4 : 1db93e333d1e1200 a5 : 1db93e333d1e1200 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9ac80 s4 : ffffffe081d9f000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe081ddbe80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8 s11: 0000003fffbd9fa2 t3 : 1db93e333d1e1200 t4 : 0000000000000002 t5 : 0000003ff778eac8 t6 : ffffffe081ddbac8status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

After:
epc: ffffffe0008dc23e ra : ffffffe0008dc23c sp : ffffffe08221bd80 gp : ffffffe0010e2c70 tp : ffffffe081cb1ec0 t0 : ffffffe001018620 t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe08221bda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baafb8 a2 : 0000000000000010 a3 : 0000000000000001 a4 : eee4a3de5cb81700 a5 : eee4a3de5cb81700 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9aca8 s4 : ffffffe081d52000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe08221be80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8
s11: 0000003fffe33fa2 t3 : eee4a3de5cb81700 t4 : 0000000000000002 t5 : 0000003fcc454ac8 t6 : ffffffe08221bac8
status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

---
 arch/riscv/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +12 -12
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+	printk("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",
+	printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
 		regs->gp, regs->tp, regs->t0);
-	pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+	printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
 		regs->t1, regs->t2, regs->s0);
-	pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+	printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
 		regs->s1, regs->a0, regs->a1);
-	pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+	printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
 		regs->a2, regs->a3, regs->a4);
-	pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+	printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
 		regs->a5, regs->a6, regs->a7);
-	pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+	printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
 		regs->s2, regs->s3, regs->s4);
-	pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+	printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
 		regs->s5, regs->s6, regs->s7);
-	pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+	printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
 		regs->s8, regs->s9, regs->s10);
-	pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+	printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
 		regs->s11, regs->t3, regs->t4);
-	pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+	printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
 		regs->t5, regs->t6);
 
-	pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+	printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
 		regs->status, regs->badaddr, regs->cause);
 }
 void show_regs(struct pt_regs *regs)
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#7 lore raw

Re: [PATCH 2/2] riscv: Fix __show_regs printing formats

Quoted 3 lines · Kefeng Wang

Using printk directly and align the printing formats.

Why switch to printk ? IIRC, pr_* is preferred over printk for any new code.

Quoted 82 lines

Before:
epc: ffffffe0008dc23a ra : ffffffe0008dc238 sp : ffffffe081ddbd80 gp : ffffffe0010e2c70 tp : ffffffe0800d47c0 t0 : ffffffe001018620
t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe081ddbda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baaf90 a2 : 0000000000000010 a3 : 0000000000000001 a4 : 1db93e333d1e1200 a5 : 1db93e333d1e1200 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9ac80 s4 : ffffffe081d9f000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe081ddbe80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8 s11: 0000003fffbd9fa2 t3 : 1db93e333d1e1200 t4 : 0000000000000002 t5 : 0000003ff778eac8 t6 : ffffffe081ddbac8status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

After:
epc: ffffffe0008dc23e ra : ffffffe0008dc23c sp : ffffffe08221bd80 gp : ffffffe0010e2c70 tp : ffffffe081cb1ec0 t0 : ffffffe001018620 t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe08221bda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baafb8 a2 : 0000000000000010 a3 : 0000000000000001 a4 : eee4a3de5cb81700 a5 : eee4a3de5cb81700 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9aca8 s4 : ffffffe081d52000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe08221be80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8
s11: 0000003fffe33fa2 t3 : eee4a3de5cb81700 t4 : 0000000000000002 t5 : 0000003fcc454ac8 t6 : ffffffe08221bac8
status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

---
 arch/riscv/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +12 -13
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+       printk("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",
+       printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
                regs->gp, regs->tp, regs->t0);
-       pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+       printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
                regs->t1, regs->t2, regs->s0);
-       pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+       printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
                regs->s1, regs->a0, regs->a1);
-       pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+       printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
                regs->a2, regs->a3, regs->a4);
-       pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+       printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
                regs->a5, regs->a6, regs->a7);
-       pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+       printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
                regs->s2, regs->s3, regs->s4);
-       pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+       printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
                regs->s5, regs->s6, regs->s7);
-       pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+       printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
                regs->s8, regs->s9, regs->s10);
-       pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+       printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
                regs->s11, regs->t3, regs->t4);
-       pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+       printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
                regs->t5, regs->t6);
 
-       pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+       printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
                regs->status, regs->badaddr, regs->cause);
 }
 void show_regs(struct pt_regs *regs)
--

2.26.2

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Signature · 7 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#8 lore raw

Re: [PATCH 2/2] riscv: Fix __show_regs printing formats

+ John

Quoted 4 lines · Atish Patra
Quoted 2 lines · Kefeng Wang

Using printk directly and align the printing formats.

Why switch to printk ? IIRC, pr_* is preferred over printk for any new code.

The stack output is strange,  that is why I move to printk,  and the old kernel looks good.

after some test, I fould first bad commit: [cfe2790b163acdc9c058a63bff310923e84a16b4] printk: move printk_info into separate array

Hi John,  there is printk-rework from you in v5.10-rc1,  could you check it ?

Thanks

Quoted 23 lines
Quoted 23 lines

Before:
epc: ffffffe0008dc23a ra : ffffffe0008dc238 sp : ffffffe081ddbd80 gp : ffffffe0010e2c70 tp : ffffffe0800d47c0 t0 : ffffffe001018620
t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe081ddbda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baaf90 a2 : 0000000000000010 a3 : 0000000000000001 a4 : 1db93e333d1e1200 a5 : 1db93e333d1e1200 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9ac80 s4 : ffffffe081d9f000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe081ddbe80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8 s11: 0000003fffbd9fa2 t3 : 1db93e333d1e1200 t4 : 0000000000000002 t5 : 0000003ff778eac8 t6 : ffffffe081ddbac8status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

After:
epc: ffffffe0008dc23e ra : ffffffe0008dc23c sp : ffffffe08221bd80 gp : ffffffe0010e2c70 tp : ffffffe081cb1ec0 t0 : ffffffe001018620 t1 : 0000000000000064 t2 : 000000000000000a s0 : ffffffe08221bda0 s1 : 0000000000000270 a0 : 000000000000002e a1 : ffffffe000baafb8 a2 : 0000000000000010 a3 : 0000000000000001 a4 : eee4a3de5cb81700 a5 : eee4a3de5cb81700 a6 : 0000000000000030 a7 : ffffffffffffffff s2 : 0000000000000000 s3 : ffffffe000b9aca8 s4 : ffffffe081d52000 s5 : 0000000000000048 s6 : 000000000000000c s7 : ffffffe08221be80 s8 : 0000000000000000 s9 : 00000000000b1688 s10: 0000000000099dc8
s11: 0000003fffe33fa2 t3 : eee4a3de5cb81700 t4 : 0000000000000002 t5 : 0000003fcc454ac8 t6 : ffffffe08221bac8
status: 0000000000000120 badaddr: 0000000000000000 cause: 000000000000000d

Quoted 1 line
Quoted 1 line

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw

Re: [PATCH 2/2] riscv: Fix __show_regs printing formats

+Petr

Quoted 8 lines · Kefeng Wang
Quoted 4 lines · Atish Patra
Quoted 2 lines · Kefeng Wang

Using printk directly and align the printing formats.

Why switch to printk ? IIRC, pr_* is preferred over printk for any new code.

The stack output is strange, that is why I move to printk, and the old kernel looks good.

This is just a quick response to let you know I can reproduce the issue and I am investigating.

@Petr: The proposed change and output difference is here [0].

John Ogness

[0] http://lists.infradead.org/pipermail/linux-riscv/2020-November/003320.html

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#10 lore raw

Re: [PATCH 2/2] riscv: Fix __show_regs printing formats

Quoted 7 lines · John Ogness
Quoted 6 lines · Kefeng Wang
Quoted 4 lines · Atish Patra
Quoted 2 lines · Kefeng Wang

Using printk directly and align the printing formats.

Why switch to printk ? IIRC, pr_* is preferred over printk for any new code.

Quoted 7 lines
Quoted 2 lines

The stack output is strange, that is why I move to printk, and the old kernel looks good.

This is just a quick response to let you know I can reproduce the issue and I am investigating.

@Petr: The proposed change and output difference is here [0].

This is a bug in continuous line handling. I have posted [0] a fix to LKML.

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued. Having a bunch of:

    pr_cont("...\n");

lines is technically wrong. If you really want the full block to be a single message, put the newline at the beginning of the pr_cont() message or add some whitespace after a newline at the end. For example:

    pr_cont("\n....");
       or
    pr_cont("...\n ");

Although I would suggest making them separate printk calls. With CONFIG_PRINTK_CALLER it is still possible to sort out simultaneous dumps from multiple CPUs.

Thank you for reporting this!

John Ogness

[0] https://lkml.kernel.org/r/[email protected]

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#11 lore raw

Re: [PATCH 2/2] riscv: Fix __show_regs printing formats

Quoted 7 lines · John Ogness
Quoted 6 lines · John Ogness
Quoted 5 lines · Kefeng Wang
Quoted 4 lines · Atish Patra
Quoted 2 lines · Kefeng Wang

Using printk directly and align the printing formats.

Why switch to printk ? IIRC, pr_* is preferred over printk for any new code.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The stack output is strange, that is why I move to printk, and the old kernel looks good.

This is just a quick response to let you know I can reproduce the issue and I am investigating.

@Petr: The proposed change and output difference is here [0].

This is a bug in continuous line handling. I have posted [0] a fix to LKML.

Yes, it fixes the output issue.

Quoted 11 lines

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued. Having a bunch of:

     pr_cont("...\n");

lines is technically wrong. If you really want the full block to be a single message, put the newline at the beginning of the pr_cont() message or add some whitespace after a newline at the end. For example:

Quoted 7 lines
     pr_cont("\n....");
        or
     pr_cont("...\n ");

Although I would suggest making them separate printk calls. With CONFIG_PRINTK_CALLER it is still possible to sort out simultaneous dumps from multiple CPUs.

Thanks for your explanation.  I will re-post patch with changelog refresh.

Quoted 8 lines

Thank you for reporting this!

John Ogness

[0] https://lkml.kernel.org/r/[email protected]
.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#12 lore raw

PATCH v2 1/1 riscv: Using printk directly in __show_regs

In reply to Kefeng Wang

Covert bulk of pr_cont("...\n") to separate printk calls.

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued, also it is possible to sort out simultaneous dumps from multiple CPUs with CONFIG_PRINTK_CALLER enabled.

And align the printing formats.

---
 arch/riscv/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +12 -12
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+	printk("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",
+	printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
 		regs->gp, regs->tp, regs->t0);
-	pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+	printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
 		regs->t1, regs->t2, regs->s0);
-	pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+	printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
 		regs->s1, regs->a0, regs->a1);
-	pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+	printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
 		regs->a2, regs->a3, regs->a4);
-	pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+	printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
 		regs->a5, regs->a6, regs->a7);
-	pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+	printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
 		regs->s2, regs->s3, regs->s4);
-	pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+	printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
 		regs->s5, regs->s6, regs->s7);
-	pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+	printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
 		regs->s8, regs->s9, regs->s10);
-	pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+	printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
 		regs->s11, regs->t3, regs->t4);
-	pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+	printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
 		regs->t5, regs->t6);
 
-	pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+	printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
 		regs->status, regs->badaddr, regs->cause);
 }
 void show_regs(struct pt_regs *regs)
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#13 lore raw

Re: [PATCH v2] riscv: Using printk directly in __show_regs

Quoted 52 lines · On Thu, 26 Nov 2020 05:33:38 PST (-0800), [email protected] wrote:

Covert bulk of pr_cont("...\n") to separate printk calls.

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued, also it is possible to sort out simultaneous dumps from multiple CPUs with CONFIG_PRINTK_CALLER enabled.

And align the printing formats.

---
 arch/riscv/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +10 -10
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+	printk("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",
+	printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
 		regs->gp, regs->tp, regs->t0);
-	pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+	printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
 		regs->t1, regs->t2, regs->s0);
-	pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+	printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
 		regs->s1, regs->a0, regs->a1);
-	pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+	printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
 		regs->a2, regs->a3, regs->a4);
-	pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+	printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
 		regs->a5, regs->a6, regs->a7);
-	pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+	printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
 		regs->s2, regs->s3, regs->s4);
-	pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+	printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
 		regs->s5, regs->s6, regs->s7);
-	pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+	printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
 		regs->s8, regs->s9, regs->s10);
-	pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+	printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",

arch/riscv/kernel/process.c void __show_regs(struct pt_regs *regs) · line 73

Quoted 10 lines
arch/riscv/kernel/process.c +2 -2
 		regs->s11, regs->t3, regs->t4);
-	pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+	printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
 		regs->t5, regs->t6);
 
-	pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+	printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
 		regs->status, regs->badaddr, regs->cause);
 }
 void show_regs(struct pt_regs *regs)

For some reason I remember having these as printk()s originally, but I don't see that in the git history so maybe it was from before we merged the port? I don't really understand the difference here, and I thought using printk() directly wasn't recommended?

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#14 lore raw

Re: [PATCH v2] riscv: Using printk directly in __show_regs

Quoted 58 lines · Palmer Dabbelt
Quoted 57 lines · On Thu, 26 Nov 2020 05:33:38 PST (-0800), [email protected] wrote:

Covert bulk of pr_cont("...\n") to separate printk calls.

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued, also it is possible to sort out simultaneous dumps from multiple CPUs with CONFIG_PRINTK_CALLER enabled.

And align the printing formats.

---
 arch/riscv/kernel/process.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +11 -11
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+	printk("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",
+	printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
 		regs->gp, regs->tp, regs->t0);
-	pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+	printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
 		regs->t1, regs->t2, regs->s0);
-	pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+	printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
 		regs->s1, regs->a0, regs->a1);
-	pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+	printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
 		regs->a2, regs->a3, regs->a4);
-	pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+	printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
 		regs->a5, regs->a6, regs->a7);
-	pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+	printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
 		regs->s2, regs->s3, regs->s4);
-	pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+	printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
 		regs->s5, regs->s6, regs->s7);
-	pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+	printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
 		regs->s8, regs->s9, regs->s10);
-	pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+	printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
 		regs->s11, regs->t3, regs->t4);
-	pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+	printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
 		regs->t5, regs->t6);
 
Quoted 10 lines

arch/riscv/kernel/process.c void __show_regs(struct pt_regs *regs) · line 73

Quoted 5 lines
arch/riscv/kernel/process.c +1 -1
-	pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+	printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
 		regs->status, regs->badaddr, regs->cause);
 }
 void show_regs(struct pt_regs *regs)

For some reason I remember having these as printk()s originally, but I don't see that in the git history so maybe it was from before we merged the port? I don't really understand the difference here, and I thought using printk() directly wasn't recommended?

There no difference between:

   pr_cont("...\n");
      and
   printk("...\n");

except for the very first call, which will try to continue from whatever was printed before. (But even that only makes a difference if the previous call did not have a newline at the end.)

Note that the printk() being used does not specify the loglevel. Perhaps it is intentional that the default loglevel (which can be specified by the user) is used? Otherwise, if a particular loglevel _is_ desired, then the appropriate pr_info/pr_warn/... should be used.

Also, this patch is also sneaking in some formatting changes. Previously the columns were not aligned correctly. That spacing is also fixed here. The spacing change _is_ a real improvement.

John Ogness

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#15 lore raw

Re: [PATCH v2] riscv: Using printk directly in __show_regs

Quoted 59 lines · John Ogness
Quoted 58 lines · Palmer Dabbelt
Quoted 57 lines · On Thu, 26 Nov 2020 05:33:38 PST (-0800), [email protected] wrote:

Covert bulk of pr_cont("...\n") to separate printk calls.

Note that a pr_cont() message with a trailing newline will "terminate" the continous line so that it can no longer be continued, also it is possible to sort out simultaneous dumps from multiple CPUs with CONFIG_PRINTK_CALLER enabled.

And align the printing formats.

---
  arch/riscv/kernel/process.c | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/kernel/process.c +11 -11
index e41b733abeaa..2119d49feea5 100644
@@ -44,30 +44,30 @@ 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",
+	printk("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",
+	printk("gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
  		regs->gp, regs->tp, regs->t0);
-	pr_cont(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
+	printk("t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
  		regs->t1, regs->t2, regs->s0);
-	pr_cont(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
+	printk("s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
  		regs->s1, regs->a0, regs->a1);
-	pr_cont(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
+	printk("a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
  		regs->a2, regs->a3, regs->a4);
-	pr_cont(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
+	printk("a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
  		regs->a5, regs->a6, regs->a7);
-	pr_cont(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
+	printk("s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
  		regs->s2, regs->s3, regs->s4);
-	pr_cont(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
+	printk("s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
  		regs->s5, regs->s6, regs->s7);
-	pr_cont(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
+	printk("s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
  		regs->s8, regs->s9, regs->s10);
-	pr_cont(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
+	printk("s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
  		regs->s11, regs->t3, regs->t4);
-	pr_cont(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
+	printk("t5 : " REG_FMT " t6 : " REG_FMT "\n",
  		regs->t5, regs->t6);
 
Quoted 9 lines
Quoted 9 lines

arch/riscv/kernel/process.c void __show_regs(struct pt_regs *regs) · line 73

Quoted 5 lines
arch/riscv/kernel/process.c +1 -1
-	pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
+	printk("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
  		regs->status, regs->badaddr, regs->cause);
  }
  void show_regs(struct pt_regs *regs)

For some reason I remember having these as printk()s originally, but I don't see that in the git history so maybe it was from before we merged the port? I don't really understand the difference here, and I thought using printk() directly wasn't recommended?

The original reason which I changed to printk is the strange out-print, see v1 patch [1],

but it's found that there is a regression in v5.10 printk rework, and being fixed by commit

4ad9921af4f1 ("printk: finalize records with trailing newlines").

The v2 patch major change is align the printing (not a big change) and in case of rearrangement of

print when CONFIG_PRINTK_CALLER enabled

[1] https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

Quoted 15 lines

There no difference between:

    pr_cont("...\n");
       and
    printk("...\n");

except for the very first call, which will try to continue from whatever was printed before. (But even that only makes a difference if the previous call did not have a newline at the end.)

Note that the printk() being used does not specify the loglevel. Perhaps it is intentional that the default loglevel (which can be specified by the user) is used? Otherwise, if a particular loglevel _is_ desired, then the appropriate pr_info/pr_warn/... should be used.

Quoted 7 lines

Also, this patch is also sneaking in some formatting changes. Previously the columns were not aligned correctly. That spacing is also fixed here. The spacing change _is_ a real improvement.

John Ogness
.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by on v1 1/2
#16 lore raw

Re: [PATCH 1/2] riscv: Add dump stack in show_regs

In reply to Kefeng Wang
Quoted 122 lines · Kefeng Wang

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

---
NOTE: The patches based on
https://patchwork.kernel.org/project/linux-riscv/list/?series=383349

 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
index d6f1ec08d97b..d3804a2f9aad 100644
@@ -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
index 470a65c4ccdc..3450c1912afd 100644
@@ -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
index 19225ec65db6..e41b733abeaa 100644
@@ -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)
        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
index 48b870a685b3..76dadf6d396b 100644
@@ -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 -2
index ad14f4466d92..570eb078b1e1 100644
@@ -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

Quoted 4 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

LGTM.

Signature · 7 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#17 lore raw

Re: [PATCH 1/2] riscv: Add dump stack in show_regs

In reply to Kefeng Wang

hi Palmer, kindly ping...

Quoted 109 lines · Kefeng Wang

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

---
NOTE: The patches based on
https://patchwork.kernel.org/project/linux-riscv/list/?series=383349

  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
index d6f1ec08d97b..d3804a2f9aad 100644
@@ -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
index 470a65c4ccdc..3450c1912afd 100644
@@ -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
index 19225ec65db6..e41b733abeaa 100644
@@ -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)
  	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
index 48b870a685b3..76dadf6d396b 100644
@@ -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 +1 -0
index ad14f4466d92..570eb078b1e1 100644
@@ -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>

arch/riscv/kernel/traps.c void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr) · line 73

Quoted 8 lines
arch/riscv/kernel/traps.c +1 -1
@@ -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);

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#18 lore raw

Re: [PATCH 1/2] riscv: Add dump stack in show_regs

Quoted 1 line · On Mon, 14 Dec 2020 03:52:19 PST (-0800), [email protected] wrote:

hi Palmer, kindly ping...

Sorry, it looks like I missed this because it's all threaded together. I'm not really sure what you're trying to do here: you've got three patch sets in one thread, one of which seems to be a v2 of only a single patch.

Do you mind sending out a standalone version of this?

Quoted 118 lines · Kefeng Wang
Quoted 116 lines

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

---
NOTE: The patches based on
https://patchwork.kernel.org/project/linux-riscv/list/?series=383349

  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
index d6f1ec08d97b..d3804a2f9aad 100644
@@ -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
index 470a65c4ccdc..3450c1912afd 100644
@@ -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
index 19225ec65db6..e41b733abeaa 100644
@@ -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)
  	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
index 48b870a685b3..76dadf6d396b 100644
@@ -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
index ad14f4466d92..570eb078b1e1 100644
@@ -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);
  	}
 
Quoted 1 line

arch/riscv/kernel/traps.c void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr) · line 73

Quoted 1 line
arch/riscv/kernel/traps.c +0 -0
  	force_sig_fault(signo, code, (void __user *)addr);

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#19 lore raw

Re: [PATCH 1/2] riscv: Add dump stack in show_regs

Quoted 7 lines · Palmer Dabbelt
Quoted 1 line · On Mon, 14 Dec 2020 03:52:19 PST (-0800), [email protected] wrote:

hi Palmer, kindly ping...

Sorry, it looks like I missed this because it's all threaded together.  I'm not really sure what you're trying to do here: you've got three patch sets in one thread, one of which seems to be a v2 of only a single patch.
Do you mind sending out a standalone version of this?

Sure, I will rebase on the top of 5.11-rc3 and resend them.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#20 lore raw
In reply to Palmer Dabbelt
Quoted 9 lines · Palmer Dabbelt
Quoted 8 lines · On Thu, 12 Nov 2020 22:42:20 PST (-0800), [email protected] wrote:

Use the newer common infrastructure and simpler arch_stack_walk() interface for stack walk.

Kefeng Wang (3):
  riscv: Cleanup stacktrace
  riscv: Make stack walk callback consistent with generic code
  riscv: Enable ARCH_STACKWALK

Quoted 8 lines
Quoted 6 lines

 arch/riscv/Kconfig                  |  1 + arch/riscv/include/asm/stacktrace.h | 17 ++++++++ arch/riscv/kernel/perf_callchain.c  | 10 +---- arch/riscv/kernel/stacktrace.c      | 62 +++++++----------------------

 4 files changed, 34 insertions(+), 56 deletions(-)

 create mode 100644 arch/riscv/include/asm/stacktrace.h

Thanks, these are on for-next.

hi Palmer,  I found a extra code about deleting "__INIT",  is there a mistaken when merged into for- next?

see link

https://kernel.googlesource.com/pub/scm/linux/kernel/git/riscv/linux/+/5cb0080f1bfdccb56d5c225d1cd648cdb33fa9bb%5E%21/#F1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv