[PATCH v10 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP

From: Wandun Chen

Date: Fri Nov 27 2026 - 04:09:18 EST


From: Wandun Chen <chenwandun@xxxxxxxxxxx>

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 and either CONFIG_KEXEC_FILE
or CONFIG_CRASH_HOTPLUG, so kernels that do not build or update crash
ELF headers do not pay the cost of splitting memblock.memory entries
at NODUMP boundaries.

Clamp the marked range to page boundaries, since a sub-page split
would leave fragments that cannot be represented as valid System
RAM resources [1].

Link: https://sashiko.dev/#/message/sashiko-outbox-181183@xxxxxxxxxx [1]
Signed-off-by: Wandun Chen <chenwandun@xxxxxxxxxxx>
Tested-by: Meijing Zhao <zhaomeijing@xxxxxxxxxxx>
Acked-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Reviewed-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
---
drivers/of/fdt.c | 2 ++
drivers/of/of_private.h | 1 +
drivers/of/of_reserved_mem.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 33 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a58efdcbac7f..f3a766310d11 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1283,6 +1283,8 @@ void __init unflatten_device_tree(void)
{
void *fdt = initial_boot_params;

+ fdt_mark_reserve_mem_nodump();
+
/* Populate an empty root node when bootloader doesn't provide one */
if (!fdt) {
fdt = (void *) __dtb_empty_root_begin;
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 895f868b4cfa..00f776819dab 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -185,6 +185,7 @@ static inline struct device_node *__of_get_dma_parent(const struct device_node *
#endif

int fdt_scan_reserved_mem(void);
+void __init fdt_mark_reserve_mem_nodump(void);

bool of_fdt_device_is_available(const void *blob, unsigned long node);

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index a5cd8c2fffc3..cef444d4c1a3 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -610,6 +610,36 @@ 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;
+
+ if (!IS_ENABLED(CONFIG_KEXEC_FILE) && !IS_ENABLED(CONFIG_CRASH_HOTPLUG))
+ return;
+
+ if (reserved_mem_reserve_failed)
+ return;
+
+ for (i = 0; i < reserved_mem_count; i++) {
+ phys_addr_t base, end;
+
+ rmem = &reserved_mem[i];
+ if (!rmem->size || rmem->dumpable)
+ continue;
+
+ base = round_up(rmem->base, PAGE_SIZE);
+ end = round_down(rmem->base + rmem->size, PAGE_SIZE);
+ if (base >= end)
+ continue;
+
+ memblock_mark_nodump(base, end - base);
+ }
+}
+
struct rmem_assigned_device {
struct device *dev;
struct reserved_mem *rmem;
--
2.43.0