[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v9 17/23] vhost: add detach SVQ operation
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v9 17/23] vhost: add detach SVQ operation |
Date: |
Wed, 6 Jul 2022 20:40:02 +0200 |
To notify the caller it needs to discard the element.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 11 +++++++++++
hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index 4300cb66f8..583b6fda5d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -46,10 +46,21 @@ typedef void (*VirtQueueUsedCallback)(VhostShadowVirtqueue
*svq,
void *used_elem_opaque,
uint32_t written);
+/**
+ * Detach the element from the shadow virtqueue. SVQ needs to free it and it
+ * cannot be pushed or discarded.
+ *
+ * @elem_opaque: The element opaque
+ *
+ * Return the guest element to detach and free if any.
+ */
+typedef VirtQueueElement *(*VirtQueueDetachCallback)(void *elem_opaque);
+
typedef struct VhostShadowVirtqueueOps {
ShadowVirtQueueStart start;
VirtQueueAvailCallback avail_handler;
VirtQueueUsedCallback used_handler;
+ VirtQueueDetachCallback detach_handler;
} VhostShadowVirtqueueOps;
/* Shadow virtqueue to relay notifications */
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index dffea256f1..4f072f040b 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -746,7 +746,16 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
for (unsigned i = 0; i < svq->vring.num; ++i) {
g_autofree VirtQueueElement *elem = NULL;
- elem = g_steal_pointer(&svq->ring_id_maps[i].opaque);
+ void *opaque = g_steal_pointer(&svq->ring_id_maps[i].opaque);
+
+ if (!opaque) {
+ continue;
+ } else if (svq->ops) {
+ elem = svq->ops->detach_handler(opaque);
+ } else {
+ elem = opaque;
+ }
+
if (elem) {
virtqueue_detach_element(svq->vq, elem, 0);
}
--
2.31.1
- [RFC PATCH v9 16/23] vhost: Add svq avail_handler callback, (continued)
- [RFC PATCH v9 10/23] vhost: Reorder vhost_svq_last_desc_of_chain, Eugenio Pérez, 2022/07/06
- [RFC PATCH v9 14/23] vhost: add vhost_svq_poll, Eugenio Pérez, 2022/07/06
- [RFC PATCH v9 15/23] vhost: Add custom used buffer callback, Eugenio Pérez, 2022/07/06
- [RFC PATCH v9 17/23] vhost: add detach SVQ operation,
Eugenio Pérez <=
- [RFC PATCH v9 18/23] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/06
- [RFC PATCH v9 19/23] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/06
- [RFC PATCH v9 21/23] vdpa: Add vhost_vdpa_start_control_svq, Eugenio Pérez, 2022/07/06
[RFC PATCH v9 22/23] vdpa: Inject virtio-net mac address via CVQ at start, Eugenio Pérez, 2022/07/06
[RFC PATCH v9 20/23] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/06