[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v8 05/28] hw/arm/smmuv3: Properly propagate S1 asid invalidation
From: |
Eric Auger |
Subject: |
[RFC v8 05/28] hw/arm/smmuv3: Properly propagate S1 asid invalidation |
Date: |
Thu, 25 Feb 2021 11:52:10 +0100 |
At the moment ASID invalidation command (CMD_TLBI_NH_ASID) is
propagated as a domain invalidation, ie. all ASIDs get invalidated,
failing to restrict the invalidation to the accurate asid.
Fix that by populating the new fields laterly introduced in the
IOTLEntry struct, namely setting the granularity to PASID and setting
the arch_id to the invalidated asid.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
hw/arm/smmuv3.c | 42 ++++++++++++++++++++++++++++++++++++++++--
hw/arm/trace-events | 1 +
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index d037d6df5b..8dffb1bcc3 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -835,6 +835,29 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,
memory_region_notify_iommu_one(n, &event);
}
+/**
+ * smmuv3_notify_asid - call the notifier @n for a given asid
+ *
+ * @mr: IOMMU mr region handle
+ * @n: notifier to be called
+ * @asid: address space ID or negative value if we don't care
+ */
+static void smmuv3_notify_asid(IOMMUMemoryRegion *mr,
+ IOMMUNotifier *n, int asid)
+{
+ IOMMUTLBEvent event = {};
+
+ event.type = IOMMU_NOTIFIER_UNMAP;
+ event.entry.target_as = &address_space_memory;
+ event.entry.perm = IOMMU_NONE;
+ event.entry.granularity = IOMMU_INV_GRAN_PASID;
+ event.entry.flags = IOMMU_INV_FLAGS_ARCHID;
+ event.entry.arch_id = asid;
+
+ memory_region_notify_iommu_one(n, &event);
+}
+
+
/* invalidate an asid/iova range tuple in all mr's */
static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, dma_addr_t iova,
uint8_t tg, uint64_t num_pages)
@@ -910,6 +933,22 @@ smmuv3_invalidate_ste(gpointer key, gpointer value,
gpointer user_data)
return true;
}
+static void smmuv3_s1_asid_inval(SMMUState *s, uint16_t asid)
+{
+ SMMUDevice *sdev;
+
+ trace_smmuv3_s1_asid_inval(asid);
+ QLIST_FOREACH(sdev, &s->devices_with_notifiers, next) {
+ IOMMUMemoryRegion *mr = &sdev->iommu;
+ IOMMUNotifier *n;
+
+ IOMMU_NOTIFIER_FOREACH(n, mr) {
+ smmuv3_notify_asid(mr, n, asid);
+ }
+ }
+ smmu_iotlb_inv_asid(s, asid);
+}
+
static int smmuv3_cmdq_consume(SMMUv3State *s)
{
SMMUState *bs = ARM_SMMU(s);
@@ -1020,8 +1059,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)
uint16_t asid = CMD_ASID(&cmd);
trace_smmuv3_cmdq_tlbi_nh_asid(asid);
- smmu_inv_notifiers_all(&s->smmu_state);
- smmu_iotlb_inv_asid(bs, asid);
+ smmuv3_s1_asid_inval(bs, asid);
break;
}
case SMMU_CMD_TLBI_NH_ALL:
diff --git a/hw/arm/trace-events b/hw/arm/trace-events
index b79a91af5f..8e530ba79d 100644
--- a/hw/arm/trace-events
+++ b/hw/arm/trace-events
@@ -46,6 +46,7 @@ smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=0x%x"
smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t
perc) "Config cache HIT for sid=0x%x (hits=%d, misses=%d, hit rate=%d)"
smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses,
uint32_t perc) "Config cache MISS for sid=0x%x (hits=%d, misses=%d, hit
rate=%d)"
smmuv3_s1_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t
num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d
num_pages=0x%"PRIx64" ttl=%d leaf=%d"
+smmuv3_s1_asid_inval(int asid) "asid=%d"
smmuv3_cmdq_tlbi_nh(void) ""
smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=%d"
smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x"
--
2.26.2
- [RFC v8 00/28] vSMMUv3/pSMMUv3 2 stage VFIO integration, Eric Auger, 2021/02/25
- [RFC v8 01/28] hw/vfio/common: trace vfio_connect_container operations, Eric Auger, 2021/02/25
- [RFC v8 02/28] update-linux-headers: Import iommu.h, Eric Auger, 2021/02/25
- [RFC v8 03/28] header update against 5.11-rc2 and IOMMU/VFIO nested stage APIs, Eric Auger, 2021/02/25
- [RFC v8 04/28] memory: Add new fields in IOTLBEntry, Eric Auger, 2021/02/25
- [RFC v8 05/28] hw/arm/smmuv3: Properly propagate S1 asid invalidation,
Eric Auger <=
- [RFC v8 06/28] memory: Add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2021/02/25
- [RFC v8 07/28] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2021/02/25
- [RFC v8 08/28] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2021/02/25
- [RFC v8 09/28] iommu: Introduce generic header, Eric Auger, 2021/02/25
- [RFC v8 10/28] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2021/02/25
- [RFC v8 11/28] vfio: Force nested if iommu requires it, Eric Auger, 2021/02/25
- [RFC v8 12/28] vfio: Introduce hostwin_from_range helper, Eric Auger, 2021/02/25
- [RFC v8 13/28] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2021/02/25
- [RFC v8 14/28] vfio: Set up nested stage mappings, Eric Auger, 2021/02/25
- [RFC v8 15/28] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2021/02/25