Skip to contentSkip to conversation

powerpc/kdump: Add support for crashkernel CMA reservation

PATCH Superseded Sourabh Jain 2 participants 3 messages Oct 23, 2025 – Oct 24, 2025 PowerPC

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc/kdump: 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.

Extend crashkernel CMA reservation support to powerpc.

The following changes are made to enable CMA reservation on powerpc:

- 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 in the usable memory ranges for the kdump kernel to use.
- Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through /proc/vmcore

To ensure proper CMA reservation, reserve_crashkernel_cma() is called after pageblock_order is initialized.

Cc Jiri Bohac <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Ritesh Harjani (IBM) <[email protected]>
Cc Shivang Upadhyay <[email protected]>

---

Changelog:

v1 -> v2:
- Fix build warnings, ensure kernel build when CONFIG_CMA is disabled

---
 arch/powerpc/include/asm/kexec.h   |  7 +++++++
 arch/powerpc/kernel/setup-common.c |  4 +++-
 arch/powerpc/kexec/core.c          | 13 ++++++++++++-
 arch/powerpc/kexec/ranges.c        | 16 +++++++++++++++-
 4 files changed, 37 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kexec.h +7 -0
index 4bbf9f699aaa..c158ffbfeadb 100644
@@ -51,9 +51,16 @@
 
 #ifndef __ASSEMBLER__
 #include <asm/reg.h>
+#include <linux/crash_reserve.h>
 
 typedef void (*crash_shutdown_t)(void);
 
+#ifdef CRASHKERNEL_CMA
+void kdump_cma_reserve(void);
+#else
+static inline void kdump_cma_reserve(void) { }
+#endif
+
 #ifdef CONFIG_KEXEC_CORE
 struct kimage;
 struct pt_regs;
arch/powerpc/kernel/setup-common.c +3 -1
index 68d47c53876c..c8c42b419742 100644
@@ -35,6 +35,7 @@
 #include <linux/of_irq.h>
 #include <linux/hugetlb.h>
 #include <linux/pgtable.h>
+#include <asm/kexec.h>
 #include <asm/io.h>
 #include <asm/paca.h>
 #include <asm/processor.h>
@@ -995,11 +996,12 @@ void __init setup_arch(char **cmdline_p)
 	initmem_init();
 
 	/*
-	 * Reserve large chunks of memory for use by CMA for fadump, KVM and
+	 * Reserve large chunks of memory for use by CMA for kdump, fadump, KVM and
 	 * hugetlb. These must be called after initmem_init(), so that
 	 * pageblock_order is initialised.
 	 */
 	fadump_cma_init();
+	kdump_cma_reserve();
 	kvm_cma_reserve();
 	gigantic_hugetlb_cma_reserve();
 
arch/powerpc/kexec/core.c +12 -1
index d1a2d755381c..6e7bf8fc868d 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/irq.h>
 #include <linux/ftrace.h>
+#include <linux/crash_reserve.h>
 
 #include <asm/kdump.h>
 #include <asm/machdep.h>
@@ -33,6 +34,8 @@ void machine_kexec_cleanup(struct kimage *image)
 {
 }
 
+unsigned long long cma_size;
+
 /*
  * Do not allocate memory (or fail in any way) in machine_kexec().
  * We are past the point of no return, committed to rebooting now.
@@ -110,7 +113,7 @@ void __init arch_reserve_crashkernel(void)
 
 	/* use common parsing */
 	ret = parse_crashkernel(boot_command_line, total_mem_sz, &crash_size,
-				&crash_base, NULL, NULL, NULL);
+				&crash_base, NULL, &cma_size, NULL);
 
 	if (ret)
 		return;
@@ -130,6 +133,14 @@ void __init arch_reserve_crashkernel(void)
 	reserve_crashkernel_generic(crash_size, crash_base, 0, false);
 }
 
