aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory.c
diff options
context:
space:
mode:
authorSuren Baghdasaryan <surenb@google.com>2023-02-27 09:36:23 -0800
committerAndrew Morton <akpm@linux-foundation.org>2023-04-05 20:03:00 -0700
commit2ac0af1b66e3b66307f53b1cc446514308ec466d (patch)
tree601322705eed941a97bdf9f872df22da8fa01765 /mm/memory.c
parent50ee32537206140e4cf6e47024be29a84d458d49 (diff)
downloadlinux-2ac0af1b66e3b66307f53b1cc446514308ec466d.tar.gz
mm: fall back to mmap_lock if vma->anon_vma is not yet set
When vma->anon_vma is not set, page fault handler will set it by either reusing anon_vma of an adjacent VMA if VMAs are compatible or by allocating a new one. find_mergeable_anon_vma() walks VMA tree to find a compatible adjacent VMA and that requires not only the faulting VMA to be stable but also the tree structure and other VMAs inside that tree. Therefore locking just the faulting VMA is not enough for this search. Fall back to taking mmap_lock when vma->anon_vma is not set. This situation happens only on the first page fault and should not affect overall performance. Link: https://lkml.kernel.org/r/20230227173632.3292573-25-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/memory.c')
-rw-r--r--mm/memory.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 1235de20af7398..10d497a5296c3d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5254,6 +5254,10 @@ retry:
if (!vma_is_anonymous(vma))
goto inval;
+ /* find_mergeable_anon_vma uses adjacent vmas which are not locked */
+ if (!vma->anon_vma)
+ goto inval;
+
if (!vma_start_read(vma))
goto inval;