public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected], [email protected]
Subject: [PATCH 4/5] io_uring: send/recv with registered buffer
Date: Sun, 15 Nov 2020 10:35:43 +0000	[thread overview]
Message-ID: <67aa100f8fb62691281a605f28e621152e768c52.1605435507.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Add support of registered buffers to send() and recv(). Done by
exploiting last bit of send/recv flags, IO_MSG_FIXED, which is cleared
before going into net stack.

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 7703291617f3..390495170fb0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -104,6 +104,8 @@
 #define IORING_MAX_RESTRICTIONS	(IORING_RESTRICTION_LAST + \
 				 IORING_REGISTER_LAST + IORING_OP_LAST)
 
+#define IO_MSG_FIXED		(1U << 31)
+
 struct io_uring {
 	u32 head ____cacheline_aligned_in_smp;
 	u32 tail ____cacheline_aligned_in_smp;
@@ -4689,18 +4691,25 @@ static int io_send(struct io_kiocb *req, bool force_nonblock,
 		   struct io_comp_state *cs)
 {
 	struct io_sr_msg *sr = &req->sr_msg;
+	unsigned int flags = sr->msg_flags;
 	struct msghdr msg;
 	struct iovec iov;
 	struct socket *sock;
-	unsigned flags;
 	int ret;
 
 	sock = sock_from_file(req->file, &ret);
 	if (unlikely(!sock))
 		return ret;
 
-	ret = import_single_range(WRITE, sr->buf, sr->len, &iov, &msg.msg_iter);
-	if (unlikely(ret))
+	if (flags & IO_MSG_FIXED) {
+		ret = io_import_fixed(req, WRITE, (u64)sr->buf, sr->len,
+				      &msg.msg_iter);
+		flags &= ~IO_MSG_FIXED;
+	} else {
+		ret = import_single_range(WRITE, sr->buf, sr->len, &iov,
+					  &msg.msg_iter);
+	}
+	if (unlikely(ret < 0))
 		return ret;
 
 	msg.msg_name = NULL;
@@ -4708,7 +4717,6 @@ static int io_send(struct io_kiocb *req, bool force_nonblock,
 	msg.msg_controllen = 0;
 	msg.msg_namelen = 0;
 
-	flags = req->sr_msg.msg_flags;
 	if (flags & MSG_DONTWAIT)
 		req->flags |= REQ_F_NOWAIT;
 	else if (force_nonblock)
@@ -4821,15 +4829,22 @@ static int io_recv(struct io_kiocb *req, bool force_nonblock,
 	if (unlikely(!sock))
 		return ret;
 
-	if (req->flags & REQ_F_BUFFER_SELECT) {
-		kbuf = io_recv_buffer_select(req, !force_nonblock);
-		if (IS_ERR(kbuf))
-			return PTR_ERR(kbuf);
-		buf = u64_to_user_ptr(kbuf->addr);
-	}
+	if (flags & IO_MSG_FIXED) {
+		ret = io_import_fixed(req, READ, (u64)buf, sr->len,
+				      &msg.msg_iter);
+		flags &= ~IO_MSG_FIXED;
+	} else {
+		if (req->flags & REQ_F_BUFFER_SELECT) {
+			kbuf = io_recv_buffer_select(req, !force_nonblock);
+			if (IS_ERR(kbuf))
+				return PTR_ERR(kbuf);
+			buf = u64_to_user_ptr(kbuf->addr);
+		}
 
-	ret = import_single_range(READ, buf, sr->len, &iov, &msg.msg_iter);
-	if (unlikely(ret))
+		ret = import_single_range(READ, buf, sr->len, &iov,
+					  &msg.msg_iter);
+	}
+	if (unlikely(ret < 0))
 		goto out_free;
 
 	msg.msg_name = NULL;
-- 
2.24.0


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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 10:35 [RFC 0/5] support for {send,recv}[msg] with registered bufs Pavel Begunkov
2020-11-15 10:35 ` [PATCH 1/5] io_uring: move io_recvmsg_copy_hdr() Pavel Begunkov
2020-11-15 10:35 ` [PATCH 2/5] io_uring: copy hdr consistently for send and recv Pavel Begunkov
2020-11-15 10:35 ` [PATCH 3/5] io_uring: opcode independent import_fixed Pavel Begunkov
2020-11-15 10:35 ` Pavel Begunkov [this message]
2020-11-15 10:35 ` [PATCH 5/5] io_uring: sendmsg/recvmsg with registered buffers Pavel Begunkov

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=67aa100f8fb62691281a605f28e621152e768c52.1605435507.git.asml.silence@gmail.com \
    [email protected] \
    [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