libnvdimm, dax: fix 1GB-aligned namespaces vs physical misalignment

The following namespace configuration attempt:

# ndctl create-namespace -e namespace0.0 -m devdax -a 1G -f
libndctl: ndctl_dax_enable: dax0.1: failed to enable
Error: namespace0.0: failed to enable

failed to reconfigure namespace: No such device or address

...fails when the backing memory range is not physically aligned to 1G:

# cat /proc/iomem | grep Persistent
210000000-30fffffff : Persistent Memory (legacy)

In the above example the 4G persistent memory range starts and ends on a
256MB boundary.

We handle this case correctly when needing to handle cases that violate
section alignment (128MB) collisions against "System RAM", and we simply
need to extend that padding/truncation for the 1GB alignment use case.

Cc: <stable@vger.kernel.org>
Fixes: 315c562536c4 ("libnvdimm, pfn: add 'align' attribute...")
Reported-and-tested-by: Jane Chu <jane.chu@oracle.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Changed files
+12 -3
drivers
nvdimm
+12 -3
drivers/nvdimm/pfn_devs.c
··· 583 583 return altmap; 584 584 } 585 585 586 + static u64 phys_pmem_align_down(struct nd_pfn *nd_pfn, u64 phys) 587 + { 588 + return min_t(u64, PHYS_SECTION_ALIGN_DOWN(phys), 589 + ALIGN_DOWN(phys, nd_pfn->align)); 590 + } 591 + 586 592 static int nd_pfn_init(struct nd_pfn *nd_pfn) 587 593 { 588 594 u32 dax_label_reserve = is_nd_dax(&nd_pfn->dev) ? SZ_128K : 0; ··· 644 638 start = nsio->res.start; 645 639 size = PHYS_SECTION_ALIGN_UP(start + size) - start; 646 640 if (region_intersects(start, size, IORESOURCE_SYSTEM_RAM, 647 - IORES_DESC_NONE) == REGION_MIXED) { 641 + IORES_DESC_NONE) == REGION_MIXED 642 + || !IS_ALIGNED(start + resource_size(&nsio->res), 643 + nd_pfn->align)) { 648 644 size = resource_size(&nsio->res); 649 - end_trunc = start + size - PHYS_SECTION_ALIGN_DOWN(start + size); 645 + end_trunc = start + size - phys_pmem_align_down(nd_pfn, 646 + start + size); 650 647 } 651 648 652 649 if (start_pad + end_trunc) 653 - dev_info(&nd_pfn->dev, "%s section collision, truncate %d bytes\n", 650 + dev_info(&nd_pfn->dev, "%s alignment collision, truncate %d bytes\n", 654 651 dev_name(&ndns->dev), start_pad + end_trunc); 655 652 656 653 /*