Blame SOURCES/kvm-virtio-Add-queue-interface-to-restore-avail-index-fr.patch

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