selftests/mm: fix deadlock for fork after pthread_create with atomic_bool

Some additional synchronization is needed on Android ARM64; we see a
deadlock with pthread_create when the parent thread races forward before
the child has a chance to start doing work.

Link: https://lkml.kernel.org/r/20241018171734.2315053-4-edliaw@google.com
Fixes: cff2945827 ("selftests/mm: extend and rename uffd pagemap test")
Signed-off-by: Edward Liaw <edliaw@google.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Edward Liaw 2024-10-18 17:17:24 +00:00 committed by Andrew Morton
parent 3673167a3a
commit f2330b650e

View file

@ -241,6 +241,8 @@ static void *fork_event_consumer(void *data)
fork_event_args *args = data; fork_event_args *args = data;
struct uffd_msg msg = { 0 }; struct uffd_msg msg = { 0 };
ready_for_fork = true;
/* Read until a full msg received */ /* Read until a full msg received */
while (uffd_read_msg(args->parent_uffd, &msg)); while (uffd_read_msg(args->parent_uffd, &msg));
@ -308,8 +310,11 @@ static int pagemap_test_fork(int uffd, bool with_event, bool test_pin)
/* Prepare a thread to resolve EVENT_FORK */ /* Prepare a thread to resolve EVENT_FORK */
if (with_event) { if (with_event) {
ready_for_fork = false;
if (pthread_create(&thread, NULL, fork_event_consumer, &args)) if (pthread_create(&thread, NULL, fork_event_consumer, &args))
err("pthread_create()"); err("pthread_create()");
while (!ready_for_fork)
; /* Wait for the poll_thread to start executing before forking */
} }
child = fork(); child = fork();