From 12e4219d4990505fc560c3733fac169b1075acc5 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sun, 30 Oct 2022 17:34:25 +0000 Subject: [PATCH] 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. Signed-off-by: Suren Baghdasaryan Suggested-by: Peter Xu --- mm/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 57279e03f8885..a4982e16cf19f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5267,6 +5267,13 @@ retry: if (!vma_is_anonymous(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)) + goto inval; + if (!vma_read_trylock(vma)) { count_vm_vma_lock_event(VMA_LOCK_ABORT); goto inval; -- 2.50.1