Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] mm: Generalize HVO vmemmap population
@ 2026-12-01 11:56 Muchun Song
  2026-12-01 11:56 ` [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

PowerPC radix currently uses a private HVO vmemmap population path because
the generic path lacks several properties it requires. This duplicates the
generic sparse-vmemmap page-table walk even though the HVO layout itself
does not require architecture-specific handling.

First, PowerPC uses the regular page-table allocators for runtime vmemmap
tables, while the generic path uses vmemmap_alloc_block() for intermediate
tables, bypassing the normal page-table constructor and destructor
lifecycle.

Second, with 64 KiB base pages, multiple sparsemem sections can share one
vmemmap PTE. The generic HVO path rejects an existing PTE even when it maps
the expected shared tail page.

Third, a PMD-sized vmemmap mapping can also span multiple sections. An
HVO-capable section can therefore encounter an ordinary mapping created
for a neighboring section. The generic path rejects it instead of reusing
it and disabling HVO for the current section.

This series removes these restrictions. Patches 1 and 2 address the first
issue, patch 3 the second, and patch 4 the third.

Patch 5 is a standalone fix posted earlier but not yet merged:

  https://lore.kernel.org/all/20261030115326.1005755-1-songmuchun@bytedance.com/

Since the final conversion removes the affected PowerPC code, carrying the
fix here preserves it as a distinct commit that can be backported to
kernels using the old implementation.

Patches 6 and 7 then remove the PowerPC-specific PMD overrides and HVO
page-table walk, and switch radix to the generic path.

Muchun Song (7):
  mm/sparse-vmemmap: use page-table constructors for runtime tables
  mm/sparse-vmemmap: align page-table helpers with core MM
  mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate
  mm/sparse-vmemmap: support PMD mappings spanning sections
  powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs
  powerpc/mm: remove radix-specific vmemmap PMD overrides
  powerpc/mm: reuse generic HVO vmemmap population

 arch/powerpc/mm/book3s64/radix_pgtable.c | 167 ++---------------
 mm/sparse-vmemmap.c                      | 219 ++++++++++++++---------
 2 files changed, 148 insertions(+), 238 deletions(-)


base-commit: 872ceec1e3caf227655a58f7407a9c8493dcf56f
-- 
2.54.0



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-02 13:35   ` Lance Yang
  2026-12-01 11:56 ` [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM Muchun Song
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

Runtime page-table pages are expected to pass through matching
constructors and destructors. The generic sparse-vmemmap path instead
allocates intermediate tables with vmemmap_alloc_block(), leaving even
runtime tables constructor-free.

This mixed lifecycle has already required NR_PAGETABLE teardown fixes on
x86-64, arm64, and RISC-V. Use the standard page-table allocators once
slab is available, while retaining memblock allocation for early tables.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/sparse-vmemmap.c | 90 ++++++++++++++++++++++++++++++---------------
 1 file changed, 60 insertions(+), 30 deletions(-)

diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 51fa77982ca5..5224eb4d8cf0 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -150,17 +150,6 @@ int __meminit section_nr_vmemmap_pages(unsigned long pfn, unsigned long nr_pages
 	return 0;
 }
 
-static void * __meminit vmemmap_alloc_block_zero(unsigned long size, int node)
-{
-	void *p = vmemmap_alloc_block(size, node);
-
-	if (!p)
-		return NULL;
-	memset(p, 0, size);
-
-	return p;
-}
-
 #ifdef CONFIG_VMEMMAP_OPTIMIZATION
 #define VMEMMAP_OPTIMIZATION_NR_ORDERS	(MAX_FOLIO_ORDER - VMEMMAP_OPTIMIZATION_MIN_ORDER + 1)
 
@@ -317,15 +306,32 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in
 	return pte;
 }
 
+static __ref void *vmemmap_pgtable_alloc(int node)
+{
+	void *pgtable = memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
+						   __pa(MAX_DMA_ADDRESS),
+						   MEMBLOCK_ALLOC_NOLEAKTRACE,
+						   node);
+	if (!pgtable)
+		panic("Failed to allocate page table for vmemmap\n");
+	memset(pgtable, 0, PAGE_SIZE);
+
+	return pgtable;
+}
+
 static pmd_t * __meminit vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node)
 {
 	pmd_t *pmd = pmd_offset(pud, addr);
 	if (pmd_none(*pmd)) {
-		void *p = vmemmap_alloc_block_zero(PAGE_SIZE, node);
-		if (!p)
-			return NULL;
-		kernel_pte_init(p);
-		pmd_populate_kernel(&init_mm, pmd, p);
+		if (slab_is_available()) {
+			if (!pte_alloc_kernel(pmd, addr))
+				return NULL;
+		} else {
+			pte_t *pte = vmemmap_pgtable_alloc(node);
+
+			kernel_pte_init(pte);
+			pmd_populate_kernel(&init_mm, pmd, pte);
+		}
 	}
 	return pmd;
 }
@@ -334,11 +340,19 @@ static pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, in
 {
 	pud_t *pud = pud_offset(p4d, addr);
 	if (pud_none(*pud)) {
-		void *p = vmemmap_alloc_block_zero(PAGE_SIZE, node);
-		if (!p)
-			return NULL;
-		pmd_init(p);
-		pud_populate(&init_mm, pud, p);
+		pmd_t *pmd;
+
+		if (slab_is_available()) {
+			pmd = pmd_alloc_one(&init_mm, addr);
+			if (!pmd)
+				return NULL;
+		} else {
+			pmd = vmemmap_pgtable_alloc(node);
+			pmd_init(pmd);
+		}
+
+		smp_wmb(); /* See comment in pmd_install(). */
+		pud_populate(&init_mm, pud, pmd);
 	}
 	return pud;
 }
@@ -347,11 +361,19 @@ static p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, in
 {
 	p4d_t *p4d = p4d_offset(pgd, addr);
 	if (p4d_none(*p4d)) {
-		void *p = vmemmap_alloc_block_zero(PAGE_SIZE, node);
-		if (!p)
-			return NULL;
-		pud_init(p);
-		p4d_populate_kernel(addr, p4d, p);
+		pud_t *pud;
+
+		if (slab_is_available()) {
+			pud = pud_alloc_one(&init_mm, addr);
+			if (!pud)
+				return NULL;
+		} else {
+			pud = vmemmap_pgtable_alloc(node);
+			pud_init(pud);
+		}
+
+		smp_wmb(); /* See comment in pmd_install(). */
+		p4d_populate_kernel(addr, p4d, pud);
 	}
 	return p4d;
 }
@@ -360,10 +382,18 @@ static pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
 {
 	pgd_t *pgd = pgd_offset_k(addr);
 	if (pgd_none(*pgd)) {
-		void *p = vmemmap_alloc_block_zero(PAGE_SIZE, node);
-		if (!p)
-			return NULL;
-		pgd_populate_kernel(addr, pgd, p);
+		p4d_t *p4d;
+
+		if (slab_is_available()) {
+			p4d = p4d_alloc_one(&init_mm, addr);
+			if (!p4d)
+				return NULL;
+		} else {
+			p4d = vmemmap_pgtable_alloc(node);
+		}
+
+		smp_wmb(); /* See comment in pmd_install(). */
+		pgd_populate_kernel(addr, pgd, p4d);
 	}
 	return pgd;
 }
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
  2026-12-01 11:56 ` [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-02 13:55   ` Lance Yang
  2026-12-01 11:56 ` [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate Muchun Song
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

Core MM page-table allocators take a parent entry and address and return
the next-level entry. The sparse-vmemmap helpers instead return the entry
they just populated, leaving the following helper to derive the next
level.

Make each intermediate helper take the entry it populates and return the
next-level entry, matching the core MM convention. No functional change
is intended.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/sparse-vmemmap.c | 80 +++++++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 43 deletions(-)

diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 5224eb4d8cf0..4ac4c09b1bf8 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -282,10 +282,9 @@ static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node,
 	return page_address(page);
 }
 
-static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node,
-		struct vmem_altmap *altmap)
+static __meminit int vmemmap_pte_populate(pte_t *pte, unsigned long addr,
+		int node, struct vmem_altmap *altmap)
 {
-	pte_t *pte = pte_offset_kernel(pmd, addr);
 	unsigned long pfn = page_to_pfn((struct page *)addr);
 	const unsigned int order = pfn_to_section_compound_order(pfn);
 
@@ -294,7 +293,7 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in
 		void *p = vmemmap_alloc_pte(pfn, node, altmap);
 
 		if (!p)
-			return NULL;
+			return -ENOMEM;
 
 		entry = pfn_pte(PHYS_PFN(__pa(p)), PAGE_KERNEL);
 		/* Map the shared tail page as read-only to catch illegal writes. */
@@ -302,8 +301,8 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in
 			entry = pte_wrprotect(entry);
 		set_pte_at(&init_mm, addr, pte, entry);
 	} else if (WARN_ON_ONCE(vmemmap_optimizable_pfn(pfn, order)))
