Skip to content

Commit 4a933e6

Browse files
isilenceaxboe
authored andcommitted
io_uring/net: send retry for zerocopy
io_uring handles short sends/recvs for stream sockets when MSG_WAITALL is set, however new zerocopy send is inconsistent in this regard, which might be confusing. Handle short sends. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/b876a4838597d9bba4f3215db60d72c33c448ad0.1659622472.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent cc18cc5 commit 4a933e6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

io_uring/net.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct io_sendzc {
7070
unsigned flags;
7171
unsigned addr_len;
7272
void __user *addr;
73+
size_t done_io;
7374
};
7475

7576
#define IO_APOLL_MULTI_POLLED (REQ_F_APOLL_MULTISHOT | REQ_F_POLLED)
@@ -878,6 +879,7 @@ int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
878879

879880
zc->addr = u64_to_user_ptr(READ_ONCE(sqe->addr2));
880881
zc->addr_len = READ_ONCE(sqe->addr_len);
882+
zc->done_io = 0;
881883

882884
#ifdef CONFIG_COMPAT
883885
if (req->ctx->compat)
@@ -1012,11 +1014,23 @@ int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
10121014
if (unlikely(ret < min_ret)) {
10131015
if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
10141016
return -EAGAIN;
1015-
return ret == -ERESTARTSYS ? -EINTR : ret;
1017+
if (ret > 0 && io_net_retry(sock, msg.msg_flags)) {
1018+
zc->len -= ret;
1019+
zc->buf += ret;
1020+
zc->done_io += ret;
1021+
req->flags |= REQ_F_PARTIAL_IO;
1022+
return -EAGAIN;
1023+
}
1024+
if (ret == -ERESTARTSYS)
1025+
ret = -EINTR;
1026+
} else if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH) {
1027+
io_notif_slot_flush_submit(notif_slot, 0);
10161028
}
10171029

1018-
if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH)
1019-
io_notif_slot_flush_submit(notif_slot, 0);
1030+
if (ret >= 0)
1031+
ret += zc->done_io;
1032+
else if (zc->done_io)
1033+
ret = zc->done_io;
10201034
io_req_set_res(req, ret, 0);
10211035
return IOU_OK;
10221036
}

0 commit comments

Comments
 (0)