Skip to contentSkip to conversation

Fixups to work with crash tool

PATCH Superseded Xianting Tian 6 participants 14 messages Jul 17, 2022 – Jul 24, 2022

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Fixups to work with crash tool

I ever sent the patch 1,2 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
And patch 3,4 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

This patch series just put these patches together, and with a new patch 5. these five patches are the fixups for kexec, vmcore and improvements for vmcoreinfo and memory layout dump.

The main changes in the five patchs as below,
Patch 1: Add a fast call path of crash_kexec() as other Arch(x86, arm64) do. Patch 2: use __smp_processor_id() instead of smp_processor_id() to cleanup
the console prints.
Patch 3: Add VM layout, va bits, ram base to vmcoreinfo, which can simplify

	 the development of crash tool as ARM64 already did
	 (arch/arm64/kernel/crash_core.c).

Patch 4: Add modules to virtual kernel memory layout dump. Patch 5: Fixup to get correct kernel mode PC for vmcore

With these 5 patches(patch 3 is must), crash tool can work well to analyze a vmcore. The patches for crash tool for RISCV64 is in the link:
https://lore.kernel.org/linux-riscv/[email protected]/

Xianting Tian (5):
RISC-V: Fixup fast call of crash_kexec()
RISC-V: use __smp_processor_id() instead of smp_processor_id()
RISC-V: Add arch_crash_save_vmcoreinfo support
riscv: Add modules to virtual kernel memory layout dump
RISC-V: Fixup getting correct current pc

 arch/riscv/kernel/Makefile          |  1 +
 arch/riscv/kernel/crash_core.c      | 29 +++++++++++++++++++++++++++++
 arch/riscv/kernel/crash_save_regs.S |  2 +-
 arch/riscv/kernel/machine_kexec.c   |  2 +-
 arch/riscv/kernel/traps.c           |  4 ++++
 arch/riscv/mm/init.c                |  4 ++++
 6 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/kernel/crash_core.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 RISC-V: Fixup fast call of crash_kexec()

Currently, almost all archs (x86, arm64, mips...) support fast call of crash_kexec() when "regs && kexec_should_crash()" is true. But RISC-V not, it can only enter crash system via panic(). However panic() doesn't pass the regs of the real accident scene to crash_kexec(), it caused we can't get accurate backtrace via gdb,

	$ riscv64-linux-gnu-gdb vmlinux vmcore
	Reading symbols from vmlinux...
	[New LWP 95]
	#0  console_unlock () at kernel/printk/printk.c:2557
	2557                    if (do_cond_resched)
	(gdb) bt
	#0  console_unlock () at kernel/printk/printk.c:2557
	#1  0x0000000000000000 in ?? ()

With the patch we can get the accurate backtrace,

	$ riscv64-linux-gnu-gdb vmlinux vmcore
	Reading symbols from vmlinux...
	[New LWP 95]
	#0  0xffffffe00063a4e0 in test_thread (data=<optimized out>) at drivers/test_crash.c:81
	81             *(int *)p = 0xdead;
	(gdb)
	(gdb) bt
	#0  0xffffffe00064d5c0 in test_thread (data=<optimized out>) at drivers/test_crash.c:81
	#1  0x0000000000000000 in ?? ()

Test code to produce NULL address dereference in test_crash.c,

	void *p = NULL;
	*(int *)p = 0xdead;
Fixes 76d2a0493a17 ("RISC-V: Init and Halt Code")
---
 arch/riscv/kernel/traps.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/traps.c +4 -0
index b40426509244..39d0f8bba4b4 100644
@@ -16,6 +16,7 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/irq.h>
+#include <linux/kexec.h>
 
 #include <asm/asm-prototypes.h>
 #include <asm/bug.h>
@@ -44,6 +45,9 @@ void die(struct pt_regs *regs, const char *str)
 
 	ret = notify_die(DIE_OOPS, str, regs, 0, regs->cause, SIGSEGV);
 
+	if (regs && kexec_should_crash(current))
+		crash_kexec(regs);
+
 	bust_spinlocks(0);
 	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
 	spin_unlock_irq(&die_lock);
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/5 RISC-V: use __smp_processor_id() instead of smp_processor_id()

In reply to Xianting Tian

Use __smp_processor_id() to avoid check the preemption context when CONFIG_DEBUG_PREEMPT enabled, as we will enter crash kernel and no return.

Without the patch,

