[PATCH 4/7] io_uring/net: unify sendmsg setup with zc

Pavel Begunkov
2025-03-28T23:10:27Z

io_sendmsg_zc_setup() duplicates parts of io_sendmsg_setup(), and the
only difference between them is that the former support vectored
registered buffers with nothing zerocopy specific. Merge them together,
we want regular sendmsg to eventually support fixed buffers either way.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/net.c | 28 ++++++----------------------
1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index e293f848a686..6514323f4c60 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -377,32 +377,16 @@ static int io_sendmsg_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe
/* save msg_control as sys_sendmsg() overwrites it */
sr->msg_control = kmsg->msg.msg_control_user;

+ if (sr->flags & IORING_RECVSEND_FIXED_BUF) {
+ kmsg->msg.msg_iter.nr_segs = msg.msg_iovlen;
+ return io_prep_reg_iovec(req, &kmsg->vec, msg.msg_iov,
+ msg.msg_iovlen);
+ }
if (req->flags & REQ_F_BUFFER_SELECT)
return 0;
return io_net_import_vec(req, kmsg, msg.msg_iov, msg.msg_iovlen, ITER_SOURCE);
}

-static int io_sendmsg_zc_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe)
-{
- struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
- struct io_async_msghdr *kmsg = req->async_data;
- struct user_msghdr msg;
- int ret;
-
- if (!(sr->flags & IORING_RECVSEND_FIXED_BUF))
- return io_sendmsg_setup(req, sqe);
-
- sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
-
- ret = io_msg_copy_hdr(req, kmsg, &msg, ITER_SOURCE, NULL);
- if (unlikely(ret))
- return ret;
- sr->msg_control = kmsg->msg.msg_control_user;
- kmsg->msg.msg_iter.nr_segs = msg.msg_iovlen;
-
- return io_prep_reg_iovec(req, &kmsg->vec, msg.msg_iov, msg.msg_iovlen);
-}
-
#define SENDMSG_FLAGS (IORING_RECVSEND_POLL_FIRST | IORING_RECVSEND_BUNDLE)

int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
@@ -1340,7 +1324,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
req->flags |= REQ_F_IMPORT_BUFFER;
return io_send_setup(req, sqe);
}
- ret = io_sendmsg_zc_setup(req, sqe);
+ ret = io_sendmsg_setup(req, sqe);
if (unlikely(ret))
return ret;

--
2.48.1