cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
Pablo Greco e6a3ae
From c6874c974165bd783649ae9e0fb4390881c5e79c Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Date: Thu, 4 Jul 2019 10:32:06 +0200
Pablo Greco e6a3ae
Subject: [PATCH 3/4] virtio-gpu: add iommu support
Pablo Greco e6a3ae
MIME-Version: 1.0
Pablo Greco e6a3ae
Content-Type: text/plain; charset=UTF-8
Pablo Greco e6a3ae
Content-Transfer-Encoding: 8bit
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190704103207.29158-3-kraxel@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 89371
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 2/3] virtio-gpu: add iommu support
Pablo Greco e6a3ae
Bugzilla: 1531543
Pablo Greco e6a3ae
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Switch from cpu_physical_memory_map to dma_memory_map,
Pablo Greco e6a3ae
so iommu mappings for virtio-gpu objects work properly.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Message-Id: <20180829122101.29852-3-kraxel@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 8da132a56f7ebaabc5b674b5a3a2e6fa8934be45)
Pablo Greco e6a3ae
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 hw/display/virtio-gpu.c | 25 ++++++++++++++-----------
Pablo Greco e6a3ae
 1 file changed, 14 insertions(+), 11 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
Pablo Greco e6a3ae
index cb77ece..327c2be 100644
Pablo Greco e6a3ae
--- a/hw/display/virtio-gpu.c
Pablo Greco e6a3ae
+++ b/hw/display/virtio-gpu.c
Pablo Greco e6a3ae
@@ -16,6 +16,7 @@
Pablo Greco e6a3ae
 #include "qemu/iov.h"
Pablo Greco e6a3ae
 #include "ui/console.h"
Pablo Greco e6a3ae
 #include "trace.h"
Pablo Greco e6a3ae
+#include "sysemu/dma.h"
Pablo Greco e6a3ae
 #include "hw/virtio/virtio.h"
Pablo Greco e6a3ae
 #include "hw/virtio/virtio-gpu.h"
Pablo Greco e6a3ae
 #include "hw/virtio/virtio-bus.h"
Pablo Greco e6a3ae
@@ -725,7 +726,8 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
Pablo Greco e6a3ae
         uint32_t l = le32_to_cpu(ents[i].length);
Pablo Greco e6a3ae
         hwaddr len = l;
Pablo Greco e6a3ae
         (*iov)[i].iov_len = l;
Pablo Greco e6a3ae
-        (*iov)[i].iov_base = cpu_physical_memory_map(a, &len, 1);
Pablo Greco e6a3ae
+        (*iov)[i].iov_base = dma_memory_map(VIRTIO_DEVICE(g)->dma_as,
Pablo Greco e6a3ae
+                                            a, &len, DMA_DIRECTION_TO_DEVICE);
Pablo Greco e6a3ae
         if (addr) {
Pablo Greco e6a3ae
             (*addr)[i] = a;
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
@@ -753,8 +755,10 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
Pablo Greco e6a3ae
     int i;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     for (i = 0; i < count; i++) {
Pablo Greco e6a3ae
-        cpu_physical_memory_unmap(iov[i].iov_base, iov[i].iov_len, 1,
Pablo Greco e6a3ae
-                                  iov[i].iov_len);
Pablo Greco e6a3ae
+        dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
Pablo Greco e6a3ae
+                         iov[i].iov_base, iov[i].iov_len,
Pablo Greco e6a3ae
+                         DMA_DIRECTION_TO_DEVICE,
Pablo Greco e6a3ae
+                         iov[i].iov_len);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
     g_free(iov);
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
@@ -1146,13 +1150,17 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
Pablo Greco e6a3ae
         for (i = 0; i < res->iov_cnt; i++) {
Pablo Greco e6a3ae
             hwaddr len = res->iov[i].iov_len;
Pablo Greco e6a3ae
             res->iov[i].iov_base =
Pablo Greco e6a3ae
-                cpu_physical_memory_map(res->addrs[i], &len, 1);
Pablo Greco e6a3ae
+                dma_memory_map(VIRTIO_DEVICE(g)->dma_as,
Pablo Greco e6a3ae
+                               res->addrs[i], &len, DMA_DIRECTION_TO_DEVICE);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
             if (!res->iov[i].iov_base || len != res->iov[i].iov_len) {
Pablo Greco e6a3ae
                 /* Clean up the half-a-mapping we just created... */
Pablo Greco e6a3ae
                 if (res->iov[i].iov_base) {
Pablo Greco e6a3ae
-                    cpu_physical_memory_unmap(res->iov[i].iov_base,
Pablo Greco e6a3ae
-                                              len, 0, 0);
Pablo Greco e6a3ae
+                    dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
Pablo Greco e6a3ae
+                                     res->iov[i].iov_base,
Pablo Greco e6a3ae
+                                     res->iov[i].iov_len,
Pablo Greco e6a3ae
+                                     DMA_DIRECTION_TO_DEVICE,
Pablo Greco e6a3ae
+                                     res->iov[i].iov_len);
Pablo Greco e6a3ae
                 }
Pablo Greco e6a3ae
                 /* ...and the mappings for previous loop iterations */
Pablo Greco e6a3ae
                 res->iov_cnt = i;
Pablo Greco e6a3ae
@@ -1204,11 +1212,6 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
Pablo Greco e6a3ae
     Error *local_err = NULL;
Pablo Greco e6a3ae
     int i;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-    if (virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
Pablo Greco e6a3ae
-        error_setg(errp, "virtio-gpu does not support vIOMMU yet");
Pablo Greco e6a3ae
-        return;
Pablo Greco e6a3ae
-    }
Pablo Greco e6a3ae
-
Pablo Greco e6a3ae
     if (g->conf.max_outputs > VIRTIO_GPU_MAX_SCANOUTS) {
Pablo Greco e6a3ae
         error_setg(errp, "invalid max_outputs > %d", VIRTIO_GPU_MAX_SCANOUTS);
Pablo Greco e6a3ae
         return;
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae