Skip to contentSkip to conversation

kdump: reduce vmcore size and capture time

PATCH Superseded Wandun Chen 4 participants 23 messages Sep 22 – Oct 9

Subsystems (11)
Memory management x86 RISC-V arm64 +7 more subsystems

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover kdump: reduce vmcore size and capture time

From: Wandun Chen <[email protected]>

On SoCs that carve out large firmware-owned reserved memory (GPU, camera ISP, ...), kdump currently dumps those carveouts as part of system RAM even though their contents are firmware state that is not useful for kernel crash analysis.

This series introduces a MEMBLOCK_NODUMP flag in memblock to filter reserved memory on DT-based architectures (arm64, riscv, loongarch). Reserved regions are marked MEMBLOCK_NODUMP by default so kdump omits them; reusable CMA regions are different because their pages are handed back to the buddy allocator and may carry crash-relevant data.

ACPI systems already filter reserved memory out of the vmcore through their existing path; only DT-based systems currently fail to filter these regions, which is what this series addresses. The flag lives in memblock itself rather than in a DT-only structure, so both ACPI and DT systems can benefit from it (suggested by Rob, thanks).

Since the reserved memory regions are filtered out, the vmcore is smaller in size and faster to produce.

The series is based on linux-next and is organized as follows:

Patches 1-3: Preparation and bugfixes: switch riscv crash_mem to memblock,
fold the duplicated per-arch memblock walks into the weak defaults, and serialize crash header preparation against memory hotplug.
Patches 4-8: NODUMP infrastructure: switch crash_core to
for_each_mem_region(), introduce the MEMBLOCK_NODUMP flag, add a dumpable flag to struct reserved_mem, and mark /reserved-memory and /memreserve/ entries with MEMBLOCK_NODUMP flag.
Patch 9: Exclude MEMBLOCK_NODUMP regions from the vmcore ELF
header.

v6 --> v7:
1. Fix a stale MEMBLOCK_NODUMP flag issue [1]. Memory reserved and marked as NODUMP may later be freed (the initrd, for example), so the NODUMP flag must be cleared accordingly. Since the fix is part of the NODUMP infrastructure introduced by patch 5, it has been folded into that patch.

2. Drop the "generic" related description in the cover letter.

3. Collect the Acked-by and Reviewed-by tags received during the v6 review (thanks to Baoquan, Mike, Rob and Marek). Patch 5 is the only one without a tag, as its Reviewed-by was dropped when the fix was folded in.

4. Drop patch 1 of v6, which has been merged separately.

v5 --> v6:
1. Serialize crash header preparation against memory hotplug to avoid out-of-bounds or use-after-free issues.
2. MEMBLOCK_NODUMP marking is now done after memblock allows resizing, avoiding a panic from too few regions before resize is permitted.
3. Reordered the patches, put pre-existing bugfixes earlier in the series.

v4 --> v5:
1. Rework the mechanism around a memblock-level MEMBLOCK_NODUMP flag (suggested by Rob) instead of the v4 opt-in 'dumpable' flag on DT-only struct reserved_mem [2].
2. Switch the riscv vmcore elf header preparation to use memblock instead of the resource tree, aligning it with arm64 and loongarch, so riscv also can exclude reserved memory from vmcore.
3. Deduplicate the vmcore elf header preparation: arm64, riscv and loongarch open-coded the same logic, so fold it into shared __weak defaults in crash_core.
4. Drop the v4 patch that saved /memreserve/ entries into the reserved_mem array; /memreserve/ is now marked MEMBLOCK_NODUMP directly.

v3 --> v4:
1. Rebase this series on v7.2-rc1.
2. Add two cleanup patches (patch 02/03).
3. Simplify patch 03 to avoid checking whether initial_boot_params is NULL multiple times, suggested by Rob.

v2 --> v3:
1. Fix out-of-bounds issue if device tree lacks /reserved-memory node.
2. Fix UAF issue when alloc_reserved_mem_array() fails.
3. Add some prepare patches.

v1 --> v2:
1. v1 added an opt-out DT property ('linux,no-dump'). Per Rob's feedback [3], v2 drop that property and exclude reserve memory by default.
2. Split some prepared patches from the original patches.
3. Address coding-style comments on patch 5 from Rob.

[1] https://sashiko.dev/#/message/20260917220750.GA4013814-robh%40kernel.org
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/

Wandun Chen (9):
riscv: build crash_mem ranges from memblock instead of resource tree
crash_core: fold duplicated memblock arch hooks into the weak default
crash_core: serialize crash header preparation against hotplug
crash_core: replace for_each_mem_range() with for_each_mem_region()
memblock: introduce MEMBLOCK_NODUMP flag
of: reserved_mem: add dumpable flag to opt-in vmcore
of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP
crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF
header

 arch/arm64/kernel/machine_kexec_file.c     | 29 ------------
 arch/loongarch/kernel/machine_kexec_file.c | 27 ------------
 arch/riscv/Kconfig                         |  2 +-
 arch/riscv/kernel/machine_kexec_file.c     | 33 --------------
 arch/x86/kernel/crash.c                    |  2 +-
 drivers/of/fdt.c                           |  2 +
 drivers/of/of_private.h                    |  2 +
 drivers/of/of_reserved_mem.c               | 48 ++++++++++++++++++++
 include/linux/crash_core.h                 |  2 +
 include/linux/memblock.h                   |  9 ++++
 include/linux/of_reserved_mem.h            |  1 +
 kernel/crash_core.c                        | 51 ++++++++++++++++++++--
 kernel/dma/contiguous.c                    |  1 +
 mm/memblock.c                              | 43 +++++++++++++++++-
 14 files changed, 155 insertions(+), 97 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v7 1/9 riscv: build crash_mem ranges from memblock instead of resource tree

From: Wandun Chen <[email protected]>

Replace walk_system_ram_res() with for_each_mem_range(). A later patch introduces MEMBLOCK_NODUMP in memblock, the reserved-memory regions marked with MEMBLOCK_NODUMP can be excluded from the vmcore by walking memblock.

for_each_mem_range() iterates memblock.memory, which is freed after init unless ARCH_KEEP_MEMBLOCK is selected. riscv needs ARCH_KEEP_MEMBLOCK to filter reserved memory from the vmcore, so extend its condition (ACPI || KEXEC) with CRASH_DUMP. arm64 and loongarch already select ARCH_KEEP_MEMBLOCK unconditionally.

---
 arch/riscv/Kconfig                     |  2 +-
 arch/riscv/kernel/machine_kexec_file.c | 31 ++++++++++----------------
 2 files changed, 13 insertions(+), 20 deletions(-)
arch/riscv/Kconfig +1 -1
index a590db7687c8..991657b2465f 100644
@@ -58,7 +58,7 @@ config RISCV
 	select ARCH_HAS_UBSAN
 	select ARCH_HAS_VDSO_ARCH_DATA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
-	select ARCH_KEEP_MEMBLOCK if ACPI || KEXEC
+	select ARCH_KEEP_MEMBLOCK if ACPI || KEXEC || CRASH_DUMP
 	select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE	if 64BIT && MMU
 	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
arch/riscv/kernel/machine_kexec_file.c +12 -19
index 26cd2a8bd0cd..808e872f4063 100644
@@ -37,39 +37,32 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 }
 
 #ifdef CONFIG_CRASH_DUMP
-static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
-{
-	unsigned int *nr_ranges = arg;
-
-	(*nr_ranges)++;
-	return 0;
-}
-
 unsigned int arch_get_system_nr_ranges(void)
 {
 	unsigned int nr_ranges = 2 + crashk_cma_cnt; /* For exclusion of crashkernel region */
+	u64 i;
+	phys_addr_t start, end;
 
-	walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
+	for_each_mem_range(i, &start, &end)
+		nr_ranges++;
 
 	return nr_ranges;
 }
 
-static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
+int arch_crash_populate_cmem(struct crash_mem *cmem)
 {
-	struct crash_mem *cmem = arg;
+	u64 i;
+	phys_addr_t start, end;
 
-	cmem->ranges[cmem->nr_ranges].start = res->start;
-	cmem->ranges[cmem->nr_ranges].end = res->end;
-	cmem->nr_ranges++;
+	for_each_mem_range(i, &start, &end) {
+		cmem->ranges[cmem->nr_ranges].start = start;
+		cmem->ranges[cmem->nr_ranges].end = end - 1;
+		cmem->nr_ranges++;
+	}
 
 	return 0;
 }
 
-int arch_crash_populate_cmem(struct crash_mem *cmem)
-{
-	return walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
-}
-
 static char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
 				 unsigned long cmdline_len)
 {
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v7 1/9] riscv: build crash_mem ranges from memblock instead of resource tree

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

From: Wandun Chen <[email protected]>

Replace walk_system_ram_res() with for_each_mem_range(). A later patch introduces MEMBLOCK_NODUMP in memblock, the reserved-memory regions marked with MEMBLOCK_NODUMP can be excluded from the vmcore by walking memblock.

Quoted 7 lines

for_each_mem_range() iterates memblock.memory, which is freed after init unless ARCH_KEEP_MEMBLOCK is selected. riscv needs ARCH_KEEP_MEMBLOCK to filter reserved memory from the vmcore, so extend its condition (ACPI || KEXEC) with CRASH_DUMP. arm64 and loongarch already select ARCH_KEEP_MEMBLOCK unconditionally.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v7 2/9 crash_core: fold duplicated memblock arch hooks into the weak default

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

arm64, loongarch and riscv open-code the same memblock walk in arch_get_system_nr_ranges() and arch_crash_populate_cmem(). Move it into the __weak defaults in kernel/crash_core.c and delete the arch copies.

No functional change.

---
 arch/arm64/kernel/machine_kexec_file.c     | 29 ----------------------
 arch/loongarch/kernel/machine_kexec_file.c | 27 --------------------
 arch/riscv/kernel/machine_kexec_file.c     | 26 -------------------
 kernel/crash_core.c                        | 25 +++++++++++++++++--
 4 files changed, 23 insertions(+), 84 deletions(-)
arch/arm64/kernel/machine_kexec_file.c +0 -29
index 854d872dfd0f..34d944d3f22f 100644
@@ -14,7 +14,6 @@
 #include <linux/kernel.h>
 #include <linux/kexec.h>
 #include <linux/libfdt.h>
-#include <linux/memblock.h>
 #include <linux/of.h>
 #include <linux/of_fdt.h>
 #include <linux/slab.h>
@@ -39,34 +38,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 	return kexec_image_post_load_cleanup_default(image);
 }
 
-#ifdef CONFIG_CRASH_DUMP
-unsigned int arch_get_system_nr_ranges(void)
-{
-	unsigned int nr_ranges = 2 + crashk_cma_cnt; /* for exclusion of crashkernel region */
-	phys_addr_t start, end;
-	u64 i;
-
-	for_each_mem_range(i, &start, &end)
-		nr_ranges++;
-
-	return nr_ranges;
-}
-
-int arch_crash_populate_cmem(struct crash_mem *cmem)
-{
-	phys_addr_t start, end;
-	u64 i;
-
-	for_each_mem_range(i, &start, &end) {
-		cmem->ranges[cmem->nr_ranges].start = start;
-		cmem->ranges[cmem->nr_ranges].end = end - 1;
-		cmem->nr_ranges++;
-	}
-
-	return 0;
-}
-#endif
-
 /*
  * Tries to add the initrd and DTB to the image. If it is not possible to find
  * valid locations, this function will undo changes to the image and return non
arch/loongarch/kernel/machine_kexec_file.c +0 -27
index 5412aa9f3568..481b8f906a56 100644
@@ -13,7 +13,6 @@
 #include <linux/ioport.h>
 #include <linux/kernel.h>
 #include <linux/kexec.h>
-#include <linux/memblock.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
@@ -56,32 +55,6 @@ static void cmdline_add_initrd(struct kimage *image, unsigned long *cmdline_tmpl
 }
 
 #ifdef CONFIG_CRASH_DUMP
-unsigned int arch_get_system_nr_ranges(void)
-{
-	int nr_ranges = 2; /* for exclusion of crashkernel region */
-	phys_addr_t start, end;
-	uint64_t i;
-
-	for_each_mem_range(i, &start, &end)
-		nr_ranges++;
-
-	return nr_ranges;
-}
-
-int arch_crash_populate_cmem(struct crash_mem *cmem)
-{
-	phys_addr_t start, end;
-	uint64_t i;
-
-	for_each_mem_range(i, &start, &end) {
-		cmem->ranges[cmem->nr_ranges].start = start;
-		cmem->ranges[cmem->nr_ranges].end = end - 1;
-		cmem->nr_ranges++;
-	}
-
-	return 0;
-}
-
 /*
  * Add the "mem=size@start" command line parameter to command line, indicating the
  * memory region the new kernel can use to boot into.
arch/riscv/kernel/machine_kexec_file.c +0 -26
index 808e872f4063..fdc6695e8588 100644
@@ -37,32 +37,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 }
 
 #ifdef CONFIG_CRASH_DUMP
-unsigned int arch_get_system_nr_ranges(void)
-{
-	unsigned int nr_ranges = 2 + crashk_cma_cnt; /* For exclusion of crashkernel region */
-	u64 i;
-	phys_addr_t start, end;
-
-	for_each_mem_range(i, &start, &end)
-		nr_ranges++;
-
-	return nr_ranges;
-}
-
-int arch_crash_populate_cmem(struct crash_mem *cmem)
-{
-	u64 i;
-	phys_addr_t start, end;
-
-	for_each_mem_range(i, &start, &end) {
-		cmem->ranges[cmem->nr_ranges].start = start;
-		cmem->ranges[cmem->nr_ranges].end = end - 1;
-		cmem->nr_ranges++;
-	}
-
-	return 0;
-}
-
 static char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
 				 unsigned long cmdline_len)
 {
kernel/crash_core.c +23 -2
index d0bd2d0cf899..d201638d11f3 100644
@@ -281,8 +281,29 @@ static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
 	return cmem;
 }
 
-unsigned int __weak arch_get_system_nr_ranges(void) { return 0; }
-int __weak arch_crash_populate_cmem(struct crash_mem *cmem) { return -1; }
+unsigned int __weak arch_get_system_nr_ranges(void)
+{
+	unsigned int nr_ranges = 2 + crashk_cma_cnt; /* crashk_res + crashk_low_res, +CMA splits */
+	phys_addr_t start, end;
+	u64 i;
+
+	for_each_mem_range(i, &start, &end)
+		nr_ranges++;
+	return nr_ranges;
+}
+
+int __weak arch_crash_populate_cmem(struct crash_mem *cmem)
+{
+	phys_addr_t start, end;
+	u64 i;
+
+	for_each_mem_range(i, &start, &end) {
+		cmem->ranges[cmem->nr_ranges].start = start;
+		cmem->ranges[cmem->nr_ranges].end = end - 1;
+		cmem->nr_ranges++;
+	}
+	return 0;
+}
 int __weak arch_crash_exclude_ranges(struct crash_mem *cmem) { return 0; }
 
 int __weak arch_crash_exclude_mem_range(struct crash_mem **mem,
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v7 2/9] crash_core: fold duplicated memblock arch hooks into the weak default

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

