From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>,
robh@kernel.org, baoquan.he@linux.dev, rppt@kernel.org,
m.szyprowski@samsung.com
Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
chenhuacai@kernel.org, kernel@xen0n.name, pjw@kernel.org,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
saravanak@kernel.org, akpm@linux-foundation.org,
pasha.tatashin@soleen.com, pratyush@kernel.org,
ruirui.yang@linux.dev, robin.murphy@arm.com,
devicetree@vger.kernel.org, kexec@lists.infradead.org,
linux-mm@kvack.org, conor+dt@kernel.org
Subject: Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug
Date: Thu, 22 Oct 2026 08:33:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-181179@kernel.org> (raw)
In-Reply-To: <20261021083011.2170525-4-chenwandun1@gmail.com>
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
next prev parent reply other threads:[~2026-10-22 8:33 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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-21 9:05 ` Jinjie Ruan
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-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
2026-10-21 8:30 ` Wandun Chen
2026-10-21 9:10 ` Jinjie Ruan
2026-10-21 9:13 ` Jinjie Ruan
2026-10-21 9:13 ` Jinjie Ruan
2026-10-21 9:48 ` Wandun
2026-10-21 9:48 ` Wandun
2026-10-22 2:00 ` Jinjie Ruan
2026-10-22 2:00 ` Jinjie Ruan
2026-10-22 7:44 ` Wandun
2026-10-22 7:44 ` Wandun
2026-10-22 8:33 ` sashiko-bot [this message]
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 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 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 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 8:30 ` [PATCH v9 8/8] crash_core: skip MEMBLOCK_NODUMP regions when building vmcore ELF header 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
2026-10-21 13:23 ` Rob Herring
2026-10-22 7:04 ` Wandun
2026-10-22 7:04 ` Wandun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-181179@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=baoquan.he@linux.dev \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=chenwandun1@gmail.com \
--cc=conor+dt@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=hpa@zytor.com \
--cc=kernel@xen0n.name \
--cc=kexec@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pasha.tatashin@soleen.com \
--cc=pjw@kernel.org \
--cc=pratyush@kernel.org \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rppt@kernel.org \
--cc=ruirui.yang@linux.dev \
--cc=saravanak@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.