Commit bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative PFN walkers") added this warning alongside RCU protection that serialized page_ref_add_unless() against HVO remapping. The zero head refcount was part of that protocol while the vmemmap was folded or unfolded. That RCU protection was later removed by commit 32c440d67e6c ("mm: drop fake head checks") and commit 01b1d0ffb6f7 ("hugetlb: remove VMEMMAP_SYNCHRONIZE_RCU"). Commit 0120a603afad ("mm/hugetlb_vmemmap: map the shared tail page writable") now handles the original race by allowing a late cmpxchg to fail safely against the zero refcount on the shared tail page. The head folio refcount no longer participates in this protection. Drop the stale warning from the restore path. The matching warning in the optimize path remains necessary because that path copies the head struct page. A zero refcount prevents concurrent users from acquiring a reference and writing to it during the copy. Document this requirement at the warning. Signed-off-by: Muchun Song Reviewed-by: Lance Yang --- v2: - Document why the optimize path still requires a zero refcount in code and the commit message (suggested by Lance Yang) - Collect Reviewed-by from Lance Yang --- mm/hugetlb_vmemmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 7ede6b6fb4eb..336b1405cd6a 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -348,6 +348,11 @@ static int vmemmap_optimize_folio(const struct folio *folio, rwsem_assert_held(&vmemmap_remap_rwsem); + /* + * The refcount must remain zero to prevent concurrent users from + * acquiring a reference and writing to the head struct page while it + * is copied during remapping. + */ VM_WARN_ON_ONCE_FOLIO(folio_ref_count(folio), folio); if (!vmemmap_optimizable_order(folio_order(folio))) @@ -408,7 +413,6 @@ static int __hugetlb_vmemmap_restore_folio(struct folio *folio, unsigned long fl int ret; VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio); - VM_WARN_ON_ONCE_FOLIO(folio_ref_count(folio), folio); if (!folio_test_hugetlb_vmemmap_optimized(folio)) return 0; -- 2.54.0