Skip to content

Commit 7b7699c

Browse files
committed
Merge branch 'work.iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull iov_iter fixes from Al Viro: "Fixes for io-uring handling of iov_iter reexpands" * 'work.iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: io_uring: reexpand under-reexpanded iters iov_iter: track truncated size
2 parents 70868a1 + 89c2b3b commit 7b7699c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

fs/io_uring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
34803480
if (req->flags & REQ_F_NOWAIT)
34813481
goto done;
34823482
/* some cases will consume bytes even on error returns */
3483+
iov_iter_reexpand(iter, iter->count + iter->truncated);
34833484
iov_iter_revert(iter, io_size - iov_iter_count(iter));
34843485
ret = 0;
34853486
} else if (ret == -EIOCBQUEUED) {
@@ -3619,6 +3620,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
36193620
} else {
36203621
copy_iov:
36213622
/* some cases will consume bytes even on error returns */
3623+
iov_iter_reexpand(iter, iter->count + iter->truncated);
36223624
iov_iter_revert(iter, io_size - iov_iter_count(iter));
36233625
ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false);
36243626
return ret ?: -EAGAIN;

include/linux/uio.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct iov_iter {
4747
};
4848
loff_t xarray_start;
4949
};
50+
size_t truncated;
5051
};
5152

5253
static inline enum iter_type iov_iter_type(const struct iov_iter *i)
@@ -254,8 +255,10 @@ static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
254255
* conversion in assignement is by definition greater than all
255256
* values of size_t, including old i->count.
256257
*/
257-
if (i->count > count)
258+
if (i->count > count) {
259+
i->truncated += i->count - count;
258260
i->count = count;
261+
}
259262
}
260263

261264
/*
@@ -264,6 +267,7 @@ static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
264267
*/
265268
static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
266269
{
270+
i->truncated -= count - i->count;
267271
i->count = count;
268272
}
269273

0 commit comments

Comments
 (0)