Re: [PATCH RFC 08/15] hw/virtio/vhost-shadow-virtqueue: used handler

Stefan Hajnoczi <[email protected]>
Newsgroups gmane.comp.emulators.qemu,gmane.comp.emulators.qemu.block
Message-ID <20260728150631.GF371693@fedora>
On Thu, Jul 23, 2026 at 03:30:07PM -0700, 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);
> +            }
> +
>              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

The doc comment should mention what non-0 look like. Are errors reported
as a negative errno?

> + */
> +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 */
> 
> -- 
> 2.43.0
>
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmpoxXcACgkQnKSrs4Gr
c8gEPAgAnM6gyWjjb6vq24pJXR1H067s9W6tNHemw0rnqT+tOhL0zrKs5bwsa7QJ
C5GmytVPByQVkR5AAvGVNioKhkx366NbjkUFCb9T+lJUACWTWZHha/4fH+HuLaI/
+paYr3L5wQ2DWD5sTeHw9kUa5koz+zZEX3dBFh8rRGT8NuxsizK43ObYziMx4tlQ
maxC4ffSsCnQ1JtVlkfbD4OhgJFilrpwXoHCmWaR/MynF/QCVcN2rIQPmB9BEUZC
siRj6oL3FVHYBqy2yFWusYLvaUb0ksEjxZWr4hA4ZpJrzXlxF1JFPf9KChzI43B3
2s/BlDWvdUL7ZLNJfdHVgOqS3OiwTw==
=7ZzM
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.