[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v6 13/23] vhost: Add custom used buffer callback
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v6 13/23] vhost: Add custom used buffer callback |
Date: |
Mon, 11 Apr 2022 16:50:16 +0200 |
The callback allows SVQ users to know the VirtQueue requests and
responses. QEMU can use this to synchronize virtio device model state,
allowing to migrate it with minimum changes to the migration code.
In the case of networking, this will be used to inspect control
virtqueue messages.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 16 +++++++++++++++-
include/hw/virtio/vhost-vdpa.h | 2 ++
hw/virtio/vhost-shadow-virtqueue.c | 9 ++++++++-
hw/virtio/vhost-vdpa.c | 3 ++-
4 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index 72aadb0aec..4ff6a0cda0 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -19,6 +19,13 @@ typedef struct SVQElement {
VirtQueueElement elem;
} SVQElement;
+typedef void (*VirtQueueElementCallback)(VirtIODevice *vdev,
+ const VirtQueueElement *elem);
+
+typedef struct VhostShadowVirtqueueOps {
+ VirtQueueElementCallback used_elem_handler;
+} VhostShadowVirtqueueOps;
+
/* Shadow virtqueue to relay notifications */
typedef struct VhostShadowVirtqueue {
/* Shadow vring */
@@ -57,6 +64,12 @@ typedef struct VhostShadowVirtqueue {
/* Next VirtQueue element that guest made available */
SVQElement *next_guest_avail_elem;
+ /* Optional callbacks */
+ const VhostShadowVirtqueueOps *ops;
+
+ /* Optional custom used virtqueue element handler */
+ VirtQueueElementCallback used_elem_cb;
+
/* Next head to expose to the device */
uint16_t shadow_avail_idx;
@@ -83,7 +96,8 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice
*vdev,
VirtQueue *vq);
void vhost_svq_stop(VhostShadowVirtqueue *svq);
-VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree);
+VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
+ const VhostShadowVirtqueueOps *ops);
void vhost_svq_free(gpointer vq);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free);
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index a29dbb3f53..f1ba46a860 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -17,6 +17,7 @@
#include "hw/virtio/vhost-iova-tree.h"
#include "hw/virtio/virtio.h"
#include "standard-headers/linux/vhost_types.h"
+#include "hw/virtio/vhost-shadow-virtqueue.h"
typedef struct VhostVDPAHostNotifier {
MemoryRegion mr;
@@ -35,6 +36,7 @@ typedef struct vhost_vdpa {
/* IOVA mapping used by the Shadow Virtqueue */
VhostIOVATree *iova_tree;
GPtrArray *shadow_vqs;
+ const VhostShadowVirtqueueOps *shadow_vq_ops;
struct vhost_dev *dev;
VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
} VhostVDPA;
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index cf701576d1..208832a698 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -419,6 +419,10 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
return;
}
virtqueue_fill(vq, elem, len, i++);
+
+ if (svq->ops && svq->ops->used_elem_handler) {
+ svq->ops->used_elem_handler(svq->vdev, elem);
+ }
}
virtqueue_flush(vq, i);
@@ -605,12 +609,14 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
* shadow methods and file descriptors.
*
* @iova_tree: Tree to perform descriptors translations
+ * @ops: SVQ operations hooks
*
* Returns the new virtqueue or NULL.
*
* In case of error, reason is reported through error_report.
*/
-VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree)
+VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
+ const VhostShadowVirtqueueOps *ops)
{
g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
int r;
@@ -632,6 +638,7 @@ VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree
*iova_tree)
event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND);
event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call);
svq->iova_tree = iova_tree;
+ svq->ops = ops;
return g_steal_pointer(&svq);
err_init_hdev_call:
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 3f8fa66e8e..421eddf8ca 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -411,7 +411,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev,
struct vhost_vdpa *v,
shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free);
for (unsigned n = 0; n < hdev->nvqs; ++n) {
- g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree);
+ g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new(v->iova_tree,
+ v->shadow_vq_ops);
if (unlikely(!svq)) {
error_setg(errp, "Cannot create svq %u", n);
--
2.27.0
- [RFC PATCH v6 01/23] vdpa: Add missing tracing to batch mapping functions, (continued)
- [RFC PATCH v6 01/23] vdpa: Add missing tracing to batch mapping functions, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 03/23] util: Return void on iova_tree_remove, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 05/23] vhost: Fix bad return of descriptors to SVQ, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 04/23] hw/virtio: Replace g_memdup() by g_memdup2(), Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 02/23] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 06/23] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 07/23] vhost: move descriptor translation to vhost_svq_vring_write_descs, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 09/23] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 11/23] virtio: Make virtqueue_alloc_element non-static, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 10/23] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 13/23] vhost: Add custom used buffer callback,
Eugenio Pérez <=
- [RFC PATCH v6 08/23] vdpa: Fix index calculus at vhost_vdpa_svqs_start, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 14/23] vdpa: control virtqueue support on shadow virtqueue, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 15/23] vhost: Add vhost_iova_tree_find, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 18/23] vdpa: add NetClientState->start() callback, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 12/23] vhost: Add SVQElement, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 21/23] vhost: Make possible to check for device exclusive vq group, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 19/23] vdpa: Add vhost_vdpa_start_control_svq, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 16/23] vdpa: Add map/unmap operation callback to SVQ, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 23/23] vdpa: Add x-cvq-svq, Eugenio Pérez, 2022/04/11
- [RFC PATCH v6 17/23] vhost: Add vhost_svq_inject, Eugenio Pérez, 2022/04/11