From: Suren Baghdasaryan Date: Mon, 27 Feb 2023 17:36:26 +0000 (-0800) Subject: mm: prevent userfaults to be handled under per-vma lock X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1692a6ebc9df3b97a5316b7aba2116ced4280bd4;p=users%2Fjedix%2Flinux-maple.git 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 Suggested-by: Peter Xu Signed-off-by: Andrew Morton --- diff --git a/mm/memory.c b/mm/memory.c index bc6b6128e6b6..e37ce64c646e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5270,6 +5270,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);