]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: Use vma_iter_next_range() in mmap_region()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 24 Apr 2023 15:33:47 +0000 (11:33 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 24 Apr 2023 20:20:43 +0000 (16:20 -0400)
When checking the surrounding VMAs, the VMA iterator is moved to the
previous VMA. If they can merge, then the VMA iterator is in the correct
position.  If they are not, then the iterator needs to be moved back to
the gap that will be filled.  Use vma_iter_next_range() to move the
iterator to the next range instead of re-walking the VMA tree.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c

index c0140a556870a2148cbc0a3ebcd1a1b404eea4b9..4c7c0e2c8fab7b65c75d691fb8a86297a4732059 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2575,8 +2575,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 
        next = vma_next(&vmi);
        prev = vma_prev(&vmi);
-       if (vm_flags & VM_SPECIAL)
+       if (vm_flags & VM_SPECIAL) {
+               vma_iter_next_range(&vmi);
                goto cannot_expand;
+       }
 
        /* Attempt to expand an old mapping */
        /* Check next */
@@ -2597,6 +2599,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
                merge_start = prev->vm_start;
                vma = prev;
                vm_pgoff = prev->vm_pgoff;
+       } else {
+               vma_iter_next_range(&vmi);
        }
 
 
@@ -2607,6 +2611,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
                goto expanded;
        }
 
+       if (prev && prev == vma) /* vma_expand() failed to expand prev */
+               vma_iter_next_range(&vmi);
+
 cannot_expand:
        /*
         * Determine the object being mapped and call the appropriate
@@ -2619,7 +2626,6 @@ cannot_expand:
                goto unacct_error;
        }
 
-       vma_iter_set(&vmi, addr);
        vma->vm_start = addr;
        vma->vm_end = end;
        vm_flags_init(vma, vm_flags);