]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring/rsrc: refactor io_import_fixed
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 17 Apr 2025 09:32:33 +0000 (10:32 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 17 Apr 2025 12:21:13 +0000 (06:21 -0600)
io_import_fixed is a mess. Even though we know the final len of the
iterator, we still assign offset + len and do some magic after to
correct for that.

Do offset calculation first and finalise it with iov_iter_bvec at the
end.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/2d5107fed24f8b23245ef2ede9a5a7f7c426df61.1744882081.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rsrc.c

index fddde8ffe81e9873442754a7a9edf1e566dca0a5..5cf854318b1dd07659887b52e1de988c132bfbad 100644 (file)
@@ -1037,6 +1037,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
                           u64 buf_addr, size_t len)
 {
        const struct bio_vec *bvec;
+       unsigned nr_segs;
        size_t offset;
        int ret;
 
@@ -1056,8 +1057,6 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
                return 0;
        }
 
-       iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, offset + len);
-
        /*
         * Don't use iov_iter_advance() here, as it's really slow for
         * using the latter parts of a big fixed buffer - it iterates
@@ -1067,30 +1066,21 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
         * 1) it's a BVEC iter, we set it up
         * 2) all bvecs are the same in size, except potentially the
         *    first and last bvec
-        *
-        * So just find our index, and adjust the iterator afterwards.
-        * If the offset is within the first bvec (or the whole first
-        * bvec, just use iov_iter_advance(). This makes it easier
-        * since we can just skip the first segment, which may not
-        * be folio_size aligned.
         */
        bvec = imu->bvec;
-       if (offset < bvec->bv_len) {
-               iter->count -= offset;
-               iter->iov_offset = offset;
-       } else {
+       if (offset >= bvec->bv_len) {
                unsigned long seg_skip;
 
                /* skip first vec */
                offset -= bvec->bv_len;
                seg_skip = 1 + (offset >> imu->folio_shift);
-
-               iter->bvec += seg_skip;
-               iter->nr_segs -= seg_skip;
-               iter->count -= bvec->bv_len + offset;
-               iter->iov_offset = offset & ((1UL << imu->folio_shift) - 1);
+               bvec += seg_skip;
+               offset &= (1UL << imu->folio_shift) - 1;
        }
 
+       nr_segs = imu->nr_bvecs - (bvec - imu->bvec);
+       iov_iter_bvec(iter, ddir, bvec, nr_segs, len);
+       iter->iov_offset = offset;
        return 0;
 }