linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] Avoid MAP_FIXED gap exposure
@ 2024-05-31 16:32 Liam R. Howlett
  2024-05-31 16:32 ` [RFC PATCH 1/5] mm/mmap: Correctly position vma_iterator in __split_vma() Liam R. Howlett
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Liam R. Howlett @ 2024-05-31 16:32 UTC (permalink / raw)
  To: Suren Baghdasaryan, Andrii Nakryiko
  Cc: Vlastimil Babka, sidhartha.kumar, Matthew Wilcox, Lorenzo Stoakes,
	Liam R . Howlett, linux-fsdevel, bpf, linux-mm, linux-kernel

It is now possible to walk the vma tree using the rcu read locks and is
beneficial to do so to reduce lock contention.  Doing so while a
MAP_FIXED mapping is executing means that a reader may see a gap in the
vma tree that should never logically exist - and does not when using the
mmap lock in read mode.  The temporal gap exists because mmap_region()
calls munmap() prior to installing the new mapping.

This patch set stops rcu readers from seeing the temporal gap by
splitting up the munmap() function into two parts.  The first part
prepares the vma tree for modifications by doing the necessary splits
and tracks the vmas in a side tree.  The second part completes the
munmapping of the vmas after the vma tree has been overwritten (either
by a MAP_FIXED replacement vma or by a NULL in the munmap() case).

Please note that rcu walkers will still be able to see a temporary state
of split vmas that may be in the process of being removed, but the
temporal gap will not be exposed.  vma_start_write() are called on both
parts of the split vma, so this state is detectable.

I am sending this as an RFC as Andrii Nakryiko [1] and Suren
Baghdasaryan are both working on features that require the vma tree to
avoid exposing this temporal gap to rcu readers.

[1] https://lore.kernel.org/all/gkhzuurhqhtozk6u53ufkesbhtjse5ba6kovqm7mnzrqe3szma@3tpbspq7hxjl/

Liam R. Howlett (5):
  mm/mmap: Correctly position vma_iterator in __split_vma()
  mm/mmap: Split do_vmi_align_munmap() into a gather and complete
    operation
  mm/mmap: Introduce vma_munmap_struct for use in munmap operations
  mm/mmap: Change munmap to use vma_munmap_struct() for accounting and
    surrounding vmas
  mm/mmap: Use split munmap calls for MAP_FIXED

 mm/internal.h |  22 +++
 mm/mmap.c     | 382 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 258 insertions(+), 146 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-06-10 12:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31 16:32 [RFC PATCH 0/5] Avoid MAP_FIXED gap exposure Liam R. Howlett
2024-05-31 16:32 ` [RFC PATCH 1/5] mm/mmap: Correctly position vma_iterator in __split_vma() Liam R. Howlett
2024-06-06  0:51   ` Suren Baghdasaryan
2024-06-07 14:25     ` Liam R. Howlett
2024-06-10 12:09   ` Lorenzo Stoakes
2024-05-31 16:32 ` [RFC PATCH 2/5] mm/mmap: Split do_vmi_align_munmap() into a gather and complete operation Liam R. Howlett
2024-06-07  0:14   ` Suren Baghdasaryan
2024-06-07 14:23     ` Liam R. Howlett
2024-05-31 16:32 ` [RFC PATCH 3/5] mm/mmap: Introduce vma_munmap_struct for use in munmap operations Liam R. Howlett
2024-06-07 14:38   ` Suren Baghdasaryan
2024-05-31 16:32 ` [RFC PATCH 4/5] mm/mmap: Change munmap to use vma_munmap_struct() for accounting and surrounding vmas Liam R. Howlett
2024-06-07 14:38   ` Suren Baghdasaryan
2024-06-07 15:24     ` Liam R. Howlett
2024-05-31 16:32 ` [RFC PATCH 5/5] mm/mmap: Use split munmap calls for MAP_FIXED Liam R. Howlett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).