]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring: mark known and harmless racy ctx->int_flags uses
authorJens Axboe <axboe@kernel.dk>
Sat, 14 Mar 2026 14:46:17 +0000 (08:46 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 16 Mar 2026 21:33:10 +0000 (15:33 -0600)
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
io_uring/io_uring.h
io_uring/tw.c

index bfeb3bc3849d61da7a4f92d3c2c46b14d0b77ad4..fb5a263706be4d139a2d0ddac6bca66f49adb2d4 100644 (file)
@@ -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
index 5cb1983043cde77745e840852cc6aa8a9655a01b..91cf67b5d85bc846856886f380608152363b1b07 100644 (file)
@@ -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);
 }
 
index 022fe8753c1995e2e24d05d7f357805b1ff0e140..fdff81eebc95cbb635d53aab498b0b4a051d5665 100644 (file)
@@ -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);
        }