On Thu, Sep 24, 2026 at 10:50:35AM +0800, Muchun Song wrote:
> dev_dax->align describes the page size used by a Device DAX mapping.
> Both the start and size of every range must therefore be aligned to it;
> otherwise the starting PFN cannot represent a naturally aligned page of
> that size.
> 
> Only range sizes are currently validated. A dynamic device can therefore
> select a large-page alignment and allocate a range whose start is not
> naturally aligned to that page size. The device binds successfully, but a
> subsequent write to a userspace mapping may trigger a kernel panic.
> 
> The automatic resize path can also split a size-aligned request across
> arbitrary free gaps. When devices with different alignments fragment a
> region, this can extend a range by less than its alignment. A later
> allocation then fails, leaving the failed resize partially applied.
> 
> Validate both the start and size of allocated and adjusted ranges. Make
> the resize path account only for usable aligned space before changing any
> ranges, and skip gaps that cannot satisfy the device alignment. Initialize
> the device alignment before allocating its initial range so that all
> allocations use the same validation. Perform size validation under the
> same locks as alignment updates so the alignment cannot change before
> resizing begins.
> 
> A mapping with an unaligned start is now rejected with -EINVAL, while a
> naturally aligned mapping still binds successfully.

Hi Muchun,

The commit message could be condensed. I think the two failure scenarios and
the changes needed to address them are sufficient.Implementation details
are excessive.

But before that, need to address something else, see below-

> 
> Fixes: 6d82120f4156 ("device-dax: add an 'align' attribute")
> Assisted-by: LLM
> Signed-off-by: Muchun Song <[email protected]>
> ---
> v3:
> - Serialize size alignment validation with alignment updates to avoid a
>   partial shrink after a concurrent alignment change (reported by Sashiko)
> - Document the size validation serialization in the commit message
> 
> v2:
> - Keep the alloc_is_aligned() name to avoid unrelated helper renaming
>   (suggested by Dave Jiang)
> - Move this patch after the mapping error reporting fix for independent
>   backports (suggested by Dave Jiang)
> ---
>  drivers/dax/bus.c | 144 +++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 109 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c

snip


> @@ -1468,6 +1542,7 @@ static struct dev_dax *__devm_create_dev_dax(struct 
> dev_dax_data *data)
>               return ERR_PTR(-ENOMEM);
>  
>       dev_dax->region = dax_region;
> +     dev_dax->align = dax_region->align;


Moving this assignment means that initial allocations for static
pmem regions now go through the new range_is_aligned() check.

I'm concerned this may reject existing namespaces with 4K alignment.
nd_pfn_validate() doesn't require the data offset to be aligned to
memremap_compat_align(), and older namespace formats may have offsets
that don't meet that requirement.

Can you check whether an existing namespace with such an offset
would still probe successfully after this change?

I'm also wondering whether the initial range needs to satisfy
memremap_compat_align(), or whether checking dev_dax->align is
sufficient here.

Have you also tested the static pmem Device DAX path, particularly
with namespaces created by older kernels? The reproducer described
in the cover letter addresses the alignment failure, but I'd like
to make sure we aren't introducing a regression for existing
namespaces.

-- Alison



>       if (is_static(dax_region)) {
>               if (dev_WARN_ONCE(parent, data->id < 0,
>                               "dynamic id specified to static region\n")) {
> @@ -1526,7 +1601,6 @@ static struct dev_dax *__devm_create_dev_dax(struct 
> dev_dax_data *data)
>  
>       dev_dax->dax_dev = dax_dev;
>       dev_dax->target_node = dax_region->target_node;
> -     dev_dax->align = dax_region->align;
>       ida_init(&dev_dax->ida);
>  
>       dev_dax->memmap_on_memory = data->memmap_on_memory;
> -- 
> 2.54.0
> 

Reply via email to