[RESEND v7 17/29] mm/hmm: fault PMD swap entries on demand

From: Usama Arif

Date: Mon Sep 14 2026 - 09:18:52 EST


hmm_vma_handle_absent_pmd() reports anything non-present that is not
device-private as HMM_PFN_ERROR, so a swapped-out THP would look like a
permanent failure rather than memory that needs paging in.

Treat it like a PTE swap entry: record the fault when one was asked for,
and otherwise report the range as non-resident with no flags, which is what
hmm_vma_handle_pte() already does in snapshot mode.

Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
---
mm/hmm.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index 2f1e98c6b6440..95575ac378888 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -377,12 +377,21 @@ static int hmm_vma_handle_absent_pmd(struct mm_walk *walk, unsigned long start,
required_fault = hmm_range_need_fault(hmm_vma_walk, hmm_pfns,
npages, 0);
if (required_fault) {
- if (softleaf_is_device_private(entry))
+ if (softleaf_is_device_private(entry) ||
+ softleaf_is_swap(entry))
return hmm_record_fault(addr, end, required_fault, walk);
else
return -EFAULT;
}

+ /*
+ * A swapped-out THP is not resident. Report it as not-valid,
+ * matching what hmm_vma_handle_pte() does for a PTE swap entry when
+ * no fault was requested.
+ */
+ if (softleaf_is_swap(entry))
+ return hmm_pfns_fill(start, end, range, 0);
+
return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR);
}
#else
--
2.53.0-Meta