From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA7BD314B73 for ; Fri, 24 Apr 2026 02:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999394; cv=none; b=BH331sRcvRpPXR83G/q+xIEmvoTLVcKBAkuLa66sxTeBaLCNNrU/Ko8Jh9bx1bPZxANUQNZa/qMa8UKYZtLb03+IZ/6i6L+U2OyWOCfqicf07mSao6i6KGV0nrxScHN/sjzPMNX0dHogF3S2xYtwq5ThaOJ12tY1fvXZHInSih0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776999394; c=relaxed/simple; bh=yaDJsF6niQhRHztNmySVX7QcIen1LwiglGYRWBKHNss=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XnCAYdUnxh8yGlGDYLrEhVuYDLZ4SMA7YzZ2I9IyW02Rv/3aqyiW4TkktzamiSyfK7tlct2+4GRPytkgp19Lvhun4N8GD6UQHgQrmZ9bYuhRZNHrO7WT39JmKdtMljA/XsaKaPxHScyInBhlnBIfx4vL9HzrLQqYnul+e0gb3os= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ga8y5FCN; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ga8y5FCN" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2b2d3a9e149so39417675ad.1 for ; Thu, 23 Apr 2026 19:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1776999387; x=1777604187; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gorQ8nwUKwQQqSP5JrI9Qb+od9YHCs59YbEIcdvGJzM=; b=ga8y5FCNuRCGn8QRo7KBGR5G6SZ4Y8zbMbdtXzKuYpSJUHfdTZYOBmy0ZitUOg2fRC nb5nR9o5kqCHNRaIS7GSQNYtTikgogtoRfbVdUsAegQVIBokiQNsp6ddjLpx5pjeeO2Q JO76EiQ0JG3ZR86fFZE3cdoVd+S6sfHtDF49PfMiADoyPFhwfUknVFmoGHtdnUZMONBO wwU84iuY8wt9zcR4yWxxBF+nvfMWi/2FuNehnNwNR09rZWVVHKNs8UlgYO1mG0RR5HXV 5NIsCPUK+6gsHNGFeAz4fDOMi2tNBt97sBR383VTNbuyHWfjE5F1sbKTn6qKy7QB4qsh Ds5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776999387; x=1777604187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gorQ8nwUKwQQqSP5JrI9Qb+od9YHCs59YbEIcdvGJzM=; b=nH8ZLsOfEX42ZlNRgLRZeYK5R3qMfMLoK3FhKt9IHjVFxEI2pyU62zh2OdMy+y469n tyZnp9PwFw41bIM3CTPrOtJ9HkdSP7ScuaWyYM2aBVyWHiZiKzv0dZv5f5pUgUBhts9j WIx549RzD2xMuNuSFhQVajtAj/ebsEyrkbxOnV767rm0o+s9w/+D97/uIwNW9xhngK09 5f3KgGDT5qmidgXdMCma/VmRDgGdhoLuiieYTNfRUHhZzgL/ZuAgSZWmqaohJGlHODFV 0/1pndyH8njeQWyPTLqvyBFcPijIdT6S2c8a6HTPMCr612boIQMZWhA/mS0oQ48ahUiC BaeQ== X-Forwarded-Encrypted: i=1; AFNElJ+NpzO3N5ze9JDvN5Ty4FTqtD3mpTtMnt8u0np6SNvkwbUN1VicYO2yeETn8w6donJlwbrNb0MhZ3Zqtm8=@vger.kernel.org X-Gm-Message-State: AOJu0YzI9LGPKqFbr+uakaMa1rasZKViguZDcuIhsViwc8TNm0IslUc0 QTpO8LbhlshqkuVkvrWfnqWLdlGFWWcMjd/Z6Jwb68SYrexupHJkwtQ/atcS5qFzUsY= X-Gm-Gg: AeBDiesiwnRiEfefqvnUy+eEHAkyQ0BzzIzqHDhtY7r6ZcgOnXCO/QGT1Kbh6wkVpHI OVAcuvjAecNs9A6hxwRrOS2z95aTYwZNbDbTeKlss9jq4Bu/DkBIJDloX5S2Q76tNM01+a55XEu 20+7nPrcMGTXqzz/eso36kkgYa6d1qswAM4V2yfb7ydQEW8QTISBaNOVor9IHYJuIQDjYnrvCmA 5g5a3gieMP504LSYs/AsUEeY+eRoYDkHfw5EGksD0ui/UySS6VanQrO3G0pg0Nn6PDtQO+Sh5+C w/fvZoppY75/OmJkMiMkH7TQFrFxMz5e36Jc/bM9l0S5maOStUoSsy1WT0U5EwS7WlkD3VpxvDi BV4X7URcE6UlgGFpn0VXkQNumdfO0ZftKv0HOrDAo/vQjGb/UnYLOAbGjVndF8R8j+yx/3rEnvz RF1nIP3qhNZk6s+3/Wz/RvJe29373gjEMv2gtOK3/i8QeHA8KKyUCWYDrQnsOefEyDag== X-Received: by 2002:a17:902:e748:b0:2b4:5d0c:7a85 with SMTP id d9443c01a7336-2b5f9dbcd42mr277705665ad.3.1776999387049; Thu, 23 Apr 2026 19:56:27 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab20d33sm221668325ad.63.2026.04.23.19.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 19:56:26 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song , stable@vger.kernel.org Subject: [PATCH v6 6/7] mm/mm_init: Fix uninitialized struct pages for ZONE_DEVICE Date: Fri, 24 Apr 2026 10:55:46 +0800 Message-Id: <20260424025547.3806072-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260424025547.3806072-1-songmuchun@bytedance.com> References: <20260424025547.3806072-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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@vger.kernel.org Signed-off-by: Muchun Song Acked-by: David Hildenbrand (Arm) --- 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