Re: [PATCH v4 1/3] mm: memfd/hugetlb: memfd-based userspace HugeTLB MFR policy

From: William Roche

Date: Tue Nov 24 2026 - 19:23:00 EST


Hello Jiaqi and Chris,

I think we may have another problem to consider:

@@ -1229,6 +1259,15 @@ static int me_huge_page(struct page_state *ps, struct page *p)
/* The page is kept in page cache. */
extra_pins = true;
folio_unlock(folio);
+
+ if (hugetlb_should_keep_hwpoison_mapped(folio, mapping)) {
+ /*
+ * Page cache keeps the folio until
+ * filemap_offline_hwpoison_folio() dissolves it.
+ */
+ folio_put(folio);
+ return res;
+ }

Shouldn't we evaluate hugetlb_should_keep_hwpoison_mapped() before
releasing the folio lock? AFAIK, the folio reference alone does not
keep the mapping alive.

Maybe something like that could be more appropriate ?
if (mapping) {
bool keep;

res = truncate_error_folio(folio, page_to_pfn(p), mapping);
/* The page is kept in page cache. */
extra_pins = true;
keep = hugetlb_should_keep_hwpoison_mapped(folio, mapping);
folio_unlock(folio);

if (keep) {
/*
* Page cache keeps the folio until
* filemap_offline_hwpoison_folio() dissolves it.
*/
folio_put(folio);
return res;
}
} else {
...


On 11/17/26 05:50, Chris Down wrote:
...
This doesn't look right to me. For example, hugetlb_mfill_atomic_pte() also
checks folio_test_hwpoison(), so UFFDIO_CONTINUE on such a folio still fails
with -EIO.

We are dealing here with memory errors in a HugeTLB-backed region
registered with userfaultfd.
For an application using userfaultfd minor faults on HugeTLB-backed
memory, returning EIO from UFFDIO_CONTINUE would prevent it from
resolving a fault on an otherwise usable part of a kept-mapped poisoned
hugepage. We can imagine a VM using this type of memory, and starting
a migration where userfaultfd is used to track access to an already
transferred memory area, an EIO could disrupt the migration workflow.

So we should fix this limitation in a way that the kept-mapped
poisoned hugepage is not rejected by hugetlb_mfill_atomic_pte().
Would this introduce any other problems?



Also, do_migrate_range() calls unmap_poisoned_folio() on any
mapped folio with HWPoison set, so offlining the memory block unmaps the
hugepage after all.

Here too, we would need to avoid the unmapping for a kept-mapped
poisoned hugepage.
Memory migration should not be allowed for such a poisoned hugetlb page,
as it relies on the hardware to generate an event (an MCE for example)
when the failed location is accessed.
If the page was moved, this needed mechanism would stop working.
Preserving the mapping may therefore require memory offlining to fail
while the hugepage remains in use.


HTH,
William.