thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
586cba
From a26eb02b3a49c5d1163685ba5b83b67138c09047 Mon Sep 17 00:00:00 2001
586cba
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
586cba
Date: Thu, 21 Jul 2022 15:38:55 +0200
586cba
Subject: [PATCH 17/32] vhost: add vhost_svq_push_elem
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: 108: Net Control Virtqueue shadow Support
586cba
RH-Commit: [17/27] d064b40a262f2dfdc9f648d250aa8c8020c40385 (eperezmartin/qemu-kvm)
586cba
RH-Bugzilla: 1939363
586cba
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
586cba
RH-Acked-by: Cindy Lu <lulu@redhat.com>
586cba
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
586cba
586cba
Bugzilla: https://bugzilla.redhat.com/1939363
586cba
586cba
Upstream Status: git://git.qemu.org/qemu.git
586cba
586cba
commit 432efd144e990b6e040862de25f8f0b6a6eeb03d
586cba
Author: Eugenio Pérez <eperezma@redhat.com>
586cba
Date:   Wed Jul 20 08:59:36 2022 +0200
586cba
586cba
    vhost: add vhost_svq_push_elem
586cba
586cba
    This function allows external SVQ users to return guest's available
586cba
    buffers.
586cba
586cba
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
586cba
    Signed-off-by: Jason Wang <jasowang@redhat.com>
586cba
586cba
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
586cba
---
586cba
 hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++++++++++
586cba
 hw/virtio/vhost-shadow-virtqueue.h |  3 +++
586cba
 2 files changed, 19 insertions(+)
586cba
586cba
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
586cba
index 4d99075e73..1ce52d5b4a 100644
586cba
--- a/hw/virtio/vhost-shadow-virtqueue.c
586cba
+++ b/hw/virtio/vhost-shadow-virtqueue.c
586cba
@@ -428,6 +428,22 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
586cba
     return g_steal_pointer(&svq->desc_state[used_elem.id].elem);
586cba
 }
586cba
 
586cba
+/**
586cba
+ * Push an element to SVQ, returning it to the guest.
586cba
+ */
586cba
+void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
586cba
+                         const VirtQueueElement *elem, uint32_t len)
586cba
+{
586cba
+    virtqueue_push(svq->vq, elem, len);
586cba
+    if (svq->next_guest_avail_elem) {
586cba
+        /*
586cba
+         * Avail ring was full when vhost_svq_flush was called, so it's a
586cba
+         * good moment to make more descriptors available if possible.
586cba
+         */
586cba
+        vhost_handle_guest_kick(svq);
586cba
+    }
586cba
+}
586cba
+
586cba
 static void vhost_svq_flush(VhostShadowVirtqueue *svq,
586cba
                             bool check_for_avail_queue)
586cba
 {
586cba
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
586cba
index 5c7e7cbab6..d9fc1f1799 100644
586cba
--- a/hw/virtio/vhost-shadow-virtqueue.h
586cba
+++ b/hw/virtio/vhost-shadow-virtqueue.h
586cba
@@ -84,6 +84,9 @@ typedef struct VhostShadowVirtqueue {
586cba
 
586cba
 bool vhost_svq_valid_features(uint64_t features, Error **errp);
586cba
 
586cba
+void vhost_svq_push_elem(VhostShadowVirtqueue *svq,
586cba
+                         const VirtQueueElement *elem, uint32_t len);
586cba
+
586cba
 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
586cba
 void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
586cba
 void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq,
586cba
-- 
586cba
2.31.1
586cba