Skip to contentSkip to conversation

selftests/futex: Skip futex_requeue_pi on unprivileged thread creation

PATCH In review Rénich Bon Ćirić 2 participants 2 messages Nov 4 – Nov 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes b7d837c2d49e ("selftests/futex: Migrate futex_requeue_pi to harness")
Fixes 7fe733f11215 ("selftests/futex: Migrate futex_requeue_pi_signal_restart to harness")
---
 .../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
index 65326cbef3a4..afcede02fe9c 100644
@@ -143,6 +143,10 @@ int create_rt_thread(struct __test_metadata *_metadata, pthread_t *pth, void*(*f
 		TH_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
index 4933612a7b55..69de80790bbd 100644
@@ -61,6 +61,10 @@ int create_rt_thread(struct __test_metadata *_metadata, pthread_t *pth, void*(*f
 		TH_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
reviewer Reviewed-by on v1 1/1
#1 lore raw

Thanks for the patch!

Em 04/11/2026 12:05, Rénich Bon Ćirić escreveu:

Quoted 17 lines

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.

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")