On Thu, Jul 16, 2020 at 10:31 AM Joao Martins <joao.m.martins@xxxxxxxxxx> wrote: > > Introduce a device align attribute. While doing so, > rename the region align attribute to be more explicitly > named as so, but keep it named as @align to retain the API > for tools like daxctl. > > Changes on align may not always be valid, when say certain > mappings were created with 2M and then we switch to 1G. So, we > validate all ranges against the new value being attempted, > post resizing. > > Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx> > --- > drivers/dax/bus.c | 101 +++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 92 insertions(+), 9 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 2578651c596e..eb384dd6a376 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -230,14 +230,15 @@ static ssize_t region_size_show(struct device *dev, > static struct device_attribute dev_attr_region_size = __ATTR(size, 0444, > region_size_show, NULL); > > -static ssize_t align_show(struct device *dev, > +static ssize_t region_align_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > struct dax_region *dax_region = dev_get_drvdata(dev); > > return sprintf(buf, "%u\n", dax_region->align); > } > -static DEVICE_ATTR_RO(align); > +static struct device_attribute dev_attr_region_align = > + __ATTR(align, 0400, region_align_show, NULL); > > #define for_each_dax_region_resource(dax_region, res) \ > for (res = (dax_region)->res.child; res; res = res->sibling) > @@ -488,7 +489,7 @@ static umode_t dax_region_visible(struct kobject *kobj, struct attribute *a, > static struct attribute *dax_region_attributes[] = { > &dev_attr_available_size.attr, > &dev_attr_region_size.attr, > - &dev_attr_align.attr, > + &dev_attr_region_align.attr, > &dev_attr_create.attr, > &dev_attr_seed.attr, > &dev_attr_delete.attr, > @@ -855,14 +856,13 @@ static ssize_t size_show(struct device *dev, > return sprintf(buf, "%llu\n", size); > } > > -static bool alloc_is_aligned(struct dax_region *dax_region, > - resource_size_t size) > +static bool alloc_is_aligned(resource_size_t size, unsigned long align) For type safety, let's make this take @dev_dax as a parameter. For the dev_dax_set_align() case I think it is ok to provisionally adjust dev_dax->align under the lock before entry and revert to the old alignment on failure. I can fix that up locally on applying.