@@ -139,6 +139,7 @@ static inline bool is_zone_device_page(const struct page *page);
int dev_pagemap_add_pages(unsigned long phys_start_pfn, unsigned nr_pages);
bool dev_pagemap_free_pages(struct page *page, unsigned nr_pages);
unsigned long dev_pagemap_offset(struct page *page);
+unsigned long dev_pagemap_start_pfn(unsigned long start_pfn);
#else
static inline void *devm_memremap_pages(struct device *dev,
struct resource *res, struct percpu_ref *ref,
@@ -174,6 +175,11 @@ static inline unsigned long dev_pagemap_offset(struct page *page)
{
return 0;
}
+
+static inline unsigned long dev_pagemap_start_pfn(unsigned long start_pfn)
+{
+ return 0;
+}
#endif /* CONFIG_ZONE_DEVICE */
#if defined(CONFIG_DEVICE_PRIVATE) || defined(CONFIG_DEVICE_PUBLIC)
@@ -493,6 +493,15 @@ int dev_pagemap_add_pages(unsigned long phys_start_pfn, unsigned nr_pages)
return 0;
}
+unsigned long dev_pagemap_start_pfn(unsigned long start_pfn)
+{
+ struct vmem_altmap *pgmap = to_vmem_altmap(__pfn_to_phys(start_pfn));
+
+ if (pgmap && start_pfn == pgmap->base_pfn)
+ return pgmap->reserve;
+ return 0;
+}
+
bool dev_pagemap_free_pages(struct page *page, unsigned nr_pages)
{
struct vmem_altmap *pgmap = to_vmem_altmap((uintptr_t)page);
@@ -5305,7 +5305,6 @@ void __ref build_all_zonelists(pg_data_t *pgdat)
void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
unsigned long start_pfn, enum memmap_context context)
{
- struct vmem_altmap *altmap = to_vmem_altmap(__pfn_to_phys(start_pfn));
unsigned long end_pfn = start_pfn + size;
pg_data_t *pgdat = NODE_DATA(nid);
unsigned long pfn;
@@ -5321,8 +5320,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
* Honor reservation requested by the driver for this ZONE_DEVICE
* memory
*/
- if (altmap && start_pfn == altmap->base_pfn)
- start_pfn += altmap->reserve;
+ start_pfn += dev_pagemap_start_pfn(start_pfn);
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
/*
Signed-off-by: Christoph Hellwig <hch@lst.de> --- include/linux/memremap.h | 6 ++++++ kernel/memremap.c | 9 +++++++++ mm/page_alloc.c | 4 +--- 3 files changed, 16 insertions(+), 3 deletions(-)