Skip to content

Commit

Permalink
mm/mmap: remove preallocation from do_mas_align_munmap()
Browse files Browse the repository at this point in the history
In preparation of passing the vma state through split, the pre-allocation
that occurs before the split has to be moved to after.  Since the
preallocation would then live right next to the store, just call store
instead of preallocating.  This effectively restores the potential error
path of splitting and not munmap'ing which pre-dates the maple tree.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Liam R. Howlett <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
howlett authored and akpm00 committed Feb 10, 2023
1 parent 79e4f2c commit 0378c0a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2329,9 +2329,6 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
mt_init_flags(&mt_detach, MT_FLAGS_LOCK_EXTERN);
mt_set_external_lock(&mt_detach, &mm->mmap_lock);

if (mas_preallocate(mas, GFP_KERNEL))
return -ENOMEM;

mas->last = end - 1;
/*
* If we need to split any vma, do it now to save pain later.
Expand Down Expand Up @@ -2422,15 +2419,14 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
goto userfaultfd_error;
}

/* Point of no return */
mas_set_range(mas, start, end - 1);
#if defined(CONFIG_DEBUG_VM_MAPLE_TREE)
/* Make sure no VMAs are about to be lost. */
{
MA_STATE(test, &mt_detach, start, end - 1);
struct vm_area_struct *vma_mas, *vma_test;
int test_count = 0;

mas_set_range(mas, start, end - 1);
rcu_read_lock();
vma_test = mas_find(&test, end - 1);
mas_for_each(mas, vma_mas, end - 1) {
Expand All @@ -2440,10 +2436,13 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
}
rcu_read_unlock();
BUG_ON(count != test_count);
mas_set_range(mas, start, end - 1);
}
#endif
mas_store_prealloc(mas, NULL);
/* Point of no return */
mas_set_range(mas, start, end - 1);
if (mas_store_gfp(mas, NULL, GFP_KERNEL))
return -ENOMEM;

mm->map_count -= count;
/*
* Do not downgrade mmap_lock if we are next to VM_GROWSDOWN or
Expand Down Expand Up @@ -2475,7 +2474,6 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma,
__mt_destroy(&mt_detach);
start_split_failed:
map_count_exceeded:
mas_destroy(mas);
return error;
}

Expand Down

0 comments on commit 0378c0a

Please sign in to comment.