[PATCH] io_uring: remove WRITE_ONCE() in io_uring_create()

Caleb Sander Mateos posted 1 patch 1 month ago
There is a newer version of this series
io_uring/io_uring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] io_uring: remove WRITE_ONCE() in io_uring_create()
Posted by Caleb Sander Mateos 1 month ago
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().

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 io_uring/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 6c07efac977c..545a7d5eefec 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -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;
-- 
2.45.2
Re: [PATCH] io_uring: remove WRITE_ONCE() in io_uring_create()
Posted by Jens Axboe 1 month ago
On 9/2/25 3:51 PM, Caleb Sander Mateos wrote:
> 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.

-- 
Jens Axboe
Re: [PATCH] io_uring: remove WRITE_ONCE() in io_uring_create()
Posted by Caleb Sander Mateos 1 month ago
On Tue, Sep 2, 2025 at 6:20 PM Jens Axboe <axboe@kernel.dk> wrote:
>
> On 9/2/25 3:51 PM, Caleb Sander Mateos wrote:
> > 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
Re: [PATCH] io_uring: remove WRITE_ONCE() in io_uring_create()
Posted by Jens Axboe 4 weeks, 1 day ago
On 9/2/25 9:32 PM, Caleb Sander Mateos wrote:
> On Tue, Sep 2, 2025 at 6:20 PM Jens Axboe <axboe@kernel.dk> wrote:
>>
>> On 9/2/25 3:51 PM, Caleb Sander Mateos wrote:
>>> 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.

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.

-- 
Jens Axboe