Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings
Date: Sat,  5 Dec 2026 23:11:44 +0000	[thread overview]
Message-ID: <20261205231147.4095031-12-axboe@kernel.dk> (raw)
In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk>

From: Andrea Parri <parri.andrea@gmail.com>

Commit e20a070b2a2ba35411251850c8969c1ac1838433 upstream.

An epoll waiter can hang with completions pending when polling a
disabled SINGLE_ISSUER ring races with IORING_REGISTER_ENABLE_RINGS:

        CPU0                            CPU1
        ----                            ----
        io_activate_pollwq()
          submitter_task == NULL
                                        submitter_task = current
                                        wq_has_sleeper() == false
        poll_wait()

Neither side retries the activation.  The activation flag remains
clear, so completion and deferred task work paths skip poll_wq wakeups.

Cure this by registering the poll waiter before trying to activate
poll_wq.  The full barrier in poll_wait() pairs with the barrier in
wq_has_sleeper(), which ensures that either the poller observes
submitter_task or the ring enable path observes the waiter.

Tested in a 2-vCPU x86-64 KVM guest with a reproducer that races
EPOLL_CTL_ADD on a disabled ring against IORING_REGISTER_ENABLE_RINGS.
v7.4-rc5 missed the wakeup in each of three runs, at iterations 177,
505 and 26826.  With this patch, three runs of 100000 iterations passed.

The bug was found with the help of an LLM, which was also used to write
the fix, the changelog and the tests.

Fixes: bca39f390585 ("io_uring: add lazy poll_wq activation")
Cc: stable@vger.kernel.org
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Link: https://patch.msgid.link/20261204174710.131485-1-parri.andrea@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.18 has ctx->poll_activated rather than
IO_RING_F_POLL_ACTIVATED in ctx->int_flags]
---
 io_uring/io_uring.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index d300026c74bf..2a8fb7a43c80 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3115,13 +3115,14 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
 	struct io_ring_ctx *ctx = file->private_data;
 	__poll_t mask = 0;
 
-	if (unlikely(!ctx->poll_activated))
-		io_activate_pollwq(ctx);
 	/*
-	 * provides mb() which pairs with barrier from wq_has_sleeper
-	 * call in io_commit_cqring
+	 * The poll_wait() barrier pairs with wq_has_sleeper() on the CQ
+	 * wakeup and ring enable paths.
 	 */
 	poll_wait(file, &ctx->poll_wq, wait);
+	/* A stale flag only causes a redundant activation attempt. */
+	if (unlikely(!ctx->poll_activated))
+		io_activate_pollwq(ctx);
 
 	rcu_read_lock();
 
-- 
2.55.0


  parent reply	other threads:[~2026-12-05 23:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 09/14] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:11 ` Jens Axboe [this message]
2026-12-05 23:11 ` [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs Jens Axboe

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=20261205231147.4095031-12-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=io-uring@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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