Skip to contentSkip to conversation

userfaultfd: non-cooperative: avoid MADV_DONTNEED race condition

PATCH New [email protected] 1 participant 1 message Feb 22, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 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).

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]>

---

 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
diff -puN mm/madvise.c~userfaultfd-non-cooperative-avoid-madv_dontneed-race-condition mm/madvise.c
@@ -477,8 +477,8 @@ static long madvise_dontneed(struct vm_a
 	if (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;
 }
 

_