2022-07-17 10:25:08

by Xianting Tian

[permalink] [raw]
Subject: [PATCH 0/5] 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

--
2.17.1


2022-07-17 10:43:55

by Xianting Tian

[permalink] [raw]
Subject: [PATCH 3/5] RISC-V: Add arch_crash_save_vmcoreinfo support

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.

Signed-off-by: Xianting Tian <[email protected]>
---
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

diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index c71d6591d539..54e4183db080 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -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

diff --git a/arch/riscv/kernel/crash_core.c b/arch/riscv/kernel/crash_core.c
new file mode 100644
index 000000000000..8d7f5ff108da
--- /dev/null
+++ b/arch/riscv/kernel/crash_core.c
@@ -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);
+ }
+}
--
2.17.1

2022-07-17 11:03:18

by Xianting Tian

[permalink] [raw]
Subject: [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")
Reviewed-by: Guo Ren <[email protected]>
Reviewed-by: Kefeng Wang <[email protected]>
Signed-off-by: Xianting Tian <[email protected]>
---
arch/riscv/kernel/traps.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index b40426509244..39d0f8bba4b4 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -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);
--
2.17.1

2022-07-22 08:18:06

by Dave Young

[permalink] [raw]
Subject: Re: [Crash-utility] [PATCH 0/5] Fixups to work with crash tool

Hi,

On Sun, 17 Jul 2022 at 18:13, Xianting Tian
<[email protected]> wrote:
>
> 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

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.


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

2022-07-24 02:40:08

by Xianting Tian

[permalink] [raw]
Subject: Re: [Crash-utility] [PATCH 0/5] Fixups to work with crash tool


在 2022/7/22 下午4:13, Dave Young 写道:
> Hi,
>
> On Sun, 17 Jul 2022 at 18:13, Xianting Tian
> <[email protected]> wrote:
>> 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
> 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.
>> 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
>>
>> --
>> 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