[RFC 07/27] vhost: change to single IOTLB cache per device
Xia, Chenbo
chenbo.xia at intel.com
Tue Apr 25 08:19:53 CEST 2023
Hi Maxime,
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin at redhat.com>
> Sent: Friday, March 31, 2023 11:43 PM
> To: dev at dpdk.org; david.marchand at redhat.com; Xia, Chenbo
> <chenbo.xia at intel.com>; mkp at redhat.com; fbl at redhat.com;
> jasowang at redhat.com; Liang, Cunming <cunming.liang at intel.com>; Xie, Yongji
> <xieyongji at bytedance.com>; echaudro at redhat.com; eperezma at redhat.com;
> amorenoz at redhat.com
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Subject: [RFC 07/27] vhost: change to single IOTLB cache per device
>
> This patch simplifies IOTLB implementation and improves
> IOTLB memory consumption by having a single IOTLB cache
> per device, instead of having one per queue.
>
> In order to not impact performance, it keeps an IOTLB lock
> per virtqueue, so that there is no contention between
> multiple queue trying to acquire it.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
> lib/vhost/iotlb.c | 212 +++++++++++++++++++----------------------
> lib/vhost/iotlb.h | 43 ++++++---
> lib/vhost/vhost.c | 18 ++--
> lib/vhost/vhost.h | 16 ++--
> lib/vhost/vhost_user.c | 25 +++--
> 5 files changed, 160 insertions(+), 154 deletions(-)
>
[...]
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index d60e39b6bc..81ebef0137 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -7,7 +7,7 @@
> * The vhost-user protocol connection is an external interface, so it
> must be
> * robust against invalid inputs.
> *
> - * This is important because the vhost-user frontend is only one step
> removed
> +* This is important because the vhost-user frontend is only one step
> removed
This is changed by accident?
Thanks,
Chenbo
> * from the guest. Malicious guests that have escaped will then launch
> further
> * attacks from the vhost-user frontend.
> *
> @@ -237,6 +237,8 @@ vhost_backend_cleanup(struct virtio_net *dev)
> }
>
> dev->postcopy_listening = 0;
> +
> + vhost_user_iotlb_destroy(dev);
> }
>
> static void
> @@ -539,7 +541,6 @@ numa_realloc(struct virtio_net **pdev, struct
> vhost_virtqueue **pvq)
> if (vq != dev->virtqueue[vq->index]) {
> VHOST_LOG_CONFIG(dev->ifname, INFO, "reallocated virtqueue on
> node %d\n", node);
> dev->virtqueue[vq->index] = vq;
> - vhost_user_iotlb_init(dev, vq);
> }
>
> if (vq_is_packed(dev)) {
> @@ -664,6 +665,8 @@ numa_realloc(struct virtio_net **pdev, struct
> vhost_virtqueue **pvq)
> return;
> }
> dev->guest_pages = gp;
> +
> + vhost_user_iotlb_init(dev);
> }
> #else
> static void
> @@ -1360,8 +1363,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev,
>
> /* Flush IOTLB cache as previous HVAs are now invalid */
> if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))
> - for (i = 0; i < dev->nr_vring; i++)
> - vhost_user_iotlb_flush_all(dev, dev->virtqueue[i]);
> + vhost_user_iotlb_flush_all(dev);
>
> free_mem_region(dev);
> rte_free(dev->mem);
> @@ -2194,7 +2196,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
> ctx->msg.size = sizeof(ctx->msg.payload.state);
> ctx->fd_num = 0;
>
> - vhost_user_iotlb_flush_all(dev, vq);
> + vhost_user_iotlb_flush_all(dev);
>
> vring_invalidate(dev, vq);
>
> @@ -2639,15 +2641,14 @@ vhost_user_iotlb_msg(struct virtio_net **pdev,
> if (!vva)
> return RTE_VHOST_MSG_RESULT_ERR;
>
> + vhost_user_iotlb_cache_insert(dev, imsg->iova, vva, len, imsg-
> >perm);
> +
> for (i = 0; i < dev->nr_vring; i++) {
> struct vhost_virtqueue *vq = dev->virtqueue[i];
>
> if (!vq)
> continue;
>
> - vhost_user_iotlb_cache_insert(dev, vq, imsg->iova, vva,
> - len, imsg->perm);
> -
> if (is_vring_iotlb(dev, vq, imsg)) {
> rte_spinlock_lock(&vq->access_lock);
> translate_ring_addresses(&dev, &vq);
> @@ -2657,15 +2658,14 @@ vhost_user_iotlb_msg(struct virtio_net **pdev,
> }
> break;
> case VHOST_IOTLB_INVALIDATE:
> + vhost_user_iotlb_cache_remove(dev, imsg->iova, imsg->size);
> +
> for (i = 0; i < dev->nr_vring; i++) {
> struct vhost_virtqueue *vq = dev->virtqueue[i];
>
> if (!vq)
> continue;
>
> - vhost_user_iotlb_cache_remove(dev, vq, imsg->iova,
> - imsg->size);
> -
> if (is_vring_iotlb(dev, vq, imsg)) {
> rte_spinlock_lock(&vq->access_lock);
> vring_invalidate(dev, vq);
> @@ -2674,8 +2674,7 @@ vhost_user_iotlb_msg(struct virtio_net **pdev,
> }
> break;
> default:
> - VHOST_LOG_CONFIG(dev->ifname, ERR,
> - "invalid IOTLB message type (%d)\n",
> + VHOST_LOG_CONFIG(dev->ifname, ERR, "invalid IOTLB message type
> (%d)\n",
> imsg->type);
> return RTE_VHOST_MSG_RESULT_ERR;
> }
> --
> 2.39.2
More information about the dev
mailing list