yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-intel_iommu-move-ce-fetching-out-when-sync-shadow.patch

ae23c9
From 4084168a694381238dadf1f5c0cc4af756ac883f Mon Sep 17 00:00:00 2001
ae23c9
From: Peter Xu <peterx@redhat.com>
ae23c9
Date: Thu, 8 Nov 2018 06:29:37 +0000
ae23c9
Subject: [PATCH 09/35] intel_iommu: move ce fetching out when sync shadow
ae23c9
ae23c9
RH-Author: Peter Xu <peterx@redhat.com>
ae23c9
Message-id: <20181108062938.21143-7-peterx@redhat.com>
ae23c9
Patchwork-id: 82965
ae23c9
O-Subject: [RHEL-8 qemu-kvm PATCH 6/7] intel_iommu: move ce fetching out when sync shadow
ae23c9
Bugzilla: 1625173
ae23c9
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
ae23c9
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
ae23c9
Bugzilla: 1629616
ae23c9
ae23c9
There are two callers for vtd_sync_shadow_page_table_range(): one
ae23c9
provided a valid context entry and one not.  Move that fetching
ae23c9
operation into the caller vtd_sync_shadow_page_table() where we need to
ae23c9
fetch the context entry.
ae23c9
ae23c9
Meanwhile, remove the error_report_once() directly since we're already
ae23c9
tracing all the error cases in the previous call.  Instead, return error
ae23c9
number back to caller.  This will not change anything functional since
ae23c9
callers are dropping it after all.
ae23c9
ae23c9
We do this move majorly because we want to do something more later in
ae23c9
vtd_sync_shadow_page_table().
ae23c9
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
Reviewed-by: Eric Auger <eric.auger@redhat.com>
ae23c9
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
(cherry picked from commit 95ecd3df7815b4bc4f9a0f47e1c64d81434715aa)
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/i386/intel_iommu.c | 41 +++++++++++++----------------------------
ae23c9
 1 file changed, 13 insertions(+), 28 deletions(-)
ae23c9
ae23c9
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
ae23c9
index a6e87a9..c95128d 100644
ae23c9
--- a/hw/i386/intel_iommu.c
ae23c9
+++ b/hw/i386/intel_iommu.c
ae23c9
@@ -1045,7 +1045,6 @@ static int vtd_sync_shadow_page_hook(IOMMUTLBEntry *entry,
ae23c9
     return 0;
ae23c9
 }
ae23c9
 
ae23c9
-/* If context entry is NULL, we'll try to fetch it on our own. */
ae23c9
 static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as,
ae23c9
                                             VTDContextEntry *ce,
ae23c9
                                             hwaddr addr, hwaddr size)
ae23c9
@@ -1057,39 +1056,25 @@ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as,
ae23c9
         .notify_unmap = true,
ae23c9
         .aw = s->aw_bits,
ae23c9
         .as = vtd_as,
ae23c9
+        .domain_id = VTD_CONTEXT_ENTRY_DID(ce->hi),
ae23c9
     };
ae23c9
-    VTDContextEntry ce_cache;
ae23c9
-    int ret;
ae23c9
-
ae23c9
-    if (ce) {
ae23c9
-        /* If the caller provided context entry, use it */
ae23c9
-        ce_cache = *ce;
ae23c9
-    } else {
ae23c9
-        /* If the caller didn't provide ce, try to fetch */
ae23c9
-        ret = vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),
ae23c9
-                                       vtd_as->devfn, &ce_cache);
ae23c9
-        if (ret) {
ae23c9
-            /*
ae23c9
-             * This should not really happen, but in case it happens,
ae23c9
-             * we just skip the sync for this time.  After all we even
ae23c9
-             * don't have the root table pointer!
ae23c9
-             */
ae23c9
-            error_report_once("%s: invalid context entry for bus 0x%x"
ae23c9
-                              " devfn 0x%x",
ae23c9
-                              __func__, pci_bus_num(vtd_as->bus),
ae23c9
-                              vtd_as->devfn);
ae23c9
-            return 0;
ae23c9
-        }
ae23c9
-    }
ae23c9
 
ae23c9
-    info.domain_id = VTD_CONTEXT_ENTRY_DID(ce_cache.hi);
ae23c9
-
ae23c9
-    return vtd_page_walk(&ce_cache, addr, addr + size, &info;;
ae23c9
+    return vtd_page_walk(ce, addr, addr + size, &info;;
ae23c9
 }
ae23c9
 
ae23c9
 static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as)
ae23c9
 {
ae23c9
-    return vtd_sync_shadow_page_table_range(vtd_as, NULL, 0, UINT64_MAX);
ae23c9
+    int ret;
ae23c9
+    VTDContextEntry ce;
ae23c9
+
ae23c9
+    ret = vtd_dev_to_context_entry(vtd_as->iommu_state,
ae23c9
+                                   pci_bus_num(vtd_as->bus),
ae23c9
+                                   vtd_as->devfn, &ce);
ae23c9
+    if (ret) {
ae23c9
+        return ret;
ae23c9
+    }
ae23c9
+
ae23c9
+    return vtd_sync_shadow_page_table_range(vtd_as, &ce, 0, UINT64_MAX);
ae23c9
 }
ae23c9
 
ae23c9
 /*
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9