Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.66 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796479235; b=cGNkWiUg22x/UYAswyhVAKwkeU5ZqW41ryAmBudVz+qLT4l8nlUYkdHmrDjhfJFYfoqn JeTMLWUts8gqdCDYsB0B+Sv8YlS5/d0tWtD2smmBY5RepJRVX0iw030J9d+gnewPXDSEK RHLQa/cl5f0jEj6BkImHVmk288eQBBKvoP1o/Ztxxnz15ogOp5T92+g5w4/Tj6CbLMeiC Y88zv3MbbMLbBHBxDPk/Y4zK5my76mrHFJGTdKcDbktND/gJruLTjvPcBQwxcEYCd8f4c OtqtrcTc8SV8rXXMDCg3dl5hQ5iVyOf0wT/Oc6ulusOn29UhqBlR75hW7ZClqt0wRZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796479235; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=QpI4DRtokyrT5rIjcQXZDb8X2Q9rCOGiNaC0JFXKOHA=; b=iO3BqhZfkJzNDakCTiDkhy0I08E+CUmmSG84TNfEZWgQjC5V7szgg9iYLWj7pyUizLK0 +FYVXAZ7uNriLgPb9XNNW4K2JKBXr7E8W9rrnN7XuC0Y9RahLmNjuOc2M7hkCyTy/yfwO C+eJhTmExsZvbQzU9A9WdWPohRgRzT9iBb+wzEqD1lGQL4tkk+ItDQC/d2WAx43SUZ5T/ XidfftfnGIyuY6yLZbZusHuM/zKkcUltdq0IYykNpiBSiOIPDnNIcR0blYkFGUUtwmFyL c2axgNqoj7llAT9ovuyCnxbHUHt9E0P9zHlarS96dYlOpm+gAvVEUrCvchHFMh68hOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=XroCPmx7; arc=none smtp.remote-ip=91.218.175.66 Received: from mta0.migadu.com (out-66.mta0.migadu.com [91.218.175.66]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A289606A335 for ; Sat, 5 Dec 2026 14:00:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A289606A335 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=XroCPmx7 X-Envelope-To: sashiko-reviews@lists.linux.dev 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=1796479231; v=1; x=1797084031; b=XroCPmx7GEX7+KxfvfsjHQi2s6tDb2zeV5xUi/besfb9czFjiiuSPGSem4gfAqsdpmudabk9 4nuc+yktmjn6TaNrqBWUrlsFgJF70CR4EALWLfFEbkdrRa5LTa7jGv9TR5e4xcE8feOhQ3QO6pU FHifeylDyrOCoUkdqxyNm/KI= X-Envelope-To: sashiko-reviews@lists.linux.dev 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-Mailing-List: sashiko-reviews@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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) > 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