From 375f74f473cfcb0c73a64088a6a5880829c155da Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Wed, 29 Mar 2017 12:10:04 +0800 Subject: vhost: generalize iommu memory region We assumes the iommu_ops were attached to the root region of address space. This may not be true for all kinds of IOMMU implementation and especially after commit 3716d5902d74 ("pci: introduce a bus master container"). So fix this by not assuming as->root has iommu_ops, instead depending on the regions reported by memory listener through: - register a memory listener to dma_as - during region_add, if it's a region of IOMMU, register a specific IOMMU notifier, and store all notifiers in a list. - during region_del, compare and delete the IOMMU notifier from the list This is also a must for making vhost device IOTLB works for all types of IOMMUs. Note, since we register one notifier during each .region_add, the IOTLB may be flushed more than one times, this is suboptimal and could be optimized in the future. Reported-by: Maxime Coquelin Fixes: 3716d5902d74 ("pci: introduce a bus master container") Cc: Peter Xu Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Peter Xu Tested-by: Maxime Coquelin --- include/hw/virtio/vhost.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 52f633e..a450321 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -37,10 +37,20 @@ struct vhost_log { vhost_log_chunk_t *log; }; +struct vhost_dev; +struct vhost_iommu { + struct vhost_dev *hdev; + MemoryRegion *mr; + hwaddr iommu_offset; + IOMMUNotifier n; + QLIST_ENTRY(vhost_iommu) iommu_next; +}; + struct vhost_memory; struct vhost_dev { VirtIODevice *vdev; MemoryListener memory_listener; + MemoryListener iommu_listener; struct vhost_memory *mem; int n_mem_sections; MemoryRegionSection *mem_sections; @@ -64,6 +74,7 @@ struct vhost_dev { void *opaque; struct vhost_log *log; QLIST_ENTRY(vhost_dev) entry; + QLIST_HEAD(, vhost_iommu) iommu_list; IOMMUNotifier n; }; -- cgit v1.1