Re: [PATCH v3 01/11] mm/mm_init: verify zones for template-initialized pages
From: Qi Zheng
Date: Mon Nov 23 2026 - 01:39:42 EST
Hi Muchun,
On 11/20/26 6:08 PM, Muchun Song wrote:
Template-based ZONE_DEVICE initialization bypasses
__init_single_page(), which means copied struct pages do not run the
vmemmap zone consistency check.
Verify each destination after copying the template so the fast path gets
the same validation as regular page initialization.
Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>
---
v3:
- Retarget zone verification to
zone_device_page_init_from_template() after integrating the helper
series (suggested by Mike Rapoport)
- Collect Reviewed-by from Lance Yang
v2:
- Apply the zone verification in memmap_init_page_from_template().
- Collect Reviewed-by from Mike Rapoport.
---
mm/mm_init.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index a9d848c92678..0129152b74d8 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1082,6 +1082,7 @@ static void zone_device_page_init_from_template(struct page *page,
set_page_address(template, __va(pfn << PAGE_SHIFT));
#endif
memcpy_nontemporal(page, template, sizeof(*page));
+ vmemmap_optimization_verify_zone(page);
For PAGE_SIZE-aligned devdax, dev_dax_probe() leaves
pgmap->vmemmap_shift at zero. When section_activate() populates a full
section for this pgmap, it records compound_page_order = 0.
memmap_init_zone_device() (pfns_per_compound == 1)
-> zone_device_page_init_from_template() (each template copy)
-> vmemmap_optimization_verify_zone()
-> pfn_to_section_compound_order(page_to_pfn(page)) returns 0
-> vmemmap_optimizable_order(0) returns false
With CONFIG_DEBUG_VM and CONFIG_VMEMMAP_OPTIMIZATION enabled, the
section-order lookup runs for each copy. The zero order makes the
condition short-circuit before either page_zone_id() call.
Once patch #4 splits out the base-page loop, could we put this check in
the compound tail-copy loop? Like the following:
diff --git a/mm/mm_init.c b/mm/mm_init.c
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -734,7 +734,6 @@ static void __meminit memmap_init_page_from_template(struct page *page,
memcpy_nontemporal(page, template, sizeof(*page));
else
memcpy(page, template, sizeof(*page));
- vmemmap_optimization_verify_zone(page);
}
void __meminit memmap_init_compound_page(struct page *head, unsigned long pfn,
@@ -754,8 +753,10 @@ void __meminit memmap_init_compound_page(struct page *head, unsigned long pfn,
if (vmemmap_optimizable_order(pfn_to_section_compound_order(pfn)))
nr_pages = VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES;
/* Initialize the tail pages from PFN-independent template page. */
- for (unsigned long i = 1; i < nr_pages; i++)
+ for (unsigned long i = 1; i < nr_pages; i++) {
memmap_init_page_from_template(head + i, pfn + i, zone, &template);
+ vmemmap_optimization_verify_zone(head + i);
+ }
prep_compound_head(head, order);
pageblock_migratetype_init_range(pfn, 1UL << order, MIGRATE_MOVABLE,
Thanks,
Qi
}
/*