From: Liam R. Howlett Date: Thu, 21 Apr 2022 22:00:09 +0000 (-0400) Subject: convert vma_expand() to prealloc X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1797ae91c515ee03e5ad60c13de1703426a18c95;p=users%2Fjedix%2Flinux-maple.git convert vma_expand() to prealloc Signed-off-by: Liam R. Howlett --- diff --git a/mm/mmap.c b/mm/mmap.c index 2aa27adb39b1..4ef7d19e9ca8 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -559,6 +559,7 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma, struct anon_vma *anon_vma = vma->anon_vma; struct file *file = vma->vm_file; bool remove_next = false; + bool anon_cloned = false; if (next && (vma != next) && (end == next->vm_end)) { remove_next = true; @@ -569,6 +570,7 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma, error = anon_vma_clone(vma, next); if (error) return error; + anon_cloned = true; } } @@ -577,6 +579,9 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma, /* Only handles expanding */ VM_BUG_ON(vma->vm_start < start || vma->vm_end > end); + if (mas_preallocate(mas, vma, GFP_KERNEL)) + goto nomem; + vma_adjust_trans_huge(vma, start, end, 0); if (file) { @@ -631,6 +636,11 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma, validate_mm(mm); return 0; + +nomem: + if (anon_cloned) + unlink_anon_vmas(vma); + return -ENOMEM; } /*