public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/2] io_uring: mark known and harmless racy ctx->int_flags uses
Date: Sat, 14 Mar 2026 08:58:06 -0600	[thread overview]
Message-ID: <20260314145920.86796-3-axboe@kernel.dk> (raw)
In-Reply-To: <20260314145920.86796-1-axboe@kernel.dk>

There are a few of these, where flags are read outside of the
uring_lock, yet it's harmless to race on them.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/io_uring.c | 2 +-
 io_uring/io_uring.h | 7 ++++---
 io_uring/tw.c       | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index bfeb3bc3849d..fb5a263706be 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2242,7 +2242,7 @@ 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->int_flags & IO_RING_F_POLL_ACTIVATED)))
+	if (unlikely(!(data_race(ctx->int_flags) & IO_RING_F_POLL_ACTIVATED)))
 		io_activate_pollwq(ctx);
 	/*
 	 * provides mb() which pairs with barrier from wq_has_sleeper
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 5cb1983043cd..91cf67b5d85b 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -470,11 +470,12 @@ static inline void io_req_complete_defer(struct io_kiocb *req)
 	wq_list_add_tail(&req->comp_list, &state->compl_reqs);
 }
 
+#define SHOULD_FLUSH_MASK	(IO_RING_F_OFF_TIMEOUT_USED | \
+				 IO_RING_F_HAS_EVFD | IO_RING_F_POLL_ACTIVATED)
+
 static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx)
 {
-	if (unlikely(ctx->int_flags & (IO_RING_F_OFF_TIMEOUT_USED |
-				       IO_RING_F_HAS_EVFD |
-				       IO_RING_F_POLL_ACTIVATED)))
+	if (unlikely(data_race(ctx->int_flags) & SHOULD_FLUSH_MASK))
 		__io_commit_cqring_flush(ctx);
 }
 
diff --git a/io_uring/tw.c b/io_uring/tw.c
index 022fe8753c19..fdff81eebc95 100644
--- a/io_uring/tw.c
+++ b/io_uring/tw.c
@@ -222,7 +222,7 @@ void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
 
 	if (!head) {
 		io_ctx_mark_taskrun(ctx);
-		if (ctx->int_flags & IO_RING_F_HAS_EVFD)
+		if (data_race(ctx->int_flags) & IO_RING_F_HAS_EVFD)
 			io_eventfd_signal(ctx, false);
 	}
 
-- 
2.53.0


      parent reply	other threads:[~2026-03-14 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 14:58 [PATCHSET for-next 0/2] Replace io_ring_ctx bitfields with flags Jens Axboe
2026-03-14 14:58 ` [PATCH 1/2] io_uring: switch struct io_ring_ctx internal bitfields to flags Jens Axboe
2026-03-15  3:16   ` Gabriel Krisman Bertazi
2026-03-14 14:58 ` Jens Axboe [this message]

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=20260314145920.86796-3-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@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