Skip to content

Commit f2330b6

Browse files
edliawakpm00
authored andcommitted
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/[email protected] Fixes: cff2945 ("selftests/mm: extend and rename uffd pagemap test") Signed-off-by: Edward Liaw <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Peter Xu <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3673167 commit f2330b6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/testing/selftests/mm/uffd-unit-tests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ static void *fork_event_consumer(void *data)
241241
fork_event_args *args = data;
242242
struct uffd_msg msg = { 0 };
243243

244+
ready_for_fork = true;
245+
244246
/* Read until a full msg received */
245247
while (uffd_read_msg(args->parent_uffd, &msg));
246248

@@ -308,8 +310,11 @@ static int pagemap_test_fork(int uffd, bool with_event, bool test_pin)
308310

309311
/* Prepare a thread to resolve EVENT_FORK */
310312
if (with_event) {
313+
ready_for_fork = false;
311314
if (pthread_create(&thread, NULL, fork_event_consumer, &args))
312315
err("pthread_create()");
316+
while (!ready_for_fork)
317+
; /* Wait for the poll_thread to start executing before forking */
313318
}
314319

315320
child = fork();

0 commit comments

Comments
 (0)