-		return NULL;
-	return pte;
+		return -ENOMEM;
+	return 0;
 }
 
 static __ref void *vmemmap_pgtable_alloc(int node)
@@ -319,26 +318,23 @@ static __ref void *vmemmap_pgtable_alloc(int node)
 	return pgtable;
 }
 
-static pmd_t * __meminit vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node)
+static __meminit pte_t *vmemmap_pmd_populate(pmd_t *pmd, unsigned long addr, int node)
 {
-	pmd_t *pmd = pmd_offset(pud, addr);
+	if (slab_is_available())
+		return pte_alloc_kernel(pmd, addr);
+
 	if (pmd_none(*pmd)) {
-		if (slab_is_available()) {
-			if (!pte_alloc_kernel(pmd, addr))
-				return NULL;
-		} else {
-			pte_t *pte = vmemmap_pgtable_alloc(node);
+		pte_t *pte = vmemmap_pgtable_alloc(node);
 
-			kernel_pte_init(pte);
-			pmd_populate_kernel(&init_mm, pmd, pte);
-		}
+		kernel_pte_init(pte);
+		pmd_populate_kernel(&init_mm, pmd, pte);
 	}
-	return pmd;
+
+	return pte_offset_kernel(pmd, addr);
 }
 
-static pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node)
+static __meminit pmd_t *vmemmap_pud_populate(pud_t *pud, unsigned long addr, int node)
 {
-	pud_t *pud = pud_offset(p4d, addr);
 	if (pud_none(*pud)) {
 		pmd_t *pmd;
 
@@ -354,12 +350,12 @@ static pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, in
 		smp_wmb(); /* See comment in pmd_install(). */
 		pud_populate(&init_mm, pud, pmd);
 	}
-	return pud;
+
+	return pmd_offset(pud, addr);
 }
 
