From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA1533A2E12 for ; Thu, 14 May 2026 08:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746451; cv=none; b=deQnRSuJl+VULMHoacniokDvXAnwWytAvHlJOpxN6nySKRNuLjSxjCi3FqFVUy4u1pqYP0QVL/vx2wq5Wcrez9OLBgIE5himiISP7nnsP7o6teJwb8rFLN4Kf2hgIRSuOkEg69rcV0ZZ5f0PJ5Qp4lfUKts0wgHZ5sWPhX7ZxGc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746451; c=relaxed/simple; bh=bgxUz5Gqg8g0uncuVS6alChMymUj4DHOIrp/Fzhz/R4=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=t4LcGH46AjAITWSqma7W8YuRX1osn7Q2Urams3bDfGpaGErWeWN0e8GxyvFfo3L9wTvgGxjS6X2X96vLVVJzymSghY0tmGmXlZVSBXrIbubgVH7A0Kc4jLeRHnxnRHq2zV2PqQlh/MnAOU6UYalsSFnjWnZ1YbjvzJWAzYjv5ho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=j3fsDcx7; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="j3fsDcx7" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778746447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=co+PDVFtUfeY9Azvp0wD3jOOEodjcJ+478dVQU/LkoI=; b=j3fsDcx7/FSW0gAiMjYPF67lTpafzHKsRZrrN1bIwXHyEJPS1uPVvvuH28QY+dfTux6xmh 7sKJS7p3MQRsLJDf21qNOWrDPiNOnr+7z97BLGVlh257j83+tRLHMFug09EbLrs8pF/H1R 2Fx+bM7aYiicP20yCmvvUR9rRb8d1pg= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.500.181\)) Subject: Re: [PATCH v2 01/69] mm/hugetlb: Fix boot panic with CONFIG_DEBUG_VM and HVO bootmem pages X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: Date: Thu, 14 May 2026 16:13:15 +0800 Cc: Muchun Song , Andrew Morton , David Hildenbrand , Michael Ellerman , Madhavan Srinivasan , 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 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260513130542.35604-1-songmuchun@bytedance.com> <20260513130542.35604-2-songmuchun@bytedance.com> To: Oscar Salvador X-Migadu-Flow: FLOW_OUT > On May 14, 2026, at 15:51, Oscar Salvador wrote: >=20 > On Wed, May 13, 2026 at 09:04:29PM +0800, Muchun Song wrote: >> Commit 622026e87c40 ("mm/hugetlb: remove fake head pages") switched >> HVO to reuse per-zone shared tail pages from zone->vmemmap_tails[]. >>=20 >> 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=3Don, 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. >>=20 >> Initialize zone->vmemmap_tails[] from gather_bootmem_prealloc(), = before >> bootmem HugeTLB folios are processed, and drop the later = initialization >> from hugetlb_vmemmap_init(). >>=20 >> This bug only affects CONFIG_DEBUG_VM kernels, where the relevant >> assertion is evaluated. >>=20 >> Fixes: 622026e87c40 ("mm/hugetlb: remove fake head pages") >> Signed-off-by: Muchun Song >=20 > For the correctness of the change >=20 > Acked-by: Oscar Salvador Thanks. >=20 > but I have a couple of comments: >=20 >> --- >> mm/hugetlb.c | 19 +++++++++++++++++++ >> mm/hugetlb_vmemmap.c | 17 ----------------- >> 2 files changed, 19 insertions(+), 17 deletions(-) >>=20 >> 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 =3D num_node_state(N_MEMORY), >> .numa_aware =3D true, >> }; >> +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP >> + struct zone *zone; >> + >> + for_each_zone(zone) { >> + for (int i =3D 0; i < NR_VMEMMAP_TAILS; i++) { >> + struct page *tail, *p; >> + unsigned int order; >> + >> + tail =3D zone->vmemmap_tails[i]; >> + if (!tail) >> + continue; >> + >> + order =3D i + VMEMMAP_TAIL_MIN_ORDER; >> + p =3D page_to_virt(tail); >> + for (int j =3D 0; j < PAGE_SIZE / sizeof(struct = page); j++) >> + init_compound_tail(p + j, NULL, order, = zone); >> + } >> + } >=20 > This deserves a comment why do we need to initialize those pages here, = no need for > a fat one but a hint, because everybody else looking at this will = wonder why do not > have it in hugetlb_vmemmap_init(), as the name suggests. Make sense. >=20 >=20 >> +#endif >>=20 >> 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[] =3D { >> static int __init hugetlb_vmemmap_init(void) >=20 > At this point, hugetlb_vmemmap_init only initialites the sysctls for > each hstate, should the name reflect that better? A good point. I can add a new cleanup patch. >=20 > Also, vmemmap_get_tail() still thinks that tail pages are initialized > here from this comment: Good catch. I'll fix it. >=20 > "/* > * Only allocate the page, but do not initialize it. > * > * Any initialization done here will be overwritten by memmap_init(). > * > * hugetlb_vmemmap_init() will take care of initialization after > * memmap_init(). > */" >=20 > so we might want to adjust that as well, and I am not sure if we have > more comments in the tree referencing hugetlb_vmemmap_init() as the = init > point for those pages that need correction. Only this one. >=20 >=20 > Having said that, and this is just a question, we cannot really make > gather_bootmem_prealloc() also do the initialization of the sysfs = right? > I see that hugetlb sysfs gets initialized from hugetlb_init() a few > calls after, so.. meh. hugetlb_vmemmap_init() is introduced by me. I want to hide some symbols from mm/hugetlb_vmemmap.c at that time. So I used late_initcall() for = that. >=20 > Anyway, maybe just convert hugetlb_vmemmap_init to = hugetlb_vmemmap_sysfs_create > (pick a better name), so it does not look like having two entry points > for vmemmap init stuff. This bug fix is a temporary change, the whole zone initialization will removed later in patch 30. Then, there will be only one place for = vmemmap init :) I=E2=80=99m curious about your thoughts on the practice of minimizing = external symbols. Personally, I=E2=80=99d prefer to move these initializations = into their respective files: - hugetlb_sysfs_init(); - hugetlb_cgroup_file_init(); - hugetlb_sysctl_init(); Of course, that=E2=80=99s just my personal preference. Muchun, Thanks. >=20 > --=20 > Oscar Salvador > SUSE Labs