[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 16/22] vhost: add detach SVQ operation
From: |
Eugenio Pérez |
Subject: |
[PATCH 16/22] vhost: add detach SVQ operation |
Date: |
Fri, 8 Jul 2022 12:50:07 +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 cfc891e2e8..dc0059adc6 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -44,9 +44,20 @@ 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 {
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 78579b9e0b..626691ac4e 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -749,7 +749,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
- [PATCH 04/22] virtio-net: Expose ctrl virtqueue logic, (continued)
- [PATCH 04/22] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/08
- [PATCH 06/22] vhost: Reorder vhost_svq_last_desc_of_chain, Eugenio Pérez, 2022/07/08
- [PATCH 05/22] vhost: Decouple vhost_svq_add_split from VirtQueueElement, Eugenio Pérez, 2022/07/08
- [PATCH 07/22] vhost: Add SVQElement, Eugenio Pérez, 2022/07/08
- [PATCH 08/22] vhost: Move last chain id to SVQ element, Eugenio Pérez, 2022/07/08
- [PATCH 11/22] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/08
- [PATCH 10/22] vdpa: Small rename of error labels, Eugenio Pérez, 2022/07/08
- [PATCH 09/22] vhost: Add opaque member to SVQElement, Eugenio Pérez, 2022/07/08
- [PATCH 12/22] vhost: Add vhost_svq_inject, Eugenio Pérez, 2022/07/08
- [PATCH 13/22] vhost: add vhost_svq_poll, Eugenio Pérez, 2022/07/08
- [PATCH 16/22] vhost: add detach SVQ operation,
Eugenio Pérez <=
- [PATCH 18/22] vdpa: manual forward CVQ buffers, Eugenio Pérez, 2022/07/08
- [PATCH 15/22] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/08
- [PATCH 17/22] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/08
- [PATCH 19/22] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/08
- [PATCH 20/22] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/08
- [PATCH 14/22] vhost: Add custom used buffer callback, Eugenio Pérez, 2022/07/08
- [PATCH 21/22] vdpa: Add device migration blocker, Eugenio Pérez, 2022/07/08
- [PATCH 22/22] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/07/08