The "sub-section memory hotplug" facility allows memremap_pages() users like libnvdimm to compensate for hardware platforms like x86 that have a section size larger than their hardware memory mapping granularity. The compensation that sub-section support affords is being tolerant of physical memory resources shifting by units smaller (64MiB on x86) than the memory-hotplug section size (128 MiB). Where the platform physical-memory mapping granularity is limited by the number and capability of address-decode-registers in the memory controller. While the sub-section support allows memremap_pages() to operate on sub-section (2MiB) granularity, the Power architecture may still require 16MiB alignment on "!radix_enabled()" platforms. In order for libnvdimm to be able to detect and manage this per-arch limitation, introduce memremap_compat_align() as a common minimum alignment across all driver-facing memory-mapping interfaces, and let Power override it to 16MiB in the "!radix_enabled()" case. The assumption / requirement for 16MiB to be a viable memremap_compat_align() value is that Power does not have platforms where its equivalent of address-decode-registers never hardware remaps a persistent memory resource on smaller than 16MiB boundaries. Note that I tried my best to not add a new Kconfig symbol, but header include entanglements defeated the #ifndef memremap_compat_align design pattern and the need to export it defeats the __weak design pattern for arch overrides. Based on an initial patch by Aneesh.
Unified · Split
| @@ -122,6 +122,7 @@ config PPC · 121 unmodified lines | ||
| 122 | 122 | select ARCH_HAS_GCOV_PROFILE_ALL |
| 123 | 123 | select ARCH_HAS_KCOV |
| 124 | 124 | select ARCH_HAS_HUGEPD if HUGETLB_PAGE |
| 125 | + select ARCH_HAS_MEMREMAP_COMPAT_ALIGN | |
| 125 | 126 | select ARCH_HAS_MMIOWB if PPC64 |
| 126 | 127 | select ARCH_HAS_PHYS_TO_DMA |
| 127 | 128 | select ARCH_HAS_PMEM_API |
| @@ -2,6 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | #include <linux/io.h> |
| 4 | 4 | #include <linux/slab.h> |
| 5 | +#include <linux/mmzone.h> | |
| 5 | 6 | #include <linux/vmalloc.h> |
| 6 | 7 | #include <asm/io-workarounds.h> |
| 7 | 8 | |
| @@ -97,3 +98,23 @@ void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size, · 89 unmodified lines | ||
| 97 | 98 | |
| 98 | 99 | return NULL; |
| 99 | 100 | } |
| 101 | + | |
| 102 | +#ifdef CONFIG_ZONE_DEVICE | |
| 103 | +/* | |
| 104 | + * Override the generic version in mm/memremap.c. | |
| 105 | + * | |
| 106 | + * With hash translation, the direct-map range is mapped with just one | |
| 107 | + * page size selected by htab_init_page_sizes(). Consult | |
| 108 | + * mmu_psize_defs[] to determine the minimum page size alignment. | |
| 109 | +*/ | |
| 110 | +unsigned long memremap_compat_align(void) | |
| 111 | +{ | |
| 112 | + unsigned int shift = mmu_psize_defs[mmu_linear_psize].shift; | |
| 113 | + | |
| 114 | + if (radix_enabled()) | |
| 115 | + return SUBSECTION_SIZE; | |
| 116 | + return max(SUBSECTION_SIZE, 1UL << shift); | |
| 117 | + | |
| 118 | +} | |
| 119 | +EXPORT_SYMBOL_GPL(memremap_compat_align); | |
| 120 | +#endif | |
| @@ -750,7 +750,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn) · 749 unmodified lines | ||
| 750 | 750 | start = nsio->res.start; |
| 751 | 751 | size = resource_size(&nsio->res); |
| 752 | 752 | npfns = PHYS_PFN(size - SZ_8K); |
| 753 | − align = max(nd_pfn->align, (1UL << SUBSECTION_SHIFT)); | |
| 753 | + align = max(nd_pfn->align, SUBSECTION_SIZE); | |
| 754 | 754 | end_trunc = start + size - ALIGN_DOWN(start + size, align); |
| 755 | 755 | if (nd_pfn->mode == PFN_MODE_PMEM) { |
| 756 | 756 | /* |
| @@ -132,6 +132,7 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, · 131 unmodified lines | ||
| 132 | 132 | |
| 133 | 133 | unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); |
| 134 | 134 | void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns); |
| 135 | +unsigned long memremap_compat_align(void); | |
| 135 | 136 | #else |
| 136 | 137 | static inline void *devm_memremap_pages(struct device *dev, |
| 137 | 138 | struct dev_pagemap *pgmap) |
| @@ -165,6 +166,12 @@ static inline void vmem_altmap_free(struct vmem_altmap *altmap, · 27 unmodified lines | ||
| 165 | 166 | unsigned long nr_pfns) |
| 166 | 167 | { |
| 167 | 168 | } |
| 169 | + | |
| 170 | +/* when memremap_pages() is disabled all archs can remap a single page */ | |
| 171 | +static inline unsigned long memremap_compat_align(void) | |
| 172 | +{ | |
| 173 | + return PAGE_SIZE; | |
| 174 | +} | |
| 168 | 175 | #endif /* CONFIG_ZONE_DEVICE */ |
| 169 | 176 | |
| 170 | 177 | static inline void put_dev_pagemap(struct dev_pagemap *pgmap) |
| @@ -172,4 +179,5 @@ static inline void put_dev_pagemap(struct dev_pagemap *pgmap) · 1 unmodified line | ||
| 172 | 179 | if (pgmap) |
| 173 | 180 | percpu_ref_put(pgmap->ref); |
| 174 | 181 | } |
| 182 | + | |
| 175 | 183 | #endif /* _LINUX_MEMREMAP_H_ */ |
| @@ -1170,6 +1170,7 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec) · 1169 unmodified lines | ||
| 1170 | 1170 | #define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK) |
| 1171 | 1171 | |
| 1172 | 1172 | #define SUBSECTION_SHIFT 21 |
| 1173 | +#define SUBSECTION_SIZE (1UL << SUBSECTION_SHIFT) | |
| 1173 | 1174 | |
| 1174 | 1175 | #define PFN_SUBSECTION_SHIFT (SUBSECTION_SHIFT - PAGE_SHIFT) |
| 1175 | 1176 | #define PAGES_PER_SUBSECTION (1UL << PFN_SUBSECTION_SHIFT) |
| @@ -615,6 +615,9 @@ config ARCH_HAS_PMEM_API · 614 unmodified lines | ||
| 615 | 615 | config MEMREGION |
| 616 | 616 | bool |
| 617 | 617 | |
| 618 | +config ARCH_HAS_MEMREMAP_COMPAT_ALIGN | |
| 619 | + bool | |
| 620 | + | |
| 618 | 621 | # use memcpy to implement user copies for nommu architectures |
| 619 | 622 | config UACCESS_MEMCPY |
| 620 | 623 | bool |
| @@ -7,6 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <linux/mm.h> |
| 8 | 8 | #include <linux/pfn_t.h> |
| 9 | 9 | #include <linux/swap.h> |
| 10 | +#include <linux/mmzone.h> | |
| 10 | 11 | #include <linux/swapops.h> |
| 11 | 12 | #include <linux/types.h> |
| 12 | 13 | #include <linux/wait_bit.h> |
| @@ -14,6 +15,28 @@ · 1 unmodified line | ||
| 14 | 15 | |
| 15 | 16 | static DEFINE_XARRAY(pgmap_array); |
| 16 | 17 | |
| 18 | +/* | |
| 19 | + * The memremap() and memremap_pages() interfaces are alternately used | |
| 20 | + * to map persistent memory namespaces. These interfaces place different | |
| 21 | + * constraints on the alignment and size of the mapping (namespace). | |
| 22 | + * memremap() can map individual PAGE_SIZE pages. memremap_pages() can | |
| 23 | + * only map subsections (2MB), and at least one architecture (PowerPC) | |
| 24 | + * the minimum mapping granularity of memremap_pages() is 16MB. | |
| 25 | + * | |
| 26 | + * The role of memremap_compat_align() is to communicate the minimum | |
| 27 | + * arch supported alignment of a namespace such that it can freely | |
| 28 | + * switch modes without violating the arch constraint. Namely, do not | |
| 29 | + * allow a namespace to be PAGE_SIZE aligned since that namespace may be | |
| 30 | + * reconfigured into a mode that requires SUBSECTION_SIZE alignment. | |
| 31 | + */ | |
| 32 | +#ifndef CONFIG_ARCH_HAS_MEMREMAP_COMPAT_ALIGN | |
| 33 | +unsigned long memremap_compat_align(void) | |
| 34 | +{ | |
| 35 | + return SUBSECTION_SIZE; | |
| 36 | +} | |
| 37 | +EXPORT_SYMBOL_GPL(memremap_compat_align); | |
| 38 | +#endif | |
| 39 | + | |
| 17 | 40 | #ifdef CONFIG_DEV_PAGEMAP_OPS |
| 18 | 41 | DEFINE_STATIC_KEY_FALSE(devmap_managed_key); |
| 19 | 42 | EXPORT_SYMBOL(devmap_managed_key); |