From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 9591A283FD9 for ; Wed, 13 May 2026 13:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677661; cv=none; b=GVX6h24SZzVpZtdea1VEUuALWNgsLiuyyvLshb3N+SJALZSzx4AFJ2suceXmtkv0oOgwwpoETKD6aiknMshbB6Mfn9xwVigy4SqWeyWiyYI1ABrTEbSzKHVuEshccXIfPKK9b151ZjoMlPi6TSafn0MDVq7HYh5v6cfkNeWreQo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677661; c=relaxed/simple; bh=Dt6H8TwXugHucu2XosoXntW8idoxMcf+fXUENFdhoO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHmQcO35sC4NGsMZwWlth9/Bj6DslVQdjzQ7MYnQj3V7q185bjB75A3XEW2OiXG3efPCMEDXaUUiy+yfgLsmliwH8d5P3NKQSt7572xqCJVEqpNbJ1hiPs+immElegUFEV8WZRYNsKIiWbQzVu/lyfMnKJ9vAlj+rQB306PX5ew= 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=LQXGiEdu; arc=none smtp.client-ip=209.85.215.170 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="LQXGiEdu" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c82471904fcso2966384a12.2 for ; Wed, 13 May 2026 06:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677659; x=1779282459; 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=glZCSgCcQPUR5mPOULt0p1weLkVndlFTk9nY8tD6isc=; b=LQXGiEdupEGpeJZd5LY1NM/GCEiv836V2wvOjey+UvZ9Pc8lpzxFV9ibDqJPIeXfZn U8IB5Y7cRur5XkcMBsHUulGyaR0UB89H9YEeZ2XhCNzFgvqFO5JJjVUH2lu7Ky5ewJIR DSOD50UIPJ4IP3QpU0duKVdfxidk3qZq7aIqekHjf3RSM4rDUfeAcRiJQJmlCPzftKee 3Ydj3KquPjXpqiGxcGkP99SQDpusoSsXv3CsPycdwgJn0c1Ug2UeP22Zd0CbVIBkmoY7 lW19odw9XjXGCk3gWWgT73X7W3gS7eQMQ0CjJD6hCuHBsjMcbMVbe+Iiy0k7nD/yKas7 Ywxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677659; x=1779282459; 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=glZCSgCcQPUR5mPOULt0p1weLkVndlFTk9nY8tD6isc=; b=bW+NFJ7bKscnrF/1etFdCZT97COeE+H213ssO+mDr1OZRoIl+a2zoYUuY/wWDyHD+7 WbJaaprnuTnYLKOV4siXHoeCf9XouEjCtUt3Tog6nKAla0mNfxn8U0C9l1eUn8dcKcRj S4ThAurRX0SvYhyuDWgEJLCEQLIGMfGVGKy9pBHmBxOkqkRNRhLAYTFX4hmhULjk7U12 4bh4FjVKvvWRcCWZCdFE1OvFp/HTIaeW8WEoOA5V/RpBeylTS2AhOvxiyxJZL4Q2hyNN pZrEsiiSHfBny25D+mlDC8niSLLwKCYErq5lttzQNYvaaII48eeFd9By5IZlikpPmiia poHA== X-Forwarded-Encrypted: i=1; AFNElJ8Q+CP+KMEUpoghAyedFPwjdgp4gnY9J0Op5Xm1D1Dgk9TpVD7+R2aCnF8RkJ1HCKtc+cyyzKU2edjDmBM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxs3g3z99Bcvwg7ea9nwydaO3xUiFbWX98z7L7TZ9dr679CdEnu MxstILtVAHIDmwSZVOOzk1uTknqC3tfYSZZT3sW1D/tEUzA+KHGJleVqzqITXQnID3c= X-Gm-Gg: Acq92OGABMjFDGDnWPmiKyb8F9cyKEILVP4CAZwuMW4fsnvAsZMXAeeRB34l5Q7IUxS K4CHu0KdqnoKOPkyBro8UeQHV47/mEtKvnLq6YH24ONuVb6XOopP8lkPh8kf+Czy29phF/uyBL4 rk7jHBs64TVzzvV8kDDyR/nfIAuH7T/QyrQ45ApLSw1QLMdpIssKVf2iw9G0dHBHxo9TdOP27N9 wp9cWqa+NXMkbyoMbhvAJMQDnmqIqBvuoXubKxi7ZIdkc7WyNgI4ZIeTEM6aF9vf551B/RpAmAX iLUrIa8Z9qDHcKqkS53BKXDraROOi1NhbMmA4uAdSzuSxGDPh2fqUi4GMxE/hKlYFMYkWld2qWl EqolsxRBFuglG0Kw0PBBDe4wz71E71LzshCn3VEqw4gsB7H7eCjiKT6OlgXQpQvkYjVFtIUU5R/ EsnBNkfUn50snw/mU4tLZikGfdgNGGBOIthrlkwfSd7GitiAZGG7bxQfCHlWA= X-Received: by 2002:a17:903:907:b0:2bc:e216:db47 with SMTP id d9443c01a7336-2bd2713c36cmr35966965ad.8.1778677658559; Wed, 13 May 2026 06:07:38 -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.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:07:38 -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 01/69] mm/hugetlb: Fix boot panic with CONFIG_DEBUG_VM and HVO bootmem pages Date: Wed, 13 May 2026 21:04:29 +0800 Message-ID: <20260513130542.35604-2-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 Commit 622026e87c40 ("mm/hugetlb: remove fake head pages") switched HVO to reuse per-zone shared tail pages from zone->vmemmap_tails[]. Those shared tail pages were initialized in hugetlb_vmemmap_init(), but bootmem HugeTLB folios are prepared earlier from gather_bootmem_prealloc(). With hugetlb_free_vmemmap=on, prep_and_add_bootmem_folios() can access pageblock flags on bootmem HugeTLB pages whose mirrored tail struct pages already point to the shared tail page. On CONFIG_DEBUG_VM kernels, get_pfnblock_bitmap_bitidx() then dereferences the still-uninitialized shared tail page and can panic during boot. Initialize zone->vmemmap_tails[] from gather_bootmem_prealloc(), before bootmem HugeTLB folios are processed, and drop the later initialization from hugetlb_vmemmap_init(). This bug only affects CONFIG_DEBUG_VM kernels, where the relevant assertion is evaluated. Fixes: 622026e87c40 ("mm/hugetlb: remove fake head pages") Signed-off-by: Muchun Song --- mm/hugetlb.c | 19 +++++++++++++++++++ mm/hugetlb_vmemmap.c | 17 ----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 31b34ca0f402..d22683ab30a1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3382,6 +3382,25 @@ static void __init gather_bootmem_prealloc(void) .max_threads = num_node_state(N_MEMORY), .numa_aware = true, }; +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + struct zone *zone; + + for_each_zone(zone) { + for (int i = 0; i < NR_VMEMMAP_TAILS; i++) { + struct page *tail, *p; + unsigned int order; + + tail = zone->vmemmap_tails[i]; + if (!tail) + continue; + + order = i + VMEMMAP_TAIL_MIN_ORDER; + p = page_to_virt(tail); + for (int j = 0; j < PAGE_SIZE / sizeof(struct page); j++) + init_compound_tail(p + j, NULL, order, zone); + } + } +#endif padata_do_multithreaded(&job); } diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 4a077d231d3a..62e61af18c9a 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -870,27 +870,10 @@ static const struct ctl_table hugetlb_vmemmap_sysctls[] = { static int __init hugetlb_vmemmap_init(void) { const struct hstate *h; - struct zone *zone; /* HUGETLB_VMEMMAP_RESERVE_SIZE should cover all used struct pages */ BUILD_BUG_ON(__NR_USED_SUBPAGE > HUGETLB_VMEMMAP_RESERVE_PAGES); - for_each_zone(zone) { - for (int i = 0; i < NR_VMEMMAP_TAILS; i++) { - struct page *tail, *p; - unsigned int order; - - tail = zone->vmemmap_tails[i]; - if (!tail) - continue; - - order = i + VMEMMAP_TAIL_MIN_ORDER; - p = page_to_virt(tail); - for (int j = 0; j < PAGE_SIZE / sizeof(struct page); j++) - init_compound_tail(p + j, NULL, order, zone); - } - } - for_each_hstate(h) { if (hugetlb_vmemmap_optimizable(h)) { register_sysctl_init("vm", hugetlb_vmemmap_sysctls); -- 2.54.0