cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
a19a21
From 7833c0bf8321cb39614ee889cf3e3a64511c0aa5 Mon Sep 17 00:00:00 2001
a19a21
From: eperezma <eperezma@redhat.com>
a19a21
Date: Tue, 12 Jan 2021 14:36:28 -0500
a19a21
Subject: [PATCH 04/17] hw/arm/smmu: Introduce smmu_get_iotlb_key()
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-4-eperezma@redhat.com>
a19a21
Patchwork-id: 100596
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 03/13] hw/arm/smmu: Introduce smmu_get_iotlb_key()
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
Introduce the smmu_get_iotlb_key() helper and the
a19a21
SMMU_IOTLB_ASID() macro. Also move smmu_get_iotlb_key and
a19a21
smmu_iotlb_key_hash in the IOTLB related code section.
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-4-eric.auger@redhat.com
a19a21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
a19a21
(cherry picked from commit 60a61f1b31fc03080aadb63c9b1006f8b1972adb)
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         | 66 ++++++++++++++++++++----------------
a19a21
 hw/arm/smmu-internal.h       |  1 +
a19a21
 include/hw/arm/smmu-common.h |  1 +
a19a21
 3 files changed, 38 insertions(+), 30 deletions(-)
a19a21
a19a21
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
a19a21
index 8e01505dbee..0b89c9fbbbc 100644
a19a21
--- a/hw/arm/smmu-common.c
a19a21
+++ b/hw/arm/smmu-common.c
a19a21
@@ -32,10 +32,42 @@
a19a21
 
a19a21
 /* IOTLB Management */
a19a21
 
a19a21
+static guint smmu_iotlb_key_hash(gconstpointer v)
a19a21
+{
a19a21
+    SMMUIOTLBKey *key = (SMMUIOTLBKey *)v;
a19a21
+    uint32_t a, b, c;
a19a21
+
a19a21
+    /* Jenkins hash */
a19a21
+    a = b = c = JHASH_INITVAL + sizeof(*key);
a19a21
+    a += key->asid;
a19a21
+    b += extract64(key->iova, 0, 32);
a19a21
+    c += extract64(key->iova, 32, 32);
a19a21
+
a19a21
+    __jhash_mix(a, b, c);
a19a21
+    __jhash_final(a, b, c);
a19a21
+
a19a21
+    return c;
a19a21
+}
a19a21
+
a19a21
+static gboolean smmu_iotlb_key_equal(gconstpointer v1, gconstpointer v2)
a19a21
+{
a19a21
+    const SMMUIOTLBKey *k1 = v1;
a19a21
+    const SMMUIOTLBKey *k2 = v2;
a19a21
+
a19a21
+    return (k1->asid == k2->asid) && (k1->iova == k2->iova);
a19a21
+}
a19a21
+
a19a21
+SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint64_t iova)
a19a21
+{
a19a21
+    SMMUIOTLBKey key = {.asid = asid, .iova = iova};
a19a21
+
a19a21
+    return key;
a19a21
+}
a19a21
+
a19a21
 IOMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg,
a19a21
                                  hwaddr iova)
a19a21
 {
a19a21
-    SMMUIOTLBKey key = {.asid = cfg->asid, .iova = iova};
a19a21
+    SMMUIOTLBKey key = smmu_get_iotlb_key(cfg->asid, iova);
a19a21
     IOMMUTLBEntry *entry = g_hash_table_lookup(bs->iotlb, &key);
a19a21
 
a19a21
     if (entry) {
a19a21
@@ -62,8 +94,7 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, IOMMUTLBEntry *entry)
a19a21
         smmu_iotlb_inv_all(bs);
a19a21
     }
a19a21
 
a19a21
-    key->asid = cfg->asid;
a19a21
-    key->iova = entry->iova;
a19a21
+    *key = smmu_get_iotlb_key(cfg->asid, entry->iova);
a19a21
     trace_smmu_iotlb_insert(cfg->asid, entry->iova);
a19a21
     g_hash_table_insert(bs->iotlb, key, entry);
a19a21
 }
a19a21
@@ -80,12 +111,12 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,
a19a21
     uint16_t asid = *(uint16_t *)user_data;
a19a21
     SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key;
a19a21
 
a19a21
-    return iotlb_key->asid == asid;
a19a21
+    return SMMU_IOTLB_ASID(*iotlb_key) == asid;
a19a21
 }
a19a21
 
a19a21
 inline void smmu_iotlb_inv_iova(SMMUState *s, uint16_t asid, dma_addr_t iova)
a19a21
 {
a19a21
-    SMMUIOTLBKey key = {.asid = asid, .iova = iova};
a19a21
+    SMMUIOTLBKey key = smmu_get_iotlb_key(asid, iova);
a19a21
 
a19a21
     trace_smmu_iotlb_inv_iova(asid, iova);
a19a21
     g_hash_table_remove(s->iotlb, &key);
a19a21
@@ -382,31 +413,6 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid)
a19a21
     return NULL;
a19a21
 }
a19a21
 
a19a21
-static guint smmu_iotlb_key_hash(gconstpointer v)
a19a21
-{
a19a21
-    SMMUIOTLBKey *key = (SMMUIOTLBKey *)v;
a19a21
-    uint32_t a, b, c;
a19a21
-
a19a21
-    /* Jenkins hash */
a19a21
-    a = b = c = JHASH_INITVAL + sizeof(*key);
a19a21
-    a += key->asid;
a19a21
-    b += extract64(key->iova, 0, 32);
a19a21
-    c += extract64(key->iova, 32, 32);
a19a21
-
a19a21
-    __jhash_mix(a, b, c);
a19a21
-    __jhash_final(a, b, c);
a19a21
-
a19a21
-    return c;
a19a21
-}
a19a21
-
a19a21
-static gboolean smmu_iotlb_key_equal(gconstpointer v1, gconstpointer v2)
a19a21
-{
a19a21
-    const SMMUIOTLBKey *k1 = v1;
a19a21
-    const SMMUIOTLBKey *k2 = v2;
a19a21
-
a19a21
-    return (k1->asid == k2->asid) && (k1->iova == k2->iova);
a19a21
-}
a19a21
-
a19a21
 /* Unmap the whole notifier's range */
a19a21
 static void smmu_unmap_notifier_range(IOMMUNotifier *n)
a19a21
 {
a19a21
diff --git a/hw/arm/smmu-internal.h b/hw/arm/smmu-internal.h
a19a21
index 7794d6d3947..3104f768cd2 100644
a19a21
--- a/hw/arm/smmu-internal.h
a19a21
+++ b/hw/arm/smmu-internal.h
a19a21
@@ -96,4 +96,5 @@ uint64_t iova_level_offset(uint64_t iova, int inputsize,
a19a21
             MAKE_64BIT_MASK(0, gsz - 3);
a19a21
 }
a19a21
 
a19a21
+#define SMMU_IOTLB_ASID(key) ((key).asid)
a19a21
 #endif
a19a21
diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
a19a21
index a28650c9350..bceba40885c 100644
a19a21
--- a/include/hw/arm/smmu-common.h
a19a21
+++ b/include/hw/arm/smmu-common.h
a19a21
@@ -155,6 +155,7 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid);
a19a21
 
a19a21
 IOMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, hwaddr iova);
a19a21
 void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, IOMMUTLBEntry *entry);
a19a21
+SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint64_t iova);
a19a21
 void smmu_iotlb_inv_all(SMMUState *s);
a19a21
 void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid);
a19a21
 void smmu_iotlb_inv_iova(SMMUState *s, uint16_t asid, dma_addr_t iova);
a19a21
-- 
a19a21
2.27.0
a19a21