Blame SOURCES/kvm-exec-small-changes-to-flatview_do_translate.patch

383d26
From 035c7c0a1c88284d2628532a70f43c04aa0aba56 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Fri, 25 Jan 2019 22:50:02 +0100
383d26
Subject: [PATCH 02/23] exec: small changes to flatview_do_translate
383d26
MIME-Version: 1.0
383d26
Content-Type: text/plain; charset=UTF-8
383d26
Content-Transfer-Encoding: 8bit
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190125225007.8197-3-jsnow@redhat.com>
383d26
Patchwork-id: 84117
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v2 2/7] exec: small changes to flatview_do_translate
383d26
Bugzilla: 1597482
383d26
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
383d26
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
383d26
RH-Acked-by: Peter Xu <peterx@redhat.com>
383d26
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
383d26
383d26
From: Paolo Bonzini <pbonzini@redhat.com>
383d26
383d26
Prepare for extracting the IOMMU part to a separate function.  Mostly
383d26
cosmetic; the only semantic change is that, if there is more than one
383d26
cascaded IOMMU and the second one fails to translate, *plen_out is now
383d26
adjusted according to the page mask of the first IOMMU.
383d26
383d26
Reviewed-by: Peter Xu <peterx@redhat.com>
383d26
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
383d26
(cherry picked from commit ad2804d9e47df2dab642a253502b5ceef233f450)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 exec.c | 33 ++++++++++++++-------------------
383d26
 1 file changed, 14 insertions(+), 19 deletions(-)
383d26
383d26
diff --git a/exec.c b/exec.c
383d26
index 9028700..c6aeded 100644
383d26
--- a/exec.c
383d26
+++ b/exec.c
383d26
@@ -459,6 +459,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x
383d26
  *            would tell. It can be @NULL if we don't care about it.
383d26
  * @is_write: whether the translation operation is for write
383d26
  * @is_mmio: whether this can be MMIO, set true if it can
383d26
+ * @target_as: the address space targeted by the IOMMU
383d26
  *
383d26
  * This function is called from RCU critical section
383d26
  */
383d26
@@ -478,14 +479,14 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv,
383d26
     hwaddr page_mask = (hwaddr)(-1);
383d26
     hwaddr plen = (hwaddr)(-1);
383d26
 
383d26
-    if (plen_out) {
383d26
-        plen = *plen_out;
383d26
+    if (!plen_out) {
383d26
+        plen_out = &ple;;
383d26
     }
383d26
 
383d26
     for (;;) {
383d26
         section = address_space_translate_internal(
383d26
-                flatview_to_dispatch(fv), addr, &addr,
383d26
-                &plen, is_mmio);
383d26
+                flatview_to_dispatch(fv), addr, xlat,
383d26
+                plen_out, is_mmio);
383d26
 
383d26
         iommu_mr = memory_region_get_iommu(section->mr);
383d26
         if (!iommu_mr) {
383d26
@@ -493,35 +494,29 @@ static MemoryRegionSection flatview_do_translate(FlatView *fv,
383d26
         }
383d26
         imrc = memory_region_get_iommu_class_nocheck(iommu_mr);
383d26
 
383d26
+        addr = *xlat;
383d26
         iotlb = imrc->translate(iommu_mr, addr, is_write ?
383d26
                                 IOMMU_WO : IOMMU_RO);
383d26
-        addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
383d26
-                | (addr & iotlb.addr_mask));
383d26
-        page_mask &= iotlb.addr_mask;
383d26
-        plen = MIN(plen, (addr | iotlb.addr_mask) - addr + 1);
383d26
         if (!(iotlb.perm & (1 << is_write))) {
383d26
             goto translate_fail;
383d26
         }
383d26
 
383d26
+        addr = ((iotlb.translated_addr & ~iotlb.addr_mask)
383d26
+                | (addr & iotlb.addr_mask));
383d26
+        page_mask &= iotlb.addr_mask;
383d26
+        *plen_out = MIN(*plen_out, (addr | iotlb.addr_mask) - addr + 1);
383d26
         fv = address_space_to_flatview(iotlb.target_as);
383d26
         *target_as = iotlb.target_as;
383d26
     }
383d26
 
383d26
-    *xlat = addr;
383d26
-
383d26
-    if (page_mask == (hwaddr)(-1)) {
383d26
-        /* Not behind an IOMMU, use default page size. */
383d26
-        page_mask = ~TARGET_PAGE_MASK;
383d26
-    }
383d26
-
383d26
     if (page_mask_out) {
383d26
+        if (page_mask == (hwaddr)(-1)) {
383d26
+            /* Not behind an IOMMU, use default page size. */
383d26
+            page_mask = ~TARGET_PAGE_MASK;
383d26
+        }
383d26
         *page_mask_out = page_mask;
383d26
     }
383d26
 
383d26
-    if (plen_out) {
383d26
-        *plen_out = plen;
383d26
-    }
383d26
-
383d26
     return *section;
383d26
 
383d26
 translate_fail:
383d26
-- 
383d26
1.8.3.1
383d26