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

Revert "selftests/mm: replace atomic_bool with pthread_barrier_t"

This reverts commit e61ef21e27e8deed8c474e9f47f4aa7bc37e138c.

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/20241018171734.2315053-3-edliaw@google.com
Fixes: e61ef21e27e8 ("selftests/mm: replace atomic_bool with pthread_barrier_t")
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
3673167a 5bb1f4c9

+10 -12
+2 -3
tools/testing/selftests/mm/uffd-common.c
··· 18 18 unsigned long long *count_verify; 19 19 uffd_test_ops_t *uffd_test_ops; 20 20 uffd_test_case_ops_t *uffd_test_case_ops; 21 - pthread_barrier_t ready_for_fork; 21 + atomic_bool ready_for_fork; 22 22 23 23 static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) 24 24 { ··· 519 519 pollfd[1].fd = pipefd[cpu*2]; 520 520 pollfd[1].events = POLLIN; 521 521 522 - /* Ready for parent thread to fork */ 523 - pthread_barrier_wait(&ready_for_fork); 522 + ready_for_fork = true; 524 523 525 524 for (;;) { 526 525 ret = poll(pollfd, 2, -1);
+2 -1
tools/testing/selftests/mm/uffd-common.h
··· 33 33 #include <inttypes.h> 34 34 #include <stdint.h> 35 35 #include <sys/random.h> 36 + #include <stdatomic.h> 36 37 37 38 #include "../kselftest.h" 38 39 #include "vm_util.h" ··· 105 104 extern bool test_uffdio_wp; 106 105 extern unsigned long long *count_verify; 107 106 extern volatile bool test_uffdio_copy_eexist; 108 - extern pthread_barrier_t ready_for_fork; 107 + extern atomic_bool ready_for_fork; 109 108 110 109 extern uffd_test_ops_t anon_uffd_test_ops; 111 110 extern uffd_test_ops_t shmem_uffd_test_ops;
+6 -8
tools/testing/selftests/mm/uffd-unit-tests.c
··· 774 774 char c; 775 775 struct uffd_args args = { 0 }; 776 776 777 - pthread_barrier_init(&ready_for_fork, NULL, 2); 777 + ready_for_fork = false; 778 778 779 779 fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); 780 780 ··· 791 791 if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) 792 792 err("uffd_poll_thread create"); 793 793 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 */ 797 796 798 797 pid = fork(); 799 798 if (pid < 0) ··· 833 834 char c; 834 835 struct uffd_args args = { 0 }; 835 836 836 - pthread_barrier_init(&ready_for_fork, NULL, 2); 837 + ready_for_fork = false; 837 838 838 839 fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); 839 840 if (uffd_register(uffd, area_dst, nr_pages * page_size, ··· 844 845 if (pthread_create(&uffd_mon, NULL, uffd_poll_thread, &args)) 845 846 err("uffd_poll_thread create"); 846 847 847 - /* Wait for child thread to start before forking */ 848 - pthread_barrier_wait(&ready_for_fork); 849 - pthread_barrier_destroy(&ready_for_fork); 848 + while (!ready_for_fork) 849 + ; /* Wait for the poll_thread to start executing before forking */ 850 850 851 851 pid = fork(); 852 852 if (pid < 0)