Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vhost_net: revert upend_idx only on retriable error

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 <asmetanin@yandex-team.ru>
Message-Id: <20230424204411.24888-1-asmetanin@yandex-team.ru>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andrey Smetanin <asmetanin@yandex-team.ru>
Acked-by: Jason Wang <jasowang@redhat.com>

authored by

Andrey Smetanin and committed by
Michael S. Tsirkin
1f5d2e3b 376daf31

+8 -3
+8 -3
drivers/vhost/net.c
··· 935 935 936 936 err = sock->ops->sendmsg(sock, &msg, len); 937 937 if (unlikely(err < 0)) { 938 + bool retry = err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS; 939 + 938 940 if (zcopy_used) { 939 941 if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) 940 942 vhost_net_ubuf_put(ubufs); 941 - nvq->upend_idx = ((unsigned)nvq->upend_idx - 1) 942 - % UIO_MAXIOV; 943 + if (retry) 944 + nvq->upend_idx = ((unsigned)nvq->upend_idx - 1) 945 + % UIO_MAXIOV; 946 + else 947 + vq->heads[ubuf->desc].len = VHOST_DMA_DONE_LEN; 943 948 } 944 - if (err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS) { 949 + if (retry) { 945 950 vhost_discard_vq_desc(vq, 1); 946 951 vhost_net_enable_vq(net, vq); 947 952 break;