Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 6b91fd6

Browse files
edliawgregkh
authored andcommitted
selftests/mm: fix deadlock for fork after pthread_create on ARM
commit e142cc8 upstream. On Android with arm, there is some synchronization needed to avoid a deadlock when forking after pthread_create. 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: Lokesh Gidra <[email protected]> Cc: Peter Xu <[email protected]> Cc: Shuah Khan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8f5fa1c commit 6b91fd6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ static void *fork_event_consumer(void *data)
237237
fork_event_args *args = data;
238238
struct uffd_msg msg = { 0 };
239239

240+
/* Ready for parent thread to fork */
241+
pthread_barrier_wait(&ready_for_fork);
242+
240243
/* Read until a full msg received */
241244
while (uffd_read_msg(args->parent_uffd, &msg));
242245

@@ -304,8 +307,12 @@ static int pagemap_test_fork(int uffd, bool with_event, bool test_pin)
304307

305308
/* Prepare a thread to resolve EVENT_FORK */
306309
if (with_event) {
310+
pthread_barrier_init(&ready_for_fork, NULL, 2);
307311
if (pthread_create(&thread, NULL, fork_event_consumer, &args))
308312
err("pthread_create()");
313+
/* Wait for child thread to start before forking */
314+
pthread_barrier_wait(&ready_for_fork);
315+
pthread_barrier_destroy(&ready_for_fork);
309316
}
310317

311318
child = fork();

0 commit comments

Comments
 (0)