On Sat, May 23, 2026 at 02:43:17AM -0700, Anisa Su wrote:
> From: Ira Weiny <[email protected]>
> 
> Dynamic Capacity (DC) DAX regions back their dax devices with per-extent
> resource children of the region, rather than carving from a single
> contiguous dax_region->res.  Allocating space for a DC dax device — on
> initial uuid claim of its backing extents and on shrink-to-0 during
> destroy — needs the same allocator the static case uses, but pointed at
> a different parent resource.
> 
> Factor the body of dev_dax_resize() into __dev_dax_resize(parent, ...)
> and add a dev_dax_resize_static() wrapper that passes dax_region->res
> for static (non-DC) regions.  alloc_dev_dax_range() gains the same
> parent parameter so it can operate under either kind of parent.
> 
Stale commit message :( __dev_dax_resize is introduced in a subsequent
commit. Updated commit message to reflect actual state.

> No functional change.
> 
> Reviewed-by: Jonathan Cameron <[email protected]>
> Reviewed-by: Dave Jiang <[email protected]>
> Signed-off-by: Ira Weiny <[email protected]>
> 
[snip]
> +
> +static ssize_t dev_dax_resize(struct dax_region *dax_region,
> +             struct dev_dax *dev_dax, resource_size_t size)
> +{
> +     resource_size_t avail = dax_region_avail_size(dax_region);
> +     resource_size_t dev_size = dev_dax_size(dev_dax);
> +     struct device *dev = &dev_dax->dev;
> +     resource_size_t to_alloc;
> +     resource_size_t alloc;
> +
> +     if (dev->driver)
> +             return -EBUSY;
> +     if (size == dev_size)
> +             return 0;
> +     if (size > dev_size && size - dev_size > avail)
> +             return -ENOSPC;
> +     if (size < dev_size)
> +             return dev_dax_shrink(dev_dax, size);
> +
> +     to_alloc = size - dev_size;
> +     if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc),
> +                     "resize of %pa misaligned\n", &to_alloc))
> +             return -ENXIO;
> +
> +retry:
> +     alloc = dev_dax_resize_static(&dax_region->res, dev_dax, to_alloc);
>From Sashiko: 
>https://sashiko.dev/#/patchset/cover.1779528761.git.anisa.su%40samsung.com?part=23

alloc is declared as unsigned resource_size_t. A negative errno isn't
returned correctly. Instead, the below line to_alloc -= alloc underflows
and the goto retry loops forever.

Fix: declare ssize_t alloc.

> +     if (alloc <= 0)
> +             return alloc;
>       to_alloc -= alloc;
>       if (to_alloc)
>               goto retry;
> @@ -1367,7 +1396,8 @@ static ssize_t mapping_store(struct device *dev, struct 
> device_attribute *attr,
>  
>       to_alloc = range_len(&r);
>       if (alloc_is_aligned(dev_dax, to_alloc))
> -             rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc, NULL);
> +             rc = alloc_dev_dax_range(&dax_region->res, dev_dax, r.start,
> +                                      to_alloc, NULL);
>       up_write(&dax_dev_rwsem);
>       up_write(&dax_region_rwsem);
>  
> @@ -1659,7 +1689,8 @@ static struct dev_dax *__devm_create_dev_dax(struct 
> dev_dax_data *data)
>       device_initialize(dev);
>       dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id);
>  
> -     rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, data->size, 
> NULL);
> +     rc = alloc_dev_dax_range(&dax_region->res, dev_dax, 
> dax_region->res.start,
> +                              data->size, NULL);
>       if (rc)
>               goto err_range;
>  
> -- 
> 2.43.0
> 

Reply via email to