-static p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node)
+static __meminit pud_t *vmemmap_p4d_populate(p4d_t *p4d, unsigned long addr, int node)
 {
-	p4d_t *p4d = p4d_offset(pgd, addr);
 	if (p4d_none(*p4d)) {
 		pud_t *pud;
 
@@ -375,12 +371,12 @@ static p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, in
 		smp_wmb(); /* See comment in pmd_install(). */
 		p4d_populate_kernel(addr, p4d, pud);
 	}
-	return p4d;
+
+	return pud_offset(p4d, addr);
 }
 
-static pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
+static __meminit p4d_t *vmemmap_pgd_populate(pgd_t *pgd, unsigned long addr, int node)
 {
-	pgd_t *pgd = pgd_offset_k(addr);
 	if (pgd_none(*pgd)) {
 		p4d_t *p4d;
 
@@ -395,7 +391,8 @@ static pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
 		smp_wmb(); /* See comment in pmd_install(). */
 		pgd_populate_kernel(addr, pgd, p4d);
 	}
-	return pgd;
+
+	return p4d_offset(pgd, addr);
 }
 
 int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end,
@@ -408,21 +405,21 @@ int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end,
 	pte_t *pte;
 
 	for (unsigned long addr = start; addr < end; addr += PAGE_SIZE) {
-		pgd = vmemmap_pgd_populate(addr, node);
-		if (!pgd)
-			return -ENOMEM;
-		p4d = vmemmap_p4d_populate(pgd, addr, node);
+		pgd = pgd_offset_k(addr);
+		p4d = vmemmap_pgd_populate(pgd, addr, node);
 		if (!p4d)
 			return -ENOMEM;
-		pud = vmemmap_pud_populate(p4d, addr, node);
+		pud = vmemmap_p4d_populate(p4d, addr, node);
 		if (!pud)
 			return -ENOMEM;
-		pmd = vmemmap_pmd_populate(pud, addr, node);
+		pmd = vmemmap_pud_populate(pud, addr, node);
 		if (!pmd)
 			return -ENOMEM;
-		pte = vmemmap_pte_populate(pmd, addr, node, altmap);
+		pte = vmemmap_pmd_populate(pmd, addr, node);
 		if (!pte)
 			return -ENOMEM;
+		if (vmemmap_pte_populate(pte, addr, node, altmap))
+			return -ENOMEM;
 		vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
 	}
 
@@ -459,21 +456,18 @@ int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,
 		unsigned long pfn = page_to_pfn((struct page *)addr);
 		const struct mem_section *ms = __pfn_to_section(pfn);
 
-		next = pmd_addr_end(addr, end);
-
-		pgd = vmemmap_pgd_populate(addr, node);
-		if (!pgd)
-			return -ENOMEM;
-
-		p4d = vmemmap_p4d_populate(pgd, addr, node);
+		pgd = pgd_offset_k(addr);
+		p4d = vmemmap_pgd_populate(pgd, addr, node);
 		if (!p4d)
 			return -ENOMEM;
-
-		pud = vmemmap_pud_populate(p4d, addr, node);
+		pud = vmemmap_p4d_populate(p4d, addr, node);
 		if (!pud)
 			return -ENOMEM;
+		pmd = vmemmap_pud_populate(pud, addr, node);
+		if (!pmd)
+			return -ENOMEM;
 
-		pmd = pmd_offset(pud, addr);
+		next = pmd_addr_end(addr, end);
 		if (pmd_none(pmdp_get(pmd)) && !section_vmemmap_optimizable(ms)) {
 			void *p;
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
  2026-12-01 11:56 ` [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
  2026-12-01 11:56 ` [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-02 22:56   ` Chris Down
  2026-12-01 11:56 ` [PATCH 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections Muchun Song
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

Generic vmemmap population rejects existing PTEs in optimized tail
ranges, even when they already map the expected shared tail page.
On PowerPC with 64 KiB pages, multiple sparsemem sections can share
one vmemmap PTE, so successive section population may encounter an
existing shared tail mapping.

Allow an existing optimized PTE to be reused only when it maps the
expected shared tail page, without acquiring another reference.
This is needed before PowerPC radix can switch to the generic HVO
vmemmap population path.

Factor this handling into a separate helper to ease a later move of
the generic vmemmap optimization code into a dedicated source file.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/sparse-vmemmap.c | 48 +++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 4ac4c09b1bf8..6ec0cac8eab6 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -235,15 +235,14 @@ void __meminit section_vmemmap_optimization_disable(unsigned long start,
 }
 #endif
 
-static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node,
-		struct vmem_altmap *altmap)
+static int __meminit vmemmap_optimizable_pte_populate(pte_t *pte,
+		unsigned long addr, int node)
 {
+	const unsigned long pfn = page_to_pfn((struct page *)addr);
+	const unsigned int order = pfn_to_section_compound_order(pfn);
+	pte_t entry = ptep_get(pte);
 	struct zone *zone;
 	struct page *page;
-	const unsigned int order = pfn_to_section_compound_order(pfn);
-
-	if (!vmemmap_optimizable_pfn(pfn, order))
-		return vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap);
 
 	/*
 	 * Before slab is available, vmemmap optimization is used for early
@@ -257,7 +256,10 @@ static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node,
 	zone = slab_is_available() ? device_zone(node) : pfn_to_zone(pfn, node);
 	page = vmemmap_shared_tail_page(order, zone);
 	if (!page)
-		return NULL;
+		return -ENOMEM;
+
+	if (!pte_none(entry))
+		return pte_page(entry) == page ? 0 : -EOPNOTSUPP;
 
 	/*
 	 * During early vmemmap population, the shared tail vmemmap backing
@@ -277,31 +279,35 @@ static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node,
 	 * vmemmap if another reference cannot be acquired.
 	 */
 	if (slab_is_available() && !try_get_page(page))
-		return NULL;
+		return -EOVERFLOW;
+
+	/* Map the shared tail page as read-only to catch illegal writes. */
+	entry = pfn_pte(page_to_pfn(page), PAGE_KERNEL_RO);
+	set_pte_at(&init_mm, addr, pte, entry);
 
-	return page_address(page);
+	return 0;
 }
 
 static __meminit int vmemmap_pte_populate(pte_t *pte, unsigned long addr,
 		int node, struct vmem_altmap *altmap)
 {
-	unsigned long pfn = page_to_pfn((struct page *)addr);
+	const unsigned long pfn = page_to_pfn((struct page *)addr);
 	const unsigned int order = pfn_to_section_compound_order(pfn);
+	pte_t entry;
+	void *vaddr;
 
-	if (pte_none(ptep_get(pte))) {
-		pte_t entry;
-		void *p = vmemmap_alloc_pte(pfn, node, altmap);
+	if (vmemmap_optimizable_pfn(pfn, order))
+		return vmemmap_optimizable_pte_populate(pte, addr, node);
 
-		if (!p)
-			return -ENOMEM;
+	if (!pte_none(ptep_get(pte)))
+		return 0;
 
-		entry = pfn_pte(PHYS_PFN(__pa(p)), PAGE_KERNEL);
-		/* Map the shared tail page as read-only to catch illegal writes. */
-		if (vmemmap_optimizable_pfn(pfn, order))
-			entry = pte_wrprotect(entry);
-		set_pte_at(&init_mm, addr, pte, entry);
-	} else if (WARN_ON_ONCE(vmemmap_optimizable_pfn(pfn, order)))
+	vaddr = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap);
+	if (!vaddr)
 		return -ENOMEM;
+	entry = pfn_pte(PHYS_PFN(__pa(vaddr)), PAGE_KERNEL);
+	set_pte_at(&init_mm, addr, pte, entry);
+
 	return 0;
 }
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
                   ` (2 preceding siblings ...)
  2026-12-01 11:56 ` [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-01 11:56 ` [PATCH 5/7] powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs Muchun Song
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

Some architectures can use a PMD-sized vmemmap mapping that covers the
vmemmap space for more than one sparsemem section.  When such a mapping
is created for one section, a later HVO-capable section covered by the
same PMD can find the PMD mapping already populated.

That PMD entry is ordinary vmemmap backing, not an HVO-specific mapping
for this section.  So mark the section as not HVO-enabled.

An existing PMD mapping can be reused only if it came from ordinary
vmemmap population for a neighboring section in the same PMD-sized
vmemmap range.  If the naturally aligned HVO-capable compound page spans
that whole range, the mapping must have been left behind by an earlier
removal path, so warn and fail instead.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/sparse-vmemmap.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 6ec0cac8eab6..6aeb55c38525 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -460,7 +460,7 @@ int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,
 
 	for (addr = start; addr < end; addr = next) {
 		unsigned long pfn = page_to_pfn((struct page *)addr);
-		const struct mem_section *ms = __pfn_to_section(pfn);
+		struct mem_section *ms = __pfn_to_section(pfn);
 
 		pgd = pgd_offset_k(addr);
 		p4d = vmemmap_pgd_populate(pgd, addr, node);
@@ -493,8 +493,23 @@ int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,
 				return -ENOMEM;
 			}
 		} else if (vmemmap_check_pmd(pmd, node, addr, next)) {
-			if (WARN_ON_ONCE(section_vmemmap_optimizable(ms)))
+			unsigned long nr_pages = 1UL << section_compound_order(ms);
+
+			/*
+			 * A naturally aligned HVO compound page covering a full
+			 * PMD-sized vmemmap range cannot share that range with
+			 * a neighboring section. An existing PMD mapping is
+			 * therefore unexpected.
+			 */
+			if (WARN_ON_ONCE(nr_pages >= PMD_SIZE / sizeof(struct page)))
 				return -EOPNOTSUPP;
+
+			/*
+			 * A PMD mapping from a neighboring section may also cover
+			 * this section. Reuse its ordinary vmemmap backing and
+			 * disable HVO.
+			 */
+			section_set_compound_order(ms, 0);
 			continue;
 		}
 		if (vmemmap_populate_basepages(addr, next, node, altmap))
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
                   ` (3 preceding siblings ...)
  2026-12-01 11:56 ` [PATCH 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-01 11:56 ` [PATCH 6/7] powerpc/mm: remove radix-specific vmemmap PMD overrides Muchun Song
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song, stable

PowerPC radix vmemmap population can reuse an existing PMD mapping for
a device DAX range marked HVO-enabled. The reused mapping is ordinary:
its tail struct pages are not remapped to the shared tail page.

Leaving the section marked HVO-enabled makes memmap_init_zone_device()
treat the range as optimized and skip initializing real tail struct pages
that remain in use. This first triggers a zone mismatch warning, then
faults while initializing the pageblock flags:

  WARNING: mm/mm_init.c:600 at __init_single_page+0xd0/0xf4
  Call Trace:
    memmap_init_zone_device+0x164/0x430
    memremap_pages+0x43c/0x93c
    devm_memremap_pages+0x3c/0xa4
    dev_dax_probe+0x264/0x3d0
    dax_bus_probe+0x140/0x1c8

  BUG: Kernel NULL pointer dereference on read at 0x00001400
    __set_pfnblock_flags_mask.constprop.0+0x34/0x160
    memmap_init_zone_device+0x358/0x430

Without these diagnostics, the uninitialized metadata remains latent until
userspace accesses the device DAX range and triggers a later panic.

Mark the section non-HVO when reusing a PMD mapping so its state matches
the actual vmemmap layout and core ZONE_DEVICE code initializes all real
struct pages.

The Fixes target predates the section-based vmemmap optimization
infrastructure, so this patch cannot be applied directly to some older
kernels. Older kernels instead need to pass the vmemmap bounds to a
range-aware vmemmap_can_optimize() and reject optimization on PowerPC if
a PMD leaf overlaps the range. This reuses the existing mapping normally
and makes core ZONE_DEVICE code initialize all real tail entries.

Fixes: f2b79c0d7968 ("powerpc/book3s64/radix: add support for vmemmap optimization for radix")
Cc: <stable@vger.kernel.org> # see patch description, needs a different fix for <= 7.3
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reported-by: Pavithra <pavrampu@linux.ibm.com>
Closes: https://lore.kernel.org/r/97f85592bb78a273be8519e6897e7f9b9bd31469.1793070429.git.ritesh.list@gmail.com
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Tested-by: Pavithra Prakash <pavrampu@linux.ibm.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 63f369d296b4..23deabb53e09 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -1255,7 +1255,16 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn,
 			return -ENOMEM;
 
 		if (pmd_leaf(READ_ONCE(*pmd))) {
-			/* existing huge mapping. Skip the range */
+			unsigned long addr_pfn = page_to_pfn((struct page *)addr);
+			struct mem_section *ms = __pfn_to_section(addr_pfn);
+
+			/*
+			 * Existing PMD mappings can cover the edges of a valid
+			 * HVO populate range. They are ordinary vmemmap mappings,
+			 * so the current section must not be treated as HVO-backed
+			 * when its struct pages are initialized later.
+			 */
+			section_set_compound_order(ms, 0);
 			next = pmd_addr_end(addr, end);
 			continue;
 		}
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] powerpc/mm: remove radix-specific vmemmap PMD overrides
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
                   ` (4 preceding siblings ...)
  2026-12-01 11:56 ` [PATCH 5/7] powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-01 11:56 ` [PATCH 7/7] powerpc/mm: reuse generic HVO vmemmap population Muchun Song
  2026-12-02 22:56 ` [PATCH 0/7] mm: Generalize " Chris Down
  7 siblings, 0 replies; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

PowerPC radix vmemmap population has private implementations of
vmemmap_set_pmd() and vmemmap_check_pmd() that duplicate the generic
helpers in mm/sparse-vmemmap.c.

Remove the radix-specific overrides so the common helpers are used
instead. Since commit 4edd70ee6a7d ("mm/sparse-vmemmap:
flush_cache_vmap() after hotplugging vmemmap"), the generic sparse
vmemmap code calls flush_cache_vmap() after vmemmap population. On
PowerPC, that provides the necessary ptesync.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 26 ------------------------
 1 file changed, 26 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 23deabb53e09..6558fc74483f 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -978,31 +978,6 @@ int __meminit radix__vmemmap_create_mapping(unsigned long start,
 	return 0;
 }
 
-int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node,
-				unsigned long addr, unsigned long next)
-{
-	int large = pmd_leaf(*pmdp);
-
-	if (large)
-		vmemmap_verify(pmdp_ptep(pmdp), node, addr, next);
-
-	return large;
-}
-
-void __meminit vmemmap_set_pmd(pmd_t *pmdp, void *p, int node,
-			       unsigned long addr, unsigned long next)
-{
-	pte_t entry;
-	pte_t *ptep = pmdp_ptep(pmdp);
-
-	VM_BUG_ON(!IS_ALIGNED(addr, PMD_SIZE));
-	entry = pfn_pte(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL);
-	set_pte_at(&init_mm, addr, ptep, entry);
-	asm volatile("ptesync": : :"memory");
-
-	vmemmap_verify(ptep, node, addr, next);
-}
-
 static pte_t * __meminit radix__vmemmap_pte_populate(pmd_t *pmdp, unsigned long addr,
 						     int node,
 						     struct vmem_altmap *altmap,
@@ -1053,7 +1028,6 @@ static pte_t * __meminit radix__vmemmap_pte_populate(pmd_t *pmdp, unsigned long
 		if (reuse)
 			entry = pte_wrprotect(entry);
 		set_pte_at(&init_mm, addr, pte, entry);
-		asm volatile("ptesync": : :"memory");
 	}
 	return pte;
 }
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] powerpc/mm: reuse generic HVO vmemmap population
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
                   ` (5 preceding siblings ...)
  2026-12-01 11:56 ` [PATCH 6/7] powerpc/mm: remove radix-specific vmemmap PMD overrides Muchun Song
@ 2026-12-01 11:56 ` Muchun Song
  2026-12-02 22:56 ` [PATCH 0/7] mm: Generalize " Chris Down
  7 siblings, 0 replies; 12+ messages in thread
From: Muchun Song @ 2026-12-01 11:56 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Madhavan Srinivasan
  Cc: Muchun Song, David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev, Muchun Song

PowerPC radix has a PMD-sized vmemmap mapping that can cover more than
one sparsemem section, so its HVO populate path handled preexisting
ordinary PMD mappings while populating an HVO-capable range.

Now that the generic sparse-vmemmap helper supports that case, switch the
PowerPC HVO path to vmemmap_populate_hugepages() and remove the duplicate
local page-table walk.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 150 +++--------------------
 1 file changed, 16 insertions(+), 134 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 6558fc74483f..4dc1e0940e7b 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -980,8 +980,7 @@ int __meminit radix__vmemmap_create_mapping(unsigned long start,
 
 static pte_t * __meminit radix__vmemmap_pte_populate(pmd_t *pmdp, unsigned long addr,
 						     int node,
-						     struct vmem_altmap *altmap,
-						     struct page *reuse)
+						     struct vmem_altmap *altmap)
 {
 	pte_t *pte = pte_offset_kernel(pmdp, addr);
 
@@ -989,44 +988,22 @@ static pte_t * __meminit radix__vmemmap_pte_populate(pmd_t *pmdp, unsigned long
 		pte_t entry;
 		void *p;
 
-		if (!reuse) {
-			/*
-			 * make sure we don't create altmap mappings
-			 * covering things outside the device.
-			 */
-			if (altmap && altmap_cross_boundary(altmap, addr, PAGE_SIZE))
-				altmap = NULL;
-
-			p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap);
-			if (!p && altmap)
-				p = vmemmap_alloc_block_buf(PAGE_SIZE, node, NULL);
-			if (!p)
-				return NULL;
-			pr_debug("PAGE_SIZE vmemmap mapping\n");
-		} else {
-			/*
-			 * When a PTE/PMD entry is freed from the init_mm
-			 * there's a free_pages() call to this page allocated
-			 * above. Thus this try_get_page() is paired with the
-			 * put_page_testzero() on the freeing path.
-			 * This can only called by certain ZONE_DEVICE path,
-			 * and through vmemmap_populate_compound_pages() when
-			 * slab is available.
-			 *
-			 * Use try_get_page() to prevent the shared page refcount
-			 * from overflowing.
-			 */
-			if (!try_get_page(reuse))
-				return NULL;
-			p = page_to_virt(reuse);
-			pr_debug("Tail page reuse vmemmap mapping\n");
-		}
+		/*
+		 * make sure we don't create altmap mappings
+		 * covering things outside the device.
+		 */
+		if (altmap && altmap_cross_boundary(altmap, addr, PAGE_SIZE))
+			altmap = NULL;
+
+		p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap);
+		if (!p && altmap)
+			p = vmemmap_alloc_block_buf(PAGE_SIZE, node, NULL);
+		if (!p)
+			return NULL;
+		pr_debug("PAGE_SIZE vmemmap mapping\n");
 
 		VM_BUG_ON(!PAGE_ALIGNED(addr));
 		entry = pfn_pte(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL);
-		/* Map the shared tail page as read-only to catch illegal writes. */
-		if (reuse)
-			entry = pte_wrprotect(entry);
 		set_pte_at(&init_mm, addr, pte, entry);
 	}
 	return pte;
@@ -1081,10 +1058,6 @@ static inline pte_t *vmemmap_pte_alloc(pmd_t *pmdp, int node,
 	return pte_offset_kernel(pmdp, address);
 }
 
-static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn,
-						     unsigned long start,
-						     unsigned long end, int node);
-
 int __meminit radix__vmemmap_populate(unsigned long start, unsigned long end, int node,
 				      struct vmem_altmap *altmap)
 {
@@ -1098,7 +1071,7 @@ int __meminit radix__vmemmap_populate(unsigned long start, unsigned long end, in
 	unsigned long pfn = page_to_pfn((struct page *)start);
 
 	if (vmemmap_optimizable_order(pfn_to_section_compound_order(pfn)))
-		return vmemmap_populate_compound_pages(pfn, start, end, node);
+		return vmemmap_populate_hugepages(start, end, node, NULL);
 	/*
 	 * If altmap is present, Make sure we align the start vmemmap addr
 	 * to PAGE_SIZE so that we calculate the correct start_pfn in
@@ -1184,7 +1157,7 @@ int __meminit radix__vmemmap_populate(unsigned long start, unsigned long end, in
 		if (!pte)
 			return -ENOMEM;
 
-		pte = radix__vmemmap_pte_populate(pmd, addr, node, altmap, NULL);
+		pte = radix__vmemmap_pte_populate(pmd, addr, node, altmap);
 		if (!pte)
 			return -ENOMEM;
 
@@ -1194,97 +1167,6 @@ int __meminit radix__vmemmap_populate(unsigned long start, unsigned long end, in
 	return 0;
 }
 
-static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn,
-						     unsigned long start,
-						     unsigned long end, int node)
-{
-	/*
-	 * we want to map things as base page size mapping so that
-	 * we can save space in vmemmap. We could have huge mapping
-	 * covering out both edges.
-	 */
-	unsigned long addr;
-	unsigned long next;
-	pgd_t *pgd;
-	p4d_t *p4d;
-	pud_t *pud;
-	pmd_t *pmd;
-	pte_t *pte;
-	struct page *tail_page;
-	unsigned int order = pfn_to_section_compound_order(start_pfn);
-
-	tail_page = vmemmap_shared_tail_page(order, device_zone(node));
-	if (!tail_page)
-		return -ENOMEM;
-
-	for (addr = start; addr < end; addr = next) {
-
-		pgd = pgd_offset_k(addr);
-		p4d = p4d_offset(pgd, addr);
-		pud = vmemmap_pud_alloc(p4d, node, addr);
-		if (!pud)
-			return -ENOMEM;
-		pmd = vmemmap_pmd_alloc(pud, node, addr);
-		if (!pmd)
-			return -ENOMEM;
-
-		if (pmd_leaf(READ_ONCE(*pmd))) {
-			unsigned long addr_pfn = page_to_pfn((struct page *)addr);
-			struct mem_section *ms = __pfn_to_section(addr_pfn);
-
-			/*
-			 * Existing PMD mappings can cover the edges of a valid
-			 * HVO populate range. They are ordinary vmemmap mappings,
-			 * so the current section must not be treated as HVO-backed
-			 * when its struct pages are initialized later.
-			 */
-			section_set_compound_order(ms, 0);
-			next = pmd_addr_end(addr, end);
-			continue;
-		}
-		pte = vmemmap_pte_alloc(pmd, node, addr);
-		if (!pte)
-			return -ENOMEM;
-		if (!pte_none(*pte)) {
-			/*
-			 * This could be because we already have a compound
-			 * page whose retained vmemmap page was mapped and
-			 * this request fall in those pages.
-			 */
-			next = addr + PAGE_SIZE;
-			continue;
-		} else {
-			unsigned long nr_pages = 1UL << order;
-			unsigned long addr_pfn = page_to_pfn((struct page *)addr);
-			unsigned long pfn_offset = addr_pfn - ALIGN_DOWN(addr_pfn, nr_pages);
-
-			/*
-			 * if the address is aligned to huge page size it is the
-			 * head mapping.
-			 */
-			if (pfn_offset == 0) {
-				/* Populate the head page vmemmap page */
-				pte = radix__vmemmap_pte_populate(pmd, addr, node, NULL, NULL);
-				if (!pte)
-					return -ENOMEM;
-				vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
-
-				next = addr + PAGE_SIZE;
-				continue;
-			}
-
-			pte = radix__vmemmap_pte_populate(pmd, addr, node, NULL, tail_page);
-			if (!pte)
-				return -ENOMEM;
-			vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
-
-			next = addr + PAGE_SIZE;
-			continue;
-		}
-	}
-	return 0;
-}
-
 
 #ifdef CONFIG_MEMORY_HOTPLUG
 void __meminit radix__vmemmap_remove_mapping(unsigned long start, unsigned long page_size)
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables
  2026-12-01 11:56 ` [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
@ 2026-12-02 13:35   ` Lance Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Lance Yang @ 2026-12-02 13:35 UTC (permalink / raw)
  To: songmuchun
  Cc: akpm, rppt, maddy, muchun.song, david, mpe, ritesh.list,
	aneesh.kumar, pavrampu, lance.yang, qi.zheng, linux-mm,
	linuxppc-dev


On Tue, Dec 01, 2026 at 07:56:45PM +0800, Muchun Song wrote:
>Runtime page-table pages are expected to pass through matching
>constructors and destructors. The generic sparse-vmemmap path instead
>allocates intermediate tables with vmemmap_alloc_block(), leaving even
>runtime tables constructor-free.
>
>This mixed lifecycle has already required NR_PAGETABLE teardown fixes on
>x86-64, arm64, and RISC-V. Use the standard page-table allocators once
>slab is available, while retaining memblock allocation for early tables.

Nice cleanup!

>Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>---
> mm/sparse-vmemmap.c | 90 ++++++++++++++++++++++++++++++---------------
> 1 file changed, 60 insertions(+), 30 deletions(-)
>
>diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
>index 51fa77982ca5..5224eb4d8cf0 100644
>--- a/mm/sparse-vmemmap.c
>+++ b/mm/sparse-vmemmap.c
>@@ -150,17 +150,6 @@ int __meminit section_nr_vmemmap_pages(unsigned long pfn, unsigned long nr_pages
> 	return 0;
> }
> 
>-static void * __meminit vmemmap_alloc_block_zero(unsigned long size, int node)
>-{
>-	void *p = vmemmap_alloc_block(size, node);
>-
>-	if (!p)
>-		return NULL;
>-	memset(p, 0, size);
>-
>-	return p;
>-}
>-
> #ifdef CONFIG_VMEMMAP_OPTIMIZATION
> #define VMEMMAP_OPTIMIZATION_NR_ORDERS	(MAX_FOLIO_ORDER - VMEMMAP_OPTIMIZATION_MIN_ORDER + 1)
> 
>@@ -317,15 +306,32 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in
> 	return pte;
> }
> 
>+static __ref void *vmemmap_pgtable_alloc(int node)
>+{
>+	void *pgtable = memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
>+						   __pa(MAX_DMA_ADDRESS),
>+						   MEMBLOCK_ALLOC_NOLEAKTRACE,
>+						   node);
>+	if (!pgtable)
>+		panic("Failed to allocate page table for vmemmap\n");
>+	memset(pgtable, 0, PAGE_SIZE);

