From: Andrea Arcangeli Date: Wed, 22 Feb 2017 23:42:43 +0000 (-0800) Subject: userfaultfd: non-cooperative: avoid MADV_DONTNEED race condition X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0594f58dbd954f7747553c041d7cbbf9b6ef1947;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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). Link: http://lkml.kernel.org/r/20161216144821.5183-15-aarcange@redhat.com Signed-off-by: Andrea Arcangeli Cc: "Dr. David Alan Gilbert" Cc: Hillf Danton Cc: Michael Rapoport Cc: Mike Kravetz Cc: Mike Rapoport Cc: Pavel Emelyanov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/madvise.c b/mm/madvise.c index 06ffb5a170de..ca75b8a01ba0 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -477,8 +477,8 @@ static long madvise_dontneed(struct vm_area_struct *vma, 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; }