Skip to content

Commit 28c5609

Browse files
howlettakpm00
authored andcommitted
mm/mmap: preallocate maple nodes for brk vma expansion
If the brk VMA is the last vma in a maple node and meets the rare criteria that it can be expanded, then preallocation is necessary to avoid a potential fs_reclaim circular lock issue on low resources. At the same time use the actual vma start address (unaligned) when calling vma_adjust_trans_huge(). Link: https://lkml.kernel.org/r/[email protected] Fixes: 2e7ce7d (mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()) Signed-off-by: Liam R. Howlett <[email protected]> Reported-by: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7be1c1a commit 28c5609

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

mm/mmap.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,17 +2942,18 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
29422942
if (vma &&
29432943
(!vma->anon_vma || list_is_singular(&vma->anon_vma_chain)) &&
29442944
((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) {
2945-
mas->index = vma->vm_start;
2946-
mas->last = addr + len - 1;
2947-
vma_adjust_trans_huge(vma, addr, addr + len, 0);
2945+
mas_set_range(mas, vma->vm_start, addr + len - 1);
2946+
if (mas_preallocate(mas, vma, GFP_KERNEL))
2947+
return -ENOMEM;
2948+
2949+
vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0);
29482950
if (vma->anon_vma) {
29492951
anon_vma_lock_write(vma->anon_vma);
29502952
anon_vma_interval_tree_pre_update_vma(vma);
29512953
}
29522954
vma->vm_end = addr + len;
29532955
vma->vm_flags |= VM_SOFTDIRTY;
2954-
if (mas_store_gfp(mas, vma, GFP_KERNEL))
2955-
goto mas_expand_failed;
2956+
mas_store_prealloc(mas, vma);
29562957

29572958
if (vma->anon_vma) {
29582959
anon_vma_interval_tree_post_update_vma(vma);
@@ -2993,13 +2994,6 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma,
29932994
vma_alloc_fail:
29942995
vm_unacct_memory(len >> PAGE_SHIFT);
29952996
return -ENOMEM;
2996-
2997-
mas_expand_failed:
2998-
if (vma->anon_vma) {
2999-
anon_vma_interval_tree_post_update_vma(vma);
3000-
anon_vma_unlock_write(vma->anon_vma);
3001-
}
3002-
return -ENOMEM;
30032997
}
30042998

30052999
int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags)

0 commit comments

Comments
 (0)