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

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