Skip to contentSkip to conversation

mm/memory: don't map hardware-poisoned pages in finish_fault()

PATCH Applied Kiryl Shutsemau (Meta) 7 participants 8 messages Nov 19 – Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/memory: don't map hardware-poisoned pages in finish_fault()

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")

---
Found while reviewing Usama's fix for the swap-in side:
https://patch.msgid.link/[email protected]

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(+)
mm/memory.c +4 -0
index c966b3fe48b1..1f899d1be407 100644
@@ -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

Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Kiryl Shutsemau (Meta)

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")

---
Found while reviewing Usama's fix for the swap-in side:
https://patch.msgid.link/[email protected]

Quoted 8 lines

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(+)

LGTM. Thanks.

Best Regards,
Yan, Zi

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 18 lines · Kiryl Shutsemau (Meta)

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.

Quoted 7 lines

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")

---

Queuing this for next merge window.

Signature · 3 lines
Cheers,

David
maintainer Applied
#3 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 15 lines · Kiryl Shutsemau (Meta)

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
Quoted 1 line

[...]

Applied, thanks!

tree: mm/core.git
branch: core-7.5.misc

Applied patches will appear soon in mm-next, followed by linux-next.

Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.

It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.

[1/1] mm/memory: don't map hardware-poisoned pages in finish_fault()

      https://git.kernel.org/mm/core/c/2c536883
Signature · 3 lines
Cheers,

David
Reviewed-by on v1 1/1
#4 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 18 lines · Kiryl Shutsemau (Meta)

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.

Quoted 6 lines

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")

LGTM. Thanks.

Reviewed-by on v1 1/1
#5 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 18 lines · Kiryl Shutsemau (Meta)

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.

Quoted 6 lines

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")
Signature · 2 lines
Oscar Salvador
SUSE Labs
Reviewed-by on v1 1/1
#6 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 18 lines · Kiryl Shutsemau (Meta)

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.

Quoted 7 lines

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")

---

LGTM. Thanks.

Acked-by on v1 1/1
#7 lore raw
In reply to Kiryl Shutsemau (Meta)
Quoted 18 lines · Kiryl Shutsemau (Meta)

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.

Quoted 7 lines

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")

---

Looks good to me,

Signature · 2 lines
Cheers,
Harry / Hyeonggon