[PATCH 2/2] io_uring: setup iter for recv BUFFER_SELECT once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <asml.silence@xxxxxxxxx>
---
 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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux