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

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