userfaultfd: selftest: recycle lock threads first
authorPeter Xu <peterx@redhat.com>
Fri, 26 Oct 2018 22:09:17 +0000 (15:09 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Oct 2018 23:26:35 +0000 (16:26 -0700)
Now we recycle the uffd servicing threads earlier than the lock threads.
It might happen that when the lock thread is still blocked at a pthread
mutex lock while the servicing thread has already quitted for the cpu so
the lock thread will be blocked forever and hang the test program.  To fix
the possible race, recycle the lock threads first.

This never happens with current missing-only tests, but when I start to
run the write-protection tests (the feature is not yet posted upstream) it
happens every time of the run possibly because in that new test we'll need
to service two page faults for each lock operation.

Link: http://lkml.kernel.org/r/20180930074259.18229-4-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Zi Yan <zi.yan@cs.rutgers.edu>
Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
Cc: Shaohua Li <shli@fb.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
tools/testing/selftests/vm/userfaultfd.c

index 7a8c693..5d1db82 100644 (file)
@@ -626,6 +626,12 @@ static int stress(unsigned long *userfaults)
        if (uffd_test_ops->release_pages(area_src))
                return 1;
 
+
+       finished = 1;
+       for (cpu = 0; cpu < nr_cpus; cpu++)
+               if (pthread_join(locking_threads[cpu], NULL))
+                       return 1;
+
        for (cpu = 0; cpu < nr_cpus; cpu++) {
                char c;
                if (bounces & BOUNCE_POLL) {
@@ -643,11 +649,6 @@ static int stress(unsigned long *userfaults)
                }
        }
 
-       finished = 1;
-       for (cpu = 0; cpu < nr_cpus; cpu++)
-               if (pthread_join(locking_threads[cpu], NULL))
-                       return 1;
-
        return 0;
 }