From 0166112bf9b190bb38208d507b7af4a6dca81063 Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Tue, 5 Dec 2017 09:28:39 +0100 Subject: [PATCH 17/21] vhost: restore avail index from vring used index on disconnection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Maxime Coquelin Message-id: <20171205092839.17597-3-maxime.coquelin@redhat.com> Patchwork-id: 78141 O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 2/2] vhost: restore avail index from vring used index on disconnection Bugzilla: 1491909 RH-Acked-by: wexu@redhat.com RH-Acked-by: Marc-André Lureau RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Xiao Wang vhost_virtqueue_stop() gets avail index value from the backend, except if the backend is not responding. It happens when the backend crashes, and in this case, internal state of the virtio queue is inconsistent, making packets to corrupt the vring state. With a Linux guest, it results in following error message on backend reconnection: [ 22.444905] virtio_net virtio0: output.0:id 0 is not a head! [ 22.446746] net enp0s3: Unexpected TXQ (0) queue failure: -5 [ 22.476360] net enp0s3: Unexpected TXQ (0) queue failure: -5 Fixes: 283e2c2adcb8 ("net: virtio-net discards TX data after link down") Cc: qemu-stable@nongnu.org Signed-off-by: Maxime Coquelin Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 2ae39a113af311cb56a0c35b7f212dafcef15303) Signed-off-by: Maxime Coquelin Signed-off-by: Miroslav Rezanina --- hw/virtio/vhost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b737ca9..76f6e1f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1137,6 +1137,10 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev, r = dev->vhost_ops->vhost_get_vring_base(dev, &state); if (r < 0) { VHOST_OPS_DEBUG("vhost VQ %d ring restore failed: %d", idx, r); + /* Connection to the backend is broken, so let's sync internal + * last avail idx to the device used idx. + */ + virtio_queue_restore_last_avail_idx(vdev, idx); } else { virtio_queue_set_last_avail_idx(vdev, idx, state.num); } -- 1.8.3.1