userfaultfd: non-cooperative: avoid MADV_DONTNEED race condition
Subsystems (2)
[email protected]
maintainerPATCH 59/142 userfaultfd: non-cooperative: avoid MADV_DONTNEED race condition
From: Andrea Arcangeli <[email protected]>
Subject: userfaultfd: non-cooperative: avoid MADV_DONTNEED race condition
MADV_DONTNEED must be notified to userland before the pages are zapped. This allows userland to immediately stop adding pages to the userfaultfd ranges before the pages are actually zapped or there could be non-zeropage leftovers as result of concurrent UFFDIO_COPY run in between zap_page_range and madvise_userfault_dontneed (both MADV_DONTNEED and UFFDIO_COPY runs under the mmap_sem for reading, so they can run concurrently).
Signed-off-by Andrea Arcangeli <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Michael Rapoport <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Pavel Emelyanov <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
mm/madvise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/madvise.c renamed from mm/madvise.c~userfaultfd-non-cooperative-avoid-madv_dontneed-race-condition +1 -1
@@ -477,8 +477,8 @@ static long madvise_dontneed(struct vm_aif (vma->vm_flags & (VM_LOCKED |VM_HUGETLB |VM_PFNMAP ))return -EINVAL ; -zap_page_range (vma, start, end - start,NULL );madvise_userfault_dontneed (vma, prev, start, end); +zap_page_range (vma, start, end - start,NULL );return 0 ; }
_