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

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