Re: [PATCH v3 2/5] mm: don't PTE-batch a swap-in of a folio with a hardware-poisoned page

From: Lorenzo Stoakes (ARM)

Date: Mon Nov 23 2026 - 12:20:42 EST


On Mon, Nov 23, 2026 at 08:32:08AM -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>
> Reviewed-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>
> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>

Neat! I didn't even know about that function :)

Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>

> ---
> mm/memory.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 282266dd5e5dfa..d7b200e00bce17 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -5194,6 +5194,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> pte_t *folio_ptep;
> pte_t folio_pte;
>
> + /* A poisoned page in the folio must take its own fault. */
> + if (folio_test_anon(folio) &&
> + folio_contain_hwpoisoned_page(folio))
> + goto check_folio;
> +
> folio_pte_range(folio, vma, address, idx, &folio_start,
> &folio_end);
> if (unlikely((folio_end - folio_start) >> PAGE_SHIFT != nr))
> --
> 2.53.1-Meta
>

--
Cheers, Lorenzo