[PATCH v6 6/7] mm/mm_init: Fix uninitialized struct pages for ZONE_DEVICE
Mike Rapoport
rppt at kernel.org
Fri Apr 24 18:20:20 AEST 2026
On Fri, Apr 24, 2026 at 10:55:46AM +0800, Muchun Song wrote:
> If DAX memory is hotplugged into an unoccupied subsection of an early
> section, section_activate() reuses the unoptimized boot memmap.
> However, compound_nr_pages() still assumes that vmemmap optimization is
> in effect and initializes only the reduced number of struct pages. As a
> result, the remaining tail struct pages are left uninitialized, which
> can later lead to unexpected behavior or crashes.
>
> Fix this by treating early sections as unoptimized when calculating how
> many struct pages to initialize.
>
> Fixes: 6fd3620b3428 ("mm/page_alloc: reuse tail struct pages for compound devmaps")
> Cc: stable at vger.kernel.org
> Signed-off-by: Muchun Song <songmuchun at bytedance.com>
> Acked-by: David Hildenbrand (Arm) <david at kernel.org>
Acked-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> ---
> mm/mm_init.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index cfc76953e249..bd466a3c10c8 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -1055,10 +1055,17 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,
> * of how the sparse_vmemmap internals handle compound pages in the lack
> * of an altmap. See vmemmap_populate_compound_pages().
> */
> -static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap,
> +static inline unsigned long compound_nr_pages(unsigned long pfn,
> + struct vmem_altmap *altmap,
> struct dev_pagemap *pgmap)
> {
> - if (!vmemmap_can_optimize(altmap, pgmap))
> + /*
> + * If DAX memory is hot-plugged into an unoccupied subsection
> + * of an early section, the unoptimized boot memmap is reused.
> + * See section_activate().
> + */
> + if (early_section(__pfn_to_section(pfn)) ||
> + !vmemmap_can_optimize(altmap, pgmap))
> return pgmap_vmemmap_nr(pgmap);
>
> return VMEMMAP_RESERVE_NR * (PAGE_SIZE / sizeof(struct page));
> @@ -1128,7 +1135,7 @@ void __ref memmap_init_zone_device(struct zone *zone,
> continue;
>
> memmap_init_compound(page, pfn, zone_idx, nid, pgmap,
> - compound_nr_pages(altmap, pgmap));
> + compound_nr_pages(pfn, altmap, pgmap));
> }
>
> pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE);
> --
> 2.20.1
>
--
Sincerely yours,
Mike.
More information about the Linuxppc-dev
mailing list