Skip to content

Commit 3673167

Browse files
edliawakpm00
authored andcommitted
Revert "selftests/mm: replace atomic_bool with pthread_barrier_t"
This reverts commit e61ef21. uffd_poll_thread may be called by other tests that do not initialize the pthread_barrier, so this approach is not correct. This will revert to using atomic_bool instead. Link: https://lkml.kernel.org/r/[email protected] Fixes: e61ef21 ("selftests/mm: replace atomic_bool with pthread_barrier_t") Signed-off-by: Edward Liaw <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Peter Xu <[email protected]> Cc: Shuah Khan <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5bb1f4c commit 3673167

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

tools/testing/selftests/mm/uffd-common.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool test_uffdio_wp = true;
1818
unsigned long long *count_verify;
1919
uffd_test_ops_t *uffd_test_ops;
2020
uffd_test_case_ops_t *uffd_test_case_ops;
21-
pthread_barrier_t ready_for_fork;
21+
atomic_bool ready_for_fork;
2222

2323
static int uffd_mem_fd_create(off_t mem_size, bool hugetlb)
2424
{
@@ -519,8 +519,7 @@ void *uffd_poll_thread(void *arg)
519519
pollfd[1].fd = pipefd[cpu*2];
520520
pollfd[1].events = POLLIN;
521521

522-
/* Ready for parent thread to fork */
523-
pthread_barrier_wait(&ready_for_fork);
522+
ready_for_fork = true;
524523

525524
for (;;) {
526525
ret = poll(pollfd, 2, -1);

tools/testing/selftests/mm/uffd-common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <inttypes.h>
3434
#include <stdint.h>
3535
#include <sys/random.h>
36+
#include <stdatomic.h>
3637

3738
#include "../kselftest.h"
3839
#include "vm_util.h"
@@ -104,7 +105,7 @@ extern bool map_shared;
104105
extern bool test_uffdio_wp;
105106
extern unsigned long long *count_verify;
106107
extern volatile bool test_uffdio_copy_eexist;
107-
extern pthread_barrier_t ready_for_fork;
108+
extern atomic_bool ready_for_fork;
108109

109110
extern uffd_test_ops_t anon_uffd_test_ops;
110111
extern uffd_test_ops_t shmem_uffd_test_ops;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ static void uffd_sigbus_test_common(bool wp)
774774
char c;
775775
struct uffd_args args = { 0 };
776776

777-
pthread_barrier_init(&ready_for_fork, NULL, 2);
777+
ready_for_fork = false;
778778

779779
fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK);
780780

@@ -791,9 +791,8 @@ static void uffd_sigbus_test_common(bool wp)
791791
if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args))
792792
err("uffd_poll_thread create");
793793

794-
/* Wait for child thread to start before forking */
795-
pthread_barrier_wait(&ready_for_fork);
796-
pthread_barrier_destroy(&ready_for_fork);
794+
while (!ready_for_fork)
795+
; /* Wait for the poll_thread to start executing before forking */
797796

798797
pid = fork();
799798
if (pid < 0)
@@ -834,7 +833,7 @@ static void uffd_events_test_common(bool wp)
834833
char c;
835834
struct uffd_args args = { 0 };
836835

837-
pthread_barrier_init(&ready_for_fork, NULL, 2);
836+
ready_for_fork = false;
838837

839838
fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK);
840839
if (uffd_register(uffd, area_dst, nr_pages * page_size,
@@ -845,9 +844,8 @@ static void uffd_events_test_common(bool wp)
845844
if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args))
846845
err("uffd_poll_thread create");
847846

848-
/* Wait for child thread to start before forking */
849-
pthread_barrier_wait(&ready_for_fork);
850-
pthread_barrier_destroy(&ready_for_fork);
847+
while (!ready_for_fork)
848+
; /* Wait for the poll_thread to start executing before forking */
851849

852850
pid = fork();
853851
if (pid < 0)

0 commit comments

Comments
 (0)