]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: use vma_start_write_killable() in dup_mmap()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 10 Nov 2025 20:32:02 +0000 (20:32 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 20 Nov 2025 21:43:59 +0000 (13:43 -0800)
Allow waiting for the VMA write lock to be interrupted by fatal signals.
The explicit check for fatal_signal_pending() can be removed as it is
checked during vma_start_write_killable().  Improves the latency of
killing the task as we do not wait for the reader to finish before
checking for signals.

Link: https://lkml.kernel.org/r/20251110203204.1454057-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Chris Li <chriscli@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c

index 4f51ca644903494475d6ac03f00bd05677dd8ded..dc51680824ecdb04adcb3fc4a36faff51f5e922f 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1747,7 +1747,9 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
        for_each_vma(vmi, mpnt) {
                struct file *file;
 
-               vma_start_write(mpnt);
+               retval = vma_start_write_killable(mpnt);
+               if (retval < 0)
+                       goto loop_out;
                if (mpnt->vm_flags & VM_DONTCOPY) {
                        retval = vma_iter_clear_gfp(&vmi, mpnt->vm_start,
                                                    mpnt->vm_end, GFP_KERNEL);
@@ -1758,14 +1760,6 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
                        continue;
                }
                charge = 0;
-               /*
-                * Don't duplicate many vmas if we've been oom-killed (for
-                * example)
-                */
-               if (fatal_signal_pending(current)) {
-                       retval = -EINTR;
-                       goto loop_out;
-               }
                if (mpnt->vm_flags & VM_ACCOUNT) {
                        unsigned long len = vma_pages(mpnt);