[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v7 23/26] hw/arm/smmuv3: Implement fault injection
From: |
Eric Auger |
Subject: |
[RFC v7 23/26] hw/arm/smmuv3: Implement fault injection |
Date: |
Mon, 16 Nov 2020 19:13:46 +0100 |
We convert iommu_fault structs received from the kernel
into the data struct used by the emulation code and record
the evnts into the virtual event queue.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v3 -> v4:
- fix compil issue on mingw
Exhaustive mapping remains to be done
---
hw/arm/smmuv3.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 2b36bb4e4f..5488c9e925 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1572,6 +1572,76 @@ static int smmuv3_get_attr(IOMMUMemoryRegion *iommu,
return -EINVAL;
}
+struct iommu_fault;
+
+static inline int
+smmuv3_inject_faults(IOMMUMemoryRegion *iommu_mr, int count,
+ struct iommu_fault *buf)
+{
+#ifdef __linux__
+ SMMUDevice *sdev = container_of(iommu_mr, SMMUDevice, iommu);
+ SMMUv3State *s3 = sdev->smmu;
+ uint32_t sid = smmu_get_sid(sdev);
+ int i;
+
+ for (i = 0; i < count; i++) {
+ SMMUEventInfo info = {};
+ struct iommu_fault_unrecoverable *record;
+
+ if (buf[i].type != IOMMU_FAULT_DMA_UNRECOV) {
+ continue;
+ }
+
+ info.sid = sid;
+ record = &buf[i].event;
+
+ switch (record->reason) {
+ case IOMMU_FAULT_REASON_PASID_INVALID:
+ info.type = SMMU_EVT_C_BAD_SUBSTREAMID;
+ /* TODO further fill info.u.c_bad_substream */
+ break;
+ case IOMMU_FAULT_REASON_PASID_FETCH:
+ info.type = SMMU_EVT_F_CD_FETCH;
+ break;
+ case IOMMU_FAULT_REASON_BAD_PASID_ENTRY:
+ info.type = SMMU_EVT_C_BAD_CD;
+ /* TODO further fill info.u.c_bad_cd */
+ break;
+ case IOMMU_FAULT_REASON_WALK_EABT:
+ info.type = SMMU_EVT_F_WALK_EABT;
+ info.u.f_walk_eabt.addr = record->addr;
+ info.u.f_walk_eabt.addr2 = record->fetch_addr;
+ break;
+ case IOMMU_FAULT_REASON_PTE_FETCH:
+ info.type = SMMU_EVT_F_TRANSLATION;
+ info.u.f_translation.addr = record->addr;
+ break;
+ case IOMMU_FAULT_REASON_OOR_ADDRESS:
+ info.type = SMMU_EVT_F_ADDR_SIZE;
+ info.u.f_addr_size.addr = record->addr;
+ break;
+ case IOMMU_FAULT_REASON_ACCESS:
+ info.type = SMMU_EVT_F_ACCESS;
+ info.u.f_access.addr = record->addr;
+ break;
+ case IOMMU_FAULT_REASON_PERMISSION:
+ info.type = SMMU_EVT_F_PERMISSION;
+ info.u.f_permission.addr = record->addr;
+ break;
+ default:
+ warn_report("%s Unexpected fault reason received from host: %d",
+ __func__, record->reason);
+ continue;
+ }
+
+ smmuv3_record_event(s3, &info);
+ }
+ return 0;
+#else
+ return -1;
+#endif
+}
+
static void smmuv3_iommu_memory_region_class_init(ObjectClass *klass,
void *data)
{
@@ -1580,6 +1650,7 @@ static void
smmuv3_iommu_memory_region_class_init(ObjectClass *klass,
imrc->translate = smmuv3_translate;
imrc->notify_flag_changed = smmuv3_notify_flag_changed;
imrc->get_attr = smmuv3_get_attr;
+ imrc->inject_faults = smmuv3_inject_faults;
}
static const TypeInfo smmuv3_type_info = {
--
2.21.3
- [RFC v7 12/26] vfio: Set up nested stage mappings, (continued)
- [RFC v7 12/26] vfio: Set up nested stage mappings, Eric Auger, 2020/11/16
- [RFC v7 13/26] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2020/11/16
- [RFC v7 14/26] vfio: Helper to get IRQ info including capabilities, Eric Auger, 2020/11/16
- [RFC v7 15/26] vfio/pci: Register handler for iommu fault, Eric Auger, 2020/11/16
- [RFC v7 16/26] vfio/pci: Set up the DMA FAULT region, Eric Auger, 2020/11/16
- [RFC v7 17/26] vfio/pci: Implement the DMA fault handler, Eric Auger, 2020/11/16
- [RFC v7 18/26] hw/arm/smmuv3: Advertise MSI_TRANSLATE attribute, Eric Auger, 2020/11/16
- [RFC v7 19/26] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2020/11/16
- [RFC v7 20/26] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2020/11/16
- [RFC v7 21/26] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2020/11/16
- [RFC v7 23/26] hw/arm/smmuv3: Implement fault injection,
Eric Auger <=
- [RFC v7 22/26] hw/arm/smmuv3: Pass stage 1 configurations to the host, Eric Auger, 2020/11/16
- [RFC v7 24/26] hw/arm/smmuv3: Allow MAP notifiers, Eric Auger, 2020/11/16
- [RFC v7 25/26] pci: Add return_page_response pci ops, Eric Auger, 2020/11/16
- [RFC v7 26/26] vfio/pci: Implement return_page_response page response callback, Eric Auger, 2020/11/16