mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/futex: Skip futex_requeue_pi on unprivileged thread creation
@ 2026-11-04 15:05 Rénich Bon Ćirić
  0 siblings, 0 replies; only message in thread
From: Rénich Bon Ćirić @ 2026-11-04 15:05 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Shuah Khan
  Cc: Peter Zijlstra, Darren Hart, Davidlohr Bueso, André Almeida,
	Wake Liu, linux-kselftest, linux-kernel,
	Rénich Bon Ćirić

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")
Signed-off-by: Rénich Bon Ćirić <renich@evalinux.com>
---
 .../futex/functional/futex_requeue_pi.c         | 17 ++++++++++++-----
 .../futex_requeue_pi_signal_restart.c           |  7 ++++++-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
index 65326cbef3a4..afcede02fe9c 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c
@@ -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 */
diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c
index 4933612a7b55..69de80790bbd 100644
--- a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c
+++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c
@@ -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);
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-04 15:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 15:05 [PATCH] selftests/futex: Skip futex_requeue_pi on unprivileged thread creation Rénich Bon Ćirić

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®