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

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