29b115
From 24b8cf88f53f9fc7cb393c9cad908f759980bfee Mon Sep 17 00:00:00 2001
29b115
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
29b115
Date: Thu, 21 Jul 2022 15:38:55 +0200
29b115
Subject: [PATCH 16/32] vhost: Track number of descs in SVQDescState
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eugenio Pérez <eperezma@redhat.com>
29b115
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
29b115
RH-Commit: [16/27] 26f30cb6dd35c1eb1ddabe25113431bed3d744aa (eperezmartin/qemu-kvm)
29b115
RH-Bugzilla: 1939363
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
RH-Acked-by: Cindy Lu <lulu@redhat.com>
29b115
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/1939363
29b115
29b115
Upstream Status: git://git.qemu.org/qemu.git
29b115
29b115
commit ac4cfdc6f39c06732d27554523f9d5f8a53b4ffa
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:35 2022 +0200
29b115
29b115
    vhost: Track number of descs in SVQDescState
29b115
29b115
    A guest's buffer continuos on GPA may need multiple descriptors on
29b115
    qemu's VA, so SVQ should track its length sepparatedly.
29b115
29b115
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
29b115
    Signed-off-by: Jason Wang <jasowang@redhat.com>
29b115
29b115
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
---
29b115
 hw/virtio/vhost-shadow-virtqueue.c | 4 ++--
29b115
 hw/virtio/vhost-shadow-virtqueue.h | 6 ++++++
29b115
 2 files changed, 8 insertions(+), 2 deletions(-)
29b115
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
29b115
index a08e3d4025..4d99075e73 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.c
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.c
29b115
@@ -257,6 +257,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
29b115
     }
29b115
 
29b115
     svq->desc_state[qemu_head].elem = elem;
29b115
+    svq->desc_state[qemu_head].ndescs = ndescs;
29b115
     vhost_svq_kick(svq);
29b115
     return 0;
29b115
 }
29b115
@@ -418,8 +419,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
29b115
         return NULL;
29b115
     }
29b115
 
29b115
-    num = svq->desc_state[used_elem.id].elem->in_num +
29b115
-          svq->desc_state[used_elem.id].elem->out_num;
29b115
+    num = svq->desc_state[used_elem.id].ndescs;
29b115
     last_used_chain = vhost_svq_last_desc_of_chain(svq, num, used_elem.id);
29b115
     svq->desc_next[last_used_chain] = svq->free_head;
29b115
     svq->free_head = used_elem.id;
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
29b115
index d646c35054..5c7e7cbab6 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.h
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.h
29b115
@@ -17,6 +17,12 @@
29b115
 
29b115
 typedef struct SVQDescState {
29b115
     VirtQueueElement *elem;
29b115
+
29b115
+    /*
29b115
+     * Number of descriptors exposed to the device. May or may not match
29b115
+     * guest's
29b115
+     */
29b115
+    unsigned int ndescs;
29b115
 } SVQDescState;
29b115
 
29b115
 /* Shadow virtqueue to relay notifications */
29b115
-- 
29b115
2.31.1
29b115