Skip to content

Commit 9f1e8cd

Browse files
tujinjiang11akpm00
authored andcommitted
mm/vmscan: fix hwpoisoned large folio handling in shrink_folio_list
In shrink_folio_list(), the hwpoisoned folio may be large folio, which can't be handled by unmap_poisoned_folio(). For THP, try_to_unmap_one() must be passed with TTU_SPLIT_HUGE_PMD to split huge PMD first and then retry. Without TTU_SPLIT_HUGE_PMD, we will trigger null-ptr deref of pvmw.pte. Even we passed TTU_SPLIT_HUGE_PMD, we will trigger a WARN_ON_ONCE due to the page isn't in swapcache. Since UCE is rare in real world, and race with reclaimation is more rare, just skipping the hwpoisoned large folio is enough. memory_failure() will handle it if the UCE is triggered again. This happens when memory reclaim for large folio races with memory_failure(), and will lead to kernel panic. The race is as follows: cpu0 cpu1 shrink_folio_list memory_failure TestSetPageHWPoison unmap_poisoned_folio --> trigger BUG_ON due to unmap_poisoned_folio couldn't handle large folio [[email protected]: add comment to unmap_poisoned_folio()] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jinjiang Tu <[email protected]> Fixes: 1b04495 ("mm/vmscan: don't try to reclaim hwpoison folio") Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Miaohe Lin <[email protected]> Acked-by: Zi Yan <[email protected]> Reviewed-by: Oscar Salvador <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent db6cc3f commit 9f1e8cd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mm/memory-failure.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,10 @@ static int get_hwpoison_page(struct page *p, unsigned long flags)
15611561
return ret;
15621562
}
15631563

1564+
/*
1565+
* The caller must guarantee the folio isn't large folio, except hugetlb.
1566+
* try_to_unmap() can't handle it.
1567+
*/
15641568
int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, bool must_kill)
15651569
{
15661570
enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC | TTU_HWPOISON;

mm/vmscan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,14 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
11381138
goto keep;
11391139

11401140
if (folio_contain_hwpoisoned_page(folio)) {
1141+
/*
1142+
* unmap_poisoned_folio() can't handle large
1143+
* folio, just skip it. memory_failure() will
1144+
* handle it if the UCE is triggered again.
1145+
*/
1146+
if (folio_test_large(folio))
1147+
goto keep_locked;
1148+
11411149
unmap_poisoned_folio(folio, folio_pfn(folio), false);
11421150
folio_unlock(folio);
11431151
folio_put(folio);

0 commit comments

Comments
 (0)