[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260126080738.696723-1-ruanjinjie@huawei.com>
Date: Mon, 26 Jan 2026 16:07:38 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <corbet@....net>, <pjw@...nel.org>, <palmer@...belt.com>,
<aou@...s.berkeley.edu>, <alex@...ti.fr>, <akpm@...ux-foundation.org>,
<bp@...en8.de>, <rdunlap@...radead.org>, <mingo@...nel.org>,
<pawan.kumar.gupta@...ux.intel.com>, <feng.tang@...ux.alibaba.com>,
<kees@...nel.org>, <elver@...gle.com>, <arnd@...db.de>,
<lirongqing@...du.com>, <fvdl@...gle.com>, <bhelgaas@...gle.com>,
<leitao@...ian.org>, <songshuaishuai@...ylab.org>, <bjorn@...osinc.com>,
<rppt@...nel.org>, <dave.hansen@...ux.intel.com>, <kevin.brodsky@....com>,
<samuel.holland@...ive.com>, <vishal.moola@...il.com>,
<junhui.liu@...moral.tech>, <cuiyunhui@...edance.com>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-riscv@...ts.infradead.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH] riscv: kexec: Add support for crashkernel CMA reservation
Commit 35c18f2933c5 ("Add a new optional ",cma" suffix to the
crashkernel= command line option") and commit ab475510e042 ("kdump:
implement reserve_crashkernel_cma") added CMA support for kdump
crashkernel reservation. This allows the kernel to dynamically allocate
contiguous memory for crash dumping when needed, rather than permanently
reserving a fixed region at boot time.
So extend crashkernel CMA reservation support to riscv. The following
changes are made to enable CMA reservation:
- Parse and obtain the CMA reservation size along with other crashkernel
parameters.
- Call reserve_crashkernel_cma() to allocate the CMA region for kdump.
- Include the CMA-reserved ranges for kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to
prevent them from being exported through /proc/vmcore.
Update kernel-parameters.txt to document CMA support for crashkernel on
riscv architecture.
Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
---
Documentation/admin-guide/kernel-parameters.txt | 2 +-
arch/riscv/kernel/machine_kexec_file.c | 17 +++++++++++++++--
arch/riscv/mm/init.c | 5 +++--
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 1058f2a6d6a8..52414c254208 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1119,7 +1119,7 @@ Kernel parameters
It will be ignored when crashkernel=X,high is not used
or memory reserved is below 4G.
crashkernel=size[KMG],cma
- [KNL, X86, ppc] Reserve additional crash kernel memory from
+ [KNL, X86, RISCV, ppc] Reserve additional crash kernel memory from
CMA. This reservation is usable by the first system's
userspace memory and kernel movable allocations (memory
balloon, zswap). Pages allocated from this memory range
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index dd9d92a96517..5c8f3cccbc83 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -59,9 +59,9 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
{
struct crash_mem *cmem;
unsigned int nr_ranges;
- int ret;
+ int ret, i;
- nr_ranges = 1; /* For exclusion of crashkernel region */
+ nr_ranges = 1 + crashk_cma_cnt; /* For exclusion of crashkernel region */
walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
cmem = kmalloc(struct_size(cmem, ranges, nr_ranges), GFP_KERNEL);
@@ -74,11 +74,24 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
if (ret)
goto out;
+ for (i = 0; i < crashk_cma_cnt; i++) {
+ cmem->ranges[cmem->nr_ranges].start = crashk_cma_ranges[i].start;
+ cmem->ranges[cmem->nr_ranges].end = crashk_cma_ranges[i].end;
+ cmem->nr_ranges++;
+ }
+
/* 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);
+ for (i = 0; i < crashk_cma_cnt; ++i) {
+ ret = crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
+ crashk_cma_ranges[i].end);
+ if (ret)
+ goto out;
+ }
+
out:
kfree(cmem);
return ret;
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index addb8a9305be..074d2d5f79ee 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -1404,7 +1404,7 @@ static inline void setup_vm_final(void)
*/
static void __init arch_reserve_crashkernel(void)
{
- unsigned long long low_size = 0;
+ unsigned long long low_size = 0, cma_size = 0;
unsigned long long crash_base, crash_size;
bool high = false;
int ret;
@@ -1414,11 +1414,12 @@ static void __init arch_reserve_crashkernel(void)
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&crash_size, &crash_base,
- &low_size, NULL, &high);
+ &low_size, &cma_size, &high);
if (ret)
return;
reserve_crashkernel_generic(crash_size, crash_base, low_size, high);
+ reserve_crashkernel_cma(cma_size);
}
void __init paging_init(void)
--
2.34.1
Powered by blists - more mailing lists