All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Price" <gourry@gourry.net>
Cc: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v7 08/10] dax/kmem: extract hotplug/hotremove helper functions
Date: Sun, 12 Jul 2026 15:54:10 +0000	[thread overview]
Message-ID: <20260712155411.00D391F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260712154505.3564379-9-gourry@gourry.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] If a DAX device has multiple ranges and at least one is too small to be aligned, removing the device will unconditionally leak driver data and memory group registrations.
--

--- Patch [8]: [PATCH v7 08/10] dax/kmem: extract hotplug/hotremove helper functions ---
commit 44ad562618b0448a09ed81ab105fa4c8551b6718
Author: Gregory Price <gourry@gourry.net>

dax/kmem: extract hotplug/hotremove helper functions

Refactor kmem _probe() _remove() by extracting init, cleanup, hotplug,
and hot-remove logic into separate helper functions. This splits the
hotplug and init phases to have resources available for hot-add, while
enabling future granular hotplug operation control.

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>

> diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
> index 38ed5c4e9c83d..6174f7d3d05bd 100644
> --- a/drivers/dax/kmem.c
> +++ b/drivers/dax/kmem.c

[ ... ]

> +static int dax_kmem_do_hotremove(struct dev_dax *dev_dax,
> +				 struct dax_kmem_data *data)
> +{
> +	struct device *dev = &dev_dax->dev;
> +	int i, success = 0;
> +
> +	for (i = 0; i < dev_dax->nr_range; i++) {
> +		struct range range;
> +		int rc;
> +
> +		rc = dax_kmem_range(dev_dax, i, &range);
> +		if (rc)
> +			continue;
> +
> +		/* range was never added during probe, count as removed */
> +		if (!data->res[i]) {
> +			success++;
> +			continue;
> +		}
> +
> +		rc = remove_memory(range.start, range_len(&range));
> +		if (rc == 0) {
> +			/* Release the resource for the successfully removed range */
> +			remove_resource(data->res[i]);
> +			kfree(data->res[i]);
> +			data->res[i] = NULL;
> +			success++;
> +			continue;
> +		}
> +		any_hotremove_failed = true;
> +		dev_err(dev, "mapping%d: %#llx-%#llx hotremove failed\n",
> +			i, range.start, range.end);
> +	}
> +
> +	return success;
> +}

[ ... ]

> @@ -208,7 +354,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
>  #ifdef CONFIG_MEMORY_HOTREMOVE
>  static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
>  {
> -	int i, success = 0;
> +	int success;
>  	int node = dev_dax->target_node;
>  	struct device *dev = &dev_dax->dev;
>  	struct dax_kmem_data *data = dev_get_drvdata(dev);
> @@ -219,48 +365,25 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
>  	 * there is no way to hotremove this memory until reboot because device
>  	 * unbind will succeed even if we return failure.
>  	 */
> -	for (i = 0; i < dev_dax->nr_range; i++) {
> -		struct range range;
> -		int rc;
> -
> -		rc = dax_kmem_range(dev_dax, i, &range);
> -		if (rc)
> -			continue;
> -
> -		/* range was never added during probe */
> -		if (!data->res[i]) {
> -			success++;
> -			continue;
> -		}
> -
> -		rc = remove_memory(range.start, range_len(&range));
> -		if (rc == 0) {
> -			remove_resource(data->res[i]);
> -			kfree(data->res[i]);
> -			data->res[i] = NULL;
> -			success++;
> -			continue;
> -		}
> -		any_hotremove_failed = true;
> -		dev_err(dev,
> -			"mapping%d: %#llx-%#llx cannot be hotremoved until the next reboot\n",
> -				i, range.start, range.end);
> +	success = dax_kmem_do_hotremove(dev_dax, data);
> +	if (success < dev_dax->nr_range) {
> +		dev_err(dev, "Hotplug regions stuck online until reboot\n");
> +		return;
>  	}

[Severity: High]
This is a pre-existing issue, but does this logic handle unaligned ranges
correctly during device unbind?

If a DAX device is created with a memory range smaller than the block
alignment, dax_kmem_range() returns an error (like -ENOSPC) during probe,
but the device can still probe successfully.

During removal, dax_kmem_do_hotremove() will also get an error from
dax_kmem_range() for that small range and skip incrementing the success
counter.

This causes success to evaluate as strictly less than dev_dax->nr_range,
resulting in an early return here.

Since device unbind can be triggered from userspace, does this early return
unconditionally leak the memory group registrations, device name string,
and driver data on every unbind for devices with unaligned ranges?

>  
> -	if (success >= dev_dax->nr_range) {
> -		memory_group_unregister(data->mgid);
> -		kfree(data->res_name);
> -		kfree(data);
> -		dev_set_drvdata(dev, NULL);

[ ... ]

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

  reply	other threads:[~2026-07-12 15:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 15:44 [PATCH v7 00/10] dax/kmem: atomic whole-device hotplug via sysfs Gregory Price
2026-07-12 15:44 ` [PATCH v7 01/10] mm/memory: add memory_block_aligned_range() helper Gregory Price
2026-07-12 15:52   ` sashiko-bot
2026-07-12 15:44 ` [PATCH v7 02/10] mm/memory_hotplug: add mhp_online_type_to_str() and export string helpers Gregory Price
2026-07-12 15:44 ` [PATCH v7 03/10] mm/memory_hotplug: pass online_type to online_memory_block() via arg Gregory Price
2026-07-12 15:53   ` sashiko-bot
2026-07-12 15:44 ` [PATCH v7 04/10] mm/memory_hotplug: export mhp_get_default_online_type Gregory Price
2026-07-12 15:56   ` sashiko-bot
2026-07-12 15:44 ` [PATCH v7 05/10] mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg Gregory Price
2026-07-12 15:45 ` [PATCH v7 06/10] mm/memory_hotplug: add offline_and_remove_memory_ranges() Gregory Price
2026-07-12 15:53   ` sashiko-bot
2026-07-12 15:45 ` [PATCH v7 07/10] dax/kmem: resolve default online type at probe time Gregory Price
2026-07-12 15:56   ` sashiko-bot
2026-07-12 15:45 ` [PATCH v7 08/10] dax/kmem: extract hotplug/hotremove helper functions Gregory Price
2026-07-12 15:54   ` sashiko-bot [this message]
2026-07-12 15:45 ` [PATCH v7 09/10] dax/kmem: add sysfs interface for atomic whole-device hotplug Gregory Price
2026-07-12 15:45 ` [PATCH v7 10/10] selftests/dax: add dax/kmem hotplug sysfs regression test Gregory Price
2026-07-12 16:48 ` [PATCH v7 00/10] 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=20260712155411.00D391F000E9@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.