From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 D2E79285058 for ; Wed, 13 May 2026 13:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677677; cv=none; b=ovDpskPi1+Nnw6wRPRmZfFWZVJ95vVeEmQSL/c7W+bDf2/yMFmqniXXj4bACq73UN/n/ziKtgrfUpjtQ3n2InThu+ke6/GZpF3Bdf+KJosPWgHRsTyIRx6s2r8Sozp00p5YosKESMkQ/uu2apTCmcZTW1uHJM6eID0xjjvzBbw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677677; c=relaxed/simple; bh=m/WIhGV5AJrlycK1IXOS/CiV+GHJhxxENmjNXn6dwmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LK6xlRQcy29nvm193LeTJfdbC4TCYWHQub9Mb25MNcMUmO3QbV8y0GKvFu3zP4DKoSXzbqG0IHACjmdj828Q+E6S2Il+8Ly6jRu/Pk3uPyf22gF8PcomRAB9f/AfsEi/C/rQOghai2+8PGsAH7YhwnRDPhmuDwhUrfTVnq1Kye8= 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=N1Ojv3Zp; arc=none smtp.client-ip=209.85.214.179 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="N1Ojv3Zp" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2adff872068so36259455ad.1 for ; Wed, 13 May 2026 06:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677675; x=1779282475; 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=vB6yS1z5EFpHn1m3zCB1eARc99Wr/QTdVrJKUDK61SU=; b=N1Ojv3ZpRptJ/DGpfdt0Y2uNlokRhpQM6mGcYAFGT6lmQAzMwPL1URLCBPay7Xyf2G 4psDLC5UfilZSjSuyvdVH7+sbtIiJFNg6mrTJa8x7NsO/L4WzNmFYJnDk09rdojw3ZGg E/l+wpjkYUNY1gxE+9PDQMgvt+r6/FEF7SbKogMU03Rd207omS7AU+UMFg7hvIbqliGO 6FMsZ+pMPN/tK0BsTuTgyPeaWZ3ud41iBcx7B39OduOinvzEvAbDqchBuOrfkVnrqRuz czLvCUM62Lt/W3He/3UHBSupBCY3vhTAK7X0VLvpv2Nn4rO/bw+QkgpBK9PAcUvy9VC6 mrrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677675; x=1779282475; 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=vB6yS1z5EFpHn1m3zCB1eARc99Wr/QTdVrJKUDK61SU=; b=Xh3z0TyaywsCFVl1VK4prHyYfemFoWtXD5jle27YZuomOjTEnkpadby/ZvdeoUPmmW bGBVkegvEhhbj++D0wi9kV6LpDgQvKs3+B+NwHRwX8WDj37FzZbJ0BeYBUF3A9LyOBLh TObFIiIpKow5RzedU2wAc49bsDrc11LfSoDYOG6uTnxyy+vKRqdfdibjI9Lv/UheNH4s i2tVsZSm/lxZ8mnTvNFGxvF2uTvrktNT/Idx7oiJVFzKq3yiNQTZTwRQgsoCrd0xOfD0 UVkHRSdLdOL2haBdNEu0A/1iqyKKbJJH+UrecikBMkflD9Qh5hBGc6q+gWgm9jbqPNC4 I7fA== X-Forwarded-Encrypted: i=1; AFNElJ881kZPH7h59CqpMDMxECP61EqSLRySrcIVpXMrgVz4DvdEWySlDyp4qNE7tmSr3R6pm0ytih0/jMiITQI=@vger.kernel.org X-Gm-Message-State: AOJu0YwLv/Wow+EQCudkW8JntNvJu+/2j2GXJiqoPwspQNo1TFnjT4Sd OKx+pNL6JWG16L9cag/UfayL+3yPuZrRIX87xExs9l0iRsx7cPrLAlsUJxsf/9rU78s= X-Gm-Gg: Acq92OHR8l063/OzhaNJCUqT9v7qRlmjdn6Zc4fq/LtcMfU/HtDw+SAmL7vqfU9pVNd ZYBFnInODuUt6+GtW5SdneIjw90baC/+PDFjV3bF9JubeLPkJusEtxcExgEzgsbTpvKIS7Zzx84 AcEk8Ld9hDtIEmZENzmJiaa2N8caSMkP3Wif/G6ffpFZxJ5DVfvSt3ijvocNQG7z6ygpKgBAUj0 COSA01eEsBD9FEVIWAGSWwCLX6/0hqxJfmpeuMhpBQMCSDuTyAjMIV/kVfx2yg+iHpQ3uQF1ESZ dWa1fhVqWGf2VAOrdtg/vpk/6e1aICgi8JiE72rHAYkSwQr41lw/52qy2iyUPl2Q+H52vU3rvpE B0DRad+7I6YyuzAbI7aBj9fEyiE21R9SbGSILVW6SjUdfFgQLN0iQJVFassIZoQgNzwMVbYOIcN VSQwqANzF/nLqfh53ZKBXTeRp7G9sCXzVVDtZXF3HpFtm+F1wRHsiIO2KcHIk= X-Received: by 2002:a17:903:f8e:b0:2b2:ebed:7af5 with SMTP id d9443c01a7336-2bd271773f9mr36693205ad.13.1778677674866; Wed, 13 May 2026 06:07:54 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm166641925ad.66.2026.05.13.06.07.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:07:54 -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 , Ackerley Tng , Frank van der Linden , 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 Subject: [PATCH v2 04/69] mm/hugetlb: Initialize gigantic bootmem hugepage struct pages earlier Date: Wed, 13 May 2026 21:04:32 +0800 Message-ID: <20260513130542.35604-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513130542.35604-1-songmuchun@bytedance.com> References: <20260513130542.35604-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 Gigantic bootmem HugeTLB pages are currently initialized from hugetlb_init(), but page_alloc_init_late() runs earlier and walks pageblocks to determine zone contiguity. If a bootmem HugeTLB region is marked noinit, set_zone_contiguous() can observe still-uninitialized struct pages through __pageblock_pfn_to_page(). This may not trigger an immediate failure, but it can make set_zone_contiguous() compute the wrong zone contiguity state. If extra poisoned-page checks are added in this path, such as PF_POISONED_CHECK() in page_zone_id(), it can also trigger an early boot panic. Initialize gigantic bootmem HugeTLB struct pages from page_alloc_init_late(), before zone contiguity is evaluated, so later page allocator setup only sees valid struct page state. This also makes the initialization order more natural, as struct pages should be initialized before later code inspects them. Fixes: fde1c4ecf916 ("mm: hugetlb: skip initialization of gigantic tail struct pages if freed by HVO") Signed-off-by: Muchun Song --- include/linux/hugetlb.h | 5 +++++ mm/hugetlb.c | 3 +-- mm/mm_init.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 93418625d3c5..52a2c30f866c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -173,6 +173,7 @@ extern int movable_gigantic_pages __read_mostly; extern int sysctl_hugetlb_shm_group __read_mostly; extern struct list_head huge_boot_pages[MAX_NUMNODES]; +void hugetlb_struct_page_init(void); void hugetlb_bootmem_alloc(void); extern nodemask_t hugetlb_bootmem_nodes; void hugetlb_bootmem_set_nodes(void); @@ -1307,6 +1308,10 @@ static inline bool hugetlbfs_pagecache_present( static inline void hugetlb_bootmem_alloc(void) { } + +static inline void hugetlb_struct_page_init(void) +{ +} #endif /* CONFIG_HUGETLB_PAGE */ static inline spinlock_t *huge_pte_lock(struct hstate *h, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d22683ab30a1..b4999653a156 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3370,7 +3370,7 @@ static void __init gather_bootmem_prealloc_parallel(unsigned long start, gather_bootmem_prealloc_node(nid); } -static void __init gather_bootmem_prealloc(void) +void __init hugetlb_struct_page_init(void) { struct padata_mt_job job = { .thread_fn = gather_bootmem_prealloc_parallel, @@ -4163,7 +4163,6 @@ static int __init hugetlb_init(void) } hugetlb_init_hstates(); - gather_bootmem_prealloc(); report_hugepages(); hugetlb_sysfs_init(); diff --git a/mm/mm_init.c b/mm/mm_init.c index fde49f7bba6c..5a910cc5534c 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2335,6 +2335,7 @@ void __init page_alloc_init_late(void) /* Reinit limits that are based on free pages after the kernel is up */ files_maxfiles_init(); #endif + hugetlb_struct_page_init(); /* Accounting of total+free memory is stable at this point. */ mem_init_print_info(); -- 2.54.0