Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Caleb Sander Mateos and committed by
Jens Axboe
bcd4c957 7a8737e1

+7 -20
+1 -6
io_uring/io_uring.c
··· 3637 3637 } 3638 3638 3639 3639 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)) 3645 3641 ctx->submitter_task = get_task_struct(current); 3646 - } 3647 3642 3648 3643 file = io_uring_get_file(ctx); 3649 3644 if (IS_ERR(file)) {
+5 -13
io_uring/msg_ring.c
··· 80 80 percpu_ref_put(&ctx->refs); 81 81 } 82 82 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, 84 84 int res, u32 cflags, u64 user_data) 85 85 { 86 - if (!READ_ONCE(ctx->submitter_task)) { 87 - kfree_rcu(req, rcu_head); 88 - return -EOWNERDEAD; 89 - } 90 86 req->opcode = IORING_OP_NOP; 91 87 req->cqe.user_data = user_data; 92 88 io_req_set_res(req, res, cflags); ··· 91 95 req->tctx = NULL; 92 96 req->io_task_work.func = io_msg_tw_complete; 93 97 io_req_task_work_add_remote(req, IOU_F_TWQ_LAZY_WAKE); 94 - return 0; 95 98 } 96 99 97 100 static int io_msg_data_remote(struct io_ring_ctx *target_ctx, ··· 106 111 if (msg->flags & IORING_MSG_RING_FLAGS_PASS) 107 112 flags = msg->cqe_flags; 108 113 109 - return io_msg_remote_post(target_ctx, target, msg->len, flags, 110 - msg->user_data); 114 + io_msg_remote_post(target_ctx, target, msg->len, flags, msg->user_data); 115 + return 0; 111 116 } 112 117 113 118 static int __io_msg_ring_data(struct io_ring_ctx *target_ctx, ··· 122 127 return -EINVAL; 123 128 /* 124 129 * Keep IORING_SETUP_R_DISABLED check before submitter_task load 125 - * in io_msg_data_remote() -> io_msg_remote_post() 130 + * in io_msg_data_remote() -> io_req_task_work_add_remote() 126 131 */ 127 132 if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED) 128 133 return -EBADFD; ··· 222 227 { 223 228 struct io_ring_ctx *ctx = req->file->private_data; 224 229 struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); 225 - struct task_struct *task = READ_ONCE(ctx->submitter_task); 226 - 227 - if (unlikely(!task)) 228 - return -EOWNERDEAD; 230 + struct task_struct *task = ctx->submitter_task; 229 231 230 232 init_task_work(&msg->tw, io_msg_tw_fd_complete); 231 233 if (task_work_add(task, &msg->tw, TWA_SIGNAL))
+1 -1
io_uring/register.c
··· 181 181 return -EBADFD; 182 182 183 183 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); 185 185 /* 186 186 * Lazy activation attempts would fail if it was polled before 187 187 * submitter_task is set.