From 1797ae91c515ee03e5ad60c13de1703426a18c95 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 21 Apr 2022 18:00:09 -0400 Subject: [PATCH] convert vma_expand() to prealloc Signed-off-by: Liam R. Howlett --- mm/mmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; } /* -- 2.49.0