Skip to content

Commit 5596d9e

Browse files
MiaoheLinakpm00
authored andcommitted
mm/hugetlb: fix potential race in __update_and_free_hugetlb_folio()
There is a potential race between __update_and_free_hugetlb_folio() and try_memory_failure_hugetlb(): CPU1 CPU2 __update_and_free_hugetlb_folio try_memory_failure_hugetlb folio_test_hugetlb -- It's still hugetlb folio. folio_clear_hugetlb_hwpoison spin_lock_irq(&hugetlb_lock); __get_huge_page_for_hwpoison folio_set_hugetlb_hwpoison spin_unlock_irq(&hugetlb_lock); spin_lock_irq(&hugetlb_lock); __folio_clear_hugetlb(folio); -- Hugetlb flag is cleared but too late. spin_unlock_irq(&hugetlb_lock); When the above race occurs, raw error page info will be leaked. Even worse, raw error pages won't have hwpoisoned flag set and hit pcplists/buddy. Fix this issue by deferring folio_clear_hugetlb_hwpoison() until __folio_clear_hugetlb() is done. So all raw error pages will have hwpoisoned flag set. Link: https://lkml.kernel.org/r/[email protected] Fixes: 32c8771 ("hugetlb: do not clear hugetlb dtor until allocating vmemmap") Signed-off-by: Miaohe Lin <[email protected]> Acked-by: Muchun Song <[email protected]> Reviewed-by: Oscar Salvador <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 24be02a commit 5596d9e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mm/hugetlb.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,13 +1725,6 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
17251725
return;
17261726
}
17271727

1728-
/*
1729-
* Move PageHWPoison flag from head page to the raw error pages,
1730-
* which makes any healthy subpages reusable.
1731-
*/
1732-
if (unlikely(folio_test_hwpoison(folio)))
1733-
folio_clear_hugetlb_hwpoison(folio);
1734-
17351728
/*
17361729
* If vmemmap pages were allocated above, then we need to clear the
17371730
* hugetlb flag under the hugetlb lock.
@@ -1742,6 +1735,13 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
17421735
spin_unlock_irq(&hugetlb_lock);
17431736
}
17441737

1738+
/*
1739+
* Move PageHWPoison flag from head page to the raw error pages,
1740+
* which makes any healthy subpages reusable.
1741+
*/
1742+
if (unlikely(folio_test_hwpoison(folio)))
1743+
folio_clear_hugetlb_hwpoison(folio);
1744+
17451745
folio_ref_unfreeze(folio, 1);
17461746

17471747
/*

0 commit comments

Comments
 (0)