* [PATCH v9 0/8] kdump: reduce vmcore size and capture time
@ 2026-10-21 8:30 Wandun Chen
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
` (8 more replies)
0 siblings, 9 replies; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
ACPI systems already filter reserved memory out of the vmcore through
their existing path: firmware reports those carveouts as unusable in
the EFI memory map, they get MEMBLOCK_NOMAP set in memblock.memory
(is_usable_memory(), efi-init.c), and the ELF header builder has
always skipped nomap regions; only DT-based systems currently fail
to filter these regions, which is what this series addresses.
This series introduces a MEMBLOCK_NODUMP flag (suggested by Rob) in
memblock to filter reserved memory on DT-based architectures. A new
flag is needed because MEMBLOCK_NOMAP can only express regions without
a linear mapping, while MEMBLOCK_NODUMP can filter regions that are
linearly mapped. 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.
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-7: 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 entries with MEMBLOCK_NODUMP.
Patch 8: Skip MEMBLOCK_NODUMP regions when building the vmcore
ELF header.
v8 --> v9:
1. Patch 7: Avoid a potential boot panic on SH when NODUMP marking requires
memblock resizing before it is allowed, found by Sashiko in [1]. SH supports
neither CONFIG_KEXEC_FILE nor CONFIG_CRASH_HOTPLUG, so skip marking when
both are disabled.
v6 --> v8 (v7 mainly tried to fix the initrd issue on release in v6,
that approach is superseded here):
1. Stop marking /memreserve/ regions with NODUMP. v6 marked
/memreserve/ regions with NODUMP. But a bootloader may specify
a /memreserve/ entry for memory that the kernel later frees
(e.g. the initrd), and those pages would then be wrongly
filtered out of the vmcore after being reused as normal memory.
The v7 fix (clearing the flag in free_reserved_area()) caused
a lockless runtime mutation of memblock.memory [2]. Better solutions
exist but need extra preparation, so temporarily dropped the patch
that introduced the problem to keep this series simple in v8.
2. Fix a build failure in patch 2 with both ARCH_KEEP_MEMBLOCK and
MEMORY_HOTPLUG are unset. There the memblock arrays live in
.init.data, and the weak defaults referencing them create section
mismatches, which turn into build errors when SECTION_MISMATCH_WARN_ONLY
is also unset.
3. RISCV recently gained crash hotplug support, so adapt its handler
like x86 in patch 3: use __crash_prepare_headers() instead of
crash_prepare_headers() to avoid self-deadlock.
4. Update the cover letter per review feedback: describe how ACPI
systems filter reserved memory and why a new flag is needed
instead of reusing NOMAP.
v6 --> v7:
1. Fix a stale MEMBLOCK_NODUMP flag issue [3]. 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.
[1] https://sashiko.dev/#/patchset/20261016061549.4181390-1-chenwandun1@gmail.com?part=7
[2] https://lore.kernel.org/lkml/20260922090252.B01541F000FF@smtp.kernel.org/
[3] https://sashiko.dev/#/message/20260917220750.GA4013814-robh%40kernel.org
v5: https://lore.kernel.org/lkml/20260806093519.2907771-1-chenwandun1@gmail.com/
v4: https://lore.kernel.org/lkml/20260630074715.4126796-1-chenwandun1@gmail.com/
Wandun Chen (8):
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
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/crash.c | 2 +-
arch/riscv/kernel/machine_kexec_file.c | 33 --------------
arch/x86/kernel/crash.c | 2 +-
drivers/of/fdt.c | 1 +
drivers/of/of_private.h | 1 +
drivers/of/of_reserved_mem.c | 18 ++++++++
include/linux/crash_core.h | 2 +
include/linux/memblock.h | 9 ++++
include/linux/of_reserved_mem.h | 1 +
kernel/crash_core.c | 53 +++++++++++++++++++++-
kernel/dma/contiguous.c | 1 +
mm/memblock.c | 16 +++++++
15 files changed, 103 insertions(+), 94 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-21 9:05 ` Jinjie Ruan
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
` (7 subsequent siblings)
8 siblings, 2 replies; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Baoquan He <baoquan.he@linux.dev>
---
arch/riscv/Kconfig | 2 +-
arch/riscv/kernel/machine_kexec_file.c | 31 ++++++++++----------------
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index e7891a2a89da..e21d0bab77ee 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -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
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index 26cd2a8bd0cd..808e872f4063 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -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)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
` (6 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Baoquan He <baoquan.he@linux.dev>
---
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 | 27 ++++++++++++++++++++
4 files changed, 27 insertions(+), 82 deletions(-)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 854d872dfd0f..34d944d3f22f 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -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
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 5412aa9f3568..481b8f906a56 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -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.
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index 808e872f4063..fdc6695e8588 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -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)
{
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index d0bd2d0cf899..faa0f22dbb41 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -281,8 +281,35 @@ static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
return cmem;
}
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+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;
+}
+#else
unsigned int __weak arch_get_system_nr_ranges(void) { return 0; }
int __weak arch_crash_populate_cmem(struct crash_mem *cmem) { return -1; }
+#endif
+
int __weak arch_crash_exclude_ranges(struct crash_mem *cmem) { return 0; }
int __weak arch_crash_exclude_mem_range(struct crash_mem **mem,
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
2026-10-21 8:30 ` [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-21 9:13 ` Jinjie Ruan
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
` (5 subsequent siblings)
8 siblings, 2 replies; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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/riscv 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")
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1]
Acked-by: Baoquan He <baoquan.he@linux.dev>
---
arch/riscv/kernel/crash.c | 2 +-
arch/x86/kernel/crash.c | 2 +-
include/linux/crash_core.h | 2 ++
kernel/crash_core.c | 17 +++++++++++++++--
4 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c
index fe5a4b306aae..ac8df2edf2a7 100644
--- a/arch/riscv/kernel/crash.c
+++ b/arch/riscv/kernel/crash.c
@@ -70,7 +70,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(true, &elfbuf, &elfsz, NULL)) {
+ if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
pr_err("unable to create new elfcorehdr");
goto out;
}
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index e6f23933a6df..bef008a0cb22 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -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;
}
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index bc087124cd78..28e7a81cf263 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -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;
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index faa0f22dbb41..8a861a946e26 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -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>
@@ -344,8 +345,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;
@@ -382,6 +383,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
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region()
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (2 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
` (4 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Baoquan He <baoquan.he@linux.dev>
---
kernel/crash_core.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 8a861a946e26..e161c8b65e00 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -283,25 +283,34 @@ static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
}
#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+/* Exclude NOMAP regions from the vmcore. */
+static bool crash_should_skip_region(struct memblock_region *reg)
+{
+ return memblock_is_nomap(reg);
+}
+
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;
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (3 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
` (3 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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 entries.
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
include/linux/memblock.h | 9 +++++++++
mm/memblock.c | 16 ++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 40e6e0aa2f8d..67dbcfda6f49 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -52,6 +52,8 @@ extern unsigned long long max_possible_pfn;
* 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_NOPRSRV = 0x40, /* memory with no KHO preservations */
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_noprsrv(phys_addr_t base, phys_addr_t size);
int memblock_clear_kho_noprsrv(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_noprsrv(struct memblock_region *m)
return m->flags & MEMBLOCK_KHO_NOPRSRV;
}
+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,
diff --git a/mm/memblock.c b/mm/memblock.c
index a450092a80fb..ab1432241432 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1221,6 +1221,21 @@ __init int memblock_clear_kho_noprsrv(phys_addr_t base, phys_addr_t size)
MEMBLOCK_KHO_NOPRSRV);
}
+/**
+ * memblock_mark_nodump - Mark a memory region with flag MEMBLOCK_NODUMP.
+ * @base: the base phys addr of the region
+ * @size: the size of the region
+ *
+ * Mark the region as not to be included in crash dumps.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+int __init_memblock memblock_mark_nodump(phys_addr_t base, phys_addr_t size)
+{
+ return memblock_setclr_flag(&memblock.memory, base, size, 1,
+ MEMBLOCK_NODUMP);
+}
+
static bool should_skip_region(struct memblock_type *type,
struct memblock_region *m,
int nid, int flags)
@@ -2854,6 +2869,7 @@ static const char * const flagname[] = {
[ilog2(MEMBLOCK_RSRV_KERN)] = "RSV_KERN",
[ilog2(MEMBLOCK_KHO_NOPRSRV)] = "KHO_NOPRSRV",
[ilog2(MEMBLOCK_RSRV_HUGETLB)] = "RSV_HUGETLB",
+ [ilog2(MEMBLOCK_NODUMP)] = "NODUMP",
};
static int memblock_debug_show(struct seq_file *m, void *private)
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (4 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
` (2 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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().
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
---
include/linux/of_reserved_mem.h | 1 +
kernel/dma/contiguous.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index 49da515859f2..99c0f3ccc297 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -15,6 +15,7 @@ struct reserved_mem {
phys_addr_t base;
phys_addr_t size;
void *priv;
+ bool dumpable;
};
struct reserved_mem_ops {
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 90937dc7c627..d7bfc38ac762 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (5 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen
2026-10-21 13:23 ` [PATCH v9 0/8] kdump: reduce vmcore size and capture time Rob Herring
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
drivers/of/fdt.c | 1 +
drivers/of/of_private.h | 1 +
drivers/of/of_reserved_mem.c | 18 ++++++++++++++++++
3 files changed, 20 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index ecc923102622..a5f223a74b7e 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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) {
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 0ae16da066e2..505735732c13 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -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);
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 8c9d6395d6a3..db2bf76000d2 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -677,6 +677,24 @@ 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;
+
+ 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;
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (6 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
@ 2026-10-21 8:30 ` Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 13:23 ` [PATCH v9 0/8] kdump: reduce vmcore size and capture time Rob Herring
8 siblings, 1 reply; 24+ messages in thread
From: Wandun Chen @ 2026-10-21 8:30 UTC (permalink / raw)
To: robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
From: Wandun Chen <chenwandun@lixiang.com>
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.
Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
Acked-by: Baoquan He <baoquan.he@linux.dev>
---
kernel/crash_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index e161c8b65e00..0e2ddc933b22 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -283,10 +283,10 @@ static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
}
#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
-/* 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);
}
unsigned int __weak arch_get_system_nr_ranges(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
@ 2026-10-21 9:05 ` Jinjie Ruan
2026-10-22 8:33 ` sashiko-bot
1 sibling, 0 replies; 24+ messages in thread
From: Jinjie Ruan @ 2026-10-21 9:05 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
在 2026/10/21 16:30, Wandun Chen 写道:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
> Tested-by: Meijing Zhao <zhaomeijing@lixiang.com>
> Acked-by: Baoquan He <baoquan.he@linux.dev>
> ---
> arch/riscv/Kconfig | 2 +-
> arch/riscv/kernel/machine_kexec_file.c | 31 ++++++++++----------------
> 2 files changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index e7891a2a89da..e21d0bab77ee 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -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
> diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
> index 26cd2a8bd0cd..808e872f4063 100644
> --- a/arch/riscv/kernel/machine_kexec_file.c
> +++ b/arch/riscv/kernel/machine_kexec_file.c
> @@ -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;
The kernel prefers the reverse Christmas tree layout for local variables.
>
> - 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)
> {
--
Best regards,
Jinjie
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-21 8:30 ` [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
@ 2026-10-21 9:13 ` Jinjie Ruan
2026-10-21 9:48 ` Wandun
2026-10-22 8:33 ` sashiko-bot
1 sibling, 1 reply; 24+ messages in thread
From: Jinjie Ruan @ 2026-10-21 9:13 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
在 2026/10/21 16:30, Wandun Chen 写道:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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/riscv 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")
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
> Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1]
> Acked-by: Baoquan He <baoquan.he@linux.dev>
> ---
> arch/riscv/kernel/crash.c | 2 +-
> arch/x86/kernel/crash.c | 2 +-
> include/linux/crash_core.h | 2 ++
> kernel/crash_core.c | 17 +++++++++++++++--
> 4 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c
> index fe5a4b306aae..ac8df2edf2a7 100644
> --- a/arch/riscv/kernel/crash.c
> +++ b/arch/riscv/kernel/crash.c
> @@ -70,7 +70,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(true, &elfbuf, &elfsz, NULL)) {
> + if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
> pr_err("unable to create new elfcorehdr");
> goto out;
> }
> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> index e6f23933a6df..bef008a0cb22 100644
> --- a/arch/x86/kernel/crash.c
> +++ b/arch/x86/kernel/crash.c
> @@ -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;
> }
> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
> index bc087124cd78..28e7a81cf263 100644
> --- a/include/linux/crash_core.h
> +++ b/include/linux/crash_core.h
> @@ -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;
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index faa0f22dbb41..8a861a946e26 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -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>
> @@ -344,8 +345,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;
> @@ -382,6 +383,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();
I think this patch conflicts with my changes and would also conflict
with the implementation of arm64 crash hotplug.
https://lore.kernel.org/all/20260921090450.807575-15-ruanjinjie@huawei.com/
arm64 crash hotplug:
https://lore.kernel.org/all/20260918100442.3841135-18-ruanjinjie@huawei.com/
> +
> + 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
--
Best regards,
Jinjie
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-21 9:13 ` Jinjie Ruan
@ 2026-10-21 9:48 ` Wandun
2026-10-22 2:00 ` Jinjie Ruan
0 siblings, 1 reply; 24+ messages in thread
From: Wandun @ 2026-10-21 9:48 UTC (permalink / raw)
To: Jinjie Ruan, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
On 10/21/26 17:13, Jinjie Ruan wrote:
>
>
> 在 2026/10/21 16:30, Wandun Chen 写道:
>> From: Wandun Chen <chenwandun@lixiang.com>
>>
>> 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/riscv 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")
>> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
>> Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1]
>> Acked-by: Baoquan He <baoquan.he@linux.dev>
>> ---
>> arch/riscv/kernel/crash.c | 2 +-
>> arch/x86/kernel/crash.c | 2 +-
>> include/linux/crash_core.h | 2 ++
>> kernel/crash_core.c | 17 +++++++++++++++--
>> 4 files changed, 19 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c
>> index fe5a4b306aae..ac8df2edf2a7 100644
>> --- a/arch/riscv/kernel/crash.c
>> +++ b/arch/riscv/kernel/crash.c
>> @@ -70,7 +70,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(true, &elfbuf, &elfsz, NULL)) {
>> + if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
>> pr_err("unable to create new elfcorehdr");
>> goto out;
>> }
>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
>> index e6f23933a6df..bef008a0cb22 100644
>> --- a/arch/x86/kernel/crash.c
>> +++ b/arch/x86/kernel/crash.c
>> @@ -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;
>> }
>> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
>> index bc087124cd78..28e7a81cf263 100644
>> --- a/include/linux/crash_core.h
>> +++ b/include/linux/crash_core.h
>> @@ -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;
>> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
>> index faa0f22dbb41..8a861a946e26 100644
>> --- a/kernel/crash_core.c
>> +++ b/kernel/crash_core.c
>> @@ -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>
>> @@ -344,8 +345,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;
>> @@ -382,6 +383,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();
>
> I think this patch conflicts with my changes and would also conflict
> with the implementation of arm64 crash hotplug.
>
> https://lore.kernel.org/all/20260921090450.807575-15-ruanjinjie@huawei.com/
>
Have these patches already been merged? My current work is based on the latest
linux-next. If they have already been merged into the maintainer's branch,
please let me know, I will update my tree and rebase/re-adapt my changes accordingly.
Also, regarding the changes in kernel/crash_core.c: it looks like we modified
the same spot, the change is not wrong, is that right?
> arm64 crash hotplug:
> https://lore.kernel.org/all/20260918100442.3841135-18-ruanjinjie@huawei.com/
In addition, if arm64 gains crash hotplug support, the code there would indeed
need to be modified (to avoid a deadlock). As of now, arm64 crash hotplug
support has not been merged yet either, has it? I just want to make sure I
haven't missed anything.
>
>> +
>> + 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
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 0/8] kdump: reduce vmcore size and capture time
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
` (7 preceding siblings ...)
2026-10-21 8:30 ` [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen
@ 2026-10-21 13:23 ` Rob Herring
2026-10-22 7:04 ` Wandun
8 siblings, 1 reply; 24+ messages in thread
From: Rob Herring @ 2026-10-21 13:23 UTC (permalink / raw)
To: Wandun Chen
Cc: baoquan.he, rppt, m.szyprowski, catalin.marinas, will,
mark.rutland, chenhuacai, kernel, pjw, palmer, aou, alex, tglx,
mingo, bp, dave.hansen, x86, hpa, saravanak, akpm, pasha.tatashin,
pratyush, ruirui.yang, robin.murphy, linux-arm-kernel,
linux-kernel, loongarch, linux-riscv, devicetree, kexec, linux-mm,
iommu
On Wed, Oct 21, 2026 at 04:30:03PM +0800, Wandun Chen wrote:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> ACPI systems already filter reserved memory out of the vmcore through
> their existing path: firmware reports those carveouts as unusable in
> the EFI memory map, they get MEMBLOCK_NOMAP set in memblock.memory
> (is_usable_memory(), efi-init.c), and the ELF header builder has
> always skipped nomap regions; only DT-based systems currently fail
> to filter these regions, which is what this series addresses.
>
> This series introduces a MEMBLOCK_NODUMP flag (suggested by Rob) in
> memblock to filter reserved memory on DT-based architectures. A new
> flag is needed because MEMBLOCK_NOMAP can only express regions without
> a linear mapping, while MEMBLOCK_NODUMP can filter regions that are
> linearly mapped. 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.
There is little point in continuing to send new versions until Mike
agrees with MEMBLOCK_NODUMP being added. You didn't answer him on v7.
Also, I intend to apply this[1] before any further reserved memory
changes which will greatly simplify the code.
Rob
[1] https://lore.kernel.org/all/20261015082315.56876-1-m.szyprowski@samsung.com/
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-21 9:48 ` Wandun
@ 2026-10-22 2:00 ` Jinjie Ruan
2026-10-22 7:44 ` Wandun
0 siblings, 1 reply; 24+ messages in thread
From: Jinjie Ruan @ 2026-10-22 2:00 UTC (permalink / raw)
To: Wandun, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu
在 2026/10/21 17:48, Wandun 写道:
>
>
> On 10/21/26 17:13, Jinjie Ruan wrote:
>>
>>
>> 在 2026/10/21 16:30, Wandun Chen 写道:
>>> From: Wandun Chen <chenwandun@lixiang.com>
>>>
>>> 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/riscv 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")
>>> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
>>> Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1]
>>> Acked-by: Baoquan He <baoquan.he@linux.dev>
>>> ---
>>> arch/riscv/kernel/crash.c | 2 +-
>>> arch/x86/kernel/crash.c | 2 +-
>>> include/linux/crash_core.h | 2 ++
>>> kernel/crash_core.c | 17 +++++++++++++++--
>>> 4 files changed, 19 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c
>>> index fe5a4b306aae..ac8df2edf2a7 100644
>>> --- a/arch/riscv/kernel/crash.c
>>> +++ b/arch/riscv/kernel/crash.c
>>> @@ -70,7 +70,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(true, &elfbuf, &elfsz, NULL)) {
>>> + if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
>>> pr_err("unable to create new elfcorehdr");
>>> goto out;
>>> }
>>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
>>> index e6f23933a6df..bef008a0cb22 100644
>>> --- a/arch/x86/kernel/crash.c
>>> +++ b/arch/x86/kernel/crash.c
>>> @@ -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;
>>> }
>>> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
>>> index bc087124cd78..28e7a81cf263 100644
>>> --- a/include/linux/crash_core.h
>>> +++ b/include/linux/crash_core.h
>>> @@ -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;
>>> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
>>> index faa0f22dbb41..8a861a946e26 100644
>>> --- a/kernel/crash_core.c
>>> +++ b/kernel/crash_core.c
>>> @@ -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>
>>> @@ -344,8 +345,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;
>>> @@ -382,6 +383,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();
>>
>> I think this patch conflicts with my changes and would also conflict
>> with the implementation of arm64 crash hotplug.
>>
>> https://lore.kernel.org/all/20260921090450.807575-15-ruanjinjie@huawei.com/
>>
> Have these patches already been merged? My current work is based on the latest
> linux-next. If they have already been merged into the maintainer's branch,
> please let me know, I will update my tree and rebase/re-adapt my changes accordingly.
>
>
> Also, regarding the changes in kernel/crash_core.c: it looks like we modified
> the same spot, the change is not wrong, is that right?
Hi Wandun,
However, I think someone should have informed me in advance; otherwise,
doing duplicate fix work is pointless.
I see that part of your patch series modifies code I previously changed,
but I was not CC'd.
>
>> arm64 crash hotplug:
>> https://lore.kernel.org/all/20260918100442.3841135-18-ruanjinjie@huawei.com/
>
> In addition, if arm64 gains crash hotplug support, the code there would indeed
> need to be modified (to avoid a deadlock). As of now, arm64 crash hotplug
> support has not been merged yet either, has it? I just want to make sure I
> haven't missed anything.
Yes, you are right. If your patch series will be merged soon, I will
develop based on it.
>
>>
>>> +
>>> + 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
>>
>
--
Best regards,
Jinjie
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 0/8] kdump: reduce vmcore size and capture time
2026-10-21 13:23 ` [PATCH v9 0/8] kdump: reduce vmcore size and capture time Rob Herring
@ 2026-10-22 7:04 ` Wandun
0 siblings, 0 replies; 24+ messages in thread
From: Wandun @ 2026-10-22 7:04 UTC (permalink / raw)
To: Rob Herring, rppt@kernel.org
Cc: baoquan.he, m.szyprowski, catalin.marinas, will, mark.rutland,
chenhuacai, kernel, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, x86, hpa, saravanak, akpm, pasha.tatashin, pratyush,
ruirui.yang, robin.murphy, linux-arm-kernel, linux-kernel,
loongarch, linux-riscv, devicetree, kexec, linux-mm, iommu
On 10/21/26 21:23, Rob Herring wrote:
> On Wed, Oct 21, 2026 at 04:30:03PM +0800, Wandun Chen wrote:
>> From: Wandun Chen <chenwandun@lixiang.com>
>>
>> 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.
>>
>> ACPI systems already filter reserved memory out of the vmcore through
>> their existing path: firmware reports those carveouts as unusable in
>> the EFI memory map, they get MEMBLOCK_NOMAP set in memblock.memory
>> (is_usable_memory(), efi-init.c), and the ELF header builder has
>> always skipped nomap regions; only DT-based systems currently fail
>> to filter these regions, which is what this series addresses.
>>
>> This series introduces a MEMBLOCK_NODUMP flag (suggested by Rob) in
>> memblock to filter reserved memory on DT-based architectures. A new
>> flag is needed because MEMBLOCK_NOMAP can only express regions without
>> a linear mapping, while MEMBLOCK_NODUMP can filter regions that are
>> linearly mapped. 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.
>
> There is little point in continuing to send new versions until Mike
> agrees with MEMBLOCK_NODUMP being added. You didn't answer him on v7.
Hi Rob,
Thanks for the reminder. On v7 your reply to Mike stated exactly what
I wanted to say, after a week without further objections, so I assumed
the question was settled and went ahead with next version. That was a
mistake on my part: I should have gotten Mike's agreement on the flag
before sending a new version. I'll hold off further versions until then.
Hi Mike,
Sorry for not following up on your v7 question. The reason a new flag
is needed is described in the v9 cover letter:
A new flag is needed because MEMBLOCK_NOMAP can only express
regions without a linear mapping, while MEMBLOCK_NODUMP can
filter regions that are linearly mapped.
Put differently: today, whether a region ends up in the vmcore is a
side effect of how it is mapped, mapped regions are always dumped,
nomap regions never are. Nothing can express "mapped, but not useful
in a crash dump". MEMBLOCK_NODUMP decouples the two, and DT is simply
the first user.
>
> Also, I intend to apply this[1] before any further reserved memory
> changes which will greatly simplify the code.
Understood, and it makes sense. It removes the two-pass reserved_mem
initialization and indeed simplify the code, I'll rebase on top of
it once it lands;
Best regards,
Wandun
>
> Rob
>
> [1] https://lore.kernel.org/all/20261015082315.56876-1-m.szyprowski@samsung.com/
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-22 2:00 ` Jinjie Ruan
@ 2026-10-22 7:44 ` Wandun
0 siblings, 0 replies; 24+ messages in thread
From: Wandun @ 2026-10-22 7:44 UTC (permalink / raw)
To: Jinjie Ruan
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, linux-arm-kernel, linux-kernel, loongarch,
linux-riscv, devicetree, kexec, linux-mm, iommu, robh, baoquan.he,
rppt, m.szyprowski
On 10/22/26 10:00, Jinjie Ruan wrote:
>
>
> 在 2026/10/21 17:48, Wandun 写道:
>>
>>
>> On 10/21/26 17:13, Jinjie Ruan wrote:
>>>
>>>
>>> 在 2026/10/21 16:30, Wandun Chen 写道:
>>>> From: Wandun Chen <chenwandun@lixiang.com>
>>>>
>>>> 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/riscv 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")
>>>> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
>>>> Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1]
>>>> Acked-by: Baoquan He <baoquan.he@linux.dev>
>>>> ---
>>>> arch/riscv/kernel/crash.c | 2 +-
>>>> arch/x86/kernel/crash.c | 2 +-
>>>> include/linux/crash_core.h | 2 ++
>>>> kernel/crash_core.c | 17 +++++++++++++++--
>>>> 4 files changed, 19 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c
>>>> index fe5a4b306aae..ac8df2edf2a7 100644
>>>> --- a/arch/riscv/kernel/crash.c
>>>> +++ b/arch/riscv/kernel/crash.c
>>>> @@ -70,7 +70,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(true, &elfbuf, &elfsz, NULL)) {
>>>> + if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) {
>>>> pr_err("unable to create new elfcorehdr");
>>>> goto out;
>>>> }
>>>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
>>>> index e6f23933a6df..bef008a0cb22 100644
>>>> --- a/arch/x86/kernel/crash.c
>>>> +++ b/arch/x86/kernel/crash.c
>>>> @@ -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;
>>>> }
>>>> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
>>>> index bc087124cd78..28e7a81cf263 100644
>>>> --- a/include/linux/crash_core.h
>>>> +++ b/include/linux/crash_core.h
>>>> @@ -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;
>>>> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
>>>> index faa0f22dbb41..8a861a946e26 100644
>>>> --- a/kernel/crash_core.c
>>>> +++ b/kernel/crash_core.c
>>>> @@ -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>
>>>> @@ -344,8 +345,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;
>>>> @@ -382,6 +383,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();
>>>
>>> I think this patch conflicts with my changes and would also conflict
>>> with the implementation of arm64 crash hotplug.
>>>
>>> https://lore.kernel.org/all/20260921090450.807575-15-ruanjinjie@huawei.com/
>>>
>> Have these patches already been merged? My current work is based on the latest
>> linux-next. If they have already been merged into the maintainer's branch,
>> please let me know, I will update my tree and rebase/re-adapt my changes accordingly.
>>
>>
>> Also, regarding the changes in kernel/crash_core.c: it looks like we modified
>> the same spot, the change is not wrong, is that right?
>
> Hi Wandun,
>
> However, I think someone should have informed me in advance; otherwise,
> doing duplicate fix work is pointless.
>
> I see that part of your patch series modifies code I previously changed,
> but I was not CC'd.
Hi Jinjie,
Sorry for not CC'ing you. I keep the per-patch Cc lists short because
large recipient sets have caused my sends to be cut off midway before,
(I'm still trying to track down exactly where the problem is) you should
have been on the list that's my miss. You'll be on the Cc of every future
version.
>
>>
>>> arm64 crash hotplug:
>>> https://lore.kernel.org/all/20260918100442.3841135-18-ruanjinjie@huawei.com/
>>
>> In addition, if arm64 gains crash hotplug support, the code there would indeed
>> need to be modified (to avoid a deadlock). As of now, arm64 crash hotplug
>> support has not been merged yet either, has it? I just want to make sure I
>> haven't missed anything.
>
> Yes, you are right. If your patch series will be merged soon, I will
> develop based on it.
Also thanks for your reminder, otherwise I might later overlook the case
where arm64 has already gained crash hotplug support, and introduce bugs
as a result.
Best regards,
Wandun>
>>
>>>
>>>> +
>>>> + 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
>>>
>>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
2026-10-21 9:05 ` Jinjie Ruan
@ 2026-10-22 8:33 ` sashiko-bot
1 sibling, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=1
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default
2026-10-21 8:30 ` [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=2
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
2026-10-21 8:30 ` [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
2026-10-21 9:13 ` Jinjie Ruan
@ 2026-10-22 8:33 ` sashiko-bot
1 sibling, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, devicetree, kexec, linux-mm, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] crash_core: cmem->ranges overflow via unlocked iomem_resource hotplug
--
commit 24cd8bf08b74ae3e07f992972d3cd97b77d9fcf6
Author: Wandun Chen <chenwandun@lixiang.com>
crash_core: serialize crash header preparation against hotplug
This commit serializes crash_prepare_headers() with device_hotplug_lock
to prevent concurrent memory hotplug from changing the number of memory
ranges between counting and populating cmem->ranges. It also introduces
__crash_prepare_headers() for hotplug paths that already hold the lock.
Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index faa0f22dbb41d..8a861a946e261 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
[ ... ]
> @@ -344,8 +345,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;
> @@ -382,6 +383,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;
> +}
[Severity: Medium]
Can cmem->ranges[] still overflow during __crash_prepare_headers() even when
device_hotplug_lock is held?
In __crash_prepare_headers(), arch_get_system_nr_ranges() counts the current
system ram ranges (plus a fixed number of split slots for exclusions),
allocates cmem via alloc_cmem(max_nr_ranges), and then populates
cmem->ranges[] in arch_crash_populate_cmem().
Neither the x86 callback in arch/x86/kernel/crash.c:
static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
{
struct crash_mem *cmem = arg;
cmem->ranges[cmem->nr_ranges].start = res->start;
cmem->ranges[cmem->nr_ranges].end = res->end;
cmem->nr_ranges++;
return 0;
}
nor the weak implementation in kernel/crash_core.c:
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;
}
checks whether cmem->nr_ranges has reached cmem->max_nr_ranges before writing
to cmem->ranges[cmem->nr_ranges++].
However, Xen balloon memory hotplug inserts new system ram resources into
iomem_resource before acquiring device_hotplug_lock via the call chain:
balloon_thread() / xen_alloc_ballooned_pages()
-> add_ballooned_pages()
-> reserve_additional_memory()
-> additional_memory_resource()
Specifically, in drivers/xen/balloon.c:
static struct resource *additional_memory_resource(phys_addr_t size)
{
...
res->name = "System RAM";
res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
ret = allocate_resource(&iomem_resource, res,
size, 0, -1,
PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL);
...
}
static enum bp_state reserve_additional_memory(void)
{
...
resource = additional_memory_resource(balloon_hotplug * PAGE_SIZE);
if (!resource)
goto err;
...
mutex_unlock(&balloon_mutex);
/* add_memory_resource() requires the device_hotplug lock */
lock_device_hotplug();
rc = add_memory_resource(nid, resource, MHP_MERGE_RESOURCE);
unlock_device_hotplug();
mutex_lock(&balloon_mutex);
...
balloon_stats.total_pages += balloon_hotplug;
...
}
Because reserve_additional_memory() inserts the resource into iomem_resource
and drops balloon_mutex before waiting on lock_device_hotplug(), and only
updates balloon_stats.total_pages after add_memory_resource() completes,
concurrent callers (such as balloon_thread() and xen_alloc_ballooned_pages())
can insert new system ram entries into iomem_resource while
crash_prepare_headers() or arch_crash_handle_hotplug_event() holds
device_hotplug_lock.
If those entries are inserted between arch_get_system_nr_ranges() and
arch_crash_populate_cmem(), wouldn't the extra ranges consume the reserved
split slots (causing crash_exclude_mem_range() to fail) or overflow
cmem->ranges[]? Should arch_crash_populate_cmem() and
prepare_elf64_ram_headers_callback() also bounds-check cmem->nr_ranges
against cmem->max_nr_ranges?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=3
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region()
2026-10-21 8:30 ` [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=4
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag
2026-10-21 8:30 ` [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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 entries.
>
> Suggested-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=5
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore
2026-10-21 8:30 ` [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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().
>
> Suggested-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=6
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
2026-10-21 8:30 ` [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, devicetree, kexec, linux-mm, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] of: reserved_mem: unaligned memblock split in fdt_mark_reserve_mem_nodump()
- [Medium] of: reserved_mem: fdt_mark_reserve_mem_nodump() marks failed reservations
--
commit a452b9d1fad838de511c25fe48e4541c58357355
Author: Wandun Chen <chenwandun@lixiang.com>
of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP
This commit adds fdt_mark_reserve_mem_nodump() to mark non-dumpable
reserved-memory regions in memblock.memory so kdump omits them from the
vmcore when crash dump support is enabled.
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 8c9d6395d6a39..db2bf76000d23 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -677,6 +677,24 @@ 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;
> +
> + 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]
What happens here when rmem->base or rmem->size is not page-aligned, or
when rmem->size is smaller than a page?
Previously, mapped reserved-memory regions were only recorded in
memblock.reserved and did not split memblock.memory. Calling
memblock_mark_nodump() splits memblock.memory at rmem->base and
rmem->base + rmem->size, but reserved-memory regions are not guaranteed to
be page-aligned:
drivers/of/of_reserved_mem.c:early_init_dt_alloc_reserved_memory_arch() {
end = !end ? MEMBLOCK_ALLOC_ANYWHERE : end;
align = !align ? SMP_CACHE_BYTES : align;
base = memblock_phys_alloc_range(size, align, start, end);
}
Static device tree regions without no-map can also be smaller than a page
or unaligned to the page size (for example, cfe-stub@0 in
arch/arm64/boot/dts/broadcom/bcmbca/bcm4908.dtsi with a 0x1000 size under
16k or 64k page configurations).
When memblock.memory is split at an unaligned or sub-page boundary,
__next_mem_pfn_range() rounds each region inward to page boundaries and
skips sub-page regions:
mm/memblock.c:__next_mem_pfn_range() {
while (++*idx < type->cnt) {
r = &type->regions[*idx];
r_nid = memblock_get_region_node(r);
if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size))
continue;
}
This drops any page frame straddling an unaligned split boundary from
for_each_mem_pfn_range() and the page allocator.
In addition, request_standard_resources() in arch/arm64/kernel/setup.c and
init_resources() in arch/riscv/kernel/setup.c register each mapped
memblock.memory region using memblock_region_memory_base_pfn() and
memblock_region_memory_end_pfn():
arch/riscv/kernel/setup.c:init_resources() {
res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
ret = add_resource(&iomem_resource, res);
if (ret < 0)
goto error;
}
For a sub-page region where PFN_UP(base) >= PFN_DOWN(base + size), res->end
becomes smaller than res->start (or underflows when end_pfn is 0), causing
add_resource() on riscv to fail and tear down iomem_resource, and producing
an inverted or underflowed resource on arm64.
Splitting memblock.memory also splits hyp_memory[] on arm64 pkvm, where
check_range_allowed_memory() in arch/arm64/kvm/hyp/nvhe/mem_protect.c
requires checked ranges to fall within a single region:
arch/arm64/kvm/hyp/nvhe/mem_protect.c:check_range_allowed_memory() {
reg = find_mem_range(start, &range);
if (!is_in_mem_range(end - 1, &range))
return -EINVAL;
}
Could memblock_mark_nodump() corrupt resource registration, drop straddling
pages, or break pkvm range checks when regions are not page-aligned?
[Severity: Medium]
Can fdt_mark_reserve_mem_nodump() also end up marking active kernel memory
as non-dumpable if an early static reservation failed?
During early boot in fdt_scan_reserved_mem(), __reserved_mem_reserve_reg()
logs an error if early_init_dt_reserve_memory() fails (for example, if a
static region overlaps the kernel image or initrd), but still returns 0:
drivers/of/of_reserved_mem.c:__reserved_mem_reserve_reg() {
if (size && early_init_dt_reserve_memory(base, size, nomap) == 0) {
fdt_fixup_reserved_mem_node(node, base, size);
pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n",
uname, &base, (unsigned long)(size / SZ_1M));
} else {
pr_err("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n",
uname, &base, (unsigned long)(size / SZ_1M));
}
return 0;
}
Later, fdt_scan_reserved_mem_late() scans all available static nodes in
/reserved-memory and passes them to fdt_init_reserved_mem_node(), recording
them in reserved_mem[] regardless of whether the early reservation
succeeded:
drivers/of/of_reserved_mem.c:fdt_scan_reserved_mem_late() {
if (size) {
uname = fdt_get_name(fdt, child, NULL);
fdt_init_reserved_mem_node(child, uname, base, size);
}
}
Wouldn't fdt_mark_reserve_mem_nodump() then mark that unreserved range in
memblock.memory, causing kdump to omit memory that is actually in use by
the kernel?
> +}
> +
> struct rmem_assigned_device {
> struct device *dev;
> struct reserved_mem *rmem;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=7
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header
2026-10-21 8:30 ` [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen
@ 2026-10-22 8:33 ` sashiko-bot
0 siblings, 0 replies; 24+ messages in thread
From: sashiko-bot @ 2026-10-22 8:33 UTC (permalink / raw)
To: Wandun Chen, robh, baoquan.he, rppt, m.szyprowski
Cc: catalin.marinas, will, mark.rutland, chenhuacai, kernel, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, x86, hpa,
saravanak, akpm, pasha.tatashin, pratyush, ruirui.yang,
robin.murphy, kexec
> From: Wandun Chen <chenwandun@lixiang.com>
>
> 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.
>
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261021083011.2170525-1-chenwandun1@gmail.com?part=8
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2026-10-22 8:33 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-21 8:30 [PATCH v9 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-10-21 8:30 ` [PATCH v9 1/8] riscv: build crash_mem ranges from memblock instead of resource tree Wandun Chen
2026-10-21 9:05 ` Jinjie Ruan
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 2/8] crash_core: fold duplicated memblock arch hooks into the weak default Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug Wandun Chen
2026-10-21 9:13 ` Jinjie Ruan
2026-10-21 9:48 ` Wandun
2026-10-22 2:00 ` Jinjie Ruan
2026-10-22 7:44 ` Wandun
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 4/8] crash_core: replace for_each_mem_range() with for_each_mem_region() Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 5/8] memblock: introduce MEMBLOCK_NODUMP flag Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 6/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 7/8] of: reserved_mem: mark /reserved-memory entries with MEMBLOCK_NODUMP Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 8:30 ` [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header Wandun Chen
2026-10-22 8:33 ` sashiko-bot
2026-10-21 13:23 ` [PATCH v9 0/8] kdump: reduce vmcore size and capture time Rob Herring
2026-10-22 7:04 ` Wandun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox