If an application does not request IOMMU support, we can avoid allocating a IOMMU pool.
This saves 112kB (IOTLB_CACHE_SIZE * sizeof(struct vhost_iotlb_entry)) per vq. Signed-off-by: David Marchand <david.march...@redhat.com> --- lib/vhost/iotlb.c | 20 +++++++++++--------- lib/vhost/socket.c | 4 +++- lib/vhost/vhost.c | 7 ++++++- lib/vhost/vhost.h | 5 ++++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c index 2a78929e78..6a729e8804 100644 --- a/lib/vhost/iotlb.c +++ b/lib/vhost/iotlb.c @@ -341,16 +341,18 @@ vhost_user_iotlb_init(struct virtio_net *dev, struct vhost_virtqueue *vq) TAILQ_INIT(&vq->iotlb_list); TAILQ_INIT(&vq->iotlb_pending_list); - vq->iotlb_pool = rte_calloc_socket("iotlb", IOTLB_CACHE_SIZE, - sizeof(struct vhost_iotlb_entry), 0, socket); - if (!vq->iotlb_pool) { - VHOST_LOG_CONFIG(dev->ifname, ERR, - "Failed to create IOTLB cache pool for vq %"PRIu32"\n", - vq->index); - return -1; + if (dev->flags & VIRTIO_DEV_SUPPORT_IOMMU) { + vq->iotlb_pool = rte_calloc_socket("iotlb", IOTLB_CACHE_SIZE, + sizeof(struct vhost_iotlb_entry), 0, socket); + if (!vq->iotlb_pool) { + VHOST_LOG_CONFIG(dev->ifname, ERR, + "Failed to create IOTLB cache pool for vq %"PRIu32"\n", + vq->index); + return -1; + } + for (i = 0; i < IOTLB_CACHE_SIZE; i++) + vhost_user_iotlb_pool_put(vq, &vq->iotlb_pool[i]); } - for (i = 0; i < IOTLB_CACHE_SIZE; i++) - vhost_user_iotlb_pool_put(vq, &vq->iotlb_pool[i]); vq->iotlb_cache_nr = 0; diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index a8df2d484a..608ae577fd 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -228,7 +228,8 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) vhost_set_ifname(vid, vsocket->path, size); vhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net, - vsocket->net_compliant_ol_flags, vsocket->stats_enabled); + vsocket->net_compliant_ol_flags, vsocket->stats_enabled, + vsocket->iommu_support); vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); @@ -905,6 +906,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY; vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE; + vsocket->iommu_support = flags & RTE_VHOST_USER_IOMMU_SUPPORT; if (vsocket->async_copy && (flags & (RTE_VHOST_USER_IOMMU_SUPPORT | diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index aa671f47a3..9e5e69f72d 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -771,7 +771,8 @@ vhost_set_ifname(int vid, const char *if_name, unsigned int if_len) } void -vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats_enabled) +vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats_enabled, + bool support_iommu) { struct virtio_net *dev = get_device(vid); @@ -790,6 +791,10 @@ vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats dev->flags |= VIRTIO_DEV_STATS_ENABLED; else dev->flags &= ~VIRTIO_DEV_STATS_ENABLED; + if (support_iommu) + dev->flags |= VIRTIO_DEV_SUPPORT_IOMMU; + else + dev->flags &= ~VIRTIO_DEV_SUPPORT_IOMMU; } void diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 782d916ae0..3da6f217fd 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -37,6 +37,8 @@ #define VIRTIO_DEV_LEGACY_OL_FLAGS ((uint32_t)1 << 5) /* Used to indicate the application has requested statistics collection */ #define VIRTIO_DEV_STATS_ENABLED ((uint32_t)1 << 6) +/* Used to indicate the application has requested iommu support */ +#define VIRTIO_DEV_SUPPORT_IOMMU ((uint32_t)1 << 7) /* Backend value set by guest. */ #define VIRTIO_DEV_STOPPED -1 @@ -803,7 +805,8 @@ int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx); void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev); void vhost_set_ifname(int, const char *if_name, unsigned int if_len); -void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled); +void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled, + bool support_iommu); void vhost_enable_extbuf(int vid); void vhost_enable_linearbuf(int vid); int vhost_enable_guest_notification(struct virtio_net *dev, -- 2.37.3