From: Junjie Wan Date: Tue, 2 Feb 2021 08:38:45 +0000 (+0800) Subject: vhost: avoid IOTLB mempool allocation while IOMMU disabled X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=968bbc7e2e50ca9fd68285589af236734fd2f920;p=dpdk.git vhost: avoid IOTLB mempool allocation while IOMMU disabled If vhost device's IOMMU feature is disabled, IOTLB mempool allocation is unnecessary. Reported-by: Peng He Signed-off-by: Junjie Wan Reviewed-by: Zhihong Wang Reviewed-by: Chenbo Xia Reviewed-by: Maxime Coquelin --- diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index c9d1371e45..a70fe01d8f 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -365,7 +365,8 @@ free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq) vhost_free_async_mem(vq); } rte_free(vq->batch_copy_elems); - rte_mempool_free(vq->iotlb_pool); + if (vq->iotlb_pool) + rte_mempool_free(vq->iotlb_pool); rte_free(vq->log_cache); rte_free(vq); } @@ -569,8 +570,6 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD; vq->notif_enable = VIRTIO_UNINITIALIZED_NOTIF; - - vhost_user_iotlb_init(dev, vring_idx); } static void diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 2f4f89aeac..cdd46a0116 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -469,6 +469,10 @@ vhost_user_set_vring_num(struct virtio_net **pdev, return RTE_VHOST_MSG_RESULT_ERR; } + if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) { + if (vhost_user_iotlb_init(dev, msg->payload.state.index)) + return RTE_VHOST_MSG_RESULT_ERR; + } return RTE_VHOST_MSG_RESULT_OK; } @@ -574,7 +578,7 @@ out: dev->virtqueue[index] = vq; vhost_devices[dev->vid] = dev; - if (old_vq != vq) + if (old_vq != vq && (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) vhost_user_iotlb_init(dev, index); return dev;