yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-hw-arm-smmu-common-Factorize-some-code-in-smmu_ptw_6.patch

a19a21
From 79718d8c67c9c54fa86a77f66aa8784aca7651d5 Mon Sep 17 00:00:00 2001
a19a21
From: eperezma <eperezma@redhat.com>
a19a21
Date: Tue, 12 Jan 2021 14:36:26 -0500
a19a21
Subject: [PATCH 02/17] hw/arm/smmu-common: Factorize some code in
a19a21
 smmu_ptw_64()
a19a21
MIME-Version: 1.0
a19a21
Content-Type: text/plain; charset=UTF-8
a19a21
Content-Transfer-Encoding: 8bit
a19a21
a19a21
RH-Author: eperezma <eperezma@redhat.com>
a19a21
Message-id: <20210112143638.374060-2-eperezma@redhat.com>
a19a21
Patchwork-id: 100594
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 01/13] hw/arm/smmu-common: Factorize some code in smmu_ptw_64()
a19a21
Bugzilla: 1843852
a19a21
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
a19a21
RH-Acked-by: Peter Xu <peterx@redhat.com>
a19a21
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
a19a21
a19a21
From: Eric Auger <eric.auger@redhat.com>
a19a21
a19a21
Page and block PTE decoding can share some code. Let's
a19a21
first handle table PTE and factorize some code shared by
a19a21
page and block PTEs.
a19a21
a19a21
Signed-off-by: Eric Auger <eric.auger@redhat.com>
a19a21
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
a19a21
Message-id: 20200728150815.11446-2-eric.auger@redhat.com
a19a21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
a19a21
(cherry picked from commit 1733837d7cdb207653a849a5f1fa78de878c6ac1)
a19a21
Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com>
a19a21
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a19a21
---
a19a21
 hw/arm/smmu-common.c | 48 ++++++++++++++++----------------------------
a19a21
 1 file changed, 17 insertions(+), 31 deletions(-)
a19a21
a19a21
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
a19a21
index 245817d23e9..d2ba8b224ba 100644
a19a21
--- a/hw/arm/smmu-common.c
a19a21
+++ b/hw/arm/smmu-common.c
a19a21
@@ -187,7 +187,7 @@ static int smmu_ptw_64(SMMUTransCfg *cfg,
a19a21
         uint64_t subpage_size = 1ULL << level_shift(level, granule_sz);
a19a21
         uint64_t mask = subpage_size - 1;
a19a21
         uint32_t offset = iova_level_offset(iova, inputsize, level, granule_sz);
a19a21
-        uint64_t pte;
a19a21
+        uint64_t pte, gpa;
a19a21
         dma_addr_t pte_addr = baseaddr + offset * sizeof(pte);
a19a21
         uint8_t ap;
a19a21
 
a19a21
@@ -200,56 +200,42 @@ static int smmu_ptw_64(SMMUTransCfg *cfg,
a19a21
         if (is_invalid_pte(pte) || is_reserved_pte(pte, level)) {
a19a21
             trace_smmu_ptw_invalid_pte(stage, level, baseaddr,
a19a21
                                        pte_addr, offset, pte);
a19a21
-            info->type = SMMU_PTW_ERR_TRANSLATION;
a19a21
-            goto error;
a19a21
+            break;
a19a21
         }
a19a21
 
a19a21
-        if (is_page_pte(pte, level)) {
a19a21
-            uint64_t gpa = get_page_pte_address(pte, granule_sz);
a19a21
+        if (is_table_pte(pte, level)) {
a19a21
+            ap = PTE_APTABLE(pte);
a19a21
 
a19a21
-            ap = PTE_AP(pte);
a19a21
             if (is_permission_fault(ap, perm)) {
a19a21
                 info->type = SMMU_PTW_ERR_PERMISSION;
a19a21
                 goto error;
a19a21
             }
a19a21
-
a19a21
-            tlbe->translated_addr = gpa + (iova & mask);
a19a21
-            tlbe->perm = PTE_AP_TO_PERM(ap);
a19a21
+            baseaddr = get_table_pte_address(pte, granule_sz);
a19a21
+            level++;
a19a21
+            continue;
a19a21
+        } else if (is_page_pte(pte, level)) {
a19a21
+            gpa = get_page_pte_address(pte, granule_sz);
a19a21
             trace_smmu_ptw_page_pte(stage, level, iova,
a19a21
                                     baseaddr, pte_addr, pte, gpa);
a19a21
-            return 0;
a19a21
-        }
a19a21
-        if (is_block_pte(pte, level)) {
a19a21
+        } else {
a19a21
             uint64_t block_size;
a19a21
-            hwaddr gpa = get_block_pte_address(pte, level, granule_sz,
a19a21
-                                               &block_size);
a19a21
-
a19a21
-            ap = PTE_AP(pte);
a19a21
-            if (is_permission_fault(ap, perm)) {
a19a21
-                info->type = SMMU_PTW_ERR_PERMISSION;
a19a21
-                goto error;
a19a21
-            }
a19a21
 
a19a21
+            gpa = get_block_pte_address(pte, level, granule_sz,
a19a21
+                                        &block_size);
a19a21
             trace_smmu_ptw_block_pte(stage, level, baseaddr,
a19a21
                                      pte_addr, pte, iova, gpa,
a19a21
                                      block_size >> 20);
a19a21
-
a19a21
-            tlbe->translated_addr = gpa + (iova & mask);
a19a21
-            tlbe->perm = PTE_AP_TO_PERM(ap);
a19a21
-            return 0;
a19a21
         }
a19a21
-
a19a21
-        /* table pte */
a19a21
-        ap = PTE_APTABLE(pte);
a19a21
-
a19a21
+        ap = PTE_AP(pte);
a19a21
         if (is_permission_fault(ap, perm)) {
a19a21
             info->type = SMMU_PTW_ERR_PERMISSION;
a19a21
             goto error;
a19a21
         }
a19a21
-        baseaddr = get_table_pte_address(pte, granule_sz);
a19a21
-        level++;
a19a21
-    }
a19a21
 
a19a21
+        tlbe->translated_addr = gpa + (iova & mask);
a19a21
+        tlbe->perm = PTE_AP_TO_PERM(ap);
a19a21
+        return 0;
a19a21
+    }
a19a21
     info->type = SMMU_PTW_ERR_TRANSLATION;
a19a21
 
a19a21
 error:
a19a21
-- 
a19a21
2.27.0
a19a21