Linux CXL
 help / color / mirror / Atom feed
* [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks
@ 2026-10-28 21:21 Gregory Price (Meta)
  2026-10-29 23:24 ` Dave Jiang
  2026-10-30  1:42 ` Alison Schofield
  0 siblings, 2 replies; 3+ messages in thread
From: Gregory Price (Meta) @ 2026-10-28 21:21 UTC (permalink / raw)
  To: nvdimm, alison.schofield; +Cc: linux-cxl

daxctl_memory_online_with_zone() is meant to scan the device's blocks
after onlining them and fail with -EBUSY if any block is not in the
requested zone: an agent such as an auto-online policy or a udev rule
may have onlined some blocks first, into a zone daxctl did not ask for.
online_one_memblock() relies on that scan, it ignores a failed write
for a block that someone else onlined ("There will be a full scan for
zone correctness later").

But daxctl_memory_op() returns the number of blocks it onlined, and the
function returns early on any non-zero value, so the scan only ever
runs when no block was onlined at all.  Whenever daxctl does online
memory, a zone mismatch goes unreported.

Example: 
  memory_hotplug.online_policy=auto-movable
  reconfigure-device --no-movable -m system-ram

  => reports success with the memory in ZONE_MOVABLE.

Return early only on errors, and return the number of onlined blocks
after the scan.

Fixes: 0542201b5902 ("daxctl: detect races when onlining memory blocks")
Signed-off-by: "Gregory Price (Meta)" <gourry@gourry.net>

---
 daxctl/lib/libdaxctl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 01b1915..f4b2fda 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -1691,7 +1691,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
 	struct daxctl_dev *dev = daxctl_memory_get_dev(mem);
 	const char *devname = daxctl_dev_get_devname(dev);
 	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
-	int rc;
+	int rc, count;
 
 	switch (zone) {
 	case MEM_ZONE_MOVABLE:
@@ -1704,8 +1704,9 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
 		err(ctx, "%s: BUG: invalid zone for onlining\n", devname);
 		rc = -EINVAL;
 	}
-	if (rc)
+	if (rc < 0)
 		return rc;
+	count = rc;
 
 	/*
 	 * Detect any potential races when blocks were being brought online by
@@ -1724,7 +1725,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
 		return -EBUSY;
 	}
 
-	return rc;
+	return count;
 }
 
 DAXCTL_EXPORT int daxctl_memory_online(struct daxctl_memory *mem)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks
  2026-10-28 21:21 [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks Gregory Price (Meta)
@ 2026-10-29 23:24 ` Dave Jiang
  2026-10-30  1:42 ` Alison Schofield
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Jiang @ 2026-10-29 23:24 UTC (permalink / raw)
  To: Gregory Price (Meta), nvdimm, alison.schofield; +Cc: linux-cxl



On 10/28/26 2:21 PM, Gregory Price (Meta) wrote:
> daxctl_memory_online_with_zone() is meant to scan the device's blocks
> after onlining them and fail with -EBUSY if any block is not in the
> requested zone: an agent such as an auto-online policy or a udev rule
> may have onlined some blocks first, into a zone daxctl did not ask for.
> online_one_memblock() relies on that scan, it ignores a failed write
> for a block that someone else onlined ("There will be a full scan for
> zone correctness later").
> 
> But daxctl_memory_op() returns the number of blocks it onlined, and the
> function returns early on any non-zero value, so the scan only ever
> runs when no block was onlined at all.  Whenever daxctl does online
> memory, a zone mismatch goes unreported.
> 
> Example: 
>   memory_hotplug.online_policy=auto-movable
>   reconfigure-device --no-movable -m system-ram
> 
>   => reports success with the memory in ZONE_MOVABLE.
> 
> Return early only on errors, and return the number of onlined blocks
> after the scan.
> 
> Fixes: 0542201b5902 ("daxctl: detect races when onlining memory blocks")
> Signed-off-by: "Gregory Price (Meta)" <gourry@gourry.net>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> 
> ---
>  daxctl/lib/libdaxctl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
> index 01b1915..f4b2fda 100644
> --- a/daxctl/lib/libdaxctl.c
> +++ b/daxctl/lib/libdaxctl.c
> @@ -1691,7 +1691,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  	struct daxctl_dev *dev = daxctl_memory_get_dev(mem);
>  	const char *devname = daxctl_dev_get_devname(dev);
>  	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
> -	int rc;
> +	int rc, count;
>  
>  	switch (zone) {
>  	case MEM_ZONE_MOVABLE:
> @@ -1704,8 +1704,9 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  		err(ctx, "%s: BUG: invalid zone for onlining\n", devname);
>  		rc = -EINVAL;
>  	}
> -	if (rc)
> +	if (rc < 0)
>  		return rc;
> +	count = rc;
>  
>  	/*
>  	 * Detect any potential races when blocks were being brought online by
> @@ -1724,7 +1725,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  		return -EBUSY;
>  	}
>  
> -	return rc;
> +	return count;
>  }
>  
>  DAXCTL_EXPORT int daxctl_memory_online(struct daxctl_memory *mem)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks
  2026-10-28 21:21 [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks Gregory Price (Meta)
  2026-10-29 23:24 ` Dave Jiang
@ 2026-10-30  1:42 ` Alison Schofield
  1 sibling, 0 replies; 3+ messages in thread
From: Alison Schofield @ 2026-10-30  1:42 UTC (permalink / raw)
  To: Gregory Price (Meta); +Cc: nvdimm, linux-cxl

On Wed, Oct 28, 2026 at 02:21:23PM -0700, Gregory Price (Meta) wrote:
> daxctl_memory_online_with_zone() is meant to scan the device's blocks
> after onlining them and fail with -EBUSY if any block is not in the
> requested zone: an agent such as an auto-online policy or a udev rule
> may have onlined some blocks first, into a zone daxctl did not ask for.
> online_one_memblock() relies on that scan, it ignores a failed write
> for a block that someone else onlined ("There will be a full scan for
> zone correctness later").
> 
> But daxctl_memory_op() returns the number of blocks it onlined, and the
> function returns early on any non-zero value, so the scan only ever
> runs when no block was onlined at all.  Whenever daxctl does online
> memory, a zone mismatch goes unreported.
> 
> Example: 
>   memory_hotplug.online_policy=auto-movable
>   reconfigure-device --no-movable -m system-ram
> 
>   => reports success with the memory in ZONE_MOVABLE.

Hi Gregory,

Does writing "online" let the kernels auto-movable policy select
ZONE_MOVABLE? I'm wondering if this is a race, or if daxctl should
be using "online_kernel" for --no-movable.



> 
> Return early only on errors, and return the number of onlined blocks
> after the scan.
> 
> Fixes: 0542201b5902 ("daxctl: detect races when onlining memory blocks")
> Signed-off-by: "Gregory Price (Meta)" <gourry@gourry.net>
> 
> ---
>  daxctl/lib/libdaxctl.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
> index 01b1915..f4b2fda 100644
> --- a/daxctl/lib/libdaxctl.c
> +++ b/daxctl/lib/libdaxctl.c
> @@ -1691,7 +1691,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  	struct daxctl_dev *dev = daxctl_memory_get_dev(mem);
>  	const char *devname = daxctl_dev_get_devname(dev);
>  	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
> -	int rc;
> +	int rc, count;
>  
>  	switch (zone) {
>  	case MEM_ZONE_MOVABLE:
> @@ -1704,8 +1704,9 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  		err(ctx, "%s: BUG: invalid zone for onlining\n", devname);
>  		rc = -EINVAL;
>  	}
> -	if (rc)
> +	if (rc < 0)
>  		return rc;

What happens if the kernel places memory in ZONE_DMA32?
Will that lead to a MEM_ZONE_UNKNOWN and then an -EBUSY?

-- Alison


> +	count = rc;
>  
>  	/*
>  	 * Detect any potential races when blocks were being brought online by
> @@ -1724,7 +1725,7 @@ static int daxctl_memory_online_with_zone(struct daxctl_memory *mem,
>  		return -EBUSY;
>  	}
>  
> -	return rc;
> +	return count;
>  }
>  
>  DAXCTL_EXPORT int daxctl_memory_online(struct daxctl_memory *mem)
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-30  1:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 21:21 [ndctl PATCH] libdaxctl: check the zone of onlined memory blocks Gregory Price (Meta)
2026-10-29 23:24 ` Dave Jiang
2026-10-30  1:42 ` Alison Schofield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox