mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] io_uring/futex: don't fail a cancelled futexv wait that got woken
@ 2026-12-06  4:21 Hang Zhengyang
  0 siblings, 0 replies; only message in thread
From: Hang Zhengyang @ 2026-12-06  4:21 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Yang Xiuwei, io-uring, linux-kernel, stable

Commit 9a7cbe50dd95 ("io_uring/futex: fail soft links when cancelling a
wait") marks the request failed in __io_futex_cancel(). Since
commit 7faaa6812aba ("io_uring/futex: ensure partial wakes are
appropriately dequeued"), a wakeup of a FUTEX_WAITV can still mark one
of its futexes woken after the cancel has claimed the request, and
io_futexv_complete() then replaces -ECANCELED with the index of that
futex. The request completes with that index but is still marked
failed: its links are cancelled, and with IOSQE_CQE_SKIP_SUCCESS the
success CQE is posted while the CQEs of the links are not.

Mark the request failed when it completes, based on the final result.

Found, fixed and tested by Claude Code, I handled the review process.

Fixes: 9a7cbe50dd95 ("io_uring/futex: fail soft links when cancelling a wait")
Cc: stable@vger.kernel.org
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
---
Tested on io_uring-7.4 in a KVM guest, with a FUTEX_WAITV linked to a
NOP, then a cancel of the wait and a wake of its futex in one submit:
the wait posts 0 and the NOP -ECANCELED without this patch, in 5 of 5
runs, and both post 0 with it. A cancel without a wake still cancels
the NOP. The full liburing suite shows no new failures against the
unpatched kernel. I'll send a liburing test separately.

6.12.y and 6.18.y have 9a7cbe50dd95 but not 7faaa6812aba, so a wakeup
there doesn't mark the futex and they aren't affected; 7.3.7 has both
(from reading the code; I haven't tested 7.3.7).

 io_uring/futex.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/io_uring/futex.c b/io_uring/futex.c
index 615eaa9104b1..10cd09712b5e 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -47,7 +47,12 @@ void io_futex_cache_free(struct io_ring_ctx *ctx)
 
 static void __io_futex_complete(struct io_tw_req tw_req, io_tw_token_t tw)
 {
-	hlist_del_init(&tw_req.req->hash_node);
+	struct io_kiocb *req = tw_req.req;
+
+	/* a cancelled futexv may still complete as woken */
+	if (req->cqe.res < 0)
+		req_set_fail(req);
+	hlist_del_init(&req->hash_node);
 	io_req_task_complete(tw_req, tw);
 }
 
@@ -107,7 +112,6 @@ static bool __io_futex_cancel(struct io_kiocb *req)
 	}
 
 	hlist_del_init(&req->hash_node);
-	req_set_fail(req);
 	io_req_set_res(req, -ECANCELED, 0);
 	io_req_task_work_add(req);
 	return true;

base-commit: fc66b07da5f49aed1740b2007bf69e8774e17a1b
-- 
2.53.0


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

only message in thread, other threads:[~2026-12-06  4:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06  4:21 [PATCH] io_uring/futex: don't fail a cancelled futexv wait that got woken Hang Zhengyang

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®