From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 2140A314D26 for ; Tue, 28 Apr 2026 08:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364378; cv=none; b=exeI8MLn2lGrOGoyGJ4/54iiHje8Aj+q2WxcUaa8hGy1z+/gtfoDxuLKrQ4c6xewyS4fHPgrgDr5MDyVYJHnL/cUiJE+4wf1PM1ODZiHH+SJTgZmrkRIwXcInfXnvAgyMY7JY9QxvjUQnyC4ZLl7OPkFkV9VD9fihguvGZYZSQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364378; c=relaxed/simple; bh=ywbIjiAmJOpr0oswLhWAUDJeFXDBn1/X+WWcoQ+ww1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tK2A6rnK3RcdoFlwU9aEXrBCq427yA0pnsqK2W7s8iI3b/5SUXXhRs67UfMZl5xO0McnsKuO2iCWNo54WIYDtAJibRtD4Zgu+BqxlcFY7+C4AamBTMl8pnN6SUEhuqsYdL3KrU7jZeimq+NSFOtP6z08qYDhTIiSCbPt2mk+AyI= 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=g79PBT1P; arc=none smtp.client-ip=209.85.216.42 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="g79PBT1P" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3590042fa8eso8527127a91.1 for ; Tue, 28 Apr 2026 01:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1777364376; x=1777969176; 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=sKHGjwyqOWL6rVsBt0Sw/YSvydX7Gt+2C2Tpk5skGPU=; b=g79PBT1Pk67KA1ExCBnIF9gO23i41Rg1dXuPffVEjI3lNQX7BtqeVyfBTgXSqtg4Z4 F/1C/KsemEPg/HKR97esYM9bZ0kTb5OJwXBAIRDxqHygv0h362IXma4Y4r6W6mvK/hzE 0In5Mr/9KjmOyFQKrgHHAGvv0XRnu8G0joNGpvzWeHip4wWZkOsGL6yMm+TnDXFXHW1V VedcuG35b/CAN3cGyiARLmiDCDOiidfOrOBZxSZnY1cik29zq30SbsundI8o+2tAYJ7M kBBpRnmQ59RwUf6Q5LlJA/ToITS41acxRZjMIlW7UdEo9QiMna8+EhjNVWwEZigm24XJ bbZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777364376; x=1777969176; 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=sKHGjwyqOWL6rVsBt0Sw/YSvydX7Gt+2C2Tpk5skGPU=; b=hEhfHhhHhGBYrSu7PXYP1tzcwA5zYT0f098xPKuT2PEMIregtt43qorEboOCYxl8mn KFan8qjDLhHLG26HKuY0RV/UUa7PzdxtZ9pPhIuoLmMuqgEOR5P85Y01raEt6oZP5ue+ AGv5E6g+tW621+al/2B0NJf9k39I98cIQmEPcY4g/5Wp0iTR5JIPKJAKC9T71xv6HHJ9 mMPeKkC6PqT78C5HQ9XE8iirQYvzDfe1ACNWHQp+o0DZT+SU6Czh6dktXKrzRrtSMakf x5Z5/KS+YyT9OaT/HOpFtgG9E0gSUvhWXz+mv6TnaKv7QHUK7sS/O9cV8sv/XOk6l6GY vseQ== X-Forwarded-Encrypted: i=1; AFNElJ/+21khVOTAM3En5eDRpAFTA+tmIv6Ow14a2Gw5uVqnHKwOIQnxCaOnFqvD5N7pjdsnZFiXMCY3ioZUjQM=@vger.kernel.org X-Gm-Message-State: AOJu0YwXUtUw1rLfzohVRAxn8yQw79mma6165BmGEDE2MegJNh+jVsTU J1B8whQw3n9kL9S3IuJeI57n0yw2vJ+mj0ebIEI7ryHHcpIYG0LJuX+pcg7UjpdyeIY= X-Gm-Gg: AeBDieuKR6FwuTPD47Eqx1rQvSHlOo+U4LEYv7D/wLjrAMUwLwHCwllT4T7tSVzSgtp HmgD1qwTQx8hPEbdY8vcTq6hiWjpL9f0rX7WQxl0GCKDafgezsG3/MHzvpsvgztad46++R7cu85 6G9nfQA+KRidlcpIFSyTKDdQIJzCQvZxjN44/gXUF0CW9bBQf+UmVqkDxmYPfGMvRlzw9D4r6gV R+lkKZQUecAAgwK9KiJsywc3hArMU3lle93+N53Ib15EQeMXoygfqrdYyZgmMvGe5VxWHTZqVWx P8C1NpLKP0OKyUGcg9I/P4L2CVS7HPEwlhuIA/DLW7DsMBMjdKUnjXWnTfmDdERoGnUemG+JVOi RYAERlfLGhGPgWBcSg5rXzTYmZjqFN+0zRFOpYR20Y0Rl+IxEWhb9ayuJBt4p4n5mSQxUKkqCZZ qZd2wbyXYl3UCbHxTKqUIj9jJoZi53nHc/0Ig+8QvZ+vDnL1xd3BcSZvQ= X-Received: by 2002:a17:90b:5808:b0:35b:e5ce:73bb with SMTP id 98e67ed59e1d1-36491fbf11dmr2272598a91.1.1777364376405; Tue, 28 Apr 2026 01:19:36 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.101]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3649003650esm2181356a91.8.2026.04.28.01.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 01:19:36 -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 v8 6/6] mm/mm_init: Fix uninitialized struct pages for ZONE_DEVICE Date: Tue, 28 Apr 2026 16:18:55 +0800 Message-Id: <20260428081855.1249045-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260428081855.1249045-1-songmuchun@bytedance.com> References: <20260428081855.1249045-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) Acked-by: Mike Rapoport (Microsoft) --- 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