Skip to content

Commit

Permalink
io_uring/net: send retry for zerocopy
Browse files Browse the repository at this point in the history
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 <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/b876a4838597d9bba4f3215db60d72c33c448ad0.1659622472.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Aug 4, 2022
1 parent cc18cc5 commit 4a933e6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions io_uring/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct io_sendzc {
unsigned flags;
unsigned addr_len;
void __user *addr;
size_t done_io;
};

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

zc->addr = u64_to_user_ptr(READ_ONCE(sqe->addr2));
zc->addr_len = READ_ONCE(sqe->addr_len);
zc->done_io = 0;

#ifdef CONFIG_COMPAT
if (req->ctx->compat)
Expand Down Expand Up @@ -1012,11 +1014,23 @@ int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(ret < min_ret)) {
if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
return -EAGAIN;
return ret == -ERESTARTSYS ? -EINTR : ret;
if (ret > 0 && io_net_retry(sock, msg.msg_flags)) {
zc->len -= ret;
zc->buf += ret;
zc->done_io += ret;
req->flags |= REQ_F_PARTIAL_IO;
return -EAGAIN;
}
if (ret == -ERESTARTSYS)
ret = -EINTR;
} else if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH) {
io_notif_slot_flush_submit(notif_slot, 0);
}

if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH)
io_notif_slot_flush_submit(notif_slot, 0);
if (ret >= 0)
ret += zc->done_io;
else if (zc->done_io)
ret = zc->done_io;
io_req_set_res(req, ret, 0);
return IOU_OK;
}
Expand Down

0 comments on commit 4a933e6

Please sign in to comment.