[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v9 15/23] vhost: Add custom used buffer callback
|
From: |
Eugenio Pérez |
|
Subject: |
[RFC PATCH v9 15/23] vhost: Add custom used buffer callback |
|
Date: |
Wed, 6 Jul 2022 20:40:00 +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.
If callbacks are specified at svq creation, the buffers need to be
injected to the device using vhost_svq_inject. An opaque data must be
given with it, and its returned to the callback at used_handler call.
In the case of networking, this will be used to inspect control
virtqueue messages and to recover status injection at the first time.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.h | 5 +++++
hw/virtio/vhost-shadow-virtqueue.c | 16 +++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/hw/virtio/vhost-shadow-virtqueue.h
b/hw/virtio/vhost-shadow-virtqueue.h
index c8668fbdd6..296fef6f21 100644
--- a/hw/virtio/vhost-shadow-virtqueue.h
+++ b/hw/virtio/vhost-shadow-virtqueue.h
@@ -27,8 +27,13 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue;
typedef int (*ShadowVirtQueueStart)(VhostShadowVirtqueue *svq,
void *opaque);
+typedef void (*VirtQueueUsedCallback)(VhostShadowVirtqueue *svq,
+ void *used_elem_opaque,
+ uint32_t written);
+
typedef struct VhostShadowVirtqueueOps {
ShadowVirtQueueStart start;
+ VirtQueueUsedCallback used_handler;
} VhostShadowVirtqueueOps;
/* Shadow virtqueue to relay notifications */
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index ed7f1d0bc9..b92ca4a63f 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -506,7 +506,6 @@ static size_t vhost_svq_flush(VhostShadowVirtqueue *svq,
while (true) {
uint32_t len;
SVQElement svq_elem;
- g_autofree VirtQueueElement *elem = NULL;
if (unlikely(i >= svq->vring.num)) {
qemu_log_mask(LOG_GUEST_ERROR,
@@ -521,13 +520,20 @@ static size_t vhost_svq_flush(VhostShadowVirtqueue *svq,
break;
}
- elem = g_steal_pointer(&svq_elem.opaque);
- virtqueue_fill(vq, elem, len, i++);
+ if (svq->ops) {
+ svq->ops->used_handler(svq, svq_elem.opaque, len);
+ } else {
+ g_autofree VirtQueueElement *elem = NULL;
+ elem = g_steal_pointer(&svq_elem.opaque);
+ virtqueue_fill(vq, elem, len, i++);
+ }
ret++;
}
- virtqueue_flush(vq, i);
- event_notifier_set(&svq->svq_call);
+ if (i > 0) {
+ virtqueue_flush(vq, i);
+ event_notifier_set(&svq->svq_call);
+ }
if (check_for_avail_queue && svq->next_guest_avail_elem) {
/*
--
2.31.1
- Re: [RFC PATCH v9 12/23] vhost: Add opaque member to SVQElement, (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 <=
- [RFC PATCH v9 17/23] vhost: add detach SVQ operation, Eugenio Pérez, 2022/07/06
- [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