[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v11 04/10] virtio-iommu: Call memory notifiers in attach/detach
From: |
Jean-Philippe Brucker |
Subject: |
[PATCH v11 04/10] virtio-iommu: Call memory notifiers in attach/detach |
Date: |
Fri, 30 Oct 2020 19:05:04 +0100 |
From: Bharat Bhushan <bbhushan2@marvell.com>
Call the memory notifiers when attaching an endpoint to a domain, to
replay existing mappings, and when detaching the endpoint, to remove all
mappings.
Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
v11: Pass mapping permissions to the notifiers
---
hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 7dd15c5eacd..7b648923517 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -170,11 +170,39 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion
*mr, hwaddr virt_start,
memory_region_notify_iommu(mr, 0, entry);
}
+static gboolean virtio_iommu_notify_unmap_cb(gpointer key, gpointer value,
+ gpointer data)
+{
+ VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key;
+ IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+ virtio_iommu_notify_unmap(mr, interval->low, interval->high);
+
+ return false;
+}
+
+static gboolean virtio_iommu_notify_map_cb(gpointer key, gpointer value,
+ gpointer data)
+{
+ VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value;
+ VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key;
+ IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data;
+
+ 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;
+
if (!ep->domain) {
return;
}
+ g_tree_foreach(domain->mappings, virtio_iommu_notify_unmap_cb,
+ ep->iommu_mr);
QLIST_REMOVE(ep, next);
ep->domain = NULL;
}
@@ -317,6 +345,10 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
ep->domain = domain;
+ /* Replay domain mappings on the associated memory region */
+ g_tree_foreach(domain->mappings, virtio_iommu_notify_map_cb,
+ ep->iommu_mr);
+
return VIRTIO_IOMMU_S_OK;
}
--
2.29.1
- [PATCH v11 00/10] virtio-iommu: VFIO integration, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 01/10] virtio-iommu: Fix virtio_iommu_mr(), Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 04/10] virtio-iommu: Call memory notifiers in attach/detach,
Jean-Philippe Brucker <=
- [PATCH v11 03/10] virtio-iommu: Add memory notifiers for map/unmap, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 06/10] virtio-iommu: Add notify_flag_changed() memory region callback, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 02/10] virtio-iommu: Store memory region in endpoint struct, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 09/10] virtio-iommu: Set supported page size mask, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 08/10] vfio: Set IOMMU page size as per host supported page size, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 10/10] vfio: Don't issue full 2^64 unmap, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 05/10] virtio-iommu: Add replay() memory region callback, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 07/10] memory: Add interface to set iommu page size mask, Jean-Philippe Brucker, 2020/10/30