aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory.c
diff options
context:
space:
mode:
authorSuren Baghdasaryan <surenb@google.com>2023-02-27 09:36:26 -0800
committerAndrew Morton <akpm@linux-foundation.org>2023-04-05 20:03:01 -0700
commit444eeb17437a0ef526c606e9141a415d3b7dfddd (patch)
tree4a62168d40f3df1e5bd42084e790af170551a07c /mm/memory.c
parent17c05f18e54158a3eed0c22c85b7a756b63dcc01 (diff)
downloadlinux-444eeb17437a0ef526c606e9141a415d3b7dfddd.tar.gz
mm: prevent userfaults to be handled under per-vma lock
Due to the possibility of handle_userfault dropping mmap_lock, avoid fault handling under VMA lock and retry holding mmap_lock. This can be handled more gracefully in the future. Link: https://lkml.kernel.org/r/20230227173632.3292573-28-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Suggested-by: Peter Xu <peterx@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/memory.c')
-rw-r--r--mm/memory.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 70f4b1222e5d0..55ac9cdfd3983 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5266,6 +5266,15 @@ retry:
if (!vma_start_read(vma))
goto inval;
+ /*
+ * Due to the possibility of userfault handler dropping mmap_lock, avoid
+ * it for now and fall back to page fault handling under mmap_lock.
+ */
+ if (userfaultfd_armed(vma)) {
+ vma_end_read(vma);
+ goto inval;
+ }
+
/* Check since vm_start/vm_end might change before we lock the VMA */
if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {
vma_end_read(vma);