[  103.781044] sysrq: Trigger a crash
[  103.784625] Kernel panic - not syncing: sysrq triggered crash
[  103.837634] CPU1: off
[  103.889668] CPU2: off
[  103.933479] CPU3: off
[  103.939424] Starting crashdump kernel...
[  103.943442] BUG: using smp_processor_id() in preemptible [00000000] code: sh/346
[  103.950884] caller is debug_smp_processor_id+0x1c/0x26
[  103.956051] CPU: 0 PID: 346 Comm: sh Kdump: loaded Not tainted 5.10.113-00002-gce03f03bf4ec-dirty #149
[  103.965355] Call Trace:
[  103.967805] [<ffffffe00020372a>] walk_stackframe+0x0/0xa2
[  103.973206] [<ffffffe000bcf1f4>] show_stack+0x32/0x3e
[  103.978258] [<ffffffe000bd382a>] dump_stack_lvl+0x72/0x8e
[  103.983655] [<ffffffe000bd385a>] dump_stack+0x14/0x1c
[  103.988705] [<ffffffe000bdc8fe>] check_preemption_disabled+0x9e/0xaa
[  103.995057] [<ffffffe000bdc926>] debug_smp_processor_id+0x1c/0x26
[  104.001150] [<ffffffe000206c64>] machine_kexec+0x22/0xd0
[  104.006463] [<ffffffe000291a7e>] __crash_kexec+0x6a/0xa4
[  104.011774] [<ffffffe000bcf3fa>] panic+0xfc/0x2b0
[  104.016480] [<ffffffe000656ca4>] sysrq_reset_seq_param_set+0x0/0x70
[  104.022745] [<ffffffe000657310>] __handle_sysrq+0x8c/0x154
[  104.028229] [<ffffffe0006577e8>] write_sysrq_trigger+0x5a/0x6a
[  104.034061] [<ffffffe0003d90e0>] proc_reg_write+0x58/0xd4
[  104.039459] [<ffffffe00036cff4>] vfs_write+0x7e/0x254
[  104.044509] [<ffffffe00036d2f6>] ksys_write+0x58/0xbe
[  104.049558] [<ffffffe00036d36a>] sys_write+0xe/0x16
[  104.054434] [<ffffffe000201b9a>] ret_from_syscall+0x0/0x2
[  104.067863] Will call new kernel at ecc00000 from hart id 0
[  104.074939] FDT image at fc5ee000
[  104.079523] Bye...

With the patch we can got clear output,

[   67.740553] sysrq: Trigger a crash
[   67.744166] Kernel panic - not syncing: sysrq triggered crash
[   67.809123] CPU1: off
[   67.865210] CPU2: off
[   67.909075] CPU3: off
[   67.919123] Starting crashdump kernel...
[   67.924900] Will call new kernel at ecc00000 from hart id 0
[   67.932045] FDT image at fc5ee000
[   67.935560] Bye...
Fixes 0e105f1d0037 ("riscv: use hart id instead of cpu id on machine_kexec")
---
 arch/riscv/kernel/machine_kexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/machine_kexec.c +1 -1
index df8e24559035..86d1b5f9dfb5 100644
@@ -171,7 +171,7 @@ machine_kexec(struct kimage *image)
 	struct kimage_arch *internal = &image->arch;
 	unsigned long jump_addr = (unsigned long) image->start;
 	unsigned long first_ind_entry = (unsigned long) &image->head;
-	unsigned long this_cpu_id = smp_processor_id();
+	unsigned long this_cpu_id = __smp_processor_id();
 	unsigned long this_hart_id = cpuid_to_hartid_map(this_cpu_id);
 	unsigned long fdt_addr = internal->fdt_addr;
 	void *control_code_buffer = page_address(image->control_code_page);
Signature · 1 line
2.17.1
Reviewed-by on v1 2/5
#3 lore raw

Re: [PATCH 2/5] RISC-V: use __smp_processor_id() instead of smp_processor_id()

Am Sonntag, 17. Juli 2022, 12:13:20 CEST schrieb Xianting Tian:

Quoted 47 lines

Use __smp_processor_id() to avoid check the preemption context when CONFIG_DEBUG_PREEMPT enabled, as we will enter crash kernel and no return.

Without the patch,

