Skip to contentSkip to conversation

io_uring: remove WRITE_ONCE() in io_uring_create()

PATCH Superseded Caleb Sander Mateos 2 participants 4 messages Sep 2, 2025 – Sep 3, 2025 io_uring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 6c07efac977c..545a7d5eefec 100644
@@ -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
maintainer
#1 lore raw
Quoted 4 lines · Caleb Sander Mateos

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().

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
#2 lore raw
Quoted 9 lines · Jens Axboe
Quoted 4 lines · Caleb Sander Mateos

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().

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

maintainer
#3 lore raw
Quoted 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 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().

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 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.

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