From 257d8d98076717288519d312f1690c453bb74776 Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Tue, 5 Dec 2017 09:28:38 +0100 Subject: [PATCH 16/21] virtio: Add queue interface to restore avail index from vring used index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Maxime Coquelin Message-id: <20171205092839.17597-2-maxime.coquelin@redhat.com> Patchwork-id: 78140 O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 1/2] virtio: Add queue interface to restore avail index from vring used index 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 In case of backend crash, it is not possible to restore internal avail index from the backend value as vhost_get_vring_base callback fails. This patch provides a new interface to restore internal avail index from the vring used index, as done by some vhost-user backend on reconnection. Signed-off-by: Maxime Coquelin Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 2d4ba6cc741df15df6fbb4feaa706a02e103083a) Signed-off-by: Maxime Coquelin Signed-off-by: Miroslav Rezanina --- hw/virtio/virtio.c | 10 ++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 11 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e7a2bc2..58ecf75 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2329,6 +2329,16 @@ void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx) vdev->vq[n].shadow_avail_idx = idx; } +void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n) +{ + rcu_read_lock(); + if (vdev->vq[n].vring.desc) { + vdev->vq[n].last_avail_idx = vring_used_idx(&vdev->vq[n]); + vdev->vq[n].shadow_avail_idx = vdev->vq[n].last_avail_idx; + } + rcu_read_unlock(); +} + void virtio_queue_update_used_idx(VirtIODevice *vdev, int n) { rcu_read_lock(); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 5faa359..912310c 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -273,6 +273,7 @@ hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx); +void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n); void virtio_queue_update_used_idx(VirtIODevice *vdev, int n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n); -- 1.8.3.1