testsuite/smokey/y2038: Plug race between interruption signaler and waiter
PATCH 1/1 testsuite/smokey/y2038: Plug race between interruption signaler and waiter
From: Jan Kiszka <[email protected]>
While testing pselect interruption, force signaler and waiter on the same CPU and prioritize the latter over the former. This avoids a race between sending the signal right after being unblocked from the semaphore and blocking in pselect. Seen rather frequently now with qemu-arm 4-core machines.
With the schedule-based ordering in place, we can safely drop the nanosleep before signalling.
Signed-off-by Jan Kiszka <[email protected]>
--- testsuite/smokey/y2038/syscall-tests.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
testsuite/smokey/y2038/syscall-tests.c +22 -4
@@ -13,6 +13,7 @@#include <sys/timerfd.h> #include <sys/utsname.h> #include <mqueue.h> +#include <sched.h> #include <rtdm/ipc.h> smokey_test_plugin (y2038,SMOKEY_NOARGS ,"Validate correct y2038 support" );
@@ -1422,9 +1423,11 @@ static void pselect64_sig_handler(int sig)static void *pselect64_waiting_thread (void *arg) {struct thread_context *ctx = (struct thread_context *)arg; +struct sched_param schedp = {.sched_priority =99 };struct xn_timespec64 ts;int sock = ctx->sock;struct sigaction sa; +cpu_set_t cpuset;fd_set rfds;int ret;
@@ -1439,6 +1442,18 @@ static void *pselect64_waiting_thread(void *arg)if (ret) goto out; +CPU_ZERO (&cpuset); +CPU_SET (0 , &cpuset); + ret =sched_setaffinity (0 ,sizeof (cpuset), &cpuset); +if (!smokey_assert (ret ==0 )) { + ret = -errno; + goto out; + } + + ret =sched_setscheduler (0 ,SCHED_FIFO , &schedp); +if (!smokey_assert (ret ==0 )) + goto out; +/* Waiting for 1sec should be enough to get a signal */ ts.tv_sec =1 ; ts.tv_nsec =0 ;
@@ -1461,9 +1476,9 @@ out:static int test_pselect64_interruption (void ) { -struct timespec ts = { .tv_sec =0 , .tv_nsec =100000 };struct thread_context ctx = {0 };void *w_ret =NULL ; +cpu_set_t cpuset;pthread_t w;sem_t sem;int sock;
@@ -1481,6 +1496,12 @@ static int test_pselect64_interruption(void)if (ret)return ret; +CPU_ZERO (&cpuset); +CPU_SET (0 , &cpuset); + ret =sched_setaffinity (0 ,sizeof (cpuset), &cpuset); +if (!smokey_assert (ret ==0 )) +return -errno; + ctx.sock = sock; ctx.sc_nr = sc_cobalt_pselect64; ctx.sem = &sem;
@@ -1493,9 +1514,6 @@ static int test_pselect64_interruption(void)/* Wait for the waiting thread to be ready */ sem_wait (&sem); -/* Allow the waiting thread to enter the pselect64() syscall */ -nanosleep (&ts,NULL ); -/* Send a signal to interrupt the syscall and trigger -EINTR */ __STD (pthread_kill (w,SIGUSR1 ));
Signature · 1 line
2.43.0