Skip to content

Commit 2e5021c

Browse files
tyhicksdjbw
authored andcommitted
libnvdimm/region: Allow setting align attribute on regions without mappings
The alignment constraint for namespace creation in a region was increased, from 2M to 16M, for non-PowerPC architectures in v5.7 with commit 2522afb ("libnvdimm/region: Introduce an 'align' attribute"). The thought behind the change was that region alignment should be uniform across all architectures and, since PowerPC had the largest alignment constraint of 16M, all architectures should conform to that alignment. The change regressed namespace creation in pre-defined regions that relied on 2M alignment but a workaround was provided in the form of a sysfs attribute, named 'align', that could be adjusted to a non-default alignment value. However, the sysfs attribute's store function returned an error (-ENXIO) when userspace attempted to change the alignment of a region that had no mappings. This affected 2M aligned regions of volatile memory that were defined in a device tree using "pmem-region" and created by the of_pmem_region_driver, since those regions do not contain mappings (ndr_mappings is 0). Allow userspace to set the align attribute on pre-existing regions that do not have mappings so that namespaces can still be within those regions, despite not being aligned to 16M. Link: https://lore.kernel.org/lkml/CA+CK2bDJ3hrWoE91L2wpAk+Yu0_=GtYw=4gLDDD7mxs321b_aA@mail.gmail.com Fixes: 2522afb ("libnvdimm/region: Introduce an 'align' attribute") Signed-off-by: Tyler Hicks <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 23a2d0c commit 2e5021c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/nvdimm/region_devs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,24 +509,22 @@ static ssize_t align_store(struct device *dev,
509509
{
510510
struct nd_region *nd_region = to_nd_region(dev);
511511
unsigned long val, dpa;
512-
u32 remainder;
512+
u32 mappings, remainder;
513513
int rc;
514514

515515
rc = kstrtoul(buf, 0, &val);
516516
if (rc)
517517
return rc;
518518

519-
if (!nd_region->ndr_mappings)
520-
return -ENXIO;
521-
522519
/*
523520
* Ensure space-align is evenly divisible by the region
524521
* interleave-width because the kernel typically has no facility
525522
* to determine which DIMM(s), dimm-physical-addresses, would
526523
* contribute to the tail capacity in system-physical-address
527524
* space for the namespace.
528525
*/
529-
dpa = div_u64_rem(val, nd_region->ndr_mappings, &remainder);
526+
mappings = max_t(u32, 1, nd_region->ndr_mappings);
527+
dpa = div_u64_rem(val, mappings, &remainder);
530528
if (!is_power_of_2(dpa) || dpa < PAGE_SIZE
531529
|| val > region_size(nd_region) || remainder)
532530
return -EINVAL;

0 commit comments

Comments
 (0)