On Thu, 2 Apr 2026 16:47:28 +0300 Mike Rapoport <[email protected]> wrote:

> > Drop the retry logic from mfill_atomic().
> > 
> > Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>
> > ---
> >  mm/userfaultfd.c | 24 ------------------------
> >  1 file changed, 24 deletions(-)
> 
> After discussion with David Carlier about potential replacement of VMA in
> mfill_copy_folio_retry(), I looked again in the code and realized that
> after all the rebases I didn't remove the bit that temporarily prevented
> returning ENOENT from __mfill_atomic_pte().
> 
> Andrew, can you please fold this into "userfaultfd: mfill_atomic(): remove
> retry logic"?
> 
> For a change it applies cleanly :)

done.

> commit 5173c8f4fd32f314907b3804217ef57d4e3a2220
> Author: Mike Rapoport (Microsoft) <[email protected]>
> Date:   Thu Apr 2 16:38:39 2026 +0300
> 
>     userfaultfd: remove safety mesaure of not returning ENOENT from _copy

s/mesaure/measure/

Was "_copy" intended?

>     
>     Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>

I instafolded this.  End result:


From: "Mike Rapoport (Microsoft)" <[email protected]>
Subject: userfaultfd: mfill_atomic(): remove retry logic
Date: Thu, 2 Apr 2026 07:11:52 +0300

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

[[email protected]: remove safety measure of not returning ENOENT from _copy]
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Andrei Vagin <[email protected]>
Cc: Axel Rasmussen <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: David Hildenbrand (Arm) <[email protected]>
Cc: Harry Yoo <[email protected]>
Cc: Harry Yoo (Oracle) <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: James Houghton <[email protected]>
Cc: Liam Howlett <[email protected]>
Cc: Lorenzo Stoakes (Oracle) <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Nikita Kalyazin <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

 mm/userfaultfd.c |   27 ---------------------------
 1 file changed, 27 deletions(-)

--- a/mm/userfaultfd.c~userfaultfd-mfill_atomic-remove-retry-logic
+++ a/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;
 };
 
@@ -531,9 +530,6 @@ err_filemap_remove:
                ops->filemap_remove(folio, state->vma);
 err_folio_put:
        folio_put(folio);
-       /* Don't return -ENOENT so that our caller won't retry */
-       if (ret == -ENOENT)
-               ret = -EFAULT;
        return ret;
 }
 
@@ -899,7 +895,6 @@ static __always_inline ssize_t mfill_ato
        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 +921,6 @@ retry:
                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 +935,6 @@ retry:
 
        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);
_


Reply via email to