The patch titled Subject: mm/mmap: introduce abort_munmap_vmas() has been added to the -mm mm-unstable branch. Its filename is mm-mmap-introduce-abort_munmap_vmas.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mmap-introduce-abort_munmap_vmas.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx> Subject: mm/mmap: introduce abort_munmap_vmas() Date: Tue, 11 Jun 2024 14:01:54 -0400 Extract clean up of failed munmap() operations from do_vmi_align_munmap(). This simplifies later patches in the series. Link: https://lkml.kernel.org/r/20240611180200.711239-3-Liam.Howlett@xxxxxxxxxx Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> Cc: Lorenzo Stoakes <lstoakes@xxxxxxxxx> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) --- a/mm/mmap.c~mm-mmap-introduce-abort_munmap_vmas +++ a/mm/mmap.c @@ -2587,6 +2587,25 @@ struct vm_area_struct *vma_merge_extend( } /* + * abort_munmap_vmas - Undo any munmap work and free resources + * + * Reattach detached vmas, free up maple tree used to track the vmas. + */ +static inline void abort_munmap_vmas(struct ma_state *mas_detach) +{ + struct vm_area_struct *vma; + int limit; + + limit = mas_detach->index; + mas_set(mas_detach, 0); + /* Re-attach any detached VMAs */ + mas_for_each(mas_detach, vma, limit) + vma_mark_detached(vma, false); + + __mt_destroy(mas_detach->tree); +} + +/* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator * @vma: The starting vm_area_struct @@ -2740,11 +2759,7 @@ clear_tree_failed: userfaultfd_error: munmap_gather_failed: end_split_failed: - mas_set(&mas_detach, 0); - mas_for_each(&mas_detach, next, end) - vma_mark_detached(next, false); - - __mt_destroy(&mt_detach); + abort_munmap_vmas(&mas_detach); start_split_failed: map_count_exceeded: validate_mm(mm); _ Patches currently in -mm which might be from Liam.Howlett@xxxxxxxxxx are mm-mmap-correctly-position-vma_iterator-in-__split_vma.patch mm-mmap-introduce-abort_munmap_vmas.patch mm-mmap-introduce-vmi_complete_munmap_vmas.patch mm-mmap-extract-the-gathering-of-vmas-from-do_vmi_align_munmap.patch mm-mmap-introduce-vma_munmap_struct-for-use-in-munmap-operations.patch mm-mmap-change-munmap-to-use-vma_munmap_struct-for-accounting-and-surrounding-vmas.patch mm-mmap-extract-validate_mm-from-vma_complete.patch mm-mmap-use-split-munmap-calls-for-map_fixed.patch