Re: [PATCH v11 01/11] riscv: kexec_file: Fix crashk_low_res not exclude bug

From: Guo Ren

Date: Mon Mar 30 2026 - 03:55:22 EST


On Mon, Mar 30, 2026 at 3:11 PM Jinjie Ruan <ruanjinjie@xxxxxxxxxx> wrote:
>
>
>
> On 2026/3/30 11:49, Guo Ren wrote:
> > On Sat, Mar 28, 2026 at 3:41 PM Jinjie Ruan <ruanjinjie@xxxxxxxxxx> wrote:
> >>
> >> As done in commit 944a45abfabc ("arm64: kdump: Reimplement crashkernel=X")
> >> and commit 4831be702b95 ("arm64/kexec: Fix missing extra range for
> >> crashkres_low.") for arm64, while implementing crashkernel=X,[high,low],
> >> riscv should have excluded the "crashk_low_res" reserved ranges from
> >> the crash kernel memory to prevent them from being exported through
> >> /proc/vmcore, and the exclusion would need an extra crash_mem range.
> >>
> >> Cc: Guo Ren <guoren@xxxxxxxxxx>
> >> Cc: Baoquan He <bhe@xxxxxxxxxx>
> >> Fixes: 5882e5acf18d ("riscv: kdump: Implement crashkernel=X,[high,low]")
> >> Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
> >> ---
> >> arch/riscv/kernel/machine_kexec_file.c | 14 +++++++++++---
> >> 1 file changed, 11 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> >> index 54e2d9552e93..3f7766057cac 100644
> >> --- a/arch/riscv/kernel/machine_kexec_file.c
> >> +++ b/arch/riscv/kernel/machine_kexec_file.c
> >> @@ -61,7 +61,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
> >> unsigned int nr_ranges;
> >> int ret;
> >>
> >> - nr_ranges = 1; /* For exclusion of crashkernel region */
> >> + nr_ranges = 2; /* For exclusion of crashkernel region */
> >> walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
> >>
> >> cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
> >> @@ -76,8 +76,16 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
> >>
> >> /* Exclude crashkernel region */
> >> ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> >> - if (!ret)
> >> - ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
> >> + if (ret)
> >> + goto out;
> >> +
> >> + if (crashk_low_res.end) {
> >> + ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
> > Exclude crashk_low_res is reasonable, but have you tested this?
>
> Just simply tested on qemu with crashkernel=4G with following kexec
> mentioned in
> https://lore.kernel.org/all/20230726175000.2536220-1-chenjiahao16@xxxxxxxxxx/.
> And the second kernel can be started normally.
>
> https://github.com/chenjh005/kexec-tools/tree/build-test-riscv-v2
>
> # dmesg | grep crash
> [ 0.000000] crashkernel low memory reserved: 0xf8000000 - 0x100000000
> (128 MB)
> [ 0.000000] crashkernel reserved: 0x000000017fe00000 -
> 0x000000027fe00000 (4096 MB)
Adding a test log to the commit log makes the patch more trustworthy.

Reviewed-by: Guo Ren <guoren@xxxxxxxxxx>

>
>
>
> >
> >> + if (ret)
> >> + goto out;
> >> + }
> >> +
> >> + ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
> >>
> >> out:
> >> kfree(cmem);
> >> --
> >> 2.34.1
> >>
> >
> >



--
Best Regards
Guo Ren