29b115
From a26eb02b3a49c5d1163685ba5b83b67138c09047 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 17/32] vhost: add vhost_svq_push_elem
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: [17/27] d064b40a262f2dfdc9f648d250aa8c8020c40385 (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 432efd144e990b6e040862de25f8f0b6a6eeb03d
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:36 2022 +0200
29b115
29b115
    vhost: add vhost_svq_push_elem
29b115
29b115
    This function allows external SVQ users to return guest's available
29b115
    buffers.
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 | 16 ++++++++++++++++
29b115
 hw/virtio/vhost-shadow-virtqueue.h |  3 +++
29b115
 2 files changed, 19 insertions(+)
29b115
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
29b115
index 4d99075e73..1ce52d5b4a 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.c
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.c
29b115
@@ -428,6 +428,22 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
29b115
     return g_steal_pointer(&svq->desc_state[used_elem.id].elem);
29b115
 }
29b115
 
29b115
+/**
29b115
+ * Push an element to SVQ, returning it to the guest.
29b115
+ */
29b115
+void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
29b115
+                         const VirtQueueElement *elem, uint32_t len)
29b115
+{
29b115
+    virtqueue_push(svq->vq, elem, len);
29b115
+    if (svq->next_guest_avail_elem) {
29b115
+        /*
29b115
+         * Avail ring was full when vhost_svq_flush was called, so it's a
29b115
+         * good moment to make more descriptors available if possible.
29b115
+         */
29b115
+        vhost_handle_guest_kick(svq);
29b115
+    }
29b115
+}
29b115
+
29b115
 static void vhost_svq_flush(VhostShadowVirtqueue *svq,
29b115
                             bool check_for_avail_queue)
29b115
 {
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
29b115
index 5c7e7cbab6..d9fc1f1799 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.h
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.h
29b115
@@ -84,6 +84,9 @@ typedef struct VhostShadowVirtqueue {
29b115
 
29b115
 bool vhost_svq_valid_features(uint64_t features, Error **errp);
29b115
 
29b115
+void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
29b115
+                         const VirtQueueElement *elem, uint32_t len);
29b115
+
29b115
 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
29b115
 void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
29b115
 void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq,
29b115
-- 
29b115
2.31.1
29b115