Skip to contentSkip to conversation

selftests/futex: add FUTEX_LOCK_PI owner-exiting coverage

PATCH Applied Valery Borovsky 2 participants 2 messages Jun 7 – Jul 5

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

PATCH 1/1 selftests/futex: add FUTEX_LOCK_PI owner-exiting coverage

The futex functional tests cover FUTEX_LOCK_PI timeout semantics (futex_wait_timeout.c) and robust-list owner death (robust_list.c), but nothing exercises a non-robust PI owner exiting while holding the lock, nor the basic ownership / EDEADLK / unlock word semantics of FUTEX_LOCK_PI.

Add futex_lock_pi_exiting.c with three tests:

- lock_unlock_basic: an uncontended FUTEX_LOCK_PI puts the owner TID in the futex word, a recursive lock by the owner returns EDEADLK, and FUTEX_UNLOCK_PI clears the word.

- owner_dies_with_blocked_waiter: a thread acquires a PI futex and exits while holding it; a blocked FUTEX_LOCK_PI waiter must come out cleanly (0, EOWNERDEAD or ESRCH) and own the lock when it acquires.

- stress_owner_exits: repeatedly drive the same exiting-owner path.

The exiting-owner retry path is where commit 210d36d892de ("futex: Clear stale exiting pointer in futex_lock_pi() retry path") fixed a stale task pointer that tripped WARN_ON_ONCE() in wait_for_owner_exiting(). That warning does not change the syscall return value, so this test does not assert on it directly; the stress loop exists to give a kernel booted with panic_on_warn=1 (as fuzzers and CI commonly run) a chance to trip on it.

---
 .../selftests/futex/functional/.gitignore     |   1 +
 .../selftests/futex/functional/Makefile       |   3 +-
 .../futex/functional/futex_lock_pi_exiting.c  | 265 ++++++++++++++++++
 .../testing/selftests/futex/functional/run.sh |   3 +
 4 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_lock_pi_exiting.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index 23b9fea8d190..7c39d10b38e4 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+futex_lock_pi_exiting
 futex_numa_mpol
 futex_priv_hash
 futex_requeue
tools/testing/selftests/futex/functional/Makefile +2 -1
index 5c1c824f9740..d59faf76a2aa 100644
@@ -26,7 +26,8 @@ TEST_GEN_PROGS := \
 	futex_numa_mpol \
 	futex_waitv \
 	futex_numa \
-	robust_list
+	robust_list \
+	futex_lock_pi_exiting
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_lock_pi_exiting.c new file +265 -0

265 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index e88545c06d57..d1a681b798bd 100755
@@ -51,3 +51,6 @@ echo
 
 echo
 ./futex_numa_mpol
+
+echo
+./futex_lock_pi_exiting
Signature · 1 line
2.53.0
#1 lore raw

[tip: locking/futex] selftests/futex: Add FUTEX_LOCK_PI owner-exiting coverage

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

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

Commit-ID:     90a0286c7d3591295a55c97319de322159993c21
Gitweb:        https://git.kernel.org/tip/90a0286c7d3591295a55c97319de322159993c21
Author:        Valery Borovsky <[email protected]>
AuthorDate:    Sun, 07 Jun 2026 21:32:48 +03:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 05 Jul 2026 21:49:18 +02:00

selftests/futex: Add FUTEX_LOCK_PI owner-exiting coverage

The futex functional tests cover FUTEX_LOCK_PI timeout semantics (futex_wait_timeout.c) and robust-list owner death (robust_list.c), but nothing exercises a non-robust PI owner exiting while holding the lock, nor the basic ownership / EDEADLK / unlock word semantics of FUTEX_LOCK_PI.

Add futex_lock_pi_exiting.c with three tests:

- lock_unlock_basic: an uncontended FUTEX_LOCK_PI puts the owner TID in the futex word, a recursive lock by the owner returns EDEADLK, and FUTEX_UNLOCK_PI clears the word.

- owner_dies_with_blocked_waiter: a thread acquires a PI futex and exits while holding it; a blocked FUTEX_LOCK_PI waiter must come out cleanly (0, EOWNERDEAD or ESRCH) and own the lock when it acquires.

- stress_owner_exits: repeatedly drive the same exiting-owner path.

The exiting-owner retry path is where commit 210d36d892de ("futex: Clear stale exiting pointer in futex_lock_pi() retry path") fixed a stale task pointer that tripped WARN_ON_ONCE() in wait_for_owner_exiting(). That warning does not change the syscall return value, so this test does not assert on it directly; the stress loop exists to give a kernel booted with panic_on_warn=1 (as fuzzers and CI commonly run) a chance to trip on it.

---
 tools/testing/selftests/futex/functional/.gitignore              |   1 +-
 tools/testing/selftests/futex/functional/Makefile                |   3 +-
 tools/testing/selftests/futex/functional/futex_lock_pi_exiting.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 tools/testing/selftests/futex/functional/run.sh                  |   3 +-
 4 files changed, 269 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/futex/functional/futex_lock_pi_exiting.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
index 23b9fea..7c39d10 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+futex_lock_pi_exiting
 futex_numa_mpol
 futex_priv_hash
 futex_requeue
tools/testing/selftests/futex/functional/Makefile +2 -1
index 5c1c824..d59faf7 100644
@@ -26,7 +26,8 @@ TEST_GEN_PROGS := \
 	futex_numa_mpol \
 	futex_waitv \
 	futex_numa \
-	robust_list
+	robust_list \
+	futex_lock_pi_exiting
 
 TEST_PROGS := run.sh
 
tools/testing/selftests/futex/functional/futex_lock_pi_exiting.c new file +263 -0

263 lines not on this page · raw message

tools/testing/selftests/futex/functional/run.sh +3 -0
index e88545c..d1a681b 100755
@@ -51,3 +51,6 @@ echo
 
 echo
 ./futex_numa_mpol
+
+echo
+./futex_lock_pi_exiting