yeahuh / rpms / qemu-kvm

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