On 2026/07/24 7:30, Connor Kite wrote:
Adds a handler callback to shadow virtqueues in order to enable
non-default processing of used vring elements from the device.

Signed-off-by: Connor Kite <[email protected]>
---
  hw/virtio/vhost-shadow-virtqueue.c |  4 ++++
  hw/virtio/vhost-shadow-virtqueue.h | 14 ++++++++++++++
  2 files changed, 18 insertions(+)

diff --git a/hw/virtio/vhost-shadow-virtqueue.c 
b/hw/virtio/vhost-shadow-virtqueue.c
index bcb7f2ffc7..eb86c1ee37 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -669,6 +669,10 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
                  break;
              }
+ if (svq->ops && svq->ops->used_handler) {
+                svq->ops->used_handler(svq, elem, svq->ops_opaque);

The error of the handler that may have left elem stale is ignored here.

Regards,
Akihiko Odaki

+            }
+
              if (unlikely(i >= svq->vring.num)) {
                  qemu_log_mask(LOG_GUEST_ERROR,
                           "More than %u used buffers obtained in a %u size 
SVQ",
diff --git a/hw/virtio/vhost-shadow-virtqueue.h 
b/hw/virtio/vhost-shadow-virtqueue.h
index ec16a1e838..ccfeee36d7 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -56,8 +56,22 @@ typedef int (*VirtQueueAvailCallback)(VhostShadowVirtqueue 
*svq,
                                        VirtQueueElement *elem,
                                        void *vq_callback_opaque);
+/**
+ * Callback to handle a used buffer
+ *
+ * @svq: Shadow virtqueue
+ * @elem: Element placed in the queue by the device
+ * @vq_callback_opaque: Used to pass arguments to callback
+ *
+ * Returns 0 if the vq is running as expected
+ */
+typedef int (*VirtQueueUsedCallback)(VhostShadowVirtqueue *svq,
+                                      VirtQueueElement *elem,
+                                      void *vq_callback_opaque);
+
  typedef struct VhostShadowVirtqueueOps {
      VirtQueueAvailCallback avail_handler;
+    VirtQueueUsedCallback used_handler;
  } VhostShadowVirtqueueOps;
/* Shadow virtqueue to relay notifications */



Reply via email to