The patch titled Subject: userfaultfd: selftest: recycle lock threads first has been added to the -mm tree. Its filename is userfaultfd-selftest-recycle-lock-threads-first.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/userfaultfd-selftest-recycle-lock-threads-first.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/userfaultfd-selftest-recycle-lock-threads-first.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Peter Xu <peterx@xxxxxxxxxx> Subject: userfaultfd: selftest: recycle lock threads first 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@xxxxxxxxxx Signed-off-by: Peter Xu <peterx@xxxxxxxxxx> Acked-by: Mike Rapoport <rppt@xxxxxxxxxxxxxxxxxx> Cc: Shuah Khan <shuah@xxxxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Jerome Glisse <jglisse@xxxxxxxxxx> Cc: Zi Yan <zi.yan@xxxxxxxxxxxxxx> Cc: "Kirill A . Shutemov" <kirill@xxxxxxxxxxxxx> Cc: Shaohua Li <shli@xxxxxx> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx> Cc: "Dr . David Alan Gilbert" <dgilbert@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- tools/testing/selftests/vm/userfaultfd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftest-recycle-lock-threads-first +++ a/tools/testing/selftests/vm/userfaultfd.c @@ -626,6 +626,12 @@ static int stress(unsigned long *userfau 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 *userfau } } - finished = 1; - for (cpu = 0; cpu < nr_cpus; cpu++) - if (pthread_join(locking_threads[cpu], NULL)) - return 1; - return 0; } _ Patches currently in -mm which might be from peterx@xxxxxxxxxx are userfaultfd-selftest-cleanup-help-messages.patch userfaultfd-selftest-generalize-read-and-poll.patch userfaultfd-selftest-recycle-lock-threads-first.patch