Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "selftests/mm: fix deadlock for fork after pthread_create on ARM"

Patch series "selftests/mm: revert pthread_barrier change"

On Android arm, pthread_create followed by a fork caused a deadlock in
the case where the fork required work to be completed by the created
thread.

The previous patches incorrectly assumed that the parent would
always initialize the pthread_barrier for the child thread. This
reverts the change and replaces the fix for wp-fork-with-event with the
original use of atomic_bool.


This patch (of 3):

This reverts commit e142cc87ac4ec618f2ccf5f68aedcd6e28a59d9d.

fork_event_consumer may be called by other tests that do not initialize
the pthread_barrier, so this approach is not correct. The subsequent
patch will revert to using atomic_bool instead.

Link: https://lkml.kernel.org/r/20241018171734.2315053-1-edliaw@google.com
Link: https://lkml.kernel.org/r/20241018171734.2315053-2-edliaw@google.com
Fixes: e142cc87ac4e ("fix deadlock for fork after pthread_create on ARM")
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>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Edward Liaw and committed by
Andrew Morton
5bb1f4c9 e8133a77

-7
-7
tools/testing/selftests/mm/uffd-unit-tests.c
··· 241 241 fork_event_args *args = data; 242 242 struct uffd_msg msg = { 0 }; 243 243 244 - /* Ready for parent thread to fork */ 245 - pthread_barrier_wait(&ready_for_fork); 246 - 247 244 /* Read until a full msg received */ 248 245 while (uffd_read_msg(args->parent_uffd, &msg)); 249 246 ··· 308 311 309 312 /* Prepare a thread to resolve EVENT_FORK */ 310 313 if (with_event) { 311 - pthread_barrier_init(&ready_for_fork, NULL, 2); 312 314 if (pthread_create(&thread, NULL, fork_event_consumer, &args)) 313 315 err("pthread_create()"); 314 - /* Wait for child thread to start before forking */ 315 - pthread_barrier_wait(&ready_for_fork); 316 - pthread_barrier_destroy(&ready_for_fork); 317 316 } 318 317 319 318 child = fork();