[  103.781044] sysrq: Trigger a crash
[  103.784625] Kernel panic - not syncing: sysrq triggered crash
[  103.837634] CPU1: off
[  103.889668] CPU2: off
[  103.933479] CPU3: off
[  103.939424] Starting crashdump kernel...
[  103.943442] BUG: using smp_processor_id() in preemptible [00000000] code: sh/346
[  103.950884] caller is debug_smp_processor_id+0x1c/0x26
[  103.956051] CPU: 0 PID: 346 Comm: sh Kdump: loaded Not tainted 5.10.113-00002-gce03f03bf4ec-dirty #149
[  103.965355] Call Trace:
[  103.967805] [<ffffffe00020372a>] walk_stackframe+0x0/0xa2
[  103.973206] [<ffffffe000bcf1f4>] show_stack+0x32/0x3e
[  103.978258] [<ffffffe000bd382a>] dump_stack_lvl+0x72/0x8e
[  103.983655] [<ffffffe000bd385a>] dump_stack+0x14/0x1c
[  103.988705] [<ffffffe000bdc8fe>] check_preemption_disabled+0x9e/0xaa
[  103.995057] [<ffffffe000bdc926>] debug_smp_processor_id+0x1c/0x26
[  104.001150] [<ffffffe000206c64>] machine_kexec+0x22/0xd0
[  104.006463] [<ffffffe000291a7e>] __crash_kexec+0x6a/0xa4
[  104.011774] [<ffffffe000bcf3fa>] panic+0xfc/0x2b0
[  104.016480] [<ffffffe000656ca4>] sysrq_reset_seq_param_set+0x0/0x70
[  104.022745] [<ffffffe000657310>] __handle_sysrq+0x8c/0x154
[  104.028229] [<ffffffe0006577e8>] write_sysrq_trigger+0x5a/0x6a
[  104.034061] [<ffffffe0003d90e0>] proc_reg_write+0x58/0xd4
[  104.039459] [<ffffffe00036cff4>] vfs_write+0x7e/0x254
[  104.044509] [<ffffffe00036d2f6>] ksys_write+0x58/0xbe
[  104.049558] [<ffffffe00036d36a>] sys_write+0xe/0x16
[  104.054434] [<ffffffe000201b9a>] ret_from_syscall+0x0/0x2
[  104.067863] Will call new kernel at ecc00000 from hart id 0
[  104.074939] FDT image at fc5ee000
[  104.079523] Bye...

With the patch we can got clear output,

[   67.740553] sysrq: Trigger a crash
[   67.744166] Kernel panic - not syncing: sysrq triggered crash
[   67.809123] CPU1: off
[   67.865210] CPU2: off
[   67.909075] CPU3: off
[   67.919123] Starting crashdump kernel...
[   67.924900] Will call new kernel at ecc00000 from hart id 0
[   67.932045] FDT image at fc5ee000
[   67.935560] Bye...
Quoted 3 lines
Fixes 0e105f1d0037 ("riscv: use hart id instead of cpu id on machine_kexec")

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

Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] RISC-V: use __smp_processor_id() instead of smp_processor_id()

In reply to Xianting Tian
Quoted 72 lines · Xianting Tian

Use __smp_processor_id() to avoid check the preemption context when CONFIG_DEBUG_PREEMPT enabled, as we will enter crash kernel and no return.

Without the patch,

[  103.781044] sysrq: Trigger a crash
[  103.784625] Kernel panic - not syncing: sysrq triggered crash
[  103.837634] CPU1: off
[  103.889668] CPU2: off
[  103.933479] CPU3: off
[  103.939424] Starting crashdump kernel...
[  103.943442] BUG: using smp_processor_id() in preemptible [00000000] code: sh/346
[  103.950884] caller is debug_smp_processor_id+0x1c/0x26
[  103.956051] CPU: 0 PID: 346 Comm: sh Kdump: loaded Not tainted 5.10.113-00002-gce03f03bf4ec-dirty #149
[  103.965355] Call Trace:
[  103.967805] [<ffffffe00020372a>] walk_stackframe+0x0/0xa2
[  103.973206] [<ffffffe000bcf1f4>] show_stack+0x32/0x3e
[  103.978258] [<ffffffe000bd382a>] dump_stack_lvl+0x72/0x8e
[  103.983655] [<ffffffe000bd385a>] dump_stack+0x14/0x1c
[  103.988705] [<ffffffe000bdc8fe>] check_preemption_disabled+0x9e/0xaa
[  103.995057] [<ffffffe000bdc926>] debug_smp_processor_id+0x1c/0x26
[  104.001150] [<ffffffe000206c64>] machine_kexec+0x22/0xd0
[  104.006463] [<ffffffe000291a7e>] __crash_kexec+0x6a/0xa4
[  104.011774] [<ffffffe000bcf3fa>] panic+0xfc/0x2b0
[  104.016480] [<ffffffe000656ca4>] sysrq_reset_seq_param_set+0x0/0x70
[  104.022745] [<ffffffe000657310>] __handle_sysrq+0x8c/0x154
[  104.028229] [<ffffffe0006577e8>] write_sysrq_trigger+0x5a/0x6a
[  104.034061] [<ffffffe0003d90e0>] proc_reg_write+0x58/0xd4
[  104.039459] [<ffffffe00036cff4>] vfs_write+0x7e/0x254
[  104.044509] [<ffffffe00036d2f6>] ksys_write+0x58/0xbe
[  104.049558] [<ffffffe00036d36a>] sys_write+0xe/0x16
[  104.054434] [<ffffffe000201b9a>] ret_from_syscall+0x0/0x2
[  104.067863] Will call new kernel at ecc00000 from hart id 0
[  104.074939] FDT image at fc5ee000
[  104.079523] Bye...

