Skip to content

Commit e537592

Browse files
DylanZAaxboe
authored andcommitted
io_uring: do not clamp read length for multishot read
When doing a multishot read, the code path reuses the old read paths. However this breaks an assumption built into those paths, namely that struct io_rw::len is available for reuse by __io_import_iovec. For multishot this results in len being set for the first receive call, and then subsequent calls are clamped to that buffer length incorrectly. Instead keep len as zero after recycling buffers, to reuse the full buffer size of the next selected buffer. Fixes: fc68fcd ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT") Signed-off-by: Dylan Yudaken <dyudaken@gmail.com> Link: https://lore.kernel.org/r/20231106203909.197089-4-dyudaken@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 49fbe99 commit e537592

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

io_uring/rw.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ int io_read(struct io_kiocb *req, unsigned int issue_flags)
912912

913913
int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
914914
{
915+
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
915916
unsigned int cflags = 0;
916917
int ret;
917918

@@ -928,7 +929,12 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
928929
* handling arm it.
929930
*/
930931
if (ret == -EAGAIN) {
931-
io_kbuf_recycle(req, issue_flags);
932+
/*
933+
* Reset rw->len to 0 again to avoid clamping future mshot
934+
* reads, in case the buffer size varies.
935+
*/
936+
if (io_kbuf_recycle(req, issue_flags))
937+
rw->len = 0;
932938
return -EAGAIN;
933939
}
934940

@@ -941,6 +947,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
941947
* jump to the termination path. This request is then done.
942948
*/
943949
cflags = io_put_kbuf(req, issue_flags);
950+
rw->len = 0; /* similarly to above, reset len to 0 */
944951

945952
if (io_fill_cqe_req_aux(req,
946953
issue_flags & IO_URING_F_COMPLETE_DEFER,

0 commit comments

Comments
 (0)