Blame SOURCES/kvm-vhost-use-SVQ-element-ndescs-instead-of-opaque-data-.patch

586cba
From 78b7d9af26ae802b3ca0d7b794b366ab4d515647 Mon Sep 17 00:00:00 2001
586cba
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
586cba
Date: Tue, 23 Aug 2022 20:30:27 +0200
586cba
Subject: [PATCH 12/23] vhost: use SVQ element ndescs instead of opaque data
586cba
 for desc validation
586cba
MIME-Version: 1.0
586cba
Content-Type: text/plain; charset=UTF-8
586cba
Content-Transfer-Encoding: 8bit
586cba
586cba
RH-Author: Eugenio Pérez <eperezma@redhat.com>
586cba
RH-MergeRequest: 116: vdpa: Restore device state on destination
586cba
RH-Bugzilla: 2114060
586cba
RH-Acked-by: Cindy Lu <lulu@redhat.com>
586cba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
586cba
RH-Commit: [11/21] 536ba65ff7241c4dc66362294ba8de4354260d6f (eperezmartin/qemu-kvm)
586cba
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2114060
586cba
Upstream status: git@github.com:jasowang/qemu.git net-next
586cba
586cba
Since we're going to allow SVQ to add elements without the guest's
586cba
knowledge and without its own VirtQueueElement, it's easier to check if
586cba
an element is a valid head checking a different thing than the
586cba
VirtQueueElement.
586cba
586cba
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
Acked-by: Jason Wang <jasowang@redhat.com>
586cba
Signed-off-by: Jason Wang <jasowang@redhat.com>
586cba
(cherry picked from commit 70e0841722deb363b53cdcd465af12a0d1461b60)
586cba
---
586cba
 hw/virtio/vhost-shadow-virtqueue.c | 3 ++-
586cba
 1 file changed, 2 insertions(+), 1 deletion(-)
586cba
586cba
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
586cba
index 2ae47d90a1..7792f3db1d 100644
586cba
--- a/hw/virtio/vhost-shadow-virtqueue.c
586cba
+++ b/hw/virtio/vhost-shadow-virtqueue.c
586cba
@@ -414,7 +414,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
586cba
         return NULL;
586cba
     }
586cba
 
586cba
-    if (unlikely(!svq->desc_state[used_elem.id].elem)) {
586cba
+    if (unlikely(!svq->desc_state[used_elem.id].ndescs)) {
586cba
         qemu_log_mask(LOG_GUEST_ERROR,
586cba
             "Device %s says index %u is used, but it was not available",
586cba
             svq->vdev->name, used_elem.id);
586cba
@@ -422,6 +422,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
586cba
     }
586cba
 
586cba
     num = svq->desc_state[used_elem.id].ndescs;
586cba
+    svq->desc_state[used_elem.id].ndescs = 0;
586cba
     last_used_chain = vhost_svq_last_desc_of_chain(svq, num, used_elem.id);
586cba
     svq->desc_next[last_used_chain] = svq->free_head;
586cba
     svq->free_head = used_elem.id;
586cba
-- 
586cba
2.31.1
586cba