With the patch we can got clear output,

[   67.740553] sysrq: Trigger a crash
[   67.744166] Kernel panic - not syncing: sysrq triggered crash
[   67.809123] CPU1: off
[   67.865210] CPU2: off
[   67.909075] CPU3: off
[   67.919123] Starting crashdump kernel...
[   67.924900] Will call new kernel at ecc00000 from hart id 0
[   67.932045] FDT image at fc5ee000
[   67.935560] Bye...
Fixes 0e105f1d0037 ("riscv: use hart id instead of cpu id on machine_kexec")
---
 arch/riscv/kernel/machine_kexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/machine_kexec.c +1 -2
index df8e24559035..86d1b5f9dfb5 100644
@@ -171,7 +171,7 @@ machine_kexec(struct kimage *image)
        struct kimage_arch *internal = &image->arch;
        unsigned long jump_addr = (unsigned long) image->start;
        unsigned long first_ind_entry = (unsigned long) &image->head;
-       unsigned long this_cpu_id = smp_processor_id();
+       unsigned long this_cpu_id = __smp_processor_id();
        unsigned long this_hart_id = cpuid_to_hartid_map(this_cpu_id);
        unsigned long fdt_addr = internal->fdt_addr;
        void *control_code_buffer = page_address(image->control_code_page);
--

2.17.1

Quoted 4 lines

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

Signature · 2 lines
Regards,
Atish
#5 lore raw

PATCH 3/5 RISC-V: Add arch_crash_save_vmcoreinfo support

In reply to Xianting Tian

Add arch_crash_save_vmcoreinfo(), which exports VM layout(MODULES, VMALLOC, VMEMMAP and KERNEL_LINK_ADDR ranges), va bits and ram base to vmcore.

Default pagetable levels and PAGE_OFFSET aren't same for different kernel version as below. For default pagetable levels, it sets sv57 on defaultly in latest kernel and do fallback to try to set sv48 on boot time if sv57 is not supported in current hardware.

For ram base, the default value is 0x80200000 for qemu riscv64 env, 0x200000 for riscv64 SoC platform(eg, SoC platform of RISC-V XuanTie 910 CPU).

* Linux Kernel 5.18 ~
* PGTABLE_LEVELS = 5
* PAGE_OFFSET = 0xff60000000000000
* Linux Kernel 5.17 ~
* PGTABLE_LEVELS = 4
* PAGE_OFFSET = 0xffffaf8000000000
* Linux Kernel 4.19 ~
* PGTABLE_LEVELS = 3
* PAGE_OFFSET = 0xffffffe000000000

Since these configurations change from time to time and version to version, it is preferable to export them via vmcoreinfo than to change the crash's code frequently, it can simplify the development of crash tool.

---
 arch/riscv/kernel/Makefile     |  1 +
 arch/riscv/kernel/crash_core.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 arch/riscv/kernel/crash_core.c
arch/riscv/kernel/Makefile +1 -0
index c71d6591d539..54e4183db080 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_KEXEC)		+= kexec_relocate.o crash_save_regs.o machine_kexec.o
 obj-$(CONFIG_KEXEC_FILE)	+= elf_kexec.o machine_kexec_file.o
 obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
+obj-$(CONFIG_CRASH_CORE)	+= crash_core.o
 
 obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o
 
