selftests/futex: Skip futex_requeue_pi on unprivileged thread creation
PATCH 1/1 selftests/futex: Skip futex_requeue_pi on unprivileged thread creation
The futex_requeue_pi and futex_requeue_pi_signal_restart selftests create threads with the SCHED_FIFO real-time scheduling policy to exercise Priority Inheritance futex requeue operations.
When executed without root privileges or in environments lacking the CAP_SYS_NICE capability, pthread_create() fails with EPERM. Currently, create_rt_thread() asserts that ret == 0, causing all 24 parameterized variants in futex_requeue_pi and futex_requeue_pi_signal_restart to fail unconditionally. Missing execution permissions should be reported as a skip rather than a hard test failure.
Handle EPERM from pthread_create() in create_rt_thread() by invoking SKIP() and returning -EPERM. Update callers to check the return value and exit early so the test harness records the test as skipped. Privileged test execution with CAP_SYS_NICE or root remains unaffected and continues to run all test assertions.
--- .../futex/functional/futex_requeue_pi.c | 17 ++++++++++++----- .../futex_requeue_pi_signal_restart.c | 7 ++++++- 2 files changed, 18 insertions(+), 6 deletions(-)
tools/testing/selftests/futex/functional/futex_requeue_pi.c +12 -5
@@ -143,6 +143,10 @@ int create_rt_thread(struct __test_metadata *_metadata, pthread_t *pth, void*(*fTH_LOG ("pthread_attr_setschedparam failed" ); ret =pthread_create (pth, &attr, func, arg); +if (ret ==EPERM ) { +SKIP (return -EPERM , +"pthread_create failed with EPERM, need CAP_SYS_NICE for SCHED_FIFO" ); + } ASSERT_EQ(ret, 0)TH_LOG ("pthread_create failed" );
@@ -358,8 +362,9 @@ TEST_F(args, futex_requeue_pi)if (third_party_owner) { blocker_arg._metadata = _metadata; -create_rt_thread (_metadata, &blocker, third_party_blocker, - (void *)&blocker_arg,SCHED_FIFO ,1 ); +if (create_rt_thread (_metadata, &blocker, third_party_blocker, + (void *)&blocker_arg,SCHED_FIFO ,1 )) +return ; }atomic_set (&waiters_woken,0 );
@@ -368,12 +373,14 @@ TEST_F(args, futex_requeue_pi) args[i].id = i; args[i].timeout = tsp;TH_LOG ("Starting thread %d" , i); -create_rt_thread (_metadata, &waiter[i], waiterfn, (void *)&args[i], -SCHED_FIFO ,1 ); +if (create_rt_thread (_metadata, &waiter[i], waiterfn, (void *)&args[i], +SCHED_FIFO ,1 )) +return ; } waker_arg._metadata = _metadata; waker_arg.lock = lock; -create_rt_thread (_metadata, &waker, wakerfn, (void *)&waker_arg,SCHED_FIFO ,1 ); +if (create_rt_thread (_metadata, &waker, wakerfn, (void *)&waker_arg,SCHED_FIFO ,1 )) +return ;/* Wait for threads to finish */ /* Store the first error or failure encountered in waiter_ret */
tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c +6 -1
@@ -61,6 +61,10 @@ int create_rt_thread(struct __test_metadata *_metadata, pthread_t *pth, void*(*fTH_LOG ("pthread_attr_setschedparam failed" ); ret =pthread_create (pth, &attr, func, arg); +if (ret ==EPERM ) { +SKIP (return -EPERM , +"pthread_create failed with EPERM, need CAP_SYS_NICE for SCHED_FIFO" ); + } ASSERT_EQ(ret, 0)TH_LOG ("pthread_create failed" );
@@ -111,7 +115,8 @@ TEST(futex_requeue_pi_signal_restart)TH_LOG ("m1:f2: %x" , f2);TH_LOG ("Creating waiter" ); -create_rt_thread (_metadata, &waiter, waiterfn, _metadata,SCHED_FIFO ,1 ); +if (create_rt_thread (_metadata, &waiter, waiterfn, _metadata,SCHED_FIFO ,1 )) +return ;TH_LOG ("Calling FUTEX_LOCK_PI on f2=%x @ %p" , f2, &f2);TH_LOG ("m2:f2: %x" , f2);
Signature · 1 line
2.56.0
Thanks for the patch!
Em 04/11/2026 12:05, Rénich Bon Ćirić escreveu:
Quoted 17 lines
The
futex_requeue_piandfutex_requeue_pi_signal_restartselftests create threads with theSCHED_FIFOreal-time scheduling policy to exercise Priority Inheritance futex requeue operations.When executed without root privileges or in environments lacking the
CAP_SYS_NICEcapability,pthread_create()fails with EPERM. Currently,create_rt_thread()asserts that ret == 0, causing all 24 parameterized variants infutex_requeue_piandfutex_requeue_pi_signal_restartto fail unconditionally. Missing execution permissions should be reported as a skip rather than a hard test failure.Handle EPERM from
pthread_create()increate_rt_thread()by invokingSKIP()and returning-EPERM. Update callers to check the return value and exit early so the test harness records the test as skipped. Privileged test execution withCAP_SYS_NICEor root remains unaffected and continues to run all test assertions.
Quoted 3 lines
Fixes b7d837c2d49e ("selftests/futex: Migrate futex_requeue_pi to harness")Fixes 7fe733f11215 ("selftests/futex: Migrate futex_requeue_pi_signal_restart to harness")Signed-off-by Rénich Bon Ćirić <[email protected]>