Skip to content

Commit edbb52c

Browse files
kvaneeshdjbw
authored andcommitted
libnvdimm/pfn_dev: Add page size and struct page size to pfn superblock
This is needed so that pmem probe don't wrongly initialize a namespace which doesn't have enough space reserved for holding struct pages with the current kernel. Signed-off-by: Aneesh Kumar K.V <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent e96f0bf commit edbb52c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

drivers/nvdimm/pfn.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ struct nd_pfn_sb {
2929
/* minor-version-2 record the base alignment of the mapping */
3030
__le32 align;
3131
/* minor-version-3 guarantee the padding and flags are zero */
32-
u8 padding[4000];
32+
/* minor-version-4 record the page size and struct page size */
33+
__le32 page_size;
34+
__le16 page_struct_size;
35+
u8 padding[3994];
3336
__le64 checksum;
3437
};
3538

drivers/nvdimm/pfn_devs.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
460460
if (__le16_to_cpu(pfn_sb->version_minor) < 2)
461461
pfn_sb->align = 0;
462462

463+
if (__le16_to_cpu(pfn_sb->version_minor) < 4) {
464+
pfn_sb->page_struct_size = cpu_to_le16(64);
465+
pfn_sb->page_size = cpu_to_le32(PAGE_SIZE);
466+
}
467+
463468
switch (le32_to_cpu(pfn_sb->mode)) {
464469
case PFN_MODE_RAM:
465470
case PFN_MODE_PMEM:
@@ -475,6 +480,22 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
475480
align = 1UL << ilog2(offset);
476481
mode = le32_to_cpu(pfn_sb->mode);
477482

483+
if ((le32_to_cpu(pfn_sb->page_size) > PAGE_SIZE) &&
484+
(mode == PFN_MODE_PMEM)) {
485+
dev_err(&nd_pfn->dev,
486+
"init failed, page size mismatch %d\n",
487+
le32_to_cpu(pfn_sb->page_size));
488+
return -EOPNOTSUPP;
489+
}
490+
491+
if ((le16_to_cpu(pfn_sb->page_struct_size) < sizeof(struct page)) &&
492+
(mode == PFN_MODE_PMEM)) {
493+
dev_err(&nd_pfn->dev,
494+
"init failed, struct page size mismatch %d\n",
495+
le16_to_cpu(pfn_sb->page_struct_size));
496+
return -EOPNOTSUPP;
497+
}
498+
478499
if (!nd_pfn->uuid) {
479500
/*
480501
* When probing a namepace via nd_pfn_probe() the uuid
@@ -730,8 +751,10 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
730751
memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
731752
memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
732753
pfn_sb->version_major = cpu_to_le16(1);
733-
pfn_sb->version_minor = cpu_to_le16(3);
754+
pfn_sb->version_minor = cpu_to_le16(4);
734755
pfn_sb->align = cpu_to_le32(nd_pfn->align);
756+
pfn_sb->page_struct_size = cpu_to_le16(MAX_STRUCT_PAGE_SIZE);
757+
pfn_sb->page_size = cpu_to_le32(PAGE_SIZE);
735758
checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
736759
pfn_sb->checksum = cpu_to_le64(checksum);
737760

0 commit comments

Comments
 (0)