]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm/mmap: Use split munmap calls for MAP_FIXED map_fixed_no_hole_v1
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 19 Apr 2024 15:21:41 +0000 (11:21 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 7 Jun 2024 19:42:15 +0000 (15:42 -0400)
commit6afd9d3b1849eac4d86925336b1f55e3c1205cc4
tree4f1e286235a3e1d3c753bfed23961b68fff0e2ce
parentea539e32a3782b86f038b109047622d44395a61f
mm/mmap: Use split munmap calls for MAP_FIXED

Use vms_gather_munmap_vmas() and vms_complete_munmap_vmas() to prepare
and execute the unmapping after the new area is written to the maple
tree.  Delaying the unmapping avoids RCU readers seeing a gap in the
vmas, which isn't supposed to exist logically.

Gathering the vmas that will be unmapped allows for the accounting work
to be calculated prior to checking if there is enough memory.  Using the
number calculated during vms_gather_munmap_vmas() allows code to be
reduced in mmap_region().  This removes the only caller to
count_vma_pages_range(), so the function has been dropped.

This does have the side effect of allowing vmas to be split for unmap
and fail may_expand_vm(), but the number of pages covered will not
change.

The validate_mm() call in vma_expand() must be dropped as the MAP_FIXED
munmap may be in progress.  There is still a validate_mm() call at the
end of mmap_region(), which calls vma_expand().

Note that do_vmi_munmap() was previously used to munmap, which checked
alignment and overflow.  These checks were unnecessary as do_mmap()
already checks these cases, and arch/mips/kernel/vdso.c
arch_setup_additional_pages() uses predefined values that must already
pass these checks.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c