From: Wandun Chen <[email protected]>

arm64, loongarch and riscv open-code the same memblock walk in arch_get_system_nr_ranges() and arch_crash_populate_cmem(). Move it into the __weak defaults in kernel/crash_core.c and delete the arch copies.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v7 3/9 crash_core: serialize crash header preparation against hotplug

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

crash_prepare_headers() counts memory ranges before populating the allocated crash_mem array. The weak implementation used by ARM64, RISC-V and LoongArch walks memblock.memory, while x86 performs the same two-pass operation over system RAM resources. Concurrent memory hotplug can change range source between the two walks and make the populate pass overflow cmem->ranges.

Take device_hotplug_lock when preparing crash headers during kexec_file_load(). The x86 memory hotplug path already takes device_hotplug_lock, so call __crash_prepare_headers() directly to avoid recursive locking.

Sashiko reported this issue in [1].

Fixes 3751e728cef2 ("arm64: kexec_file: add crash dump support")
Fixes 1bcca8620a91 ("LoongArch: Add crash dump support for kexec_file")
Fixes 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Fixes dd5f726076cc ("kexec: support for kexec on panic using new system call")
---
 arch/x86/kernel/crash.c    |  2 +-
 include/linux/crash_core.h |  2 ++
 kernel/crash_core.c        | 17 +++++++++++++++--
 3 files changed, 18 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +1 -1
index e6f23933a6df..bef008a0cb22 100644
@@ -465,7 +465,7 @@ void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
 	 * Create the new elfcorehdr reflecting the changes to CPU and/or
 	 * memory resources.
 	 */
-	if (crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &elfbuf, &elfsz, NULL)) {
+	if (__crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &elfbuf, &elfsz, NULL)) {
 		pr_err("unable to create new elfcorehdr");
 		goto out;
 	}
include/linux/crash_core.h +2 -0
index bc087124cd78..28e7a81cf263 100644
@@ -61,6 +61,8 @@ extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_ma
 				       void **addr, unsigned long *sz);
 extern int crash_prepare_headers(int need_kernel_map, void **addr,
 				 unsigned long *sz, unsigned long *nr_mem_ranges);
+int __crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
+			    unsigned long *nr_mem_ranges);
 extern int crash_exclude_core_ranges(struct crash_mem **cmem);
 
 struct kimage;
kernel/crash_core.c +15 -2
index d201638d11f3..d0cc2496dc09 100644
@@ -16,6 +16,7 @@
 #include <linux/mm.h>
 #include <linux/cpuhotplug.h>
 #include <linux/memblock.h>
+#include <linux/device.h>
 #include <linux/kmemleak.h>
 #include <linux/crash_core.h>
 #include <linux/reboot.h>
@@ -338,8 +339,8 @@ int crash_exclude_core_ranges(struct crash_mem **cmem)
 	return 0;
 }
 
-int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
-			  unsigned long *nr_mem_ranges)
+int __crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
+			    unsigned long *nr_mem_ranges)
 {
 	unsigned int max_nr_ranges;
 	struct crash_mem *cmem;
@@ -376,6 +377,18 @@ int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
 	return ret;
 }
 
+int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
+			  unsigned long *nr_mem_ranges)
+{
+	int ret;
+
+	lock_device_hotplug();
+	ret = __crash_prepare_headers(need_kernel_map, addr, sz, nr_mem_ranges);
+	unlock_device_hotplug();
+
+	return ret;
+}
+
 /**
  * crash_exclude_mem_range - exclude a mem range for existing ranges
  * @mem: mem->range contains an array of ranges sorted in ascending order
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v7 3/9] crash_core: serialize crash header preparation against hotplug

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

From: Wandun Chen <[email protected]>

crash_prepare_headers() counts memory ranges before populating the allocated crash_mem array. The weak implementation used by ARM64, RISC-V and LoongArch walks memblock.memory, while x86 performs the same two-pass operation over system RAM resources. Concurrent memory hotplug can change range source between the two walks and make the populate pass overflow cmem->ranges.

Take device_hotplug_lock when preparing crash headers during kexec_file_load(). The x86 memory hotplug path already takes device_hotplug_lock, so call __crash_prepare_headers() directly to avoid recursive locking.

Quoted 7 lines

Sashiko reported this issue in [1].

Fixes 3751e728cef2 ("arm64: kexec_file: add crash dump support")
Fixes 1bcca8620a91 ("LoongArch: Add crash dump support for kexec_file")
Fixes 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Fixes dd5f726076cc ("kexec: support for kexec on panic using new system call")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH v7 4/9 crash_core: replace for_each_mem_range() with for_each_mem_region()

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

for_each_mem_range() skips MEMBLOCK_NOMAP regions implicitly. Switch the weak defaults to for_each_mem_region(), which exposes struct memblock_region and per-region flags, and filter NOMAP regions explicitly via the new crash_should_skip_region() helper. This prepares for a subsequent patch to extend the skip filter.

No functional change.

---
 kernel/crash_core.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
kernel/crash_core.c +17 -8
index d0cc2496dc09..c7acb2e449df 100644
@@ -270,6 +270,12 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
 	return 0;
 }
 
+/* Exclude NOMAP regions from the vmcore. */
+static bool crash_should_skip_region(struct memblock_region *reg)
+{
+	return memblock_is_nomap(reg);
+}
+
 static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
 {
 	struct crash_mem *cmem;
@@ -285,22 +291,25 @@ static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
 unsigned int __weak arch_get_system_nr_ranges(void)
 {
 	unsigned int nr_ranges = 2 + crashk_cma_cnt; /* crashk_res + crashk_low_res, +CMA splits */
-	phys_addr_t start, end;
-	u64 i;
+	struct memblock_region *reg;
 
-	for_each_mem_range(i, &start, &end)
+	for_each_mem_region(reg) {
+		if (crash_should_skip_region(reg))
+			continue;
 		nr_ranges++;
+	}
 	return nr_ranges;
 }
 
 int __weak arch_crash_populate_cmem(struct crash_mem *cmem)
 {
-	phys_addr_t start, end;
-	u64 i;
+	struct memblock_region *reg;
 
-	for_each_mem_range(i, &start, &end) {
-		cmem->ranges[cmem->nr_ranges].start = start;
-		cmem->ranges[cmem->nr_ranges].end = end - 1;
+	for_each_mem_region(reg) {
+		if (crash_should_skip_region(reg))
+			continue;
+		cmem->ranges[cmem->nr_ranges].start = reg->base;
+		cmem->ranges[cmem->nr_ranges].end = reg->base + reg->size - 1;
 		cmem->nr_ranges++;
 	}
 	return 0;
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v7 4/9] crash_core: replace for_each_mem_range() with for_each_mem_region()

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

From: Wandun Chen <[email protected]>

for_each_mem_range() skips MEMBLOCK_NOMAP regions implicitly. Switch the weak defaults to for_each_mem_region(), which exposes struct memblock_region and per-region flags, and filter NOMAP regions explicitly via the new crash_should_skip_region() helper. This prepares for a subsequent patch to extend the skip filter.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH v7 5/9 memblock: introduce MEMBLOCK_NODUMP flag

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

Add MEMBLOCK_NODUMP to mark regions that should be excluded from kdump vmcores.

The flag is meant for reserved memory that carries no data useful for crash analysis. Reusable reserved regions such as CMA may hold useful data, so these regions must not be marked MEMBLOCK_NODUMP. Subsequent patches wire this up for /reserved-memory and /memreserve/ entries.

Regions in /memreserve/ (such as the initrd) may be reserved at the beginning and freed later, so we also need to clear the flag when freeing reserved memory.

---
 include/linux/memblock.h |  9 +++++++++
 mm/memblock.c            | 43 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 2 deletions(-)
include/linux/memblock.h +9 -0
index aa845f488327..0126b47bc3c4 100644
@@ -52,6 +52,8 @@ extern unsigned long long max_possible_pfn;
  * kernel that we know is good to use. It is the only memory that
  * allocations may happen from in this phase.
  * @MEMBLOCK_RSRV_HUGETLB: memory is reserved for hugetlb pages
+ * @MEMBLOCK_NODUMP: exclude from kdump vmcore. It carries no data useful
+ * for crash analysis (e.g. firmware carveouts).
  */
 enum memblock_flags {
 	MEMBLOCK_NONE		= 0x0,	/* No special request */
@@ -63,6 +65,7 @@ enum memblock_flags {
 	MEMBLOCK_RSRV_KERN	= 0x20,	/* memory reserved for kernel use */
 	MEMBLOCK_KHO_SCRATCH	= 0x40,	/* scratch memory for kexec handover */
 	MEMBLOCK_RSRV_HUGETLB	= 0x80, /* memory reserved for hugetlb pages */
+	MEMBLOCK_NODUMP		= 0x100,/* exclude from kdump vmcore */
 };
 
 /**
@@ -160,6 +163,7 @@ int memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t size);
 int memblock_reserved_mark_kern(phys_addr_t base, phys_addr_t size);
 int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size);
 int memblock_clear_kho_scratch(phys_addr_t base, phys_addr_t size);
+int memblock_mark_nodump(phys_addr_t base, phys_addr_t size);
 
 void memblock_free(void *ptr, size_t size);
 
@@ -305,6 +309,11 @@ static inline bool memblock_is_kho_scratch(struct memblock_region *m)
 	return m->flags & MEMBLOCK_KHO_SCRATCH;
 }
 
+static inline bool memblock_is_nodump(struct memblock_region *m)
+{
+	return m->flags & MEMBLOCK_NODUMP;
+}
+
 int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
 			    unsigned long  *end_pfn);
 void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
mm/memblock.c +41 -2

76 lines not on this page · raw message

Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH v7 5/9] memblock: introduce MEMBLOCK_NODUMP flag

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mm: lockless mutation of memblock.memory causes UAF in concurrent readers --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: lockless mutation of memblock.memory causes UAF in concurrent readers --

commit 3e0d4f57949330268c708beeb66dc1c0fb65db32
Author: Wandun Chen <[email protected]>
Subject: memblock: introduce MEMBLOCK_NODUMP flag

This patch introduces the MEMBLOCK_NODUMP flag to mark memory regions that should be excluded from kdump vmcores. It also adds logic to clear this flag when reserved memory, such as the initrd, is freed so the memory can be properly reused.

Quoted 4 lines
mm/memblock.c +0 -0
index ea0de4b5f3568..48cabfe5cdf16 100644

[ ... ]

mm/memblock.c unsigned long free_reserved_area(void *start, void *end, int poison, const char · line 961

Quoted 13 lines
mm/memblock.c +5 -1
@@ -949,9 +951,13 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 	}
 
 	if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) {
-		if (start_pa < end_pa)
+		if (start_pa < end_pa) {
 			memblock_remove_range(&memblock.reserved,
 					      start_pa, end_pa - start_pa);
+
+			if (IS_ENABLED(CONFIG_CRASH_DUMP))
+				memblock_clear_nodump(start_pa, end_pa - start_pa);
+		}
 	}

[Severity: High]
Could this lockless mutation of memblock.memory race with concurrent readers?

This code path is triggered during asynchronous initrd freeing (e.g., via do_populate_rootfs using async_schedule_domain).

Calling memblock_clear_nodump() modifies the memblock.memory array locklessly via memblock_setclr_flag() and memblock_isolate_range(). memblock_isolate_range() can split ranges using memmove(), which disrupts array ordering, and can even call memblock_double_array() which kfree()s the old array.

Concurrently, subsystems rely on memblock.memory being immutable after early boot. For example, on ARM64, ioremap() calls pfn_is_map_memory(), which performs a lockless binary search (memblock_search()) directly on memblock.memory.regions.

If memblock_clear_nodump() splits or reallocates the array while ioremap() is executing during driver probes, could this result in a use-after-free on the freed array or an out-of-bounds access from broken binary search invariants?

[ ... ]

mm/memblock.c int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size) · line 1008

Quoted 10 lines
mm/memblock.c +4 -1
@@ -995,8 +1001,11 @@ int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size)
 
 	kmemleak_free_part_phys(base, size);
 
-	if (!slab_is_available() || IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
+	if (!slab_is_available() || IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) {
 		ret = memblock_remove_range(&memblock.reserved, base, size);
+		if (IS_ENABLED(CONFIG_CRASH_DUMP))
+			memblock_clear_nodump(base, size);
+	}

[Severity: High]
Similar to the above, does this introduce the same lockless mutation risk when called during runtime module unloads or CMA frees?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

PATCH v7 6/9 of: reserved_mem: add dumpable flag to opt-in vmcore

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

Add a 'dumpable' flag to struct reserved_mem to decide whether a reserved area should be included in the kdump vmcore. Non-dumpable regions are later marked MEMBLOCK_NODUMP;the filtering itself happens in memblock, keeping the arch kdump code independent of the DT API.

Most reserved regions are owned by devices and do not contain data useful for kernel crash analysis, so dumpable default to false. Reusable CMA regions are different: their pages are handed back to the buddy allocator and may contain key data for crash analysis, so set dumpable to true in rmem_cma_setup().

The dumpable flag is also used to check /memreserve/ entries for overlap with other dumpable regions.

---
 include/linux/of_reserved_mem.h | 1 +
 kernel/dma/contiguous.c         | 1 +
 2 files changed, 2 insertions(+)
include/linux/of_reserved_mem.h +1 -0
index 49da515859f2..99c0f3ccc297 100644
@@ -15,6 +15,7 @@ struct reserved_mem {
 	phys_addr_t			base;
 	phys_addr_t			size;
 	void				*priv;
+	bool				dumpable;
 };
 
 struct reserved_mem_ops {
kernel/dma/contiguous.c +1 -0
index 90937dc7c627..d7bfc38ac762 100644
@@ -567,6 +567,7 @@ static int __init rmem_cma_setup(unsigned long node, struct reserved_mem *rmem)
 		dma_contiguous_default_area = cma;
 
 	rmem->priv = cma;
+	rmem->dumpable = true;
 
 	pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n",
 		&rmem->base, (unsigned long)rmem->size / SZ_1M);
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH v7 6/9] of: reserved_mem: add dumpable flag to opt-in vmcore

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 13 lines

From: Wandun Chen <[email protected]>

Add a 'dumpable' flag to struct reserved_mem to decide whether a reserved area should be included in the kdump vmcore. Non-dumpable regions are later marked MEMBLOCK_NODUMP;the filtering itself happens in memblock, keeping the arch kdump code independent of the DT API.

Most reserved regions are owned by devices and do not contain data useful for kernel crash analysis, so dumpable default to false. Reusable CMA regions are different: their pages are handed back to the buddy allocator and may contain key data for crash analysis, so set dumpable to true in rmem_cma_setup().

Quoted 5 lines

The dumpable flag is also used to check /memreserve/ entries for overlap with other dumpable regions.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

PATCH v7 7/9 of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

Mark non-dumpable reserved-memory regions with MEMBLOCK_NODUMP so kdump can omit them from the vmcore.

The marking is guarded by CONFIG_CRASH_DUMP so non-kdump kernels do not pay the cost of splitting memblock.memory entries at NODUMP boundaries.

---
 drivers/of/fdt.c             |  1 +
 drivers/of/of_private.h      |  1 +
 drivers/of/of_reserved_mem.c | 15 +++++++++++++++
 3 files changed, 17 insertions(+)
drivers/of/fdt.c +1 -0
index a64afc3ded3d..286fd4db6312 100644
@@ -1285,6 +1285,7 @@ void __init unflatten_device_tree(void)
 
 	/* Save the statically-placed regions in the reserved_mem array */
 	fdt_scan_reserved_mem_late();
+	fdt_mark_reserve_mem_nodump();
 
 	/* Populate an empty root node when bootloader doesn't provide one */
 	if (!fdt) {
drivers/of/of_private.h +1 -0
index 0ae16da066e2..505735732c13 100644
@@ -187,6 +187,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node *
 
 int fdt_scan_reserved_mem(void);
 void __init fdt_scan_reserved_mem_late(void);
+void __init fdt_mark_reserve_mem_nodump(void);
 
 bool of_fdt_device_is_available(const void *blob, unsigned long node);
 
drivers/of/of_reserved_mem.c +15 -0
index 8c9d6395d6a3..f29a07e8fb23 100644
@@ -677,6 +677,21 @@ static void __init fdt_init_reserved_mem_node(unsigned long node, const char *un
 	reserved_mem_count++;
 }
 
+void __init fdt_mark_reserve_mem_nodump(void)
+{
+	struct reserved_mem *rmem;
+	int i;
+
+	if (!IS_ENABLED(CONFIG_CRASH_DUMP))
+		return;
+
+	for (i = 0; i < reserved_mem_count; i++) {
+		rmem = &reserved_mem[i];
+		if (rmem->size && !rmem->dumpable)
+			memblock_mark_nodump(rmem->base, rmem->size);
+	}
+}
+
 struct rmem_assigned_device {
 	struct device *dev;
 	struct reserved_mem *rmem;
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH v7 7/9] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] of: reserved_mem: unconditional MEMBLOCK_NODUMP breaks firmware debugging --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] of: reserved_mem: unconditional MEMBLOCK_NODUMP breaks firmware debugging --

commit 70f4cbca539766519d8967f7e857d2db27db4c13
Author: Wandun Chen <[email protected]>

of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP

This commit marks non-dumpable reserved-memory regions with MEMBLOCK_NODUMP so kdump can omit them from the vmcore. The marking is guarded by CONFIG_CRASH_DUMP to avoid splitting memblock.memory entries unnecessarily on non-kdump kernels.

Quoted 3 lines
drivers/of/of_reserved_mem.c +0 -0

[ ... ]

Quoted 6 lines
drivers/of/of_reserved_mem.c +2 -0
@@ -677,6 +677,21 @@ static void __init fdt_init_reserved_mem_node(...)
 	reserved_mem_count++;
 }
 
+void __init fdt_mark_reserve_mem_nodump(void)
+{

drivers/of/of_reserved_mem.c static void __init fdt_init_reserved_mem_node(...) · line 691

Quoted 10 lines
drivers/of/of_reserved_mem.c +10 -0
+	struct reserved_mem *rmem;
+	int i;
+
+	if (!IS_ENABLED(CONFIG_CRASH_DUMP))
+		return;
+
+	for (i = 0; i < reserved_mem_count; i++) {
+		rmem = &reserved_mem[i];
+		if (rmem->size && !rmem->dumpable)
+			memblock_mark_nodump(rmem->base, rmem->size);

[Severity: High]
Does this unconditional masking prevent debugging of coprocessor memory and firmware state in vmcores?

Since only the CMA driver sets dumpable to true, it appears all other generic /reserved-memory regions (such as DSP logs or ramoops) default to false.

Because fdt_mark_reserve_mem_nodump() unconditionally applies MEMBLOCK_NODUMP to these regions, and there is no Device Tree property provided to opt them back in, is there a risk that system administrators will lose the ability to inspect these regions after a crash?

Quoted 5 lines
drivers/of/of_reserved_mem.c +3 -0
+	}
+}
+
 struct rmem_assigned_device {
 	struct device *dev;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#15 lore raw

PATCH v7 8/9 of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

The /memreserve/ entries are memory reservations made by the bootloader or firmware, their contents are not needed for kernel crash analysis, so mark them MEMBLOCK_NODUMP to have kdump omit them from the vmcore.

Entries that overlap a dumpable region (such as CMA) are left unmarked, because the pages of a dumpable region may carry crash-relevant data.

---
 drivers/of/fdt.c             |  1 +
 drivers/of/of_private.h      |  1 +
 drivers/of/of_reserved_mem.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
drivers/of/fdt.c +1 -0
index 286fd4db6312..9a727941b5af 100644
@@ -1286,6 +1286,7 @@ void __init unflatten_device_tree(void)
 	/* Save the statically-placed regions in the reserved_mem array */
 	fdt_scan_reserved_mem_late();
 	fdt_mark_reserve_mem_nodump();
+	fdt_mark_memreserve_nodump();
 
 	/* Populate an empty root node when bootloader doesn't provide one */
 	if (!fdt) {
drivers/of/of_private.h +1 -0
index 505735732c13..6497404ec751 100644
@@ -188,6 +188,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node *
 int fdt_scan_reserved_mem(void);
 void __init fdt_scan_reserved_mem_late(void);
 void __init fdt_mark_reserve_mem_nodump(void);
+void __init fdt_mark_memreserve_nodump(void);
 
 bool of_fdt_device_is_available(const void *blob, unsigned long node);
 
drivers/of/of_reserved_mem.c +33 -0
index f29a07e8fb23..a42cf6eac55b 100644
@@ -251,6 +251,39 @@ static void __init __rmem_check_for_overlap(void)
 	}
 }
 
+void __init fdt_mark_memreserve_nodump(void)
+{
+	u64 base, size;
+	int n;
+	const void *fdt = initial_boot_params;
+
+	if (!IS_ENABLED(CONFIG_CRASH_DUMP))
+		return;
+
+	if (!fdt)
+		return;
+
+	for (n = 0; ; n++) {
+		int i;
+
+		if (fdt_get_mem_rsv(fdt, n, &base, &size))
+			break;
+		if (!size)
+			break;
+
+		for (i = 0; i < reserved_mem_count; i++) {
+			struct reserved_mem *rmem = &reserved_mem[i];
+
+			if (rmem->dumpable &&
+			    base < (u64)rmem->base + (u64)rmem->size &&
+			    (u64)rmem->base < base + size)
+				break;
+		}
+		if (i == reserved_mem_count)
+			memblock_mark_nodump(base, size);
+	}
+}
+
 /**
  * fdt_scan_reserved_mem_late() - Scan FDT and initialize remaining reserved
  * memory regions.
Signature · 1 line
2.43.0
#16 lore raw

Re: [PATCH v7 8/9] of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] of/fdt: silent u64 truncation in fdt_mark_memreserve_nodump causes nodump false positives --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] of/fdt: silent u64 truncation in fdt_mark_memreserve_nodump causes nodump false positives --

commit 070ed699ada4d456618a640c6ad541abbec98f95
Author: Wandun Chen <[email protected]>

of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP

The /memreserve/ entries are memory reservations made by the bootloader or firmware, their contents are not needed for kernel crash analysis. This commit marks them MEMBLOCK_NODUMP to omit them from the vmcore, while leaving overlapping dumpable regions unmarked.

Quoted 4 lines
drivers/of/of_reserved_mem.c +0 -0
index f29a07e8fb23e..a42cf6eac55b5 100644

[ ... ]

Quoted 9 lines
drivers/of/of_reserved_mem.c +5 -0
@@ -251,6 +251,39 @@ static void __init __rmem_check_for_overlap(void)
 	}
 }
 
+void __init fdt_mark_memreserve_nodump(void)
+{
+	u64 base, size;
+	int n;
+	const void *fdt = initial_boot_params;

[ ... ]

drivers/of/of_reserved_mem.c static void __init __rmem_check_for_overlap(void) · line 283

Quoted 10 lines
drivers/of/of_reserved_mem.c +10 -0
+		for (i = 0; i < reserved_mem_count; i++) {
+			struct reserved_mem *rmem = &reserved_mem[i];
+
+			if (rmem->dumpable &&
+			    base < (u64)rmem->base + (u64)rmem->size &&
+			    (u64)rmem->base < base + size)
+				break;
+		}
+		if (i == reserved_mem_count)
+			memblock_mark_nodump(base, size);

[Severity: Medium]
Is there a risk of silent truncation here when passing u64 arguments to memblock_mark_nodump() on 32-bit architectures?

The u64 base and size variables are passed directly to memblock_mark_nodump() which takes phys_addr_t arguments. On a 32-bit architecture where phys_addr_t is 32-bit, if the device tree contains a /memreserve/ entry with an address greater than 4GB, fdt_mark_memreserve_nodump() reads it as a 64-bit value.

It performs a 64-bit overlap check against dumpable regions in reserved_mem. Because the upper 32 bits differ, it concludes there is no overlap. It then calls memblock_mark_nodump(), where the compiler silently truncates base to 32 bits.

Could this incorrectly mark the lower 32-bit address as MEMBLOCK_NODUMP, mistakenly excluding any dumpable region located there that the overlap check was intended to protect?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#17 lore raw

PATCH v7 9/9 crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header

In reply to Wandun Chen

From: Wandun Chen <[email protected]>

Reserve regions (for GPU, DSP, ...) carry no data useful for crash analysis. Exclude MEMBLOCK_NODUMP regions from the vmcore ELF header to reduce vmcore size and capture time. crash_should_skip_region() now also returns true for MEMBLOCK_NODUMP.

---
 kernel/crash_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/crash_core.c +2 -2
index c7acb2e449df..fdfeee5afa1a 100644
@@ -270,10 +270,10 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
 	return 0;
 }
 
-/* Exclude NOMAP regions from the vmcore. */
+/* Exclude NOMAP and NODUMP regions from the vmcore. */
 static bool crash_should_skip_region(struct memblock_region *reg)
 {
-	return memblock_is_nomap(reg);
+	return memblock_is_nomap(reg) || memblock_is_nodump(reg);
 }
 
 static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
Signature · 1 line
2.43.0
#18 lore raw

Re: [PATCH v7 9/9] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

From: Wandun Chen <[email protected]>

Reserve regions (for GPU, DSP, ...) carry no data useful for crash analysis. Exclude MEMBLOCK_NODUMP regions from the vmcore ELF header to reduce vmcore size and capture time. crash_should_skip_region() now also returns true for MEMBLOCK_NODUMP.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
maintainer
#19 lore raw
In reply to Wandun Chen

Hi Wandun,

Quoted 13 lines · Wandun Chen

From: Wandun Chen <[email protected]>

On SoCs that carve out large firmware-owned reserved memory (GPU, camera ISP, ...), kdump currently dumps those carveouts as part of system RAM even though their contents are firmware state that is not useful for kernel crash analysis.

This series introduces a MEMBLOCK_NODUMP flag in memblock to filter reserved memory on DT-based architectures (arm64, riscv, loongarch). Reserved regions are marked MEMBLOCK_NODUMP by default so kdump omits them; reusable CMA regions are different because their pages are handed back to the buddy allocator and may carry crash-relevant data.

Quoted 5 lines

ACPI systems already filter reserved memory out of the vmcore through their existing path; only DT-based systems currently fail to filter these regions, which is what this series addresses. The flag lives in memblock itself rather than in a DT-only structure, so both ACPI and DT systems can benefit from it (suggested by Rob, thanks).

Can you elaborate how ACPI systems filter their reserved memory? With your patches, the memblock flag becomes a part of DT-only infrastructure, so that claim that both ACPI and DT benefit from it does not hold, doesn't it?

Quoted 111 lines

Since the reserved memory regions are filtered out, the vmcore is smaller in size and faster to produce.

The series is based on linux-next and is organized as follows:

Patches 1-3: Preparation and bugfixes: switch riscv crash_mem to memblock,
fold the duplicated per-arch memblock walks into the weak defaults, and serialize crash header preparation against memory hotplug.
Patches 4-8: NODUMP infrastructure: switch crash_core to
for_each_mem_region(), introduce the MEMBLOCK_NODUMP flag, add a dumpable flag to struct reserved_mem, and mark /reserved-memory and /memreserve/ entries with MEMBLOCK_NODUMP flag.
Patch 9: Exclude MEMBLOCK_NODUMP regions from the vmcore ELF
header.

v6 --> v7:
1. Fix a stale MEMBLOCK_NODUMP flag issue [1]. Memory reserved and marked as NODUMP may later be freed (the initrd, for example), so the NODUMP flag must be cleared accordingly. Since the fix is part of the NODUMP infrastructure introduced by patch 5, it has been folded into that patch.

2. Drop the "generic" related description in the cover letter.

3. Collect the Acked-by and Reviewed-by tags received during the v6 review (thanks to Baoquan, Mike, Rob and Marek). Patch 5 is the only one without a tag, as its Reviewed-by was dropped when the fix was folded in.

4. Drop patch 1 of v6, which has been merged separately.

v5 --> v6:
1. Serialize crash header preparation against memory hotplug to avoid out-of-bounds or use-after-free issues.
2. MEMBLOCK_NODUMP marking is now done after memblock allows resizing, avoiding a panic from too few regions before resize is permitted.
3. Reordered the patches, put pre-existing bugfixes earlier in the series.

v4 --> v5:
1. Rework the mechanism around a memblock-level MEMBLOCK_NODUMP flag (suggested by Rob) instead of the v4 opt-in 'dumpable' flag on DT-only struct reserved_mem [2].
2. Switch the riscv vmcore elf header preparation to use memblock instead of the resource tree, aligning it with arm64 and loongarch, so riscv also can exclude reserved memory from vmcore.
3. Deduplicate the vmcore elf header preparation: arm64, riscv and loongarch open-coded the same logic, so fold it into shared __weak defaults in crash_core.
4. Drop the v4 patch that saved /memreserve/ entries into the reserved_mem array; /memreserve/ is now marked MEMBLOCK_NODUMP directly.

v3 --> v4:
1. Rebase this series on v7.2-rc1.
2. Add two cleanup patches (patch 02/03).
3. Simplify patch 03 to avoid checking whether initial_boot_params is NULL multiple times, suggested by Rob.

v2 --> v3:
1. Fix out-of-bounds issue if device tree lacks /reserved-memory node.
2. Fix UAF issue when alloc_reserved_mem_array() fails.
3. Add some prepare patches.

v1 --> v2:
1. v1 added an opt-out DT property ('linux,no-dump'). Per Rob's feedback [3], v2 drop that property and exclude reserve memory by default.
2. Split some prepared patches from the original patches.
3. Address coding-style comments on patch 5 from Rob.

[1] https://sashiko.dev/#/message/20260917220750.GA4013814-robh%40kernel.org
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/

Wandun Chen (9):
riscv: build crash_mem ranges from memblock instead of resource tree
crash_core: fold duplicated memblock arch hooks into the weak default
crash_core: serialize crash header preparation against hotplug
crash_core: replace for_each_mem_range() with for_each_mem_region()
memblock: introduce MEMBLOCK_NODUMP flag
of: reserved_mem: add dumpable flag to opt-in vmcore
of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP
crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF
header

 arch/arm64/kernel/machine_kexec_file.c     | 29 ------------
 arch/loongarch/kernel/machine_kexec_file.c | 27 ------------
 arch/riscv/Kconfig                         |  2 +-
 arch/riscv/kernel/machine_kexec_file.c     | 33 --------------
 arch/x86/kernel/crash.c                    |  2 +-
 drivers/of/fdt.c                           |  2 +
 drivers/of/of_private.h                    |  2 +
 drivers/of/of_reserved_mem.c               | 48 ++++++++++++++++++++
 include/linux/crash_core.h                 |  2 +
 include/linux/memblock.h                   |  9 ++++
 include/linux/of_reserved_mem.h            |  1 +
 kernel/crash_core.c                        | 51 ++++++++++++++++++++--
 kernel/dma/contiguous.c                    |  1 +
 mm/memblock.c                              | 43 +++++++++++++++++-
 14 files changed, 155 insertions(+), 97 deletions(-)
Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
author
#20 lore raw
Quoted 22 lines · Mike Rapoport

Hi Wandun,

Quoted 18 lines · Wandun Chen

From: Wandun Chen <[email protected]>

On SoCs that carve out large firmware-owned reserved memory (GPU, camera ISP, ...), kdump currently dumps those carveouts as part of system RAM even though their contents are firmware state that is not useful for kernel crash analysis.

This series introduces a MEMBLOCK_NODUMP flag in memblock to filter reserved memory on DT-based architectures (arm64, riscv, loongarch). Reserved regions are marked MEMBLOCK_NODUMP by default so kdump omits them; reusable CMA regions are different because their pages are handed back to the buddy allocator and may carry crash-relevant data.

ACPI systems already filter reserved memory out of the vmcore through their existing path; only DT-based systems currently fail to filter these regions, which is what this series addresses. The flag lives in memblock itself rather than in a DT-only structure, so both ACPI and DT systems can benefit from it (suggested by Rob, thanks).

Hi Mike,

Thanks for the review.

Quoted 1 line

Can you elaborate how ACPI systems filter their reserved memory?

In the EFI memory map, firmware carveouts are reported with the type EFI_RESERVED_TYPE. This type of memory gets the nomap flag set in memblock.memory (is_usable_memory() returns false in reserve_regions() and mark these regions with nomap flag), during prepare_elf_headers(), for_each_mem_range() filters out these nomap regions. Therefore, the memory reserved on ACPI based systems will not be dumped into the vmcore.

I will add these description in next version.

Quoted 3 lines

With your patches, the memblock flag becomes a part of DT-only infrastructure, so that claim that both ACPI and DT benefit from it does not hold, doesn't it?

You are right, the wording was misleading. Let me clarify what I meant.

In this series only DT marks regions as MEMBLOCK_NODUMP:
/reserved-memory and /memreserve/ entries are tagged in the OF paths (of_reserved_mem.c, fdt.c). ACPI does not set the flag and keeps filtering its reserved memory through the existing path, as described above.

What I intended to convey is that the flag itself lives in memblock rather than on the DT-only struct reserved_mem, so it is available for reuse. If an ACPI system ever needed to exclude a firmware-owned region from the vmcore, it could mark that region with MEMBLOCK_NODUMP the same way DT does, instead of having to invent a parallel mechanism. That is a future option, not something this series enables for ACPI today.

Also will update these description in next verison.

Best regards,
Wandun

Quoted 113 lines
Quoted 112 lines

Since the reserved memory regions are filtered out, the vmcore is smaller in size and faster to produce.

The series is based on linux-next and is organized as follows:

Patches 1-3: Preparation and bugfixes: switch riscv crash_mem to memblock,
fold the duplicated per-arch memblock walks into the weak defaults, and serialize crash header preparation against memory hotplug.
Patches 4-8: NODUMP infrastructure: switch crash_core to
for_each_mem_region(), introduce the MEMBLOCK_NODUMP flag, add a dumpable flag to struct reserved_mem, and mark /reserved-memory and /memreserve/ entries with MEMBLOCK_NODUMP flag.
Patch 9: Exclude MEMBLOCK_NODUMP regions from the vmcore ELF
header.

v6 --> v7:
1. Fix a stale MEMBLOCK_NODUMP flag issue [1]. Memory reserved and marked as NODUMP may later be freed (the initrd, for example), so the NODUMP flag must be cleared accordingly. Since the fix is part of the NODUMP infrastructure introduced by patch 5, it has been folded into that patch.

2. Drop the "generic" related description in the cover letter.

3. Collect the Acked-by and Reviewed-by tags received during the v6 review (thanks to Baoquan, Mike, Rob and Marek). Patch 5 is the only one without a tag, as its Reviewed-by was dropped when the fix was folded in.

4. Drop patch 1 of v6, which has been merged separately.

v5 --> v6:
1. Serialize crash header preparation against memory hotplug to avoid out-of-bounds or use-after-free issues.
2. MEMBLOCK_NODUMP marking is now done after memblock allows resizing, avoiding a panic from too few regions before resize is permitted.
3. Reordered the patches, put pre-existing bugfixes earlier in the series.

v4 --> v5:
1. Rework the mechanism around a memblock-level MEMBLOCK_NODUMP flag (suggested by Rob) instead of the v4 opt-in 'dumpable' flag on DT-only struct reserved_mem [2].
2. Switch the riscv vmcore elf header preparation to use memblock instead of the resource tree, aligning it with arm64 and loongarch, so riscv also can exclude reserved memory from vmcore.
3. Deduplicate the vmcore elf header preparation: arm64, riscv and loongarch open-coded the same logic, so fold it into shared __weak defaults in crash_core.
4. Drop the v4 patch that saved /memreserve/ entries into the reserved_mem array; /memreserve/ is now marked MEMBLOCK_NODUMP directly.

v3 --> v4:
1. Rebase this series on v7.2-rc1.
2. Add two cleanup patches (patch 02/03).
3. Simplify patch 03 to avoid checking whether initial_boot_params is NULL multiple times, suggested by Rob.

v2 --> v3:
1. Fix out-of-bounds issue if device tree lacks /reserved-memory node.
2. Fix UAF issue when alloc_reserved_mem_array() fails.
3. Add some prepare patches.

v1 --> v2:
1. v1 added an opt-out DT property ('linux,no-dump'). Per Rob's feedback [3], v2 drop that property and exclude reserve memory by default.
2. Split some prepared patches from the original patches.
3. Address coding-style comments on patch 5 from Rob.

[1] https://sashiko.dev/#/message/20260917220750.GA4013814-robh%40kernel.org
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/

Wandun Chen (9):
riscv: build crash_mem ranges from memblock instead of resource tree
crash_core: fold duplicated memblock arch hooks into the weak default
crash_core: serialize crash header preparation against hotplug
crash_core: replace for_each_mem_range() with for_each_mem_region()
memblock: introduce MEMBLOCK_NODUMP flag
of: reserved_mem: add dumpable flag to opt-in vmcore
of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
of: reserved_mem: mark /memreserve/ entries as MEMBLOCK_NODUMP
crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF
header

 arch/arm64/kernel/machine_kexec_file.c     | 29 ------------
 arch/loongarch/kernel/machine_kexec_file.c | 27 ------------
 arch/riscv/Kconfig                         |  2 +-
 arch/riscv/kernel/machine_kexec_file.c     | 33 --------------
 arch/x86/kernel/crash.c                    |  2 +-
 drivers/of/fdt.c                           |  2 +
 drivers/of/of_private.h                    |  2 +
 drivers/of/of_reserved_mem.c               | 48 ++++++++++++++++++++
 include/linux/crash_core.h                 |  2 +
 include/linux/memblock.h                   |  9 ++++
 include/linux/of_reserved_mem.h            |  1 +
 kernel/crash_core.c                        | 51 ++++++++++++++++++++--
 kernel/dma/contiguous.c                    |  1 +
 mm/memblock.c                              | 43 +++++++++++++++++-
 14 files changed, 155 insertions(+), 97 deletions(-)
Signature · 1 line
2.43.0
maintainer
#21 lore raw
Quoted 51 lines · Wandun
Quoted 22 lines · Mike Rapoport

Hi Wandun,

Quoted 18 lines · Wandun Chen

From: Wandun Chen <[email protected]>

On SoCs that carve out large firmware-owned reserved memory (GPU, camera ISP, ...), kdump currently dumps those carveouts as part of system RAM even though their contents are firmware state that is not useful for kernel crash analysis.

This series introduces a MEMBLOCK_NODUMP flag in memblock to filter reserved memory on DT-based architectures (arm64, riscv, loongarch). Reserved regions are marked MEMBLOCK_NODUMP by default so kdump omits them; reusable CMA regions are different because their pages are handed back to the buddy allocator and may carry crash-relevant data.

ACPI systems already filter reserved memory out of the vmcore through their existing path; only DT-based systems currently fail to filter these regions, which is what this series addresses. The flag lives in memblock itself rather than in a DT-only structure, so both ACPI and DT systems can benefit from it (suggested by Rob, thanks).

Hi Mike,

Thanks for the review.

Quoted 1 line

Can you elaborate how ACPI systems filter their reserved memory?

In the EFI memory map, firmware carveouts are reported with the type EFI_RESERVED_TYPE. This type of memory gets the nomap flag set in memblock.memory (is_usable_memory() returns false in reserve_regions() and mark these regions with nomap flag), during prepare_elf_headers(), for_each_mem_range() filters out these nomap regions. Therefore, the memory reserved on ACPI based systems will not be dumped into the vmcore.

I will add these description in next version.

Quoted 3 lines

With your patches, the memblock flag becomes a part of DT-only infrastructure, so that claim that both ACPI and DT benefit from it does not hold, doesn't it?

You are right, the wording was misleading. Let me clarify what I meant.

In this series only DT marks regions as MEMBLOCK_NODUMP:
/reserved-memory and /memreserve/ entries are tagged in the OF paths (of_reserved_mem.c, fdt.c). ACPI does not set the flag and keeps filtering its reserved memory through the existing path, as described above.

Quoted 7 lines

What I intended to convey is that the flag itself lives in memblock rather than on the DT-only struct reserved_mem, so it is available for reuse. If an ACPI system ever needed to exclude a firmware-owned region from the vmcore, it could mark that region with MEMBLOCK_NODUMP the same way DT does, instead of having to invent a parallel mechanism. That is a future option, not something this series enables for ACPI today.

So, EFI uses NOMAP for the same purpose, right?
Why when we need a new memblock flag then?

Quoted 4 lines

Also will update these description in next verison.

Best regards,
Wandun

Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#22 lore raw
Quoted 60 lines · Mike Rapoport
Quoted 51 lines · Wandun
Quoted 22 lines · Mike Rapoport

Hi Wandun,

Quoted 18 lines · Wandun Chen

From: Wandun Chen <[email protected]>

On SoCs that carve out large firmware-owned reserved memory (GPU, camera ISP, ...), kdump currently dumps those carveouts as part of system RAM even though their contents are firmware state that is not useful for kernel crash analysis.

This series introduces a MEMBLOCK_NODUMP flag in memblock to filter reserved memory on DT-based architectures (arm64, riscv, loongarch). Reserved regions are marked MEMBLOCK_NODUMP by default so kdump omits them; reusable CMA regions are different because their pages are handed back to the buddy allocator and may carry crash-relevant data.

ACPI systems already filter reserved memory out of the vmcore through their existing path; only DT-based systems currently fail to filter these regions, which is what this series addresses. The flag lives in memblock itself rather than in a DT-only structure, so both ACPI and DT systems can benefit from it (suggested by Rob, thanks).

Hi Mike,

Thanks for the review.

Quoted 1 line

Can you elaborate how ACPI systems filter their reserved memory?

In the EFI memory map, firmware carveouts are reported with the type EFI_RESERVED_TYPE. This type of memory gets the nomap flag set in memblock.memory (is_usable_memory() returns false in reserve_regions() and mark these regions with nomap flag), during prepare_elf_headers(), for_each_mem_range() filters out these nomap regions. Therefore, the memory reserved on ACPI based systems will not be dumped into the vmcore.

I will add these description in next version.

Quoted 3 lines

With your patches, the memblock flag becomes a part of DT-only infrastructure, so that claim that both ACPI and DT benefit from it does not hold, doesn't it?

You are right, the wording was misleading. Let me clarify what I meant.

In this series only DT marks regions as MEMBLOCK_NODUMP:
/reserved-memory and /memreserve/ entries are tagged in the OF paths (of_reserved_mem.c, fdt.c). ACPI does not set the flag and keeps filtering its reserved memory through the existing path, as described above.

Quoted 7 lines

What I intended to convey is that the flag itself lives in memblock rather than on the DT-only struct reserved_mem, so it is available for reuse. If an ACPI system ever needed to exclude a firmware-owned region from the vmcore, it could mark that region with MEMBLOCK_NODUMP the same way DT does, instead of having to invent a parallel mechanism. That is a future option, not something this series enables for ACPI today.

Quoted 2 lines

So, EFI uses NOMAP for the same purpose, right?
Why when we need a new memblock flag then?

IIUC, NOMAP implies NODUMP (for EFI and DT), but NODUMP is needed for some mapped (!NOMAP) regions.

Rob