arch/riscv/kernel/crash_core.c new file +29 -0
new file mode 100644
index 000000000000..8d7f5ff108da
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/crash_core.h>
+#include <linux/pagemap.h>
+
+void arch_crash_save_vmcoreinfo(void)
+{
+	VMCOREINFO_NUMBER(VA_BITS);
+	VMCOREINFO_NUMBER(phys_ram_base);
+
+	vmcoreinfo_append_str("NUMBER(PAGE_OFFSET)=0x%lx\n", PAGE_OFFSET);
+	vmcoreinfo_append_str("NUMBER(VMALLOC_START)=0x%lx\n", VMALLOC_START);
+	vmcoreinfo_append_str("NUMBER(VMALLOC_END)=0x%lx\n", VMALLOC_END);
+	vmcoreinfo_append_str("NUMBER(VMEMMAP_START)=0x%lx\n", VMEMMAP_START);
+	vmcoreinfo_append_str("NUMBER(VMEMMAP_END)=0x%lx\n", VMEMMAP_END);
+#ifdef CONFIG_64BIT
+	vmcoreinfo_append_str("NUMBER(MODULES_VADDR)=0x%lx\n", MODULES_VADDR);
+	vmcoreinfo_append_str("NUMBER(MODULES_END)=0x%lx\n", MODULES_END);
+#endif
+
+	if (IS_ENABLED(CONFIG_64BIT)) {
+#ifdef CONFIG_KASAN
+		vmcoreinfo_append_str("NUMBER(KASAN_SHADOW_START)=0x%lx\n", KASAN_SHADOW_START);
+		vmcoreinfo_append_str("NUMBER(KASAN_SHADOW_END)=0x%lx\n", KASAN_SHADOW_END);
+#endif
+		vmcoreinfo_append_str("NUMBER(KERNEL_LINK_ADDR)=0x%lx\n", KERNEL_LINK_ADDR);
+		vmcoreinfo_append_str("NUMBER(ADDRESS_SPACE_END)=0x%lx\n", ADDRESS_SPACE_END);
+	}
+}
Signature · 1 line
2.17.1
#6 lore raw

PATCH 4/5 riscv: Add modules to virtual kernel memory layout dump

In reply to Xianting Tian

Modules always live before the kernel, MODULES_END is fixed but MODULES_VADDR isn't fixed, it depends on the kernel size. Let's add it to virtual kernel memory layout dump.

As MODULES is only defined for CONFIG_64BIT, so we dump it when CONFIG_64BIT=y.

eg,
MODULES_VADDR - MODULES_END
0xffffffff01133000 - 0xffffffff80000000

---
 arch/riscv/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/mm/init.c +4 -0
index d466ec670e1f..2c4a64e97aec 100644
@@ -135,6 +135,10 @@ static void __init print_vm_layout(void)
 		(unsigned long)VMEMMAP_END);
 	print_ml("vmalloc", (unsigned long)VMALLOC_START,
 		(unsigned long)VMALLOC_END);
+#ifdef CONFIG_64BIT
+	print_ml("modules", (unsigned long)MODULES_VADDR,
+		(unsigned long)MODULES_END);
+#endif
 	print_ml("lowmem", (unsigned long)PAGE_OFFSET,
 		(unsigned long)high_memory);
 	if (IS_ENABLED(CONFIG_64BIT)) {
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 4/5
#7 lore raw

Re: [PATCH 4/5] riscv: Add modules to virtual kernel memory layout dump

Am Sonntag, 17. Juli 2022, 12:13:22 CEST schrieb Xianting Tian:

Quoted 4 lines

Modules always live before the kernel, MODULES_END is fixed but MODULES_VADDR isn't fixed, it depends on the kernel size. Let's add it to virtual kernel memory layout dump.

Quoted 8 lines

As MODULES is only defined for CONFIG_64BIT, so we dump it when CONFIG_64BIT=y.

eg,
MODULES_VADDR - MODULES_END
0xffffffff01133000 - 0xffffffff80000000

I'm still not sure if it would be better to define MODULES_* constants even on 32bit (with their VMALLOC_START etc values) and prevent needing the CONFIG_64BIT ifdef, but that's for others to decide :-)

The below also looks good, so

Quoted 20 lines
---
 arch/riscv/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/mm/init.c +4 -0
index d466ec670e1f..2c4a64e97aec 100644
@@ -135,6 +135,10 @@ static void __init print_vm_layout(void)
 		(unsigned long)VMEMMAP_END);
 	print_ml("vmalloc", (unsigned long)VMALLOC_START,
 		(unsigned long)VMALLOC_END);
+#ifdef CONFIG_64BIT
+	print_ml("modules", (unsigned long)MODULES_VADDR,
+		(unsigned long)MODULES_END);
+#endif
 	print_ml("lowmem", (unsigned long)PAGE_OFFSET,
 		(unsigned long)high_memory);
 	if (IS_ENABLED(CONFIG_64BIT)) {
Reviewed-by
#8 lore raw

Re: [PATCH 4/5] riscv: Add modules to virtual kernel memory layout dump

Quoted 13 lines · Heiko Stübner

Am Sonntag, 17. Juli 2022, 12:13:22 CEST schrieb Xianting Tian:

Quoted 11 lines

Modules always live before the kernel, MODULES_END is fixed but MODULES_VADDR isn't fixed, it depends on the kernel size. Let's add it to virtual kernel memory layout dump.

As MODULES is only defined for CONFIG_64BIT, so we dump it when CONFIG_64BIT=y.

eg,
MODULES_VADDR - MODULES_END
0xffffffff01133000 - 0xffffffff80000000

Quoted 5 lines
Quoted 1 line

I'm still not sure if it would be better to define MODULES_* constants even on 32bit (with their VMALLOC_START etc values) and prevent needing the CONFIG_64BIT ifdef, but that's for others to decide :-)

