[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 16/38] virtio-iommu: Call memory notifiers in attach/detach
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 16/38] virtio-iommu: Call memory notifiers in attach/detach |
Date: |
Tue, 3 Nov 2020 23:51:25 -0500 |
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>
Message-Id: <20201030180510.747225-5-jean-philippe@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
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 7dd15c5eac..7b64892351 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;
}
--
MST
- [PULL v2 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path, (continued)
- [PULL v2 12/38] hw/smbios: Fix leaked fd in save_opt_one() error path, Michael S. Tsirkin, 2020/11/03
- [PULL v2 14/38] virtio-iommu: Store memory region in endpoint struct, Michael S. Tsirkin, 2020/11/03
- [PULL v2 34/38] libqtest: add qtest_socket_server(), Michael S. Tsirkin, 2020/11/03
- [PULL v2 35/38] vhost-user-blk-test: rename destroy_drive() to destroy_file(), Michael S. Tsirkin, 2020/11/03
- [PULL v2 36/38] vhost-user-blk-test: close fork child file descriptors, Michael S. Tsirkin, 2020/11/03
- [PULL v2 28/38] configure: introduce --enable-vhost-user-blk-server, Michael S. Tsirkin, 2020/11/03
- [PULL v2 33/38] tests/qtest: add multi-queue test case to vhost-user-blk-test, Michael S. Tsirkin, 2020/11/03
- [PULL v2 38/38] vhost-user-blk-test: fix races by using fd passing, Michael S. Tsirkin, 2020/11/03
- [PULL v2 32/38] test: new qTest case to test the vhost-user-blk-server, Michael S. Tsirkin, 2020/11/03
- [PULL v2 18/38] virtio-iommu: Add notify_flag_changed() memory region callback, Michael S. Tsirkin, 2020/11/03
- [PULL v2 16/38] virtio-iommu: Call memory notifiers in attach/detach,
Michael S. Tsirkin <=
- [PULL v2 31/38] contrib/vhost-user-blk: fix get_config() information leak, Michael S. Tsirkin, 2020/11/04
- [PULL v2 10/38] hw/acpi : add spaces around operator, Michael S. Tsirkin, 2020/11/04
- [PULL v2 37/38] vhost-user-blk-test: drop unused return value, Michael S. Tsirkin, 2020/11/04
- Re: [PULL v2 00/38] pc,pci,vhost,virtio: fixes, Peter Maydell, 2020/11/04