[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 21/27] vhost: Add vhost_virtqueue_memory_unmap
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH 21/27] vhost: Add vhost_virtqueue_memory_unmap |
Date: |
Fri, 20 Nov 2020 19:50:59 +0100 |
This is not a huge gain but helps in later changes.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 9a3c580dcf..eafbbaa751 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -812,6 +812,21 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev,
return 0;
}
+static void vhost_virtqueue_memory_unmap(struct vhost_dev *dev,
+ struct vhost_virtqueue *vq,
+ bool used_is_dirty)
+{
+ if (vq->used) {
+ vhost_memory_unmap(dev, vq->used, vq->used_size, used_is_dirty, 0);
+ }
+ if (vq->avail) {
+ vhost_memory_unmap(dev, vq->avail, vq->avail_size, 0, 0);
+ }
+ if (vq->desc) {
+ vhost_memory_unmap(dev, vq->desc, vq->desc_size, 0, 0);
+ }
+}
+
static int vhost_dev_set_features(struct vhost_dev *dev,
bool enable_log)
{
@@ -1301,21 +1316,21 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
vq->desc = vhost_memory_map(dev, a, &l, false);
if (!vq->desc || l != s) {
r = -ENOMEM;
- goto fail_alloc_desc;
+ goto fail_alloc;
}
vq->avail_size = s = l = virtio_queue_get_avail_size(vdev, idx);
vq->avail_phys = a = virtio_queue_get_avail_addr(vdev, idx);
vq->avail = vhost_memory_map(dev, a, &l, false);
if (!vq->avail || l != s) {
r = -ENOMEM;
- goto fail_alloc_avail;
+ goto fail_alloc;
}
vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx);
vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx);
vq->used = vhost_memory_map(dev, a, &l, true);
if (!vq->used || l != s) {
r = -ENOMEM;
- goto fail_alloc_used;
+ goto fail_alloc;
}
r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);
@@ -1358,15 +1373,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
fail_vector:
fail_kick:
fail_alloc:
- vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx),
- 0, 0);
-fail_alloc_used:
- vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, idx),
- 0, 0);
-fail_alloc_avail:
- vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
- 0, 0);
-fail_alloc_desc:
+ vhost_virtqueue_memory_unmap(dev, vq, false);
return r;
}
@@ -1408,12 +1415,7 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,
vhost_vq_index);
}
- vhost_memory_unmap(dev, vq->used, virtio_queue_get_used_size(vdev, idx),
- 1, virtio_queue_get_used_size(vdev, idx));
- vhost_memory_unmap(dev, vq->avail, virtio_queue_get_avail_size(vdev, idx),
- 0, virtio_queue_get_avail_size(vdev, idx));
- vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
- 0, virtio_queue_get_desc_size(vdev, idx));
+ vhost_virtqueue_memory_unmap(dev, vq, true);
}
static void vhost_eventfd_add(MemoryListener *listener,
--
2.18.4
- [RFC PATCH 11/27] virtio: const-ify all virtio_tswap* functions, (continued)
- [RFC PATCH 11/27] virtio: const-ify all virtio_tswap* functions, Eugenio Pérez, 2020/11/20
- [RFC PATCH 12/27] virtio: Add virtio_queue_full, Eugenio Pérez, 2020/11/20
- [RFC PATCH 13/27] vhost: Send buffers to device, Eugenio Pérez, 2020/11/20
- [RFC PATCH 14/27] virtio: Remove virtio_queue_get_used_notify_split, Eugenio Pérez, 2020/11/20
- [RFC PATCH 15/27] vhost: Do not invalidate signalled used, Eugenio Pérez, 2020/11/20
- [RFC PATCH 16/27] virtio: Expose virtqueue_alloc_element, Eugenio Pérez, 2020/11/20
- [RFC PATCH 17/27] vhost: add vhost_vring_set_notification_rcu, Eugenio Pérez, 2020/11/20
- [RFC PATCH 18/27] vhost: add vhost_vring_poll_rcu, Eugenio Pérez, 2020/11/20
- [RFC PATCH 19/27] vhost: add vhost_vring_get_buf_rcu, Eugenio Pérez, 2020/11/20
- [RFC PATCH 20/27] vhost: Return used buffers, Eugenio Pérez, 2020/11/20
- [RFC PATCH 21/27] vhost: Add vhost_virtqueue_memory_unmap,
Eugenio Pérez <=
- [RFC PATCH 22/27] vhost: Add vhost_virtqueue_memory_map, Eugenio Pérez, 2020/11/20
- [RFC PATCH 23/27] vhost: unmap qemu's shadow virtqueues on sw live migration, Eugenio Pérez, 2020/11/20
- [RFC PATCH 24/27] vhost: iommu changes, Eugenio Pérez, 2020/11/20
- [RFC PATCH 25/27] vhost: Do not commit vhost used idx on vhost_virtqueue_stop, Eugenio Pérez, 2020/11/20
- [RFC PATCH 26/27] vhost: Add vhost_hdev_can_sw_lm, Eugenio Pérez, 2020/11/20
- [RFC PATCH 27/27] vhost: forbid vhost devices logging, Eugenio Pérez, 2020/11/20
- Re: [RFC PATCH 00/27] vDPA software assisted live migration, Eugenio Perez Martin, 2020/11/20