+#ifdef CRASHKERNEL_CMA
+void __init kdump_cma_reserve(void)
+{
+	if (cma_size)
+		reserve_crashkernel_cma(cma_size);
+}
+#endif
+
 int __init overlaps_crashkernel(unsigned long start, unsigned long size)
 {
 	return (start + size) > crashk_res.start && start <= crashk_res.end;
arch/powerpc/kexec/ranges.c +15 -1
index 3702b0bdab14..dad58fc38251 100644
@@ -515,7 +515,7 @@ int get_exclude_memory_ranges(struct crash_mem **mem_ranges)
  */
 int get_usable_memory_ranges(struct crash_mem **mem_ranges)
 {
-	int ret;
+	int ret, i;
 
 	/*
 	 * Early boot failure observed on guests when low memory (first memory
@@ -528,6 +528,13 @@ int get_usable_memory_ranges(struct crash_mem **mem_ranges)
 	if (ret)
 		goto out;
 
+	for (i = 0; i < crashk_cma_cnt; i++) {
+		ret = add_mem_range(mem_ranges, crashk_cma_ranges[i].start,
+				    crashk_cma_ranges[i].end);
+		if (ret)
+			goto out;
+	}
+
 	ret = add_rtas_mem_range(mem_ranges);
 	if (ret)
 		goto out;
@@ -595,6 +602,13 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges)
 	if (ret)
 		goto out;
 
+	for (i = 0; i < crashk_cma_cnt; ++i) {
+		ret = crash_exclude_mem_range(tmem, 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
Signature · 1 line
2.51.0
#1 lore raw

arch/powerpc/kexec/ranges.c int get_crash_memory_ranges(struct crash_mem **mem_ranges) · line 611

Quoted 11 lines · Sourabh Jain
arch/powerpc/kexec/ranges.c +7 -0
@@ -595,6 +602,13 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges)
 	if (ret)
 		goto out;
 
+	for (i = 0; i < crashk_cma_cnt; ++i) {
+		ret = crash_exclude_mem_range(tmem, crashk_cma_ranges[i].start,
+					      crashk_cma_ranges[i].end);
+		if (ret)
+			goto out;
+	}
+

I think the loop needs to check if tmem->nr_ranges == tmem->max_nr_ranges and reallocate in each iteration, just like it's done when excluding the crashk_res region above:

        /* Reallocate memory ranges if there is no space to split ranges */
        tmem = *mem_ranges;
        if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) {
                tmem = realloc_mem_ranges(mem_ranges);
                if (!tmem)
                        goto out;
        }

        /* Exclude crashkernel region */
        ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end);
        if (ret)
                goto out;
Signature · 2 lines
Jiri Bohac <[email protected]>
SUSE Labs, Prague, Czechia
#2 lore raw
Quoted 5 lines · Jiri Bohac
Quoted 4 lines · Sourabh Jain
arch/powerpc/kexec/ranges.c +0 -0
@@ -595,6 +602,13 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges)
  	if (ret)
  		goto out;
 
Quoted 10 lines

arch/powerpc/kexec/ranges.c int get_crash_memory_ranges(struct crash_mem **mem_ranges) · line 611

Quoted 7 lines
arch/powerpc/kexec/ranges.c +7 -0
+	for (i = 0; i < crashk_cma_cnt; ++i) {
+		ret = crash_exclude_mem_range(tmem, crashk_cma_ranges[i].start,
+					      crashk_cma_ranges[i].end);
+		if (ret)
+			goto out;
+	}
+

I think the loop needs to check if tmem->nr_ranges == tmem->max_nr_ranges and reallocate in each iteration, just like it's done when excluding the crashk_res region above:

Yeah, nice catch. I thought it would get adjusted automatically, as it is done in the add_mem_range function.

Thanks for the review. I will update the patch and send v3.

Quoted 15 lines
         /* Reallocate memory ranges if there is no space to split ranges */
         tmem = *mem_ranges;
         if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) {
                 tmem = realloc_mem_ranges(mem_ranges);
                 if (!tmem)
                         goto out;
         }

         /* Exclude crashkernel region */
         ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end);
         if (ret)
                 goto out;