[Devel] [PATCH RHEL8 COMMIT] userfaultfd: selftest: recycle lock threads first

Konstantin Khorenko khorenko at virtuozzo.com
Mon Apr 20 10:34:00 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.6
------>
commit 03c4276aa59f7d0692999e33de15e759bf1f4b01
Author: Peter Xu <peterx at redhat.com>
Date:   Mon Apr 20 10:33:59 2020 +0300

    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@redhat.com
    Signed-off-by: Peter Xu <peterx at redhat.com>
    Acked-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
    Cc: Shuah Khan <shuah at kernel.org>
    Cc: Mike Kravetz <mike.kravetz at oracle.com>
    Cc: Jerome Glisse <jglisse at redhat.com>
    Cc: Zi Yan <zi.yan at cs.rutgers.edu>
    Cc: "Kirill A . Shutemov" <kirill at shutemov.name>
    Cc: Shaohua Li <shli at fb.com>
    Cc: Andrea Arcangeli <aarcange at redhat.com>
    Cc: "Dr . David Alan Gilbert" <dgilbert at redhat.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-102938
    (cherry picked from commit 7eaa8c969efa77127de9a05856eef9e5d22cf487)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 tools/testing/selftests/vm/userfaultfd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 7b8171e3128a..68bbe0eb203e 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -605,6 +605,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) {
@@ -622,11 +628,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;
 }
 


More information about the Devel mailing list