[tip: locking/futex] selftests/futex: Skip futex_requeue_pi on unprivileged thread creation

From: tip-bot2 for Rénich Bon Ćirić

Date: Mon Nov 30 2026 - 16:07:06 EST


The following commit has been merged into the locking/futex branch of tip:

Commit-ID: 61c909cfdc2b3a3da6b5e6ab1b2fb65b292b9087
Gitweb: https://git.kernel.org/tip/61c909cfdc2b3a3da6b5e6ab1b2fb65b292b9087
Author: Rénich Bon Ćirić <renich@xxxxxxxxxxxx>
AuthorDate: Wed, 04 Nov 2026 09:05:46 -06:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Mon, 30 Nov 2026 22:03:34 +01:00

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")
Signed-off-by: Rénich Bon Ćirić <renich@xxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Reviewed-by: André Almeida <andrealmeid@xxxxxxxxxx>
Link: https://patch.msgid.link/20261104150546.1041422-1-renich@xxxxxxxxxxxx
---
tools/testing/selftests/futex/functional/futex_requeue_pi.c | 17 ++++++++++++-----
tools/testing/selftests/futex/functional/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 2530e69..4bc721e 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 4933612..69de807 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);