[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [RFC 18/20] target/arm/kvm: Notifies IOMMU on MSI stage 1 bin
From: |
Eric Auger |
Subject: |
[Qemu-arm] [RFC 18/20] target/arm/kvm: Notifies IOMMU on MSI stage 1 binding |
Date: |
Sat, 1 Sep 2018 16:23:10 +0200 |
When the MSI route is setup, we know the MSI IOVA and
the doorbell GPA . At that point we can communicate this guest
stage 1 binding to the host. Then the host will be able
to construct a stage 2 binding taking as input address the
doorbell GPA.
We also directly use the iommu memory region translate() callback
as the addr_mask is returned in IOTLB entry. address_space_translate
does not return this information.
Signed-off-by: Eric Auger <address@hidden>
---
TODO: access to as->root field may be cleaned later on
---
target/arm/kvm.c | 46 ++++++++++++++++++++--------------------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 65f867d569..6f905215b8 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -661,41 +661,35 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry
*route,
uint64_t address, uint32_t data, PCIDevice *dev)
{
AddressSpace *as = pci_device_iommu_address_space(dev);
- hwaddr xlat, len, doorbell_gpa;
- MemoryRegionSection mrs;
- MemoryRegion *mr;
- int ret = 1;
+ IOMMUMemoryRegionClass *imrc;
+ IOMMUMemoryRegion *iommu_mr;
+ IOMMUTLBEntry entry;
if (as == &address_space_memory) {
return 0;
}
+ iommu_mr = IOMMU_MEMORY_REGION(as->root);
+ imrc = memory_region_get_iommu_class_nocheck(iommu_mr);
+
/* MSI doorbell address is translated by an IOMMU */
rcu_read_lock();
- mr = address_space_translate(as, address, &xlat, &len, true,
- MEMTXATTRS_UNSPECIFIED);
- if (!mr) {
- goto unlock;
- }
- mrs = memory_region_find(mr, xlat, 1);
- if (!mrs.mr) {
- goto unlock;
- }
-
- doorbell_gpa = mrs.offset_within_address_space;
- memory_region_unref(mrs.mr);
-
- route->u.msi.address_lo = doorbell_gpa;
- route->u.msi.address_hi = doorbell_gpa >> 32;
-
- trace_kvm_arm_fixup_msi_route(address, doorbell_gpa);
-
- ret = 0;
-
-unlock:
+ entry = imrc->translate(iommu_mr, address, IOMMU_WO, 0);
rcu_read_unlock();
- return ret;
+
+ if (entry.perm == IOMMU_NONE) {
+ return -ENOENT;
+ }
+
+ route->u.msi.address_lo = entry.translated_addr;
+ route->u.msi.address_hi = entry.translated_addr >> 32;
+
+ memory_region_iotlb_notify_iommu(iommu_mr, 0, entry);
+
+ trace_kvm_arm_fixup_msi_route(address, entry.translated_addr);
+
+ return 0;
}
int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route,
--
2.17.1
- [Qemu-arm] [RFC 00/20] vSMMUv3/pSMMUv3 2 stage VFIO integration, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 05/20] hw/arm/smmuv3: Implement get_attr API to report IOMMU_ATTR_VFIO_NESTED, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 20/20] hw/arm/smmuv3: Remove warning about unsupported MAP notifiers, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 04/20] memory: add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 19/20] vfio/pci: Always set up MSI route before enabling vectors, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 18/20] target/arm/kvm: Notifies IOMMU on MSI stage 1 binding,
Eric Auger <=
- [Qemu-arm] [RFC 16/20] hw/vfio/common: Register specific nested mode notifiers and memory_listener, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 15/20] hw/vfio/common: Introduce vfio_dma_(un)map_ram_section helpers, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 17/20] hw/vfio/common: Register MAP notifier for MSI binding, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 14/20] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 13/20] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 10/20] memory: Add IOMMUConfigNotifier, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 11/20] hw/arm/smmuv3: Store s1ctrptr in translation config data, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 12/20] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 08/20] memory: Introduce IOMMUIOLTBNotifier, Eric Auger, 2018/09/01
- [Qemu-arm] [RFC 09/20] memory: rename memory_region notify_iommu, notify_one, Eric Auger, 2018/09/01