716a394
From 2f134d800a7ac521a637a0da2116b2603b12c8c0 Mon Sep 17 00:00:00 2001
716a394
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
716a394
Date: Tue, 23 Aug 2022 20:30:29 +0200
716a394
Subject: [PATCH 14/23] vhost: Do not depend on !NULL VirtQueueElement on
716a394
 vhost_svq_flush
716a394
MIME-Version: 1.0
716a394
Content-Type: text/plain; charset=UTF-8
716a394
Content-Transfer-Encoding: 8bit
716a394
716a394
RH-Author: Eugenio Pérez <eperezma@redhat.com>
716a394
RH-MergeRequest: 116: vdpa: Restore device state on destination
716a394
RH-Bugzilla: 2114060
716a394
RH-Acked-by: Cindy Lu <lulu@redhat.com>
716a394
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
716a394
RH-Commit: [13/21] 93ec7baa2a29031db25d86b7dc1a949388623370 (eperezmartin/qemu-kvm)
716a394
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2114060
716a394
Upstream status: git@github.com:jasowang/qemu.git net-next
716a394
716a394
Since QEMU will be able to inject new elements on CVQ to restore the
716a394
state, we need not to depend on a VirtQueueElement to know if a new
716a394
element has been used by the device or not. Instead of check that, check
716a394
if there are new elements only using used idx on vhost_svq_flush.
716a394
716a394
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
716a394
Acked-by: Jason Wang <jasowang@redhat.com>
716a394
Signed-off-by: Jason Wang <jasowang@redhat.com>
716a394
(cherry picked from commit 7599f71c11c08b90f173c35ded1aaa1fdca86f1b)
716a394
---
716a394
 hw/virtio/vhost-shadow-virtqueue.c | 11 +++++++----
716a394
 1 file changed, 7 insertions(+), 4 deletions(-)
716a394
716a394
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
716a394
index d36afbc547..c0e3c92e96 100644
716a394
--- a/hw/virtio/vhost-shadow-virtqueue.c
716a394
+++ b/hw/virtio/vhost-shadow-virtqueue.c
716a394
@@ -499,17 +499,20 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
716a394
 size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
716a394
 {
716a394
     int64_t start_us = g_get_monotonic_time();
716a394
+    uint32_t len;
716a394
+
716a394
     do {
716a394
-        uint32_t len;
716a394
-        VirtQueueElement *elem = vhost_svq_get_buf(svq, &len;;
716a394
-        if (elem) {
716a394
-            return len;
716a394
+        if (vhost_svq_more_used(svq)) {
716a394
+            break;
716a394
         }
716a394
 
716a394
         if (unlikely(g_get_monotonic_time() - start_us > 10e6)) {
716a394
             return 0;
716a394
         }
716a394
     } while (true);
716a394
+
716a394
+    vhost_svq_get_buf(svq, &len;;
716a394
+    return len;
716a394
 }
716a394
 
716a394
 /**
716a394
-- 
716a394
2.31.1
716a394