Re: [PATCH v2 2/4] mm: don't PTE-batch a swap-in of a folio with a hardware-poisoned page
From: Kiryl Shutsemau (Meta)
Date: Tue Nov 17 2026 - 06:03:06 EST
On Sun, Nov 15, 2026 at 10:34:56PM -0800, Usama Arif wrote:
> do_swap_page() checks PageHWPoison() on the faulting page, but the
> large-folio batching path then maps the rest of the folio without
> looking at its other pages. A poisoned page that is not the one being
> faulted gets mapped anyway, and the fault that would have reported it
> never happens.
>
> Skip batching for such an anon folio and let each page take its own
> fault, where the existing check catches it. do_set_pmd() already backs
> off the same way.
>
> Leave a freshly read folio alone: it is not anon yet and can only be
> mapped as a whole, and falling back would free it with the poisoned
> page still in it, which the retried fault can then get back from the
> page allocator.
>
> Fixes: 508758960b8d ("mm: swap: entirely map large folios found in swapcache")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
With the check moved up as David and Zi suggested:
Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
Do we have the same problem on the file side?
If memory_failure() cannot split a large file folio, it stays in the
page cache with the poisoned page in it.
Consider a write fault through MAP_SHARED on a good page of that folio:
do_shared_fault()
__do_fault()
PageHWPoison(vmf->page)
// checks the faulting page only
finish_fault()
do_set_pmd()
folio_test_has_hwpoisoned(folio)
// backs off with VM_FAULT_FALLBACK
set_pte_range(vmf, folio, &folio->page, folio_nr_pages(folio), addr)
// maps the poisoned page as well
Possible fix is below. I can post a proper patch if the analysis looks
correct.
diff --git a/mm/memory.c b/mm/memory.c
index fb76d8922e37..25b53847943f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5893,6 +5893,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
return ret;
}
+ /* A poisoned page must take its own fault */
+ if (folio_contain_hwpoisoned_page(folio))
+ needs_fallback = true;
+
if (!needs_fallback && vma->vm_file) {
struct address_space *mapping = vma->vm_file->f_mapping;
pgoff_t file_end;
--
Kiryl Shutsemau / Kirill A. Shutemov