]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
convert __vma_adjust to prealloc
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 22:00:44 +0000 (18:00 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 22:35:00 +0000 (18:35 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c

index 4ef7d19e9ca891b4556fcb64262f5f0f99385066..a642b4e3fc4f9870feaa8221748cc4e5bef8635a 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -522,16 +522,6 @@ static void vma_link(struct mm_struct *mm, struct vm_area_struct *vma)
        validate_mm(mm);
 }
 
-/*
- * Helper for vma_adjust() in the split_vma insert case: insert a vma into the
- * mm's list and the mm tree.  It has already been inserted into the interval tree.
- */
-static void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
-{
-       vma_store(mm, vma);
-       mm->map_count++;
-}
-
 /*
  * vma_expand - Expand an existing VMA
  *
@@ -664,9 +654,10 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
        bool vma_changed = false;
        long adjust_next = 0;
        int remove_next = 0;
+       MA_STATE(mas, &mm->mm_mt, 0, 0);
+       struct vm_area_struct *exporter = NULL, *importer = NULL;
 
        if (next && !insert) {
-               struct vm_area_struct *exporter = NULL, *importer = NULL;
 
                if (end >= next->vm_end) {
                        /*
@@ -751,6 +742,12 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
 again:
        vma_adjust_trans_huge(orig_vma, start, end, adjust_next);
 
+       if (mas_preallocate(&mas, vma, GFP_KERNEL)) {
+               if (exporter && exporter->anon_vma)
+                       unlink_anon_vmas(importer);
+               return -ENOMEM;
+       }
+
        if (file) {
                mapping = file->f_mapping;
                root = &mapping->i_mmap;
@@ -814,13 +811,13 @@ again:
        }
 
        if (vma_changed)
-               vma_store(mm, vma);
+               vma_mas_store(vma, &mas);
 
        vma->vm_pgoff = pgoff;
        if (adjust_next) {
                next->vm_start += adjust_next;
                next->vm_pgoff += adjust_next >> PAGE_SHIFT;
-               vma_store(mm, next);
+               vma_mas_store(next, &mas);
        }
 
        if (file) {
@@ -838,7 +835,9 @@ again:
                 * us to insert it before dropping the locks
                 * (it may either follow vma or precede it).
                 */
-               __insert_vm_struct(mm, insert);
+               mas_reset(&mas);
+               vma_mas_store(insert, &mas);
+               mm->map_count++;
        }
 
        if (anon_vma) {
@@ -865,7 +864,9 @@ again:
                        anon_vma_merge(vma, next);
                mm->map_count--;
                mpol_put(vma_policy(next));
+               BUG_ON(vma->vm_end < next->vm_end);
                vm_area_free(next);
+
                /*
                 * In mprotect's case 6 (see comments on vma_merge),
                 * we must remove another next too. It would clutter
@@ -893,7 +894,7 @@ again:
                        next = vma;
                }
                if (remove_next == 2) {
-                       vma_changed = false;
+                       mas_reset(&mas);
                        remove_next = 1;
                        end = next->vm_end;
                        goto again;