From nobody Mon Feb 9 08:34:05 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5B3A39A7E1; Wed, 4 Feb 2026 09:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197804; cv=none; b=ZLwfS7OObWnw20LhL5kpDHUkx1TP4PUQb46aOcXCRKjHv+nTbrCODjoeuUCvx6mOnoE6qC/V1XQTi7GfkeMlJENzNDO3VdorfdzZxSG5w538BPLCqG7IW7QYC1Sp1xaHgpPopkNKLN3QsVU5iFo7QiH8MRCyJNeap595sx+A7m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197804; c=relaxed/simple; bh=1srqwd/mrEYhwK7jBUUukUUXYyzIgrsbHsUiI/JSkS4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=udmkH2bw3F4xHwbSA1h0X1geu7nlFScG5pmndRd9mKwv6qa686U1KTbsQ073OJYVbksiCrKjlZWy2BVjEfwiAoNL9/jSOfONnZ8zSe1Lfk0IJRo50sznDCNalvvxMICepy2Ahtk0VQJEzglUWFfSp8hdMmU2gO25xpMpMNUzDic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=3aga8HNk; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="3aga8HNk" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=QVg6OyxDVrqaKGU+pvZ6DlNaiN3X5DKslNqzBQhZthc=; b=3aga8HNkyvVPYyyaP7DsKfPU92VXxDmY9f7epER4l6Hw3sgYrNxgvZ1lbM4t0CmbNGfEzjYlh 7Z7dN5STGxEM45T2fuFfRB4UQbR2WGh1ZZTJVXpBzcrjn0gYSucWjZ25dZGu2oS4y1xBQwKjZY/ UA2dKT27fnDTZ0axxkIuFbo= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4f5Zr64G09zLlSs; Wed, 4 Feb 2026 17:32:06 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 8D1C84055B; Wed, 4 Feb 2026 17:36:40 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Feb 2026 17:36:37 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v3 1/3] crash: Exclude crash kernel memory in crash core Date: Wed, 4 Feb 2026 17:37:26 +0800 Message-ID: <20260204093728.1447527-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260204093728.1447527-1-ruanjinjie@huawei.com> References: <20260204093728.1447527-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" The exclude of crashk_res, crashk_low_res and crashk_cma memory are almost identical across different architectures, so handling them in the crash core would eliminate a lot of duplication, so do them in the common code. Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/machine_kexec_file.c | 12 ------- arch/loongarch/kernel/machine_kexec_file.c | 12 ------- arch/powerpc/kexec/ranges.c | 16 ++------- arch/riscv/kernel/machine_kexec_file.c | 5 +-- arch/x86/kernel/crash.c | 39 ++-------------------- kernel/crash_core.c | 28 ++++++++++++++++ 6 files changed, 34 insertions(+), 78 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/mac= hine_kexec_file.c index 410060ebd86d..ed2c45007158 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -64,20 +64,8 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) cmem->nr_ranges++; } =20 - /* Exclude crashkernel region */ - ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (ret) - goto out; - - if (crashk_low_res.end) { - ret =3D crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_r= es.end); - if (ret) - goto out; - } - ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 -out: kfree(cmem); return ret; } diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/ke= rnel/machine_kexec_file.c index fb57026f5f25..26f867e53955 100644 --- a/arch/loongarch/kernel/machine_kexec_file.c +++ b/arch/loongarch/kernel/machine_kexec_file.c @@ -80,20 +80,8 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) cmem->nr_ranges++; } =20 - /* Exclude crashkernel region */ - ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (ret < 0) - goto out; - - if (crashk_low_res.end) { - ret =3D crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_r= es.end); - if (ret < 0) - goto out; - } - ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 -out: kfree(cmem); return ret; } diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c index 867135560e5c..3f76dd266b1f 100644 --- a/arch/powerpc/kexec/ranges.c +++ b/arch/powerpc/kexec/ranges.c @@ -553,9 +553,7 @@ int get_usable_memory_ranges(struct crash_mem **mem_ran= ges) #endif /* CONFIG_KEXEC_FILE */ =20 #ifdef CONFIG_CRASH_DUMP -static int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges, - unsigned long long mstart, - unsigned long long mend) +static int crash_realloc_mem_range_guarded(struct crash_mem **mem_ranges) { struct crash_mem *tmem =3D *mem_ranges; =20 @@ -566,7 +564,7 @@ static int crash_exclude_mem_range_guarded(struct crash= _mem **mem_ranges, return -ENOMEM; } =20 - return crash_exclude_mem_range(tmem, mstart, mend); + return 0; } =20 /** @@ -604,18 +602,10 @@ int get_crash_memory_ranges(struct crash_mem **mem_ra= nges) sort_memory_ranges(*mem_ranges, true); } =20 - /* Exclude crashkernel region */ - ret =3D crash_exclude_mem_range_guarded(mem_ranges, crashk_res.start, cra= shk_res.end); + ret =3D crash_realloc_mem_range_guarded(mem_ranges); if (ret) goto out; =20 - for (i =3D 0; i < crashk_cma_cnt; ++i) { - ret =3D crash_exclude_mem_range_guarded(mem_ranges, crashk_cma_ranges[i]= .start, - crashk_cma_ranges[i].end); - if (ret) - goto out; - } - /* * FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL * regions are exported to save their context at the time of diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/mac= hine_kexec_file.c index dd9d92a96517..fec3622a13c9 100644 --- a/arch/riscv/kernel/machine_kexec_file.c +++ b/arch/riscv/kernel/machine_kexec_file.c @@ -74,10 +74,7 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) if (ret) goto out; =20 - /* Exclude crashkernel region */ - ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (!ret) - ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); + ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 out: kfree(cmem); diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 335fd2ee9766..d8341a48f6b3 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -186,41 +186,6 @@ static struct crash_mem *fill_up_crash_elf_data(void) return cmem; } =20 -/* - * Look for any unwanted ranges between mstart, mend and remove them. This - * might lead to split and split ranges are put in cmem->ranges[] array - */ -static int elf_header_exclude_ranges(struct crash_mem *cmem) -{ - int ret =3D 0; - int i; - - /* Exclude the low 1M because it is always reserved */ - ret =3D crash_exclude_mem_range(cmem, 0, SZ_1M - 1); - if (ret) - return ret; - - /* Exclude crashkernel region */ - ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (ret) - return ret; - - if (crashk_low_res.end) - ret =3D crash_exclude_mem_range(cmem, crashk_low_res.start, - crashk_low_res.end); - if (ret) - return ret; - - for (i =3D 0; i < crashk_cma_cnt; ++i) { - ret =3D crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start, - crashk_cma_ranges[i].end); - if (ret) - return ret; - } - - return 0; -} - static int prepare_elf64_ram_headers_callback(struct resource *res, void *= arg) { struct crash_mem *cmem =3D arg; @@ -247,8 +212,8 @@ static int prepare_elf_headers(void **addr, unsigned lo= ng *sz, if (ret) goto out; =20 - /* Exclude unwanted mem ranges */ - ret =3D elf_header_exclude_ranges(cmem); + /* Exclude the low 1M because it is always reserved */ + ret =3D crash_exclude_mem_range(cmem, 0, SZ_1M - 1); if (ret) goto out; =20 diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 99dac1aa972a..5c0de111ddc3 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -161,8 +162,30 @@ static inline resource_size_t crash_resource_size(cons= t struct resource *res) return !res->end ? 0 : resource_size(res); } =20 +static int crash_exclude_mem_ranges(struct crash_mem *cmem) +{ + int ret, i; + + /* Exclude crashkernel region */ + ret =3D crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + return ret; + + if (crashk_low_res.end) { + ret =3D crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_r= es.end); + if (ret) + return ret; + } =20 + for (i =3D 0; i < crashk_cma_cnt; ++i) { + ret =3D crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start, + crashk_cma_ranges[i].end); + if (ret) + return ret; + } =20 + return ret; +} =20 int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, void **addr, unsigned long *sz) @@ -174,6 +197,11 @@ int crash_prepare_elf64_headers(struct crash_mem *mem,= int need_kernel_map, unsigned int cpu, i; unsigned long long notes_addr; unsigned long mstart, mend; + int ret; + + ret =3D crash_exclude_mem_ranges(mem); + if (ret) + return ret; =20 /* extra phdr for vmcoreinfo ELF note */ nr_phdr =3D nr_cpus + 1; --=20 2.34.1 From nobody Mon Feb 9 08:34:06 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AB503AE704; Wed, 4 Feb 2026 09:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197810; cv=none; b=CJLiGcTJcE97NWXeeuSu3bRaLv5wuVaNd27MKvDM2QlBd8g+LkvsnsWf6BQ+Tfo/YpcJvLjzfxENBDU0ov6RAwff0CwyQV11+ouUX0k1AMcYjtmXhZX1SrJReaKNWTl14/7pI9cNS7wtDKuLQ90oscnRjtmOwDzAp5h6jlVXmmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197810; c=relaxed/simple; bh=ueUFBgjwghimLwosxClqIywcDoixiq767fqmAeAlyeA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NOxSZknx7Qk0Kco9BqMaPKAb8TfU9fFQ76kq1Am8VRscs8JDPLv9+eAg29RR3Z69USnxsJ99rge74Jnr6UWkewny7bZClJAjKJhRUFkIW8fOeZQ34kbS7i69ntWmxjDgZ+InIGG4FGu4xzsznAB0XyIMRW4tBUwxHIelsUmbe7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=O05tgehu; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=O05tgehu; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="O05tgehu"; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="O05tgehu" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=9dh41FuXoskin5kEyP/EzKDXWLppsq5+vDzuAG9frAc=; b=O05tgehusLXxCPdoMc3HuZGiKmyI7zPSArAukVtx29XJeeSPz6a9SN/2YFTXxU1lSlAJ79XK1 K0hTPthQMZ92VIfFMbzLuF5PiVF+fIshLc7csCP+lx0p4fKMolwvRJCvTP4q8HxXlOf5doEOqux NH1bTdersZfl51BebkcMNZM= Received: from canpmsgout01.his.huawei.com (unknown [172.19.92.178]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4f5Zwg6zmVz1BGCw; Wed, 4 Feb 2026 17:36:03 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=9dh41FuXoskin5kEyP/EzKDXWLppsq5+vDzuAG9frAc=; b=O05tgehusLXxCPdoMc3HuZGiKmyI7zPSArAukVtx29XJeeSPz6a9SN/2YFTXxU1lSlAJ79XK1 K0hTPthQMZ92VIfFMbzLuF5PiVF+fIshLc7csCP+lx0p4fKMolwvRJCvTP4q8HxXlOf5doEOqux NH1bTdersZfl51BebkcMNZM= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4f5ZrP1l8Wz1T4fn; Wed, 4 Feb 2026 17:32:21 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 9E0B5404AD; Wed, 4 Feb 2026 17:36:43 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Feb 2026 17:36:40 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v3 2/3] arm64: kexec: Add support for crashkernel CMA reservation Date: Wed, 4 Feb 2026 17:37:27 +0800 Message-ID: <20260204093728.1447527-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260204093728.1447527-1-ruanjinjie@huawei.com> References: <20260204093728.1447527-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Commit 35c18f2933c5 ("Add a new optional ",cma" suffix to the crashkernel=3D command line option") and commit ab475510e042 ("kdump: implement reserve_crashkernel_cma") added CMA support for kdump crashkernel reservation. Crash kernel memory reservation wastes production resources if too large, risks kdump failure if too small, and faces allocation difficulties on fragmented systems due to contiguous block constraints. The new CMA-based crashkernel reservation scheme splits the "large fixed reservation" into a "small fixed region + large CMA dynamic region": the CMA memory is available to userspace during normal operation to avoid waste, and is reclaimed for kdump upon crash=E2=80=94saving memory while improving reliability. So extend crashkernel CMA reservation support to arm64. 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, which is already done in the crash core. Update kernel-parameters.txt to document CMA support for crashkernel on arm64 architecture. Signed-off-by: Jinjie Ruan --- v3: - Add Acked-by. v2: - Free cmem in prepare_elf_headers() - Add the mtivation. --- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/arm64/kernel/machine_kexec_file.c | 8 +++++++- arch/arm64/mm/init.c | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 1058f2a6d6a8..36bb642a7edd 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=3DX,high is not used or memory reserved is below 4G. crashkernel=3Dsize[KMG],cma - [KNL, X86, ppc] Reserve additional crash kernel memory from + [KNL, X86, ARM64, 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/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/mac= hine_kexec_file.c index ed2c45007158..cab4aaf8cb22 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -48,7 +48,7 @@ static int prepare_elf_headers(void **addr, unsigned long= *sz) u64 i; phys_addr_t start, end; =20 - nr_ranges =3D 2; /* for exclusion of crashkernel region */ + nr_ranges =3D 2 + crashk_cma_cnt; /* for exclusion of crashkernel region = */ for_each_mem_range(i, &start, &end) nr_ranges++; =20 @@ -64,6 +64,12 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) cmem->nr_ranges++; } =20 + for (i =3D 0; i < crashk_cma_cnt; i++) { + cmem->ranges[cmem->nr_ranges].start =3D crashk_cma_ranges[i].start; + cmem->ranges[cmem->nr_ranges].end =3D crashk_cma_ranges[i].end; + cmem->nr_ranges++; + } + ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 kfree(cmem); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 524d34a0e921..28165d94af08 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -96,8 +96,8 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit; =20 static void __init arch_reserve_crashkernel(void) { + unsigned long long crash_base, crash_size, cma_size =3D 0; unsigned long long low_size =3D 0; - unsigned long long crash_base, crash_size; bool high =3D false; int ret; =20 @@ -106,11 +106,12 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D 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; =20 reserve_crashkernel_generic(crash_size, crash_base, low_size, high); + reserve_crashkernel_cma(cma_size); } =20 static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit) --=20 2.34.1 From nobody Mon Feb 9 08:34:06 2026 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1167F39A7E1; Wed, 4 Feb 2026 09:36:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197809; cv=none; b=GI+SATEKcE10ybu7IHJR9BD+w+G6w88aU+jICHNGiRSANbyPQuiR+p95ViXwjfxLkYZbGvj5pwb6bZAFtfrPJ0ff8aM+PGTynIUq9w5prtO2Fp+aHQEa6JVn4p5cj5V7R3gF9FB9w9yzEQw8uqvmYTCP7UBDmxQtRjxsVoTKr8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770197809; c=relaxed/simple; bh=rXV050Kc/51xmlnP83x+nk533vY/vf8jfe67EQdWqQg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J4nt/EUMIZ3qW//1SrfIbDGbDiuyugRoBOtQWxmeO+wEoD1TvdEIH3RJ9hBBKR7ZxoobuxSaDDKxQTbk3FbjyFC86uiwkfNvx8AG+BEh418Uzd1jlY6XopCwU9AsFWC7W3a9zgiFQxwm3QYTx+ZEl7/1AQsfuMO0ws2D3B3Vt+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Piy+D2Ae; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Piy+D2Ae" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=JCg+l/0tXKCFf/mTir6vjlLYgbGXrZ03085YKEzTp9o=; b=Piy+D2Ae8+BF6TNKkVTiXKJnuFRuLSxDv9GIoqvekPwAbC38MSuPzE4rdAmNy3fDxpahTOecm sKzwPjEQ0ep8SD+2yLXGpYWSH2DZhEAqorz6ufVLlnMdITs3Fz1ny860+YBmJ0BWnHjZrHjvE/C Qjz9qZbGW0FgfxFyHLhAxEY= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4f5ZrF0Lt0zRhRB; Wed, 4 Feb 2026 17:32:13 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id A83CA40561; Wed, 4 Feb 2026 17:36:46 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Feb 2026 17:36:43 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v3 3/3] riscv: kexec: Add support for crashkernel CMA reservation Date: Wed, 4 Feb 2026 17:37:28 +0800 Message-ID: <20260204093728.1447527-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260204093728.1447527-1-ruanjinjie@huawei.com> References: <20260204093728.1447527-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Commit 35c18f2933c5 ("Add a new optional ",cma" suffix to the crashkernel=3D 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, which is already done in the crash core. Update kernel-parameters.txt to document CMA support for crashkernel on riscv architecture. Signed-off-by: Jinjie Ruan --- Documentation/admin-guide/kernel-parameters.txt | 16 ++++++++-------- arch/riscv/kernel/machine_kexec_file.c | 10 ++++++++-- arch/riscv/mm/init.c | 5 +++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 36bb642a7edd..3b92324d3a03 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1119,14 +1119,14 @@ Kernel parameters It will be ignored when crashkernel=3DX,high is not used or memory reserved is below 4G. crashkernel=3Dsize[KMG],cma - [KNL, X86, ARM64, 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 - will not be included in the vmcore so this should not - be used if dumping of userspace memory is intended and - it has to be expected that some movable kernel pages - may be missing from the dump. + [KNL, X86, ARM64, 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 will not be included in the vmcore + so this should not be used if dumping of userspace memory + is intended and it has to be expected that some movable + kernel pages may be missing from the dump. =20 A standard crashkernel reservation, as described above, is still needed to hold the crash kernel and initrd. diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/mac= hine_kexec_file.c index fec3622a13c9..0e4ac70d5a9a 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; =20 - nr_ranges =3D 1; /* For exclusion of crashkernel region */ + nr_ranges =3D 1 + crashk_cma_cnt; /* For exclusion of crashkernel region = */ walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback); =20 cmem =3D kmalloc(struct_size(cmem, ranges, nr_ranges), GFP_KERNEL); @@ -74,6 +74,12 @@ static int prepare_elf_headers(void **addr, unsigned lon= g *sz) if (ret) goto out; =20 + for (i =3D 0; i < crashk_cma_cnt; i++) { + cmem->ranges[cmem->nr_ranges].start =3D crashk_cma_ranges[i].start; + cmem->ranges[cmem->nr_ranges].end =3D crashk_cma_ranges[i].end; + cmem->nr_ranges++; + } + ret =3D crash_prepare_elf64_headers(cmem, true, addr, sz); =20 out: 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 =3D 0; + unsigned long long low_size =3D 0, cma_size =3D 0; unsigned long long crash_base, crash_size; bool high =3D false; int ret; @@ -1414,11 +1414,12 @@ static void __init arch_reserve_crashkernel(void) =20 ret =3D 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; =20 reserve_crashkernel_generic(crash_size, crash_base, low_size, high); + reserve_crashkernel_cma(cma_size); } =20 void __init paging_init(void) --=20 2.34.1