Skip to content

Commit e96f0bf

Browse files
kvaneeshdjbw
authored andcommitted
libnvdimm/pfn_dev: Add a build check to make sure we notice when struct page size change
Namespaces created with PFN_MODE_PMEM mode stores struct page in the reserve block area. We need to make sure we account for the right struct page size while doing this. Instead of directly depending on sizeof(struct page) which can change based on different kernel config option, use the max struct page size (64) while calculating the reserve block area. This makes sure pmem device can be used across kernels built with different configs. If the above assumption of max struct page size change, we need to update the reserve block allocation space for new namespaces created. 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 1c97afa commit e96f0bf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

drivers/nvdimm/nd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ unsigned int pmem_sector_size(struct nd_namespace_common *ndns);
375375
void nvdimm_badblocks_populate(struct nd_region *nd_region,
376376
struct badblocks *bb, const struct resource *res);
377377
#if IS_ENABLED(CONFIG_ND_CLAIM)
378+
379+
/* max struct page size independent of kernel config */
380+
#define MAX_STRUCT_PAGE_SIZE 64
381+
378382
int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap);
379383
int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio);
380384
void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);

drivers/nvdimm/pfn_devs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,16 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
701701
* The altmap should be padded out to the block size used
702702
* when populating the vmemmap. This *should* be equal to
703703
* PMD_SIZE for most architectures.
704+
*
705+
* Also make sure size of struct page is less than 64. We
706+
* want to make sure we use large enough size here so that
707+
* we don't have a dynamic reserve space depending on
708+
* struct page size. But we also want to make sure we notice
709+
* when we end up adding new elements to struct page.
704710
*/
705-
offset = ALIGN(start + SZ_8K + 64 * npfns, align) - start;
711+
BUILD_BUG_ON(sizeof(struct page) > MAX_STRUCT_PAGE_SIZE);
712+
offset = ALIGN(start + SZ_8K + MAX_STRUCT_PAGE_SIZE * npfns, align)
713+
- start;
706714
} else if (nd_pfn->mode == PFN_MODE_RAM)
707715
offset = ALIGN(start + SZ_8K, align) - start;
708716
else

0 commit comments

Comments
 (0)