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