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)" <[email protected]>
>
> ---
> 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)
>