Can we use memblock_alloc_try_nid() here? It already zeroes the page,
so memset() can go :D

Nothing else jumped out at me, so, feel free to add:

Reviewed-by: Lance Yang <lance.yang@linux.dev>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM
  2026-12-01 11:56 ` [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM Muchun Song
@ 2026-12-02 13:55   ` Lance Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Lance Yang @ 2026-12-02 13:55 UTC (permalink / raw)
  To: songmuchun
  Cc: akpm, rppt, maddy, muchun.song, david, mpe, ritesh.list,
	aneesh.kumar, pavrampu, lance.yang, qi.zheng, linux-mm,
	linuxppc-dev


On Tue, Dec 01, 2026 at 07:56:46PM +0800, Muchun Song wrote:
>Core MM page-table allocators take a parent entry and address and return
>the next-level entry. The sparse-vmemmap helpers instead return the entry
>they just populated, leaving the following helper to derive the next
>level.
>
>Make each intermediate helper take the entry it populates and return the
>next-level entry, matching the core MM convention. No functional change
>is intended.
>
>Signed-off-by: Muchun Song <songmuchun@bytedance.com>
>---

LGTM. Feel free to add:

Reviewed-by: Lance Yang <lance.yang@linux.dev>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/7] mm: Generalize HVO vmemmap population
  2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
                   ` (6 preceding siblings ...)
  2026-12-01 11:56 ` [PATCH 7/7] powerpc/mm: reuse generic HVO vmemmap population Muchun Song
@ 2026-12-02 22:56 ` Chris Down
  7 siblings, 0 replies; 12+ messages in thread
From: Chris Down @ 2026-12-02 22:56 UTC (permalink / raw)
  To: Muchun Song
  Cc: Andrew Morton, Mike Rapoport, Madhavan Srinivasan, Muchun Song,
	David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev

Hi Muchun,

Thanks, this looks good, and it's nice to see the powerpc copy of the HVO
walk go away.

I ran the series on x86 with device DAX at 2M and 1G alignment and with a
boot-time 1G hugetlb page using HVO. The runtime vmemmap PTE tables are
now constructed page tables, they are all freed again when the namespace
is reconfigured, and KASAN and DEBUG_VM didn't show anything amiss.

For the series:

Reviewed-by: Chris Down <chris@chrisdown.name>

For patches 1-3:

Tested-by: Chris Down <chris@chrisdown.name>

Chris


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate
  2026-12-01 11:56 ` [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate Muchun Song
@ 2026-12-02 22:56   ` Chris Down
  0 siblings, 0 replies; 12+ messages in thread
From: Chris Down @ 2026-12-02 22:56 UTC (permalink / raw)
  To: Muchun Song
  Cc: Andrew Morton, Mike Rapoport, Madhavan Srinivasan, Muchun Song,
	David Hildenbrand, Michael Ellerman, Ritesh Harjani,
	Aneesh Kumar K . V, Pavithra Prakash, Lance Yang, Qi Zheng,
	linux-mm, linuxppc-dev

Hi Muchun,

Muchun Song writes:
>+	if (!pte_none(entry))
>+		return pte_page(entry) == page ? 0 : -EOPNOTSUPP;

Not a big deal, but the old code warned when it found a populated PTE in
the shared tail range, and now a PTE pointing at some other page fails
silently. vmemmap_populate_basepages() turns every error into -ENOMEM, so
all one sees is a failed hot-add with no real direction on why that
happened.

Maybe keep a WARN_ON_ONCE() for a PTE that points at another page?

Thanks,

Chris


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-02 22:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 11:56 [PATCH 0/7] mm: Generalize HVO vmemmap population Muchun Song
2026-12-01 11:56 ` [PATCH 1/7] mm/sparse-vmemmap: use page-table constructors for runtime tables Muchun Song
2026-12-02 13:35   ` Lance Yang
2026-12-01 11:56 ` [PATCH 2/7] mm/sparse-vmemmap: align page-table helpers with core MM Muchun Song
2026-12-02 13:55   ` Lance Yang
2026-12-01 11:56 ` [PATCH 3/7] mm/sparse-vmemmap: introduce vmemmap_optimizable_pte_populate Muchun Song
2026-12-02 22:56   ` Chris Down
2026-12-01 11:56 ` [PATCH 4/7] mm/sparse-vmemmap: support PMD mappings spanning sections Muchun Song
2026-12-01 11:56 ` [PATCH 5/7] powerpc/mm: fix uninitialized ZONE_DEVICE struct pages with PMDs Muchun Song
2026-12-01 11:56 ` [PATCH 6/7] powerpc/mm: remove radix-specific vmemmap PMD overrides Muchun Song
2026-12-01 11:56 ` [PATCH 7/7] powerpc/mm: reuse generic HVO vmemmap population Muchun Song
2026-12-02 22:56 ` [PATCH 0/7] mm: Generalize " Chris Down

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox