mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Yang Xiuwei <yangxiuwei@kylinos.cn>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] io_uring/futex: don't fail a cancelled futexv wait that got woken
Date: Sun,  6 Dec 2026 04:21:01 +0000	[thread overview]
Message-ID: <20261206042101.2023015-1-hang.zhengyang1010@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-06  4:21 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=20261206042101.2023015-1-hang.zhengyang1010@gmail.com \
    --to=hang.zhengyang1010@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yangxiuwei@kylinos.cn \
    /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®