@@ -19,6 +19,10 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue;
void vhost_shadow_vq_mask(VhostShadowVirtqueue *svq, EventNotifier *masked);
void vhost_shadow_vq_unmask(VhostShadowVirtqueue *svq);
+void vhost_shadow_vq_get_vring_addr(const VhostShadowVirtqueue *svq,
+ struct vhost_vring_addr *addr);
+size_t vhost_shadow_vq_driver_area_size(const VhostShadowVirtqueue *svq);
+size_t vhost_shadow_vq_device_area_size(const VhostShadowVirtqueue *svq);
bool vhost_shadow_vq_start(struct vhost_dev *dev,
unsigned idx,
@@ -17,6 +17,9 @@
/* Shadow virtqueue to relay notifications */
typedef struct VhostShadowVirtqueue {
+ /* Shadow vring */
+ struct vring vring;
+
/* Shadow kick notifier, sent to vhost */
EventNotifier kick_notifier;
/* Shadow call notifier, sent to vhost */
@@ -114,6 +117,35 @@ void vhost_shadow_vq_unmask(VhostShadowVirtqueue *svq)
svq->masked_notifier.n = NULL;
}
+/*
+ * Get the shadow vq vring address.
+ * @svq Shadow virtqueue
+ * @addr Destination to store address
+ */
+void vhost_shadow_vq_get_vring_addr(const VhostShadowVirtqueue *svq,
+ struct vhost_vring_addr *addr)
+{
+ addr->desc_user_addr = (uint64_t)svq->vring.desc;
+ addr->avail_user_addr = (uint64_t)svq->vring.avail;
+ addr->used_user_addr = (uint64_t)svq->vring.used;
+}
+
+size_t vhost_shadow_vq_driver_area_size(const VhostShadowVirtqueue *svq)
+{
+ uint16_t vq_idx = virtio_get_queue_index(svq->vq);
+ size_t desc_size = virtio_queue_get_desc_size(svq->vdev, vq_idx);
+ size_t avail_size = virtio_queue_get_avail_size(svq->vdev, vq_idx);
+
+ return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size);
+}
+
+size_t vhost_shadow_vq_device_area_size(const VhostShadowVirtqueue *svq)
+{
+ uint16_t vq_idx = virtio_get_queue_index(svq->vq);
+ size_t used_size = virtio_queue_get_used_size(svq->vdev, vq_idx);
+ return ROUND_UP(used_size, qemu_real_host_page_size);
+}
+
/*
* Restore the vhost guest to host notifier, i.e., disables svq effect.
*/
@@ -232,6 +264,10 @@ void vhost_shadow_vq_stop(struct vhost_dev *dev,
VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx)
{
int vq_idx = dev->vq_index + idx;
+ unsigned num = virtio_queue_get_num(dev->vdev, vq_idx);
+ size_t desc_size = virtio_queue_get_desc_size(dev->vdev, vq_idx);
+ size_t driver_size;
+ size_t device_size;
g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
int r;
@@ -251,6 +287,14 @@ VhostShadowVirtqueue *vhost_shadow_vq_new(struct vhost_dev *dev, int idx)
svq->vq = virtio_get_queue(dev->vdev, vq_idx);
svq->vdev = dev->vdev;
+ driver_size = vhost_shadow_vq_driver_area_size(svq);
+ device_size = vhost_shadow_vq_device_area_size(svq);
+ svq->vring.num = num;
+ svq->vring.desc = qemu_memalign(qemu_real_host_page_size, driver_size);
+ svq->vring.avail = (void *)((char *)svq->vring.desc + desc_size);
+ memset(svq->vring.desc, 0, driver_size);
+ svq->vring.used = qemu_memalign(qemu_real_host_page_size, device_size);
+ memset(svq->vring.used, 0, device_size);
event_notifier_set_handler(&svq->call_notifier,
vhost_shadow_vq_handle_call);
return g_steal_pointer(&svq);
@@ -270,5 +314,7 @@ void vhost_shadow_vq_free(VhostShadowVirtqueue *vq)
event_notifier_cleanup(&vq->kick_notifier);
event_notifier_set_handler(&vq->call_notifier, NULL);
event_notifier_cleanup(&vq->call_notifier);
+ qemu_vfree(vq->vring.desc);
+ qemu_vfree(vq->vring.used);
g_free(vq);
}
It reports the shadow virtqueue address from qemu virtual address space Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com> --- hw/virtio/vhost-shadow-virtqueue.h | 4 +++ hw/virtio/vhost-shadow-virtqueue.c | 46 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)