Skip to content

Commit 42a702a

Browse files
committed
io_uring: fix iowq_limits data race in tctx node addition
__io_uring_add_tctx_node() reads ctx->int_flags and ctx->iowq_limits[0..1] without holding ctx->uring_lock, while io_register_iowq_max_workers() writes these same fields under the lock. Mostly an application problem if you try and make these race, but let's silence KCSAN by just grabbing the ->uring_lock around the operation. This is a slow path operation anyway, and ->uring_lock will be grabbed by submission right after anyway. Fixes: 2e48005 ("io-wq: provide a way to limit max number of workers") Signed-off-by: Jens Axboe <[email protected]>
1 parent 4185984 commit 42a702a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

io_uring/tctx.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,13 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
146146
if (IS_ERR(tctx))
147147
return PTR_ERR(tctx);
148148

149-
if (ctx->int_flags & IO_RING_F_IOWQ_LIMITS_SET) {
150-
unsigned int limits[2] = { ctx->iowq_limits[0],
151-
ctx->iowq_limits[1], };
149+
if (data_race(ctx->int_flags) & IO_RING_F_IOWQ_LIMITS_SET) {
150+
unsigned int limits[2];
151+
152+
mutex_lock(&ctx->uring_lock);
153+
limits[0] = ctx->iowq_limits[0];
154+
limits[1] = ctx->iowq_limits[1];
155+
mutex_unlock(&ctx->uring_lock);
152156

153157
ret = io_wq_max_workers(tctx->io_wq, limits);
154158
if (ret)

0 commit comments

Comments
 (0)