The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mm/memory: don't map hardware-poisoned pages in finish_fault()
@ 2026-11-19 13:42 Kiryl Shutsemau (Meta)
  2026-11-19 14:26 ` Zi Yan
  0 siblings, 1 reply; 2+ messages in thread
From: Kiryl Shutsemau (Meta) @ 2026-11-19 13:42 UTC (permalink / raw)
  To: David Hildenbrand, Miaohe Lin, Usama Arif, Baolin Wang, Zi Yan
  Cc: Kiryl Shutsemau (Meta), Andrew Morton, Naoya Horiguchi,
	Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Kefeng Wang, linux-mm,
	linux-kernel, kernel-team, stable

When memory_failure() cannot split a large file folio, the folio stays in
the page cache with the poisoned page in it. do_set_pmd() refuses to map
such a folio with a PMD, so that the poisoned page gets its own fault and
SIGBUS. finish_fault() then falls back to PTEs, but maps the whole folio:

    do_shared_fault()
      __do_fault()
        PageHWPoison(vmf->page)
          // the faulting page only
      finish_fault()
        do_set_pmd()
          // backs off on has_hwpoisoned
        set_pte_range(vmf, folio, &folio->page, folio_nr_pages(folio), ...)
          // maps the poisoned page as well

A process that touches the poisoned page takes a machine check instead
of SIGBUS from the fault.

Map a folio with a poisoned page one page at a time. The poisoned page
then takes its own fault, which __do_fault() turns into SIGBUS.

Fixes: 43e027e41423 ("mm: memory: extend finish_fault() to support large folio")
Cc: stable@vger.kernel.org
Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
---
Found while reviewing Usama's fix for the swap-in side:
https://patch.msgid.link/20261116063624.1382944-3-usama.arif@linux.dev

Reproduced on a huge=always tmpfs, with a THP that vmsplice() keeps
memory_failure() from splitting. A write fault on a good page of the
folio maps all 512 PTEs, the poisoned page included. With the patch it
maps the faulting page only.

 mm/memory.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index c966b3fe48b1..1f899d1be407 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5920,6 +5920,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;

base-commit: 5e600d79135124a4eb8e9db30ad524224c267c07
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 13:42 [PATCH] mm/memory: don't map hardware-poisoned pages in finish_fault() Kiryl Shutsemau (Meta)
2026-11-19 14:26 ` Zi Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox