Skip to content

Commit bcd4c95

Browse files
calebsanderaxboe
authored andcommitted
io_uring/msg_ring: drop unnecessary submitter_task checks
__io_msg_ring_data() checks that the target_ctx isn't IORING_SETUP_R_DISABLED before calling io_msg_data_remote(), which calls io_msg_remote_post(). So submitter_task can't be modified concurrently with the read in io_msg_remote_post(). Additionally, submitter_task must exist, as io_msg_data_remote() is only called for io_msg_need_remote(), i.e. task_complete is set, which requires IORING_SETUP_DEFER_TASKRUN, which in turn requires IORING_SETUP_SINGLE_ISSUER. And submitter_task is assigned in io_uring_create() or io_register_enable_rings() before enabling any IORING_SETUP_SINGLE_ISSUER io_ring_ctx. Similarly, io_msg_send_fd() checks IORING_SETUP_R_DISABLED and io_msg_need_remote() before calling io_msg_fd_remote(). submitter_task therefore can't be modified concurrently with the read in io_msg_fd_remote() and must be non-null. io_register_enable_rings() can't run concurrently because it's called from io_uring_register() -> __io_uring_register() with uring_lock held. Thus, replace the READ_ONCE() and WRITE_ONCE() of submitter_task with plain loads and stores. And remove the NULL checks of submitter_task in io_msg_remote_post() and io_msg_fd_remote(). Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Joanne Koong <joannelkoong@gmail.com> Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7a8737e commit bcd4c95

3 files changed

Lines changed: 7 additions & 20 deletions

File tree

io_uring/io_uring.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,13 +3637,8 @@ static __cold int io_uring_create(struct io_ctx_config *config)
36373637
}
36383638

36393639
if (ctx->flags & IORING_SETUP_SINGLE_ISSUER
3640-
&& !(ctx->flags & IORING_SETUP_R_DISABLED)) {
3641-
/*
3642-
* Unlike io_register_enable_rings(), don't need WRITE_ONCE()
3643-
* since ctx isn't yet accessible from other tasks
3644-
*/
3640+
&& !(ctx->flags & IORING_SETUP_R_DISABLED))
36453641
ctx->submitter_task = get_task_struct(current);
3646-
}
36473642

36483643
file = io_uring_get_file(ctx);
36493644
if (IS_ERR(file)) {

io_uring/msg_ring.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,9 @@ static void io_msg_tw_complete(struct io_tw_req tw_req, io_tw_token_t tw)
8080
percpu_ref_put(&ctx->refs);
8181
}
8282

83-
static int io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
83+
static void io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
8484
int res, u32 cflags, u64 user_data)
8585
{
86-
if (!READ_ONCE(ctx->submitter_task)) {
87-
kfree_rcu(req, rcu_head);
88-
return -EOWNERDEAD;
89-
}
9086
req->opcode = IORING_OP_NOP;
9187
req->cqe.user_data = user_data;
9288
io_req_set_res(req, res, cflags);
@@ -95,7 +91,6 @@ static int io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
9591
req->tctx = NULL;
9692
req->io_task_work.func = io_msg_tw_complete;
9793
io_req_task_work_add_remote(req, IOU_F_TWQ_LAZY_WAKE);
98-
return 0;
9994
}
10095

10196
static int io_msg_data_remote(struct io_ring_ctx *target_ctx,
@@ -111,8 +106,8 @@ static int io_msg_data_remote(struct io_ring_ctx *target_ctx,
111106
if (msg->flags & IORING_MSG_RING_FLAGS_PASS)
112107
flags = msg->cqe_flags;
113108

114-
return io_msg_remote_post(target_ctx, target, msg->len, flags,
115-
msg->user_data);
109+
io_msg_remote_post(target_ctx, target, msg->len, flags, msg->user_data);
110+
return 0;
116111
}
117112

118113
static int __io_msg_ring_data(struct io_ring_ctx *target_ctx,
@@ -127,7 +122,7 @@ static int __io_msg_ring_data(struct io_ring_ctx *target_ctx,
127122
return -EINVAL;
128123
/*
129124
* Keep IORING_SETUP_R_DISABLED check before submitter_task load
130-
* in io_msg_data_remote() -> io_msg_remote_post()
125+
* in io_msg_data_remote() -> io_req_task_work_add_remote()
131126
*/
132127
if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED)
133128
return -EBADFD;
@@ -227,10 +222,7 @@ static int io_msg_fd_remote(struct io_kiocb *req)
227222
{
228223
struct io_ring_ctx *ctx = req->file->private_data;
229224
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
230-
struct task_struct *task = READ_ONCE(ctx->submitter_task);
231-
232-
if (unlikely(!task))
233-
return -EOWNERDEAD;
225+
struct task_struct *task = ctx->submitter_task;
234226

235227
init_task_work(&msg->tw, io_msg_tw_fd_complete);
236228
if (task_work_add(task, &msg->tw, TWA_SIGNAL))

io_uring/register.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
181181
return -EBADFD;
182182

183183
if (ctx->flags & IORING_SETUP_SINGLE_ISSUER && !ctx->submitter_task) {
184-
WRITE_ONCE(ctx->submitter_task, get_task_struct(current));
184+
ctx->submitter_task = get_task_struct(current);
185185
/*
186186
* Lazy activation attempts would fail if it was polled before
187187
* submitter_task is set.

0 commit comments

Comments
 (0)