Jason Wang
2023-May-11 07:31 UTC
[PATCH v2] vhost_net: revert upend_idx only on retriable error
On Tue, Apr 25, 2023 at 4:44?AM Andrey Smetanin <asmetanin at yandex-team.ru> wrote:> > 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 at yandex-team.ru>Acked-by: Jason Wang <jasowang at redhat.com> Thanks> --- > drivers/vhost/net.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > index 20265393aee7..0791fbdb3975 100644 > --- a/drivers/vhost/net.c > +++ b/drivers/vhost/net.c > @@ -934,13 +934,18 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) > > err = sock->ops->sendmsg(sock, &msg, len); > if (unlikely(err < 0)) { > + bool retry = err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS; > + > if (zcopy_used) { > if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) > vhost_net_ubuf_put(ubufs); > - nvq->upend_idx = ((unsigned)nvq->upend_idx - 1) > - % UIO_MAXIOV; > + if (retry) > + nvq->upend_idx = ((unsigned)nvq->upend_idx - 1) > + % UIO_MAXIOV; > + else > + vq->heads[ubuf->desc].len = VHOST_DMA_DONE_LEN; > } > - if (err == -EAGAIN || err == -ENOMEM || err == -ENOBUFS) { > + if (retry) { > vhost_discard_vq_desc(vq, 1); > vhost_net_enable_vq(net, vq); > break; > -- > 2.25.1 >
Apparently Analagous Threads
- [PATCH] vhost_net: revert upend_idx only on retriable error
- [PATCH RFC 08/13] vhost/net: convert to new API: heads->bufs
- [PATCH V2 4/6] vhost_net: determine whether or not to use zerocopy at one time
- [PATCH V3 4/6] vhost_net: determine whether or not to use zerocopy at one time
- [PATCH V3 4/6] vhost_net: determine whether or not to use zerocopy at one time