Skip to content

Commit 56d8e31

Browse files
isilenceaxboe
authored andcommitted
io_uring/msg_ring: fix flagging remote execution
There is a couple of problems with queueing a tw in io_msg_ring_data() for remote execution. First, once we queue it the target ring can go away and so setting IORING_SQ_TASKRUN there is not safe. Secondly, the userspace might not expect IORING_SQ_TASKRUN. Extract a helper and uniformly use TWA_SIGNAL without TWA_SIGNAL_NO_IPI tricks for now, just as it was done in the original patch. Cc: stable@vger.kernel.org Fixes: 6d043ee ("io_uring: do msg_ring in target task via tw") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e12d7a4 commit 56d8e31

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

io_uring/msg_ring.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ void io_msg_ring_cleanup(struct io_kiocb *req)
5858
msg->src_file = NULL;
5959
}
6060

61+
static inline bool io_msg_need_remote(struct io_ring_ctx *target_ctx)
62+
{
63+
if (!target_ctx->task_complete)
64+
return false;
65+
return current != target_ctx->submitter_task;
66+
}
67+
68+
static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func)
69+
{
70+
struct io_ring_ctx *ctx = req->file->private_data;
71+
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
72+
73+
init_task_work(&msg->tw, func);
74+
if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL))
75+
return -EOWNERDEAD;
76+
77+
return IOU_ISSUE_SKIP_COMPLETE;
78+
}
79+
6180
static void io_msg_tw_complete(struct callback_head *head)
6281
{
6382
struct io_msg *msg = container_of(head, struct io_msg, tw);
@@ -96,15 +115,8 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags)
96115
if (msg->src_fd || msg->dst_fd || msg->flags)
97116
return -EINVAL;
98117

99-
if (target_ctx->task_complete && current != target_ctx->submitter_task) {
100-
init_task_work(&msg->tw, io_msg_tw_complete);
101-
if (task_work_add(target_ctx->submitter_task, &msg->tw,
102-
TWA_SIGNAL_NO_IPI))
103-
return -EOWNERDEAD;
104-
105-
atomic_or(IORING_SQ_TASKRUN, &target_ctx->rings->sq_flags);
106-
return IOU_ISSUE_SKIP_COMPLETE;
107-
}
118+
if (io_msg_need_remote(target_ctx))
119+
return io_msg_exec_remote(req, io_msg_tw_complete);
108120

109121
ret = -EOVERFLOW;
110122
if (target_ctx->flags & IORING_SETUP_IOPOLL) {
@@ -202,14 +214,8 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
202214
req->flags |= REQ_F_NEED_CLEANUP;
203215
}
204216

205-
if (target_ctx->task_complete && current != target_ctx->submitter_task) {
206-
init_task_work(&msg->tw, io_msg_tw_fd_complete);
207-
if (task_work_add(target_ctx->submitter_task, &msg->tw,
208-
TWA_SIGNAL))
209-
return -EOWNERDEAD;
210-
211-
return IOU_ISSUE_SKIP_COMPLETE;
212-
}
217+
if (io_msg_need_remote(target_ctx))
218+
return io_msg_exec_remote(req, io_msg_tw_fd_complete);
213219
return io_msg_install_complete(req, issue_flags);
214220
}
215221

0 commit comments

Comments
 (0)