Skip to content

Commit 6ab9468

Browse files
Andrey Smetaningregkh
authored andcommitted
vhost_net: revert upend_idx only on retriable error
[ Upstream commit 1f5d2e3 ] Fix possible virtqueue used buffers leak and corresponding stuck in case of temporary -EIO from sendmsg() which is produced by tun driver while backend device is not up. In case of no-retriable error and zcopy do not revert upend_idx to pass packet data (that is update used_idx in corresponding vhost_zerocopy_signal_used()) as if packet data has been transferred successfully. v2: set vq->heads[ubuf->desc].len equal to VHOST_DMA_DONE_LEN in case of fake successful transmit. Signed-off-by: Andrey Smetanin <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Andrey Smetanin <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 454e4f3 commit 6ab9468

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/vhost/net.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,18 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
934934

935935
err = sock->ops->sendmsg(sock, &msg, len);
936936
if (unlikely(err < 0)) {
937+
bool retry = err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS;
938+
937939
if (zcopy_used) {
938940
if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS)
939941
vhost_net_ubuf_put(ubufs);
940-
nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
941-
% UIO_MAXIOV;
942+
if (retry)
943+
nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
944+
% UIO_MAXIOV;
945+
else
946+
vq->heads[ubuf->desc].len = VHOST_DMA_DONE_LEN;
942947
}
943-
if (err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS) {
948+
if (retry) {
944949
vhost_discard_vq_desc(vq, 1);
945950
vhost_net_enable_vq(net, vq);
946951
break;

0 commit comments

Comments
 (0)