[PATCH v3 11/15] userfaultfd: mfill_atomic(): remove retry logic

Mike Rapoport
2026-03-30T10:12:41Z

From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

Since __mfill_atomic_pte() handles the retry for both anonymous and shmem,
there is no need to retry copying the date from the userspace in the loop
in mfill_atomic().

Drop the retry logic from mfill_atomic().

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
mm/userfaultfd.c | 24 ------------------------
1 file changed, 24 deletions(-)

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index e672a9e45d0c..935a3f6ebeed 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -29,7 +29,6 @@ struct mfill_state {
struct vm_area_struct *vma;
unsigned long src_addr;
unsigned long dst_addr;
- struct folio *folio;
pmd_t *pmd;
};

@@ -899,7 +898,6 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx,
VM_WARN_ON_ONCE(src_start + len <= src_start);
VM_WARN_ON_ONCE(dst_start + len <= dst_start);

-retry:
err = mfill_get_vma(&state);
if (err)
goto out;
@@ -926,26 +924,6 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx,
err = mfill_atomic_pte(&state);
cond_resched();

- if (unlikely(err == -ENOENT)) {
- void *kaddr;
-
- mfill_put_vma(&state);
- VM_WARN_ON_ONCE(!state.folio);
-
- kaddr = kmap_local_folio(state.folio, 0);
- err = copy_from_user(kaddr,
- (const void __user *)state.src_addr,
- PAGE_SIZE);
- kunmap_local(kaddr);
- if (unlikely(err)) {
- err = -EFAULT;
- goto out;
- }
- flush_dcache_folio(state.folio);
- goto retry;
- } else
- VM_WARN_ON_ONCE(state.folio);
-
if (!err) {
state.dst_addr += PAGE_SIZE;
state.src_addr += PAGE_SIZE;
@@ -960,8 +938,6 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx,

mfill_put_vma(&state);
out:
- if (state.folio)
- folio_put(state.folio);
VM_WARN_ON_ONCE(copied < 0);
VM_WARN_ON_ONCE(err > 0);
VM_WARN_ON_ONCE(!copied && !err);
--
2.53.0