From: Suren Baghdasaryan Date: Mon, 27 Feb 2023 17:36:15 +0000 (-0800) Subject: mm/mmap: write-lock VMAs in vma_prepare before modifying them X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=10fca64a661199910c7d13077e9678c9a06bf285;p=linux.git mm/mmap: write-lock VMAs in vma_prepare before modifying them 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 Reviewed-by: David Hildenbrand Reviewed-by: Liam R. Howlett Cc: David Howells Cc: Hugh Dickins Cc: Jason Gunthorpe Cc: Laurent Dufour Cc: Mathieu Desnoyers Cc: Matthew Wilcox Cc: Pavel Tatashin Cc: Stephen Rothwell Cc: Yu Zhao Signed-off-by: Andrew Morton --- diff --git a/mm/mmap.c b/mm/mmap.c index e8f019eecd0f1..82999e0c3c319 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -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);