@@ -277,19 +277,21 @@ static gboolean virtio_iommu_notify_unmap_cb(gpointer key, gpointer value,
return false;
}
-static gboolean virtio_iommu_notify_map_cb(gpointer key, gpointer value,
- gpointer data)
+static gboolean virtio_iommu_notify_remap_cb(gpointer key, gpointer value,
+ gpointer data)
{
VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value;
VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key;
IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+ virtio_iommu_notify_unmap(mr, interval->low, interval->high);
virtio_iommu_notify_map(mr, interval->low, interval->high,
mapping->phys_addr, mapping->flags);
return false;
}
+
static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep)
{
VirtIOIOMMUDomain *domain = ep->domain;
@@ -489,7 +491,7 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
virtio_iommu_switch_address_space(sdev);
/* Replay domain mappings on the associated memory region */
- g_tree_foreach(domain->mappings, virtio_iommu_notify_map_cb,
+ g_tree_foreach(domain->mappings, virtio_iommu_notify_remap_cb,
ep->iommu_mr);
return VIRTIO_IOMMU_S_OK;
When attaching a device to a domain, we replay the existing domain mappings for that device. If there are several VFIO devices in the same group on the guest we may end up with duplicate mapping attempts because the mapping already exist on VFIO side. So let's do a proper remap, ie. first unmap and then map. Signed-off-by: Eric Auger <eric.auger@redhat.com> Fixes 2f6eeb5f0bb ("virtio-iommu: Call memory notifiers in attach/detach") --- hw/virtio/virtio-iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)