Re: [PATCH v3 01/11] mm/mm_init: verify zones for template-initialized pages
From: Qi Zheng
Date: Mon Nov 23 2026 - 03:21:31 EST
On 11/23/26 4:15 PM, Muchun Song wrote:
On 2026/11/23 14:39, Qi Zheng wrote:
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.
You are right, but we really don't care about the performance of a
debug kernel.
Yeah, it doesn't really matter much in practice.
memmap_init_page_from_template is used to init a single page, just
like __init_single_page does. Therefore, in a sense, the template
version should be handled the same way.
So, what do you think?
Acked-by: Qi Zheng <qi.zheng@xxxxxxxxx>
Thanks,
Qi