On Wed, Oct 28, 2026 at 06:55:44AM -0700, Gregory Price wrote:
> On 2026-10-22 12:56 -0700, Alison Schofield wrote:
> > memblock_in_dev() treats a DAX device as one contiguous physical address
> > range, even when the device has multiple ranges separated by gaps. This
> > misses blocks in later ranges and may incorrectly include blocks belonging
> > to another device.
> >
> > Memory block counts and per-block online/offline operations use this
> > lookup, so daxctl may operate on memory outside the requested device.
> >
> > Match blocks against each individual mapping, retaining the single-range
> > fallback for older kernels.
> >
> > Fixes: e8bf803e359b ("libdaxctl: add a 'daxctl_memory' object for memory
> > based operations")
> > Signed-off-by: Alison Schofield <[email protected]>
> > ---
> > daxctl/lib/libdaxctl.c | 15 +++++++++++++--
> > 1 file changed, 13 insertions(+), 2 deletions(-)
> >
>
> Ran through an analysis and testing round with my clanker, seems to want
> this fixup. Looked reasonable, just passing it along.
Thanks! I've applied your fixup below in v2.
>
> Will get proper tags for you this week.
>
> -- >8 --
>
> Counting an unplugged device's blocks can return -ENOENT when its node
> still has unrelated RAM. mappings_init() leaves ENOENT after probing
> past the final mapping, and unrelated blocks take continue before the
> scan resets errno. End-of-directory can preserve that stale error.
>
> Clear errno immediately before each readdir() call so the final errno
> check describes that read alone. Errors from block operations still
> exit through out_dir with their saved return value.
>
> This corrects "libdaxctl: match memory blocks against each dax device
> mapping". Returning real node-directory entries with memory entries
> last reproduces the error in the posted series and verifies the fix.
>
> ---
> daxctl/lib/libdaxctl.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
> index e106fff..c154db9 100644
> --- a/daxctl/lib/libdaxctl.c
> +++ b/daxctl/lib/libdaxctl.c
> @@ -1716,8 +1716,8 @@ static int daxctl_memory_op(struct daxctl_memory *mem,
> enum memory_op op)
> return rc;
> }
>
> - errno = 0;
> - while ((de = readdir(node_dir)) != NULL) {
> + /* Helpers may leave errno set even when a block is skipped. */
> + for (errno = 0; (de = readdir(node_dir)) != NULL; errno = 0) {
> if (strncmp(de->d_name, "memory", 6) == 0) {
> if (strncmp(de->d_name, "memory_", 7) == 0)
> continue;
> @@ -1734,7 +1734,6 @@ static int daxctl_memory_op(struct daxctl_memory *mem,
> enum memory_op op)
> if (rc == 0)
> count++;
> }
> - errno = 0;
> }
>
> if (status_flags & MEM_ST_ZONE_INCONSISTENT)
>
> --
> Gregory Price (Meta) <[email protected]>