From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4889606A322 for ; Sat, 5 Dec 2026 14:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=g9ASEDRY Received: by kanga.kvack.org (Postfix) id A87F96B00EF; Sat, 5 Dec 2026 09:00:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A5F586B05B1; Sat, 5 Dec 2026 09:00:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 975CE6B05B2; Sat, 5 Dec 2026 09:00:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 727396B00EF for ; Sat, 5 Dec 2026 09:00:38 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 080A0A05CA for ; Sat, 5 Dec 2026 14:00:38 +0000 (UTC) X-FDA: 85510089756.21.1D875E3 Received: from mta1.migadu.com (out-106.mta1.migadu.com [95.215.58.106]) by imf04.hostedemail.com (Postfix) with ESMTP id BBD0B4000A for ; Sat, 5 Dec 2026 14:00:35 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g9ASEDRY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.106 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796479236; b=3lq60VpVITr+pp9FHdaMGDud7sCM6bXLroTj+hAF5eAVRvaQlbX3+FSv2MXBVSSARrg/Hk LQ60O0Fmye5OVGJ9AK/Z9U+IcbsUjYAfm5ig1uG/GVwGifbPcuklFKu6IB908ao7v0jo1A T6nZNCG0t8XGHaAqpl/Chr2OYpOazEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796479236; h=from:from:sender: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:dkim-signature; bh=QpI4DRtokyrT5rIjcQXZDb8X2Q9rCOGiNaC0JFXKOHA=; b=n7ADgEGiTz6cL6nnEea+gI3iKvKktDjdWBo1rogbxS0wAi3ZAswRcQiK5MP/bwzIwa8SQR /s0yQPw+V7A/in1QGYNW6PwMtwyC0Jeu4GkjCNcZCf59Zn+9oAgjJbyPsoWuMIQePxKtOA PlFo4X1HSqb+zpURta6r8XUP2IVlij4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g9ASEDRY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.106 as permitted sender) smtp.mailfrom=muchun.song@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=Jhghq47F6JSOu/jnbqo5gRPkIafvAjEJ+vnCNh7SplA=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796479233; v=1; x=1797084033; b=g9ASEDRYc6vEbuo5DqZVBf6Fu/nljoAXJyx9y2ZO7ODNadC5ViW8u62ETu+N1Mw5VT0FO9BW 5M/ORHGqKf0IHY2l/0o8IqTIdWx1lLYQCkVcpX+UgY1+UOWEH5LMzKnGECofiWmnS6ZojiomwAz 8L9lhVBxzFeWJI/CcUsppjkQ= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id 1a1c7274afad5b21; Sat, 05 Dec 2026 14:00:30 +0000 X-Mizu-Trace-ID: 1a1c7274afad5b21 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=utf-8 X-Archived-By: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH 2/2] mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized From: Muchun Song In-Reply-To: Date: Sat, 5 Dec 2026 22:00:14 +0800 Cc: Muchun Song , Muchun Song , Oscar Salvador , David Hildenbrand , Mike Rapoport , Andrew Morton , "Liam R . Howlett" , Vlastimil Babka , Michal Hocko , Miaohe Lin , Naoya Horiguchi , Lance Yang , Qi Zheng , linux-mm@kvack.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20261204065009.1392156-1-songmuchun@bytedance.com> <20261204065009.1392156-3-songmuchun@bytedance.com> To: sashiko-reviews@lists.linux.dev X-Mailer: Apple Mail (2.3901.200.71.1.16) X-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: 91ueugunryw635edd4ie18ps34h4rywr X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: BBD0B4000A X-HE-Tag: 1796479235-857369 X-HE-Meta: U2FsdGVkX1/h8QRo4M59wyJnS8w2JEng25o6kfeZhttcTrY12Qqq0y6GC/ExaQMxwGm3Ii6t5Q50PE6fdct1QHELvkUPyDSqRjCR21pkgJuHMyB/UQyCZV4M87ScjL5e3qEt465iVuKXjq67cYovhbST4HvMPVPOEJ7dHyQLCuKPw3kTNjUVKFPuvXyriXiqEbuubZDiykZYupBbnp38ToiUoV1Sg32vSVWIGI/EyyU6sgB8s6E2SqmdPbmYwANqU0GipObIH3RWOKgC/IO+iG9+sCg2NefKy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9P8mo/qxA8aDtIrpLQE5n9pHUyOGzcV22SBtJBHAFyxe+/mW+aWgsA+3c9zz01oxo5eWQuQzkS7pwFXlXXMBqa9c3jc0pKqzYnEDwtMjtxjht+FT69KjRxN3tlHTPFQXGBh4WChipWpIgnPMaotMe3oBDcxCJSX+JgZVy8o/JYn5UB0qO/kW+IG/1PREc5TfYVQ72Kum/E+C3SiTYSwRd1RGC9H/UiNrybmU2kV0LMKdapVMmmW6N7DoToOHb2gWdfuFydAcwAfW0Jme6z9vKiLC3pfHqw3slkt4d5mpL20K1ceYmeAvSPYGprFz+/MSUCVrCIIbAtFM= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > On Dec 4, 2026, at 15:23, sashiko-bot@kernel.org wrote: >=20 > Thank you for your contribution! Sashiko AI review found 2 potential > issues to consider: > - [High] mm: circular header include breaks LoongArch build in > vmemmap-optimization.h > - [Medium] mm: folio_vmemmap_optimized() flips too early during > vmemmap_restore_folio() > -- >=20 > commit 46c817b207bb4d732145a6484d9eb4524b9922cf > Author: Muchun Song >=20 > mm/hugetlb_vmemmap: remove HPG_vmemmap_optimized >=20 > This commit replaces folio_test_hugetlb_vmemmap_optimized() with > folio_vmemmap_optimized() across hugetlb and memory-failure paths and > removes the HPG_vmemmap_optimized flag and its explicit updates. >=20 >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 11ab74970738f..781e5a8a99d00 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -1503,7 +1503,7 @@ void remove_hugetlb_folio(struct hstate *h, = struct folio *folio, >> * pages. Otherwise, someone (memory error handling) may try to = write >> * to tail struct pages. >> */ >> - if (!folio_test_hugetlb_vmemmap_optimized(folio)) >> + if (!folio_vmemmap_optimized(folio)) >> __folio_clear_hugetlb(folio); >=20 > [Severity: High] > Does folio_vmemmap_optimized() break the LoongArch build via a = circular > header include? Right. >=20 > In commit "mm/vmemmap-optimization: track optimization state in shared > vmemmap pages", include/linux/vmemmap-optimization.h switched to = including > linux/mm.h and added the inline helper folio_vmemmap_optimized(), = which > calls folio_order(). >=20 > On LoongArch, arch/loongarch/include/asm/pgtable.h unconditionally = includes > linux/vmemmap-optimization.h. When a translation unit includes = linux/mm.h > first, linux/mm.h -> linux/pgtable.h -> asm/pgtable.h -> > linux/vmemmap-optimization.h skips the nested linux/mm.h include = because > _LINUX_MM_H is already defined, so folio_order() is undeclared when > folio_vmemmap_optimized() is parsed. >=20 > Conversely, including linux/pgtable.h or asm/pgtable.h before = linux/mm.h > pulls in linux/mm.h while both pgtable headers are still incomplete. >=20 > [ ... ] >=20 >> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >> index 227148d116dd9..2e39a6d453e4b 100644 >> --- a/mm/memory-failure.c >> +++ b/mm/memory-failure.c >=20 > [ ... ] >=20 >> @@ -2025,7 +2025,7 @@ void folio_clear_hugetlb_hwpoison(struct folio = *folio) >> { >> if (folio_test_hugetlb_raw_hwp_unreliable(folio)) >> return; >> - if (folio_test_hugetlb_vmemmap_optimized(folio)) >> + if (folio_vmemmap_optimized(folio)) >> return; >> folio_clear_hwpoison(folio); >> folio_free_raw_hwp(folio, true); >=20 > [Severity: Medium] > Can folio_vmemmap_optimized() return false before = vmemmap_restore_folio() > finishes restoring all tail PTEs, causing SetPageHWPoison() to write = to the > shared tail page? Right. However, the actual race is much worse than what is shown here. The lower half of try_memory_failure_hugetlb() does not hold any = refcount to a HugeTLB folio, so the folio can be freed at any time, and there are many more other pre-existing issues here. I've fixed it in a separate patch here [1]. After this fix, the race mentioned here will no longer exist. [1] = https://lore.kernel.org/all/20261205121205.83068-1-songmuchun@bytedance.co= m/ >=20 > folio_vmemmap_optimized() checks PageVmemmapOptimized() on the first = tail > struct page at start + VMEMMAP_OPTIMIZATION_SIZE. = vmemmap_restore_folio() > walks tail PTEs in ascending order and overwrites that first PTE while = the > remaining tail PTEs still map the shared tail page and before the TLB = is > flushed. >=20 > Previously, __hugetlb_vmemmap_restore_folio() cleared = HPG_vmemmap_optimized > only after vmemmap_restore_folio() returned. With the flag removed, a > racing hwpoison_filter() rejection on a free HVO folio can observe > folio_vmemmap_optimized() =3D=3D false mid-restore: >=20 > CPU0 CPU1 > try_memory_failure_hugetlb() > get_huge_page_for_hwpoison() > /* free HVO folio, no ref; > drops hugetlb_lock and > vmemmap_remap_rwsem */ > dissolve_free_hugetlb_folio() > remove_hugetlb_folio() > hugetlb_vmemmap_restore_folio() > vmemmap_restore_range() > /* overwrites first tail PTE; > remaining tail PTEs still > map shared tail page */ > if (hwpoison_filter(p)) > folio_clear_hugetlb_hwpoison() > folio_vmemmap_optimized() > /* returns false */ > folio_free_raw_hwp(..., true) > SetPageHWPoison(p->page) <-- writes to shared tail page >=20 > For bootmem-preallocated HVO gigantic folios whose shared tail PTEs = are > mapped read-only, this write causes a kernel page fault. For runtime = HVO > folios with writable shared tail PTEs, it sets PG_hwpoison on the = global > shared tail page, corrupting struct page state across all HVO folios = in > that zone and order. >=20 > --=20 > Sashiko AI review =C2=B7 = https://sashiko.dev/#/patchset/20261204065009.1392156-1-songmuchun@bytedan= ce.com?part=3D2