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

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