public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 2/2] io_uring: setup iter for recv BUFFER_SELECT once
Date: Sun, 15 Nov 2020 10:17:18 +0000	[thread overview]
Message-ID: <daee149a3305d0a6a018a92cd6ed0f0f3f6cbf12.1605434816.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Instead of initialising msg.msg_iter with a selected buffer in
io_recv_msg() every time, do it once in io_recvmsg_copy_hdr(). Further
it may be copied into another msg but that's fine as
io_setup_async_msg() handles iovs copy.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 53 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 02811c90f711..aafdcf94be9d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4689,20 +4689,6 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
 }
 #endif
 
-static int io_recvmsg_copy_hdr(struct io_kiocb *req,
-			       struct io_async_msghdr *iomsg)
-{
-	iomsg->msg.msg_name = &iomsg->addr;
-	iomsg->iov = iomsg->fast_iov;
-
-#ifdef CONFIG_COMPAT
-	if (req->ctx->compat)
-		return __io_compat_recvmsg_copy_hdr(req, iomsg);
-#endif
-
-	return __io_recvmsg_copy_hdr(req, iomsg);
-}
-
 static struct io_buffer *io_recv_buffer_select(struct io_kiocb *req,
 					       bool needs_lock)
 {
@@ -4718,6 +4704,35 @@ static struct io_buffer *io_recv_buffer_select(struct io_kiocb *req,
 	return kbuf;
 }
 
+static int io_recvmsg_copy_hdr(struct io_kiocb *req,
+			       struct io_async_msghdr *iomsg)
+{
+	struct io_buffer *kbuf;
+	int ret;
+
+	iomsg->msg.msg_name = &iomsg->addr;
+	iomsg->iov = iomsg->fast_iov;
+#ifdef CONFIG_COMPAT
+	if (req->ctx->compat)
+		ret = __io_compat_recvmsg_copy_hdr(req, iomsg);
+	else
+#endif
+		ret = __io_recvmsg_copy_hdr(req, iomsg);
+	if (ret < 0)
+		return ret;
+
+	if (req->flags & REQ_F_BUFFER_SELECT) {
+		/* init is always done with uring_lock held */
+		kbuf = io_recv_buffer_select(req, false);
+		if (IS_ERR(kbuf))
+			return PTR_ERR(kbuf);
+		iomsg->fast_iov[0].iov_base = u64_to_user_ptr(kbuf->addr);
+		iov_iter_init(&iomsg->msg.msg_iter, READ, iomsg->fast_iov, 1,
+			      req->sr_msg.len);
+	}
+	return 0;
+}
+
 static inline unsigned int io_put_recv_kbuf(struct io_kiocb *req)
 {
 	return io_put_kbuf(req, req->sr_msg.kbuf);
@@ -4756,7 +4771,6 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
 {
 	struct io_async_msghdr iomsg, *kmsg;
 	struct socket *sock;
-	struct io_buffer *kbuf;
 	unsigned flags;
 	int ret, cflags = 0;
 
@@ -4772,15 +4786,6 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
 		kmsg = &iomsg;
 	}
 
-	if (req->flags & REQ_F_BUFFER_SELECT) {
-		kbuf = io_recv_buffer_select(req, !force_nonblock);
-		if (IS_ERR(kbuf))
-			return PTR_ERR(kbuf);
-		kmsg->fast_iov[0].iov_base = u64_to_user_ptr(kbuf->addr);
-		iov_iter_init(&kmsg->msg.msg_iter, READ, kmsg->fast_iov,
-				1, req->sr_msg.len);
-	}
-
 	flags = req->sr_msg.msg_flags;
 	if (flags & MSG_DONTWAIT)
 		req->flags |= REQ_F_NOWAIT;
-- 
2.24.0


      parent reply	other threads:[~2020-11-15 10:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 10:17 [PATCH 5.11 0/2] clean up async msg setup Pavel Begunkov
2020-11-15 10:17 ` [PATCH 1/2] io_uring: update msg header on copy Pavel Begunkov
2020-11-15 10:17 ` Pavel Begunkov [this message]

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=daee149a3305d0a6a018a92cd6ed0f0f3f6cbf12.1605434816.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