From 501b8f4789894b08f735f708fe818233e198bd09 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 21 Apr 2022 18:00:44 -0400 Subject: [PATCH] convert __vma_adjust to prealloc Signed-off-by: Liam R. Howlett --- mm/mmap.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4ef7d19e9ca8..a642b4e3fc4f 100644 --- 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; -- 2.49.0