>From 3177c5194c729f3056b84c67664c59b9b949bb76 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Mon, 24 Feb 2020 17:24:14 +0800 Subject: [PATCH] vhost: do not set VIRTIO_F_IOMMU_PLATFORM when IOMMU is not used We enable device IOTLB unconditionally when VIRTIO_F_IOMMU_PLATFORM is negotiated. This lead unnecessary IOTLB miss/update transactions when IOMMU is used. This patch fixes this. Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 3 +++ hw/virtio/vhost.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3627bb1717..0d50e8bd34 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -879,6 +879,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) virtio_net_apply_guest_offloads(n); } + if (vdev->dma_as == &address_space_memory) + features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM); + for (i = 0; i < n->max_queues; i++) { NetClientState *nc = qemu_get_subqueue(n->nic, i); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9edfadc81d..711b1136f6 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -288,9 +288,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size) static int vhost_dev_has_iommu(struct vhost_dev *dev) { - VirtIODevice *vdev = dev->vdev; - - return virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); + return virtio_has_feature(dev->acked_features, VIRTIO_F_IOMMU_PLATFORM); } static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr, -- 2.19.1