Skip to content

Commit

Permalink
mm/mmap: write-lock VMAs in vma_prepare before modifying them
Browse files Browse the repository at this point in the history
Write-lock all VMAs which might be affected by a merge, split, expand or
shrink operations.  All these operations use vma_prepare() before making
the modifications, therefore it provides a centralized place to perform
VMA locking.

[surenb@google.com: remove unnecessary vp->vma check in vma_prepare]
  Link: https://lkml.kernel.org/r/20230301022720.1380780-1-surenb@google.com
  Link: https://lore.kernel.org/r/202302281802.J93Nma7q-lkp@intel.com/
Link: https://lkml.kernel.org/r/20230227173632.3292573-17-surenb@google.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Laurent Dufour <laurent.dufour@fr.ibm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Suren Baghdasaryan authored and Andrew Morton committed Apr 6, 2023
1 parent 55fd6fc commit 10fca64
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ static inline void init_vma_prep(struct vma_prepare *vp,
*/
static inline void vma_prepare(struct vma_prepare *vp)
{
vma_start_write(vp->vma);
if (vp->adj_next)
vma_start_write(vp->adj_next);
/* vp->insert is always a newly created VMA, no need for locking */
if (vp->remove)
vma_start_write(vp->remove);
if (vp->remove2)
vma_start_write(vp->remove2);

if (vp->file) {
uprobe_munmap(vp->vma, vp->vma->vm_start, vp->vma->vm_end);

Expand Down

0 comments on commit 10fca64

Please sign in to comment.