Skip to content

Commit 8c55744

Browse files
committed
io_uring: mark known and harmless racy ctx->int_flags uses
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>
1 parent f1a424e commit 8c55744

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

io_uring/io_uring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
22422242
struct io_ring_ctx *ctx = file->private_data;
22432243
__poll_t mask = 0;
22442244

2245-
if (unlikely(!(ctx->int_flags & IO_RING_F_POLL_ACTIVATED)))
2245+
if (unlikely(!(data_race(ctx->int_flags) & IO_RING_F_POLL_ACTIVATED)))
22462246
io_activate_pollwq(ctx);
22472247
/*
22482248
* provides mb() which pairs with barrier from wq_has_sleeper

io_uring/io_uring.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,12 @@ static inline void io_req_complete_defer(struct io_kiocb *req)
470470
wq_list_add_tail(&req->comp_list, &state->compl_reqs);
471471
}
472472

473+
#define SHOULD_FLUSH_MASK (IO_RING_F_OFF_TIMEOUT_USED | \
474+
IO_RING_F_HAS_EVFD | IO_RING_F_POLL_ACTIVATED)
475+
473476
static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx)
474477
{
475-
if (unlikely(ctx->int_flags & (IO_RING_F_OFF_TIMEOUT_USED |
476-
IO_RING_F_HAS_EVFD |
477-
IO_RING_F_POLL_ACTIVATED)))
478+
if (unlikely(data_race(ctx->int_flags) & SHOULD_FLUSH_MASK))
478479
__io_commit_cqring_flush(ctx);
479480
}
480481

io_uring/tw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
222222

223223
if (!head) {
224224
io_ctx_mark_taskrun(ctx);
225-
if (ctx->int_flags & IO_RING_F_HAS_EVFD)
225+
if (data_race(ctx->int_flags) & IO_RING_F_HAS_EVFD)
226226
io_eventfd_signal(ctx, false);
227227
}
228228

0 commit comments

Comments
 (0)