From c82dba3183ac66ea282e817b12edf735235fc4ac Mon Sep 17 00:00:00 2001 From: Muchun Song Date: Fri, 16 Oct 2026 21:13:34 +0800 Subject: [PATCH] mm: warn on unaligned compound zone device ranges A compound page of order N must start at a PFN aligned to 2^N pages. Therefore, a range used to initialize compound pages must start on a compound-page boundary and contain an integral number of compound pages. Two recent Device DAX bugs were caused by ranges that violated this invariant, but neither was detected by memmap_init_zone_device(). Warn if the adjusted zone-device range violates this invariant so future violations are reported when the compound pages are initialized. Link: https://lore.kernel.org/20261016131334.3419393-1-songmuchun@bytedance.com Link: https://lore.kernel.org/r/20261016053944.2579541-1-songmuchun@bytedance.com Link: https://lore.kernel.org/r/20261016054914.2601510-1-songmuchun@bytedance.com Signed-off-by: Muchun Song Signed-off-by: Andrew Morton Assisted-by: LLM Cc: Mike Rapoport Cc: Vishal Verma Cc: Dave Jiang Cc: Alison Schofield Cc: Joao Martins Cc: Ritesh Harjani (IBM) --- mm/mm_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mm_init.c b/mm/mm_init.c index 4c17a892924d..01ced0553ce9 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1142,6 +1142,8 @@ void __ref memmap_init_zone_device(struct zone *zone, if (!nr_pages) return; + VM_WARN_ON(!IS_ALIGNED(start_pfn | nr_pages, pfns_per_compound)); + /* * Seed the reusable head-page template from the first real struct * page. The normal page-init and refcount helpers must operate on