From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH for-6.2 v2 3/3] io_uring/msg_ring: optimise with correct tw notify method
Date: Fri, 20 Jan 2023 16:38:07 +0000 [thread overview]
Message-ID: <018a3d4ce4d8653dd6a6710b959c597b9f98f87e.1674232514.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
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
next prev parent reply other threads:[~2023-01-20 16:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 16:38 [PATCH for-6.2 v2 0/3] msg_ring fixes Pavel Begunkov
2023-01-20 16:38 ` [PATCH for-6.2 v2 1/3] io_uring/msg_ring: fix flagging remote execution Pavel Begunkov
2023-01-20 16:38 ` [PATCH for-6.2 v2 2/3] io_uring/msg_ring: fix remote queue to disabled ring Pavel Begunkov
2023-01-20 16:38 ` Pavel Begunkov [this message]
2023-01-20 16:45 ` (subset) [PATCH for-6.2 v2 0/3] msg_ring fixes Jens Axboe
2023-01-20 16:46 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=018a3d4ce4d8653dd6a6710b959c597b9f98f87e.1674232514.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox