We may want to use TWA_SIGNAL_NO_IPI instead of TWA_SIGNAL if the target ring is configured with IORING_SETUP_COOP_TASKRUN, change io_msg_exec_remote() to use the target ring's ->notify_method. The caveat is that we have to set IORING_SQ_TASKRUN if the rings asks for it. However, once task_work_add() succeeds the target ring might go away and so we grab a ctx reference to pin the ring until we set IORING_SQ_TASKRUN. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- io_uring/msg_ring.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index 15602a136821..af802cd645b4 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -70,15 +70,22 @@ static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func) struct io_ring_ctx *ctx = req->file->private_data; struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); struct task_struct *task = READ_ONCE(ctx->submitter_task); + int ret = IOU_ISSUE_SKIP_COMPLETE; if (unlikely(!task)) return -EOWNERDEAD; + percpu_ref_get(&ctx->refs); init_task_work(&msg->tw, func); - if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL)) - return -EOWNERDEAD; - - return IOU_ISSUE_SKIP_COMPLETE; + if (task_work_add(ctx->submitter_task, &msg->tw, ctx->notify_method)) { + ret = -EOWNERDEAD; + goto out; + } + if (ctx->flags & IORING_SETUP_TASKRUN_FLAG) + atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags); +out: + percpu_ref_put(&ctx->refs); + return ret; } static void io_msg_tw_complete(struct callback_head *head) -- 2.38.1