Skip to content

Commit 0c07f2b

Browse files
axboegregkh
authored andcommitted
io_uring/net: only retry recv bundle for a full transfer
Commit 3a08988 upstream. If a shorter than assumed transfer was seen, a partial buffer will have been filled. For that case it isn't sane to attempt to fill more into the bundle before posting a completion, as that will cause a gap in the received data. Check if the iterator has hit zero and only allow to continue a bundle operation if that is the case. Also ensure that for putting finished buffers, only the current transfer is accounted. Otherwise too many buffers may be put for a short transfer. Link: axboe/liburing#1409 Cc: [email protected] Fixes: 7c71a0a ("io_uring/net: improve recv bundles") Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 399214d commit 0c07f2b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

io_uring/net.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,18 +852,24 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
852852
cflags |= IORING_CQE_F_SOCK_NONEMPTY;
853853

854854
if (sr->flags & IORING_RECVSEND_BUNDLE) {
855-
cflags |= io_put_kbufs(req, *ret, io_bundle_nbufs(kmsg, *ret),
855+
size_t this_ret = *ret - sr->done_io;
856+
857+
cflags |= io_put_kbufs(req, *ret, io_bundle_nbufs(kmsg, this_ret),
856858
issue_flags);
857859
if (sr->retry)
858860
cflags = req->cqe.flags | (cflags & CQE_F_MASK);
859861
/* bundle with no more immediate buffers, we're done */
860862
if (req->flags & REQ_F_BL_EMPTY)
861863
goto finish;
862-
/* if more is available, retry and append to this one */
863-
if (!sr->retry && kmsg->msg.msg_inq > 0 && *ret > 0) {
864+
/*
865+
* If more is available AND it was a full transfer, retry and
866+
* append to this one
867+
*/
868+
if (!sr->retry && kmsg->msg.msg_inq > 0 && this_ret > 0 &&
869+
!iov_iter_count(&kmsg->msg.msg_iter)) {
864870
req->cqe.flags = cflags & ~CQE_F_MASK;
865871
sr->len = kmsg->msg.msg_inq;
866-
sr->done_io += *ret;
872+
sr->done_io += this_ret;
867873
sr->retry = true;
868874
return false;
869875
}

0 commit comments

Comments
 (0)