There is no MODULES_VADDR for 32-bit, because it reuses vmalloc area.

We should print MODULES_VADDR here to make people clear to know.

Quoted 28 lines

The below also looks good, so

Quoted 20 lines
---
 arch/riscv/mm/init.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/mm/init.c +4 -0
index d466ec670e1f..2c4a64e97aec 100644
@@ -135,6 +135,10 @@ static void __init print_vm_layout(void)
              (unsigned long)VMEMMAP_END);
      print_ml("vmalloc", (unsigned long)VMALLOC_START,
              (unsigned long)VMALLOC_END);
+#ifdef CONFIG_64BIT
+     print_ml("modules", (unsigned long)MODULES_VADDR,
+             (unsigned long)MODULES_END);
+#endif
      print_ml("lowmem", (unsigned long)PAGE_OFFSET,
              (unsigned long)high_memory);
      if (IS_ENABLED(CONFIG_64BIT)) {
Signature · 2 lines
Best Regards
 Guo Ren
#9 lore raw

Re: [PATCH 4/5] riscv: Add modules to virtual kernel memory layout dump

In reply to Xianting Tian

arch/riscv/mm/init.c static void __init print_vm_layout(void) · line 140

Quoted 11 lines · Xianting Tian
arch/riscv/mm/init.c +3 -0
index d466ec670e1f..2c4a64e97aec 100644
@@ -135,6 +135,10 @@ static void __init print_vm_layout(void)
 		(unsigned long)VMEMMAP_END);
 	print_ml("vmalloc", (unsigned long)VMALLOC_START,
 		(unsigned long)VMALLOC_END);
+#ifdef CONFIG_64BIT
+	print_ml("modules", (unsigned long)MODULES_VADDR,
+		(unsigned long)MODULES_END);

#ifdef MODULES_VADDR ?

Signature · 8 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

Re: [PATCH 4/5] riscv: Add modules to virtual kernel memory layout dump

Quoted 14 lines · Andreas Schwab

arch/riscv/mm/init.c static void __init print_vm_layout(void) · line 140

Quoted 11 lines · Xianting Tian
arch/riscv/mm/init.c +3 -0
index d466ec670e1f..2c4a64e97aec 100644
@@ -135,6 +135,10 @@ static void __init print_vm_layout(void)
  		(unsigned long)VMEMMAP_END);
  	print_ml("vmalloc", (unsigned long)VMALLOC_START,
  		(unsigned long)VMALLOC_END);
+#ifdef CONFIG_64BIT
+	print_ml("modules", (unsigned long)MODULES_VADDR,
+		(unsigned long)MODULES_END);

#ifdef MODULES_VADDR ?

Maybe CONFIG_64BIT is better, it shows more infos(64bit defined, 32bit not). If use MODULES_VADD, people may doubt which conditions MODULES_VADD is not defined?

Quoted 1 line
#11 lore raw

PATCH 5/5 RISC-V: Fixup getting correct current pc

In reply to Xianting Tian

When use 'echo c > /proc/sysrq-trigger' to trigger kdump, riscv_crash_save_regs() will be called to save regs to vmcore, we found "epc" value 00ffffffa5537400 is not a valid kernel virtual address, but is a user virtual address. Other regs(eg, ra, sp, gp...) are correct kernel virtual address.
Actually 0x00ffffffb0dd9400 is the user mode PC of 'PID: 113 Comm: sh', which is saved in the task's stack.

[   21.201701] CPU: 0 PID: 113 Comm: sh Kdump: loaded Not tainted 5.18.9 #45
[   21.201979] Hardware name: riscv-virtio,qemu (DT)
[   21.202160] epc : 00ffffffa5537400 ra : ffffffff80088640 sp : ff20000010333b90
[   21.202435]  gp : ffffffff810dde38 tp : ff6000000226c200 t0 : ffffffff8032be7c
[   21.202707]  t1 : 0720072007200720 t2 : 30203a7375746174 s0 : ff20000010333cf0
[   21.202973]  s1 : 0000000000000000 a0 : ff20000010333b98 a1 : 0000000000000001
[   21.203243]  a2 : 0000000000000010 a3 : 0000000000000000 a4 : 28c8f0aeffea4e00
[   21.203519]  a5 : 28c8f0aeffea4e00 a6 : 0000000000000009 a7 : ffffffff8035c9b8
[   21.203794]  s2 : ffffffff810df0a8 s3 : ffffffff810df718 s4 : ff20000010333b98
[   21.204062]  s5 : 0000000000000000 s6 : 0000000000000007 s7 : ffffffff80c4a468
[   21.204331]  s8 : 00ffffffef451410 s9 : 0000000000000007 s10: 00aaaaaac0510700
[   21.204606]  s11: 0000000000000001 t3 : ff60000001218f00 t4 : ff60000001218f00
[   21.204876]  t5 : ff60000001218000 t6 : ff200000103338b8
[   21.205079] status: 0000000200000020 badaddr: 0000000000000000 cause: 0000000000000008

With the incorrect PC, the backtrace showed by crash tool as below, the first stack frame is abnormal,

crash> bt
PID: 113 TASK: ff60000002269600 CPU: 0 COMMAND: "sh"
#0 [ff2000001039bb90] __efistub_.Ldebug_info0 at 00ffffffa5537400 <-- Abnormal #1 [ff2000001039bcf0] panic at ffffffff806578ba
#2 [ff2000001039bd50] sysrq_reset_seq_param_set at ffffffff8038c030 #3 [ff2000001039bda0] __handle_sysrq at ffffffff8038c5f8
#4 [ff2000001039be00] write_sysrq_trigger at ffffffff8038cad8
#5 [ff2000001039be20] proc_reg_write at ffffffff801b7edc
#6 [ff2000001039be40] vfs_write at ffffffff80152ba6
#7 [ff2000001039be80] ksys_write at ffffffff80152ece
#8 [ff2000001039bed0] sys_write at ffffffff80152f46

With the patch, we can get current kernel mode PC, the output as below,

[   17.607658] CPU: 0 PID: 113 Comm: sh Kdump: loaded Not tainted 5.18.9 #42
[   17.607937] Hardware name: riscv-virtio,qemu (DT)
[   17.608150] epc : ffffffff800078f8 ra : ffffffff8008862c sp : ff20000010333b90
[   17.608441]  gp : ffffffff810dde38 tp : ff6000000226c200 t0 : ffffffff8032be68
[   17.608741]  t1 : 0720072007200720 t2 : 666666666666663c s0 : ff20000010333cf0
[   17.609025]  s1 : 0000000000000000 a0 : ff20000010333b98 a1 : 0000000000000001
[   17.609320]  a2 : 0000000000000010 a3 : 0000000000000000 a4 : 0000000000000000
[   17.609601]  a5 : ff60000001c78000 a6 : 000000000000003c a7 : ffffffff8035c9a4
[   17.609894]  s2 : ffffffff810df0a8 s3 : ffffffff810df718 s4 : ff20000010333b98
[   17.610186]  s5 : 0000000000000000 s6 : 0000000000000007 s7 : ffffffff80c4a468
[   17.610469]  s8 : 00ffffffca281410 s9 : 0000000000000007 s10: 00aaaaaab5bb6700
[   17.610755]  s11: 0000000000000001 t3 : ff60000001218f00 t4 : ff60000001218f00
[   17.611041]  t5 : ff60000001218000 t6 : ff20000010333988
[   17.611255] status: 0000000200000020 badaddr: 0000000000000000 cause: 0000000000000008

With the correct PC, the backtrace showed by crash tool as below,

crash> bt
PID: 113 TASK: ff6000000226c200 CPU: 0 COMMAND: "sh"
#0 [ff20000010333b90] riscv_crash_save_regs at ffffffff800078f8 <--- Normal #1 [ff20000010333cf0] panic at ffffffff806578c6
#2 [ff20000010333d50] sysrq_reset_seq_param_set at ffffffff8038c03c #3 [ff20000010333da0] __handle_sysrq at ffffffff8038c604
#4 [ff20000010333e00] write_sysrq_trigger at ffffffff8038cae4 #5 [ff20000010333e20] proc_reg_write at ffffffff801b7ee8
#6 [ff20000010333e40] vfs_write at ffffffff80152bb2
#7 [ff20000010333e80] ksys_write at ffffffff80152eda
#8 [ff20000010333ed0] sys_write at ffffffff80152f52

Fixes e53d28180d4d ("RISC-V: Add kdump support")
---
 arch/riscv/kernel/crash_save_regs.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/crash_save_regs.S +1 -1
index 7832fb763aba..b2a1908c0463 100644
@@ -44,7 +44,7 @@ SYM_CODE_START(riscv_crash_save_regs)
 	REG_S t6,  PT_T6(a0)	/* x31 */
 
 	csrr t1, CSR_STATUS
-	csrr t2, CSR_EPC
+	auipc t2, 0x0
 	csrr t3, CSR_TVAL
 	csrr t4, CSR_CAUSE
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#12 lore raw
In reply to Xianting Tian

Hi,

Quoted 22 lines · Xianting Tian

I ever sent the patch 1,2 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
And patch 3,4 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

This patch series just put these patches together, and with a new patch 5. these five patches are the fixups for kexec, vmcore and improvements for vmcoreinfo and memory layout dump.

The main changes in the five patchs as below,
Patch 1: Add a fast call path of crash_kexec() as other Arch(x86, arm64) do. Patch 2: use __smp_processor_id() instead of smp_processor_id() to cleanup
the console prints.
Patch 3: Add VM layout, va bits, ram base to vmcoreinfo, which can simplify
the development of crash tool as ARM64 already did (arch/arm64/kernel/crash_core.c).
Patch 4: Add modules to virtual kernel memory layout dump.
Patch 5: Fixup to get correct kernel mode PC for vmcore

Quoted 8 lines

With these 5 patches(patch 3 is must), crash tool can work well to analyze a vmcore. The patches for crash tool for RISCV64 is in the link:
https://lore.kernel.org/linux-riscv/[email protected]/

Xianting Tian (5):
RISC-V: Fixup fast call of crash_kexec()
RISC-V: use __smp_processor_id() instead of smp_processor_id()
RISC-V: Add arch_crash_save_vmcoreinfo support

Vmcoreinfo changes need to be documented in
Documentation/admin-guide/kdump/vmcoreinfo.rst

Otherwise, I suggest to always cc kexec mail list (added in cc) for kexec | kdump patches.

Quoted 12 lines

riscv: Add modules to virtual kernel memory layout dump
RISC-V: Fixup getting correct current pc

 arch/riscv/kernel/Makefile          |  1 +
 arch/riscv/kernel/crash_core.c      | 29 +++++++++++++++++++++++++++++
 arch/riscv/kernel/crash_save_regs.S |  2 +-
 arch/riscv/kernel/machine_kexec.c   |  2 +-
 arch/riscv/kernel/traps.c           |  4 ++++
 arch/riscv/mm/init.c                |  4 ++++
 6 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/kernel/crash_core.c
Quoted 9 lines

--
2.17.1

--
Crash-utility mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/crash-utility
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Thanks
Dave

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

#13 lore raw
Quoted 63 lines · Dave Young

Hi,

Quoted 21 lines · Xianting Tian

I ever sent the patch 1,2 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
And patch 3,4 in the link:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

This patch series just put these patches together, and with a new patch 5. these five patches are the fixups for kexec, vmcore and improvements for vmcoreinfo and memory layout dump.

The main changes in the five patchs as below,
Patch 1: Add a fast call path of crash_kexec() as other Arch(x86, arm64) do. Patch 2: use __smp_processor_id() instead of smp_processor_id() to cleanup
the console prints.
Patch 3: Add VM layout, va bits, ram base to vmcoreinfo, which can simplify
the development of crash tool as ARM64 already did (arch/arm64/kernel/crash_core.c).
Patch 4: Add modules to virtual kernel memory layout dump.
Patch 5: Fixup to get correct kernel mode PC for vmcore

Quoted 8 lines

With these 5 patches(patch 3 is must), crash tool can work well to analyze a vmcore. The patches for crash tool for RISCV64 is in the link:
https://lore.kernel.org/linux-riscv/[email protected]/

Xianting Tian (5):
RISC-V: Fixup fast call of crash_kexec()
RISC-V: use __smp_processor_id() instead of smp_processor_id()
RISC-V: Add arch_crash_save_vmcoreinfo support

Vmcoreinfo changes need to be documented in
Documentation/admin-guide/kdump/vmcoreinfo.rst

Otherwise, I suggest to always cc kexec mail list (added in cc) for kexec | kdump patches.

thanks, I will fix it in v3.

Quoted 12 lines

riscv: Add modules to virtual kernel memory layout dump
RISC-V: Fixup getting correct current pc

  arch/riscv/kernel/Makefile          |  1 +
  arch/riscv/kernel/crash_core.c      | 29 +++++++++++++++++++++++++++++
  arch/riscv/kernel/crash_save_regs.S |  2 +-
  arch/riscv/kernel/machine_kexec.c   |  2 +-
  arch/riscv/kernel/traps.c           |  4 ++++
  arch/riscv/mm/init.c                |  4 ++++
  6 files changed, 40 insertions(+), 2 deletions(-)

create mode 100644 arch/riscv/kernel/crash_core.c

Quoted 9 lines

--
2.17.1

--
Crash-utility mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/crash-utility
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Thanks
Dave