Skip to content

Commit 11a3581

Browse files
committed
libnvdimm/pfn: Account for PAGE_SIZE > info-block-size in nd_pfn_init()
Similar to "libnvdimm: Fix altmap reservation size calculation" provide for a reservation of a full page worth of info block space at info-block establishment time. Typically there is already slack in the padding from honoring the default 2MB alignment, but provide for a reservation for corner case configurations that would otherwise fit. Cc: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 07464e8 commit 11a3581

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/nvdimm/pfn_devs.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns)
580580
}
581581
EXPORT_SYMBOL(nd_pfn_probe);
582582

583+
static u32 info_block_reserve(void)
584+
{
585+
return ALIGN(SZ_8K, PAGE_SIZE);
586+
}
587+
583588
/*
584589
* We hotplug memory at section granularity, pad the reserved area from
585590
* the previous section base to the namespace base address.
@@ -593,7 +598,7 @@ static unsigned long init_altmap_base(resource_size_t base)
593598

594599
static unsigned long init_altmap_reserve(resource_size_t base)
595600
{
596-
unsigned long reserve = PFN_UP(SZ_8K);
601+
unsigned long reserve = info_block_reserve() >> PAGE_SHIFT;
597602
unsigned long base_pfn = PHYS_PFN(base);
598603

599604
reserve += base_pfn - PFN_SECTION_ALIGN_DOWN(base_pfn);
@@ -608,6 +613,7 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap)
608613
u64 offset = le64_to_cpu(pfn_sb->dataoff);
609614
u32 start_pad = __le32_to_cpu(pfn_sb->start_pad);
610615
u32 end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
616+
u32 reserve = info_block_reserve();
611617
struct nd_namespace_common *ndns = nd_pfn->ndns;
612618
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
613619
resource_size_t base = nsio->res.start + start_pad;
@@ -621,7 +627,7 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap)
621627
res->end -= end_trunc;
622628

623629
if (nd_pfn->mode == PFN_MODE_RAM) {
624-
if (offset < SZ_8K)
630+
if (offset < reserve)
625631
return -EINVAL;
626632
nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns);
627633
pgmap->altmap_valid = false;
@@ -634,7 +640,7 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap)
634640
le64_to_cpu(nd_pfn->pfn_sb->npfns),
635641
nd_pfn->npfns);
636642
memcpy(altmap, &__altmap, sizeof(*altmap));
637-
altmap->free = PHYS_PFN(offset - SZ_8K);
643+
altmap->free = PHYS_PFN(offset - reserve);
638644
altmap->alloc = 0;
639645
pgmap->altmap_valid = true;
640646
} else
@@ -687,9 +693,9 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
687693
u32 dax_label_reserve = is_nd_dax(&nd_pfn->dev) ? SZ_128K : 0;
688694
struct nd_namespace_common *ndns = nd_pfn->ndns;
689695
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
696+
u32 start_pad, end_trunc, reserve = info_block_reserve();
690697
resource_size_t start, size;
691698
struct nd_region *nd_region;
692-
u32 start_pad, end_trunc;
693699
struct nd_pfn_sb *pfn_sb;
694700
unsigned long npfns;
695701
phys_addr_t offset;
@@ -734,18 +740,18 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
734740
*/
735741
start = nsio->res.start + start_pad;
736742
size = resource_size(&nsio->res);
737-
npfns = PFN_SECTION_ALIGN_UP((size - start_pad - end_trunc - SZ_8K)
743+
npfns = PFN_SECTION_ALIGN_UP((size - start_pad - end_trunc - reserve)
738744
/ PAGE_SIZE);
739745
if (nd_pfn->mode == PFN_MODE_PMEM) {
740746
/*
741747
* The altmap should be padded out to the block size used
742748
* when populating the vmemmap. This *should* be equal to
743749
* PMD_SIZE for most architectures.
744750
*/
745-
offset = ALIGN(start + SZ_8K + 64 * npfns + dax_label_reserve,
751+
offset = ALIGN(start + reserve + 64 * npfns + dax_label_reserve,
746752
max(nd_pfn->align, PMD_SIZE)) - start;
747753
} else if (nd_pfn->mode == PFN_MODE_RAM)
748-
offset = ALIGN(start + SZ_8K + dax_label_reserve,
754+
offset = ALIGN(start + reserve + dax_label_reserve,
749755
nd_pfn->align) - start;
750756
else
751757
return -ENXIO;

0 commit comments

Comments
 (0)