vhost: restore IOTLB mempool allocation
authorDavid Marchand <david.marchand@redhat.com>
Mon, 17 May 2021 08:59:51 +0000 (10:59 +0200)
committerChenbo Xia <chenbo.xia@intel.com>
Tue, 18 May 2021 07:54:44 +0000 (09:54 +0200)
IOTLB messages will be sent when some queues are not enabled. If we
initialize IOTLB in vhost_user_set_vring_num, it could happen that IOTLB
update comes when IOTLB pool of disabled queues are not initialized.

Fixes: 968bbc7e2e50 ("vhost: avoid IOTLB mempool allocation while IOMMU disabled")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
lib/vhost/vhost.c
lib/vhost/vhost_user.c

index 9cbcf65..c96f633 100644 (file)
@@ -365,8 +365,7 @@ free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq)
 
        vhost_free_async_mem(vq);
        rte_free(vq->batch_copy_elems);
-       if (vq->iotlb_pool)
-               rte_mempool_free(vq->iotlb_pool);
+       rte_mempool_free(vq->iotlb_pool);
        rte_free(vq->log_cache);
        rte_free(vq);
 }
@@ -570,6 +569,8 @@ 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
index 611ff20..8f0eba6 100644 (file)
@@ -469,10 +469,6 @@ 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;
 }
 
@@ -578,7 +574,7 @@ out:
        dev->virtqueue[index] = vq;
        vhost_devices[dev->vid] = dev;
 
-       if (old_vq != vq && (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))
+       if (old_vq != vq)
                vhost_user_iotlb_init(dev, index);
 
        return dev;