mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rénich Bon Ćirić" <renich@evalinux.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Shuah Khan <shuah@kernel.org>
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Wake Liu" <wakel@google.com>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rénich Bon Ćirić" <renich@evalinux.com>
Subject: [PATCH] selftests/futex: Skip futex_requeue_pi on unprivileged thread creation
Date: Wed,  4 Nov 2026 09:05:46 -0600	[thread overview]
Message-ID: <20261104150546.1041422-1-renich@evalinux.com> (raw)

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


                 reply	other threads:[~2026-11-04 15:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104150546.1041422-1-renich@evalinux.com \
    --to=renich@evalinux.com \
    --cc=andrealmeid@igalia.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®