Skip to content

Commit 59852eb

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: refactor io_import_fixed
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>
1 parent 50169d0 commit 59852eb

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

io_uring/rsrc.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
10371037
u64 buf_addr, size_t len)
10381038
{
10391039
const struct bio_vec *bvec;
1040+
unsigned nr_segs;
10401041
size_t offset;
10411042
int ret;
10421043

@@ -1056,8 +1057,6 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
10561057
return 0;
10571058
}
10581059

1059-
iov_iter_bvec(iter, ddir, imu->bvec, imu->nr_bvecs, offset + len);
1060-
10611060
/*
10621061
* Don't use iov_iter_advance() here, as it's really slow for
10631062
* 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,
10671066
* 1) it's a BVEC iter, we set it up
10681067
* 2) all bvecs are the same in size, except potentially the
10691068
* first and last bvec
1070-
*
1071-
* So just find our index, and adjust the iterator afterwards.
1072-
* If the offset is within the first bvec (or the whole first
1073-
* bvec, just use iov_iter_advance(). This makes it easier
1074-
* since we can just skip the first segment, which may not
1075-
* be folio_size aligned.
10761069
*/
10771070
bvec = imu->bvec;
1078-
if (offset < bvec->bv_len) {
1079-
iter->count -= offset;
1080-
iter->iov_offset = offset;
1081-
} else {
1071+
if (offset >= bvec->bv_len) {
10821072
unsigned long seg_skip;
10831073

10841074
/* skip first vec */
10851075
offset -= bvec->bv_len;
10861076
seg_skip = 1 + (offset >> imu->folio_shift);
1087-
1088-
iter->bvec += seg_skip;
1089-
iter->nr_segs -= seg_skip;
1090-
iter->count -= bvec->bv_len + offset;
1091-
iter->iov_offset = offset & ((1UL << imu->folio_shift) - 1);
1077+
bvec += seg_skip;
1078+
offset &= (1UL << imu->folio_shift) - 1;
10921079
}
10931080

1081+
nr_segs = imu->nr_bvecs - (bvec - imu->bvec);
1082+
iov_iter_bvec(iter, ddir, bvec, nr_segs, len);
1083+
iter->iov_offset = offset;
10941084
return 0;
10951085
}
10961086

0 commit comments

Comments
 (0)