[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230324135808.855245-6-ming.lei@redhat.com>
Date: Fri, 24 Mar 2023 21:57:56 +0800
From: Ming Lei <ming.lei@...hat.com>
To: Jens Axboe <axboe@...nel.dk>, io-uring@...r.kernel.org,
linux-block@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Miklos Szeredi <mszeredi@...hat.com>,
ZiyangZhang <ZiyangZhang@...ux.alibaba.com>,
Xiaoguang Wang <xiaoguang.wang@...ux.alibaba.com>,
Bernd Schubert <bschubert@....com>,
Pavel Begunkov <asml.silence@...il.com>,
Stefan Hajnoczi <stefanha@...hat.com>,
Ming Lei <ming.lei@...hat.com>
Subject: [PATCH V4 05/17] io_uring: support OP_SEND_ZC/OP_RECV for fused slave request
Start to allow fused slave request to support OP_SEND_ZC/OP_RECV, and
the buffer can be retrieved from master request.
Once the slave request is completed, the master buffer will be returned
back.
Signed-off-by: Ming Lei <ming.lei@...hat.com>
---
io_uring/net.c | 30 ++++++++++++++++++++++++++++--
io_uring/opdef.c | 6 ++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index b7f190ca528e..bc33f89f61b3 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -16,6 +16,7 @@
#include "net.h"
#include "notif.h"
#include "rsrc.h"
+#include "fused_cmd.h"
#if defined(CONFIG_NET)
struct io_shutdown {
@@ -68,6 +69,13 @@ struct io_sr_msg {
struct io_kiocb *notif;
};
+#define user_ptr_to_u64(x) ( \
+{ \
+ typecheck(void __user *, (x)); \
+ (u64)(unsigned long)(x); \
+} \
+)
+
static inline bool io_check_multishot(struct io_kiocb *req,
unsigned int issue_flags)
{
@@ -378,7 +386,11 @@ int io_send(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(!sock))
return -ENOTSOCK;
- ret = import_ubuf(ITER_SOURCE, sr->buf, sr->len, &msg.msg_iter);
+ if (!(req->flags & REQ_F_FUSED_SLAVE))
+ ret = import_ubuf(ITER_SOURCE, sr->buf, sr->len, &msg.msg_iter);
+ else
+ ret = io_import_buf_for_slave(user_ptr_to_u64(sr->buf),
+ sr->len, ITER_SOURCE, &msg.msg_iter, req);
if (unlikely(ret))
return ret;
@@ -869,7 +881,11 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
sr->buf = buf;
}
- ret = import_ubuf(ITER_DEST, sr->buf, len, &msg.msg_iter);
+ if (!(req->flags & REQ_F_FUSED_SLAVE))
+ ret = import_ubuf(ITER_DEST, sr->buf, len, &msg.msg_iter);
+ else
+ ret = io_import_buf_for_slave(user_ptr_to_u64(sr->buf),
+ sr->len, ITER_DEST, &msg.msg_iter, req);
if (unlikely(ret))
goto out_free;
@@ -983,6 +999,9 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
if (zc->flags & IORING_RECVSEND_FIXED_BUF) {
unsigned idx = READ_ONCE(sqe->buf_index);
+ if (req->flags & REQ_F_FUSED_SLAVE)
+ return -EINVAL;
+
if (unlikely(idx >= ctx->nr_user_bufs))
return -EFAULT;
idx = array_index_nospec(idx, ctx->nr_user_bufs);
@@ -1119,8 +1138,15 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(ret))
return ret;
msg.sg_from_iter = io_sg_from_iter;
+ } else if (req->flags & REQ_F_FUSED_SLAVE) {
+ ret = io_import_buf_for_slave(user_ptr_to_u64(zc->buf),
+ zc->len, ITER_SOURCE, &msg.msg_iter, req);
+ if (unlikely(ret))
+ return ret;
+ msg.sg_from_iter = io_sg_from_iter;
} else {
io_notif_set_extended(zc->notif);
+
ret = import_ubuf(ITER_SOURCE, zc->buf, zc->len, &msg.msg_iter);
if (unlikely(ret))
return ret;
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index 9b376df91abd..e7d75bf69c0f 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -273,6 +273,8 @@ const struct io_issue_def io_issue_defs[] = {
.audit_skip = 1,
.ioprio = 1,
.manual_alloc = 1,
+ .fused_slave = 1,
+ .buf_dir = READ,
#if defined(CONFIG_NET)
.prep = io_sendmsg_prep,
.issue = io_send,
@@ -287,6 +289,8 @@ const struct io_issue_def io_issue_defs[] = {
.buffer_select = 1,
.audit_skip = 1,
.ioprio = 1,
+ .fused_slave = 1,
+ .buf_dir = WRITE,
#if defined(CONFIG_NET)
.prep = io_recvmsg_prep,
.issue = io_recv,
@@ -413,6 +417,8 @@ const struct io_issue_def io_issue_defs[] = {
.audit_skip = 1,
.ioprio = 1,
.manual_alloc = 1,
+ .fused_slave = 1,
+ .buf_dir = READ,
#if defined(CONFIG_NET)
.prep = io_send_zc_prep,
.issue = io_send_zc,
--
2.39.2
Powered by blists - more mailing lists