io_uring: remove WRITE_ONCE() in io_uring_create()
PATCH 1/1 io_uring: remove WRITE_ONCE() in io_uring_create()
There's no need to use WRITE_ONCE() to set ctx->submitter_task in io_uring_create() since no other thread can access the io_ring_ctx until a file descriptor is associated with it. So use a normal assignment instead of WRITE_ONCE().
--- io_uring/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/io_uring.c +1 -1
@@ -3890,11 +3890,11 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p, goto err; }if (ctx->flags &IORING_SETUP_SINGLE_ISSUER && !(ctx->flags &IORING_SETUP_R_DISABLED )) -WRITE_ONCE (ctx->submitter_task,get_task_struct (current)); + ctx->submitter_task =get_task_struct (current); file =io_uring_get_file (ctx);if (IS_ERR (file)) { ret =PTR_ERR (file); goto err;
Signature · 1 line
2.45.2
Jens Axboe
maintainerQuoted 4 lines · Caleb Sander Mateos
There's no need to use
WRITE_ONCE()to setctx->submitter_taskinio_uring_create()since no other thread can access theio_ring_ctxuntil a file descriptor is associated with it. So use a normal assignment instead ofWRITE_ONCE().
Would probably warrant a code comment to that effect, as just reading the code would be slightly confusing after this.
Signature · 1 line
Jens Axboe
Quoted 9 lines · Jens Axboe
Quoted 4 lines · Caleb Sander Mateos
There's no need to use
WRITE_ONCE()to setctx->submitter_taskinio_uring_create()since no other thread can access theio_ring_ctxuntil a file descriptor is associated with it. So use a normal assignment instead ofWRITE_ONCE().Would probably warrant a code comment to that effect, as just reading the code would be slightly confusing after this.
Could you elaborate on why you find it confusing? I wouldn't expect to see WRITE_ONCE() or any other atomic operation used when initializing memory prior to it being made accessible from other threads. It looks like commit 8579538c89e3 ("io_uring/msg_ring: fix remote queue to disabled ring") added the WRITE_ONCE() both here and in io_register_enable_rings(). But it's only needed in io_register_enable_rings(), where the io_ring_ctx already has an associated file descriptor and may be accessed concurrently from multiple threads.
Thanks,
Caleb
Jens Axboe
maintainerQuoted 11 lines · Caleb Sander Mateos
Quoted 9 lines · Jens Axboe
Quoted 4 lines · Caleb Sander Mateos
There's no need to use
WRITE_ONCE()to setctx->submitter_taskinio_uring_create()since no other thread can access theio_ring_ctxuntil a file descriptor is associated with it. So use a normal assignment instead ofWRITE_ONCE().Would probably warrant a code comment to that effect, as just reading the code would be slightly confusing after this.
Quoted 9 lines
Could you elaborate on why you find it confusing? I wouldn't expect to see
WRITE_ONCE()or any other atomic operation used when initializing memory prior to it being made accessible from other threads. It looks like commit8579538c89e3("io_uring/msg_ring: fix remote queue to disabled ring") added theWRITE_ONCE()both here and inio_register_enable_rings(). But it's only needed inio_register_enable_rings(), where theio_ring_ctxalready has an associated file descriptor and may be accessed concurrently from multiple threads.
Just add simple comment saying something like "No need for a WRITE_ONCE() here, as it's before the ring is visible/enabled". Otherwise I bet I'll be fielding a patch for that in the future.
Signature · 1 line
Jens Axboe