Blame SOURCES/kvm-vhost-correctly-turn-on-VIRTIO_F_IOMMU_PLATFORM.patch

902636
From e06655cfe0fa9473b1e8b311571f36d787472834 Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 29 May 2020 05:54:02 -0400
902636
Subject: [PATCH 20/42] vhost: correctly turn on VIRTIO_F_IOMMU_PLATFORM
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200529055420.16855-21-thuth@redhat.com>
902636
Patchwork-id: 97041
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 20/38] vhost: correctly turn on VIRTIO_F_IOMMU_PLATFORM
902636
Bugzilla: 1828317
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Jason Wang <jasowang@redhat.com>
902636
902636
We turn on device IOTLB via VIRTIO_F_IOMMU_PLATFORM unconditionally on
902636
platform without IOMMU support. This can lead unnecessary IOTLB
902636
transactions which will damage the performance.
902636
902636
Fixing this by check whether the device is backed by IOMMU and disable
902636
device IOTLB.
902636
902636
Reported-by: Halil Pasic <pasic@linux.ibm.com>
902636
Tested-by: Halil Pasic <pasic@linux.ibm.com>
902636
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
902636
Signed-off-by: Jason Wang <jasowang@redhat.com>
902636
Message-Id: <20200302042454.24814-1-jasowang@redhat.com>
902636
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
902636
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
902636
(cherry picked from commit f7ef7e6e3ba6e994e070cc609eb154339d1c4a11)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 hw/virtio/vhost.c | 12 +++++++++++-
902636
 1 file changed, 11 insertions(+), 1 deletion(-)
902636
902636
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
902636
index 9edfadc81d..9182a00495 100644
902636
--- a/hw/virtio/vhost.c
902636
+++ b/hw/virtio/vhost.c
902636
@@ -290,7 +290,14 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)
902636
 {
902636
     VirtIODevice *vdev = dev->vdev;
902636
 
902636
-    return virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
902636
+    /*
902636
+     * For vhost, VIRTIO_F_IOMMU_PLATFORM means the backend support
902636
+     * incremental memory mapping API via IOTLB API. For platform that
902636
+     * does not have IOMMU, there's no need to enable this feature
902636
+     * which may cause unnecessary IOTLB miss/update trnasactions.
902636
+     */
902636
+    return vdev->dma_as != &address_space_memory &&
902636
+           virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
902636
 }
902636
 
902636
 static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
902636
@@ -765,6 +772,9 @@ static int vhost_dev_set_features(struct vhost_dev *dev,
902636
     if (enable_log) {
902636
         features |= 0x1ULL << VHOST_F_LOG_ALL;
902636
     }
902636
+    if (!vhost_dev_has_iommu(dev)) {
902636
+        features &= ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM);
902636
+    }
902636
     r = dev->vhost_ops->vhost_set_features(dev, features);
902636
     if (r < 0) {
902636
         VHOST_OPS_DEBUG("vhost_set_features failed");
902636
-- 
902636
2.27.0
902636