[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 22/27] vhost: Add vhost_virtqueue_memory_map
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH 22/27] vhost: Add vhost_virtqueue_memory_map |
Date: |
Fri, 20 Nov 2020 19:51:00 +0100 |
To make it symmetric with _unmap.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost.c | 68 ++++++++++++++++++++++++++++++-----------------
1 file changed, 44 insertions(+), 24 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index eafbbaa751..f640d4edf0 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -827,6 +827,42 @@ static void vhost_virtqueue_memory_unmap(struct vhost_dev
*dev,
}
}
+static int vhost_virtqueue_memory_map(struct vhost_dev *dev,
+ struct vhost_virtqueue *vq,
+ unsigned int vhost_vq_index)
+{
+ int r;
+ hwaddr a, l, s;
+
+ a = vq->desc_phys;
+ s = l = vq->desc_size;
+ vq->desc = vhost_memory_map(dev, a, &l, false);
+ if (!vq->desc || l != s) {
+ return -ENOMEM;
+ }
+
+ a = vq->avail_phys;
+ s = l = vq->avail_size;
+ vq->avail = vhost_memory_map(dev, a, &l, false);
+ if (!vq->avail || l != s) {
+ return -ENOMEM;
+ }
+
+ a = vq->used_phys;
+ s = l = vq->used_size;
+ vq->used = vhost_memory_map(dev, a, &l, true);
+ if (!vq->used || l != s) {
+ return -ENOMEM;
+ }
+
+ r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);
+ if (r < 0) {
+ return -errno;
+ }
+
+ return 0;
+}
+
static int vhost_dev_set_features(struct vhost_dev *dev,
bool enable_log)
{
@@ -1271,7 +1307,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
- hwaddr s, l, a;
+ hwaddr a;
int r;
int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);
struct vhost_vring_file file = {
@@ -1311,31 +1347,15 @@ static int vhost_virtqueue_start(struct vhost_dev *dev,
}
}
- vq->desc_size = s = l = virtio_queue_get_desc_size(vdev, idx);
+ vq->desc_size = virtio_queue_get_desc_size(vdev, idx);
vq->desc_phys = a;
- vq->desc = vhost_memory_map(dev, a, &l, false);
- if (!vq->desc || l != s) {
- r = -ENOMEM;
- 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;
- }
- 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;
- }
+ vq->avail_size = virtio_queue_get_avail_size(vdev, idx);
+ vq->avail_phys = virtio_queue_get_avail_addr(vdev, idx);
+ vq->used_size = virtio_queue_get_used_size(vdev, idx);
+ vq->used_phys = virtio_queue_get_used_addr(vdev, idx);
- r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);
- if (r < 0) {
- r = -errno;
+ r = vhost_virtqueue_memory_map(dev, vq, vhost_vq_index);
+ if (r) {
goto fail_alloc;
}
--
2.18.4
- [RFC PATCH 12/27] virtio: Add virtio_queue_full, (continued)
- [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, 2020/11/20
- [RFC PATCH 22/27] vhost: Add vhost_virtqueue_memory_map,
Eugenio Pérez <=
- [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
- Re: [RFC PATCH 00/27] vDPA software assisted live migration, no-reply, 2020/11/20