Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Suren Baghdasaryan and committed by
Andrew Morton
444eeb17 17c05f18

+9
+9
mm/memory.c
··· 5266 5266 if (!vma_start_read(vma)) 5267 5267 goto inval; 5268 5268 5269 + /* 5270 + * Due to the possibility of userfault handler dropping mmap_lock, avoid 5271 + * it for now and fall back to page fault handling under mmap_lock. 5272 + */ 5273 + if (userfaultfd_armed(vma)) { 5274 + vma_end_read(vma); 5275 + goto inval; 5276 + } 5277 + 5269 5278 /* Check since vm_start/vm_end might change before we lock the VMA */ 5270 5279 if (unlikely(address < vma->vm_start || address >= vma->vm_end)) { 5271 5280 vma_end_read(vma);