All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Price" <gourry@gourry.net>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v4 5/9] mm/memory_hotplug: add multi-range hotunplug
Date: Fri, 05 Jun 2026 21:30:36 +0000	[thread overview]
Message-ID: <20260605213037.46CA71F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260605211911.2160954-6-gourry@gourry.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] If `try_remove_memory()` fails during Phase 2, the rollback phase irrevocably corrupts the state array and breaks the 'all-or-nothing' guarantee.
--

commit 8e30dd8a7c852dc51179b28a0c0a3841cc1be525
Author: Gregory Price <gourry@gourry.net>

mm/memory_hotplug: add multi-range hotunplug

This commit adds offline_and_remove_memory_ranges() to offline and remove
multiple memory ranges atomically. It offlines all ranges in phase 1, and
removes them in phase 2, falling back to restoring online types if failures
occur.

> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 7d145217adc6b..e486d35c22b2c 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c

[ ... ]

> +	/*
> +	 * Phase 2: only once everything is offline, remove it.  This cannot
> +	 * fail as the memory can no longer be onlined in the meantime.
> +	 */
> +	if (!rc) {
> +		for (i = 0; i < nr_ranges; i++) {
> +			rc = try_remove_memory(ranges[i].start,
> +					       range_len(&ranges[i]));
> +			if (rc) {
> +				pr_err("%s: Failed to remove memory: %d",
> +				       __func__, rc);
> +				break;
> +			}
> +		}
> +	}

[Severity: High]
The comment states that this cannot fail, but try_remove_memory() can return
errors, for example if memory_blocks_have_altmaps() returns -EINVAL.

If try_remove_memory() succeeds for the first range but fails for a subsequent
range, the blocks for the first range are irrevocably removed. Does this leave
the system in a partially removed state, breaking the all-or-nothing guarantee?

> +
> +	/*
> +	 * Roll back the offlining if anything failed.  Blocks we never offlined
> +	 * are marked MMOP_OFFLINE and skipped by try_reonline_memory_block().
> +	 */
> +	if (rc) {
> +		tmp = online_types;
> +		for (i = 0; i < nr_ranges; i++)
> +			walk_memory_blocks(ranges[i].start,
> +					   range_len(&ranges[i]), &tmp,
> +					   try_reonline_memory_block);
> +	}

[Severity: High]
If we enter this rollback path after a partial failure in phase 2, will the
state array tracking become corrupted?

Since the first range was physically removed, memory_block_get() inside
walk_memory_blocks() will return NULL and skip try_reonline_memory_block().
Because the callback is skipped, the tmp pointer will not be advanced for
those blocks.

When the rollback loop moves to the next range, it will read from the beginning
of tmp, incorrectly applying the saved states of the first range to the blocks
of the second range. Can this desynchronization be avoided?

> +	unlock_device_hotplug();
> +
> +	kfree(online_types);
> +	return rc;
> +}
> +EXPORT_SYMBOL_GPL(offline_and_remove_memory_ranges);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260605211911.2160954-1-gourry@gourry.net?part=5

  reply	other threads:[~2026-06-05 21:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 21:19 [PATCH v4 0/9] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price
2026-06-05 21:19 ` [PATCH v4 1/9] mm/memory: add memory_block_aligned_range() helper Gregory Price
2026-06-09  9:50   ` David Hildenbrand (Arm)
2026-06-05 21:19 ` [PATCH v4 2/9] mm/memory_hotplug: pass online_type to online_memory_block() via arg Gregory Price
2026-06-05 21:19 ` [PATCH v4 3/9] mm/memory_hotplug: export mhp_get_default_online_type Gregory Price
2026-06-05 21:29   ` sashiko-bot
2026-06-05 21:43     ` Gregory Price
2026-06-09  9:52   ` David Hildenbrand (Arm)
2026-06-09 15:11     ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 4/9] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg Gregory Price
2026-06-09  9:55   ` David Hildenbrand (Arm)
2026-06-09 15:12     ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 5/9] mm/memory_hotplug: add multi-range hotunplug Gregory Price
2026-06-05 21:30   ` sashiko-bot [this message]
2026-06-09 10:06   ` David Hildenbrand (Arm)
2026-06-09 15:15     ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 6/9] dax: plumb hotplug online_type through dax Gregory Price
2026-06-05 21:31   ` sashiko-bot
2026-06-05 21:54     ` Gregory Price
2026-06-09 10:21       ` David Hildenbrand (Arm)
2026-06-09 15:33         ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 7/9] dax/kmem: extract hotplug/hotremove helper functions Gregory Price
2026-06-05 21:36   ` sashiko-bot
2026-06-05 22:03     ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 8/9] dax/kmem: add sysfs interface for atomic hotplug Gregory Price
2026-06-05 21:37   ` sashiko-bot
2026-06-09 10:26   ` David Hildenbrand (Arm)
2026-06-09 15:35     ` Gregory Price
2026-06-09 18:11       ` David Hildenbrand (Arm)
2026-06-09 18:19         ` Gregory Price
2026-06-09 18:22           ` David Hildenbrand (Arm)
2026-06-09 18:33             ` Gregory Price
2026-06-05 21:19 ` [PATCH v4 9/9] selftests/dax: add dax/kmem hotplug sysfs regression test Gregory Price
2026-06-05 21:34   ` sashiko-bot

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=20260605213037.46CA71F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gourry@gourry.net \
    --cc=linux-cxl@vger.kernel.org \
    --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.