From cbd4348484986193c45235babbae6e30318d9e48 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sun, 3 Dec 2023 19:53:45 -0800 Subject: [PATCH 1/2] userfaultfd: split large pmd-mapped folio Signed-off-by: Suren Baghdasaryan --- mm/userfaultfd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 71d0281f1162..6e6f672067fe 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1382,8 +1382,25 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm, /* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd(dst_addr, src_addr, src_start + len) || !pmd_none(dst_pmdval)) { + struct folio *folio = pfn_folio(pmd_pfn(*src_pmd)); + if (!folio || !PageAnonExclusive(&folio->page)) { + spin_unlock(ptl); + err = -EBUSY; + break; + } + folio_get(folio); spin_unlock(ptl); split_huge_pmd(src_vma, src_pmd, src_addr); + if (folio_test_large(folio)) { + folio_lock(folio); + err = split_folio(folio); + folio_unlock(folio); + if (err) { + folio_put(folio); + break; + } + } + folio_put(folio); continue; } -- 2.43.0.rc2.451.g8631bc7472-goog