public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 2/2] io_uring: rely on io_prep_reg_vec for iovec placement
Date: Sat,  8 Mar 2025 18:21:16 +0000	[thread overview]
Message-ID: <08ed87ca4bbc06724373b6ce06f36b703fe60c4e.1741457480.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

All vectored reg buffer users should use io_import_reg_vec() for iovec
imports, since iovec placement is the function's responsibility and
callers shouldn't know much about it, drop the offset parameter from
io_prep_reg_vec() and calculate it inside.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/net.c  | 4 +---
 io_uring/rsrc.c | 8 ++++----
 io_uring/rsrc.h | 3 +--
 io_uring/rw.c   | 3 +--
 4 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index 6b8dbadf445f..1e36a72e4008 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1513,12 +1513,10 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
 
 	if (req->flags & REQ_F_IMPORT_BUFFER) {
 		unsigned uvec_segs = kmsg->msg.msg_iter.nr_segs;
-		unsigned iovec_off = kmsg->vec.nr - uvec_segs;
 		int ret;
 
 		ret = io_import_reg_vec(ITER_SOURCE, &kmsg->msg.msg_iter, req,
-					&kmsg->vec, uvec_segs, iovec_off,
-					issue_flags);
+					&kmsg->vec, uvec_segs, issue_flags);
 		if (unlikely(ret))
 			return ret;
 		kmsg->msg.sg_from_iter = io_sg_from_iter;
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 0e413e910f3d..607b09bd8374 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1349,11 +1349,11 @@ static int io_estimate_bvec_size(struct iovec *iov, unsigned nr_iovs,
 
 int io_import_reg_vec(int ddir, struct iov_iter *iter,
 			struct io_kiocb *req, struct iou_vec *vec,
-			unsigned nr_iovs, unsigned iovec_off,
-			unsigned issue_flags)
+			unsigned nr_iovs, unsigned issue_flags)
 {
 	struct io_rsrc_node *node;
 	struct io_mapped_ubuf *imu;
+	unsigned iovec_off;
 	struct iovec *iov;
 	unsigned nr_segs;
 
@@ -1366,6 +1366,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
 	if (!(imu->dir & (1 << ddir)))
 		return -EFAULT;
 
+	iovec_off = vec->nr - nr_iovs;
 	iov = vec->iovec + iovec_off;
 	nr_segs = io_estimate_bvec_size(iov, nr_iovs, imu);
 
@@ -1377,8 +1378,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
 		nr_segs += nr_iovs;
 	}
 
-	if (WARN_ON_ONCE(iovec_off + nr_iovs != vec->nr) ||
-	    nr_segs > vec->nr) {
+	if (nr_segs > vec->nr) {
 		struct iou_vec tmp_vec = {};
 		int ret;
 
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 43f784915573..b52242852ff3 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -65,8 +65,7 @@ int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter,
 			unsigned issue_flags);
 int io_import_reg_vec(int ddir, struct iov_iter *iter,
 			struct io_kiocb *req, struct iou_vec *vec,
-			unsigned nr_iovs, unsigned iovec_off,
-			unsigned issue_flags);
+			unsigned nr_iovs, unsigned issue_flags);
 int io_prep_reg_iovec(struct io_kiocb *req, struct iou_vec *iv,
 			const struct iovec __user *uvec, size_t uvec_segs);
 
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 4861b876f48e..246b22225919 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -390,11 +390,10 @@ static int io_rw_import_reg_vec(struct io_kiocb *req,
 {
 	struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
 	unsigned uvec_segs = rw->len;
-	unsigned iovec_off = io->vec.nr - uvec_segs;
 	int ret;
 
 	ret = io_import_reg_vec(ddir, &io->iter, req, &io->vec,
-				uvec_segs, iovec_off, issue_flags);
+				uvec_segs, issue_flags);
 	if (unlikely(ret))
 		return ret;
 	iov_iter_save_state(&io->iter, &io->iter_state);
-- 
2.48.1


  parent reply	other threads:[~2025-03-08 18:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 18:21 [PATCH 0/2] unify registered buffer iovec imports Pavel Begunkov
2025-03-08 18:21 ` [PATCH 1/2] io_uring: introduce io_prep_reg_iovec() Pavel Begunkov
2025-03-08 18:21 ` Pavel Begunkov [this message]
2025-03-10 13:14 ` [PATCH 0/2] unify registered buffer iovec imports Jens Axboe

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=08ed87ca4bbc06724373b6ce06f36b703fe60c4e.1741457480.git.asml.silence@gmail.com \
    [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