From: sashiko-bot@kernel.org
To: "Gregory Price" <gourry@gourry.net>
Cc: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v5 5/9] mm/memory_hotplug: offline_and_remove_memory_ranges()
Date: Wed, 24 Jun 2026 15:11:55 +0000 [thread overview]
Message-ID: <20260624151155.E973D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260624145744.3532049-6-gourry@gourry.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Failure in Phase 2 causes partial memory unplug without structural rollback, leading to permanently unmapped kernel memory and array pointer desynchronization.
--
commit e98e55bd875fd49e00562bd6591c9e44420c4e52
Author: Gregory Price <gourry@gourry.net>
mm/memory_hotplug: offline_and_remove_memory_ranges()
This commit adds offline_and_remove_memory_ranges() to offline and remove
multiple memory ranges atomically under a single lock_device_hotplug(). It
splits the operation into a phase that offlines all ranges, followed by a
phase that removes them, reverting the offline step if any failure occurs.
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index a66346def504b..7d56e0c6ede0c 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
[ ... ]
> @@ -2429,58 +2429,98 @@ static int try_reonline_memory_block(struct memory_block *mem, void *arg)
[ ... ]
> +int offline_and_remove_memory_ranges(const struct range *ranges, int nr_ranges)
> +{
[ ... ]
> + /*
> + * Phase 2: Remove each range. This essentially cannot fail as we hold
> + * the hotplug lock . WARN if that assumption is ever broken.
> + */
> if (!rc) {
> - rc = try_remove_memory(start, size);
> - if (rc)
> - pr_err("%s: Failed to remove memory: %d", __func__, rc);
> + for (i = 0; i < nr_ranges; i++) {
> + rc = try_remove_memory(ranges[i].start,
> + range_len(&ranges[i]));
> + if (WARN_ON_ONCE(rc)) {
> + pr_err("%s: Failed to remove memory: %d",
> + __func__, rc);
> + break;
> + }
> + }
> }
>
> - /*
> - * Rollback what we did. While memory onlining might theoretically fail
> - * (nacked by a notifier), it barely ever happens.
> - */
> + /* On fail: roll back. Blocks that were already offline are skipped */
> if (rc) {
> tmp = online_types;
> - walk_memory_blocks(start, size, &tmp,
> - try_reonline_memory_block);
> + for (i = 0; i < nr_ranges; i++)
> + walk_memory_blocks(ranges[i].start,
> + range_len(&ranges[i]), &tmp,
> + try_reonline_memory_block);
[Severity: High]
What happens if try_remove_memory() fails for a subsequent range after
successfully removing an earlier one?
If rc is set and we break out of the phase 2 loop, we enter this rollback
path. For the ranges that were already successfully removed,
walk_memory_blocks() will skip their blocks because memory_block_get()
returns NULL:
drivers/base/memory.c:walk_memory_blocks() {
...
for (block_id = start_block_id; block_id <= end_block_id; block_id++) {
mem = memory_block_get(block_id);
if (!mem)
continue;
ret = func(mem, arg);
...
}
Because try_reonline_memory_block() is not called for these skipped blocks,
the tmp pointer into online_types won't be advanced. Could this cause the
rollback to apply the saved states of the removed blocks to the remaining
valid blocks, corrupting their state?
> }
> unlock_device_hotplug();
>
> kfree(online_types);
> return rc;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260624145744.3532049-1-gourry@gourry.net?part=5
next prev parent reply other threads:[~2026-06-24 15:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 14:57 [PATCH v5 0/9] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price
2026-06-24 14:57 ` [PATCH v5 1/9] mm/memory: add memory_block_aligned_range() helper Gregory Price
2026-06-24 15:08 ` sashiko-bot
2026-06-24 14:57 ` [PATCH v5 2/9] mm/memory_hotplug: pass online_type to online_memory_block() via arg Gregory Price
2026-06-24 16:28 ` Gupta, Pankaj
2026-06-24 14:57 ` [PATCH v5 3/9] mm/memory_hotplug: export mhp_get_default_online_type Gregory Price
2026-06-24 14:57 ` [PATCH v5 4/9] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg Gregory Price
2026-06-24 16:41 ` Gupta, Pankaj
2026-06-24 14:57 ` [PATCH v5 5/9] mm/memory_hotplug: offline_and_remove_memory_ranges() Gregory Price
2026-06-24 15:11 ` sashiko-bot [this message]
2026-06-24 14:57 ` [PATCH v5 6/9] dax: plumb hotplug online_type through dax Gregory Price
2026-06-24 15:12 ` sashiko-bot
2026-06-24 14:57 ` [PATCH v5 7/9] dax/kmem: extract hotplug/hotremove helper functions Gregory Price
2026-06-24 15:09 ` sashiko-bot
2026-06-24 14:57 ` [PATCH v5 8/9] dax/kmem: add sysfs interface for atomic whole-device hotplug Gregory Price
2026-06-24 15:11 ` sashiko-bot
2026-06-24 14:57 ` [PATCH v5 9/9] selftests/dax: add dax/kmem hotplug sysfs regression test Gregory Price
2026-06-24 15:12 ` sashiko-bot
2026-06-24 18:59 ` [PATCH v5 0/9] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price
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=20260624151155.E973D1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gourry@gourry.net \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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.