From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBvtp-0008VX-Qv for qemu-devel@nongnu.org; Sun, 05 Jul 2015 22:12:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBvtj-0001e3-JT for qemu-devel@nongnu.org; Sun, 05 Jul 2015 22:12:49 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:47166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBvti-0001cD-Rr for qemu-devel@nongnu.org; Sun, 05 Jul 2015 22:12:43 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Jul 2015 12:12:39 +1000 From: Alexey Kardashevskiy Date: Mon, 6 Jul 2015 12:11:08 +1000 Message-Id: <1436148670-6592-13-git-send-email-aik@ozlabs.ru> In-Reply-To: <1436148670-6592-1-git-send-email-aik@ozlabs.ru> References: <1436148670-6592-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH qemu v10 12/14] vfio: Unregister IOMMU notifiers when container is destroyed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Michael Roth , Gavin Shan , Alex Williamson , qemu-ppc@nongnu.org, David Gibson On systems with guest visible IOMMU, adding a new memory region onto PCI bus calls vfio_listener_region_add() for every DMA window. This installs a notifier for IOMMU memory regions. The notifier is supposed to be removed by vfio_listener_region_del(), however in the case of mixed PHB (emulated + VFIO devices) when last VFIO device is unplugged and container gets destroyed, all existing DMA windows stay alive altogether with the notifiers which are on the linked list which head was in the destroyed container. This unregisters IOMMU memory region notifier when a container is destroyed. Signed-off-by: Alexey Kardashevskiy --- Changes: v10: * new to the patchset --- hw/vfio/common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 89ef37b..8eacfd7 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -772,11 +772,19 @@ static void vfio_disconnect_container(VFIOGroup *group) if (QLIST_EMPTY(&container->group_list)) { VFIOAddressSpace *space = container->space; + VFIOGuestIOMMU *giommu, *tmp; if (container->iommu_data.release) { container->iommu_data.release(container); } QLIST_REMOVE(container, next); + + QLIST_FOREACH_SAFE(giommu, &container->giommu_list, giommu_next, tmp) { + memory_region_unregister_iommu_notifier(&giommu->n); + QLIST_REMOVE(giommu, giommu_next); + g_free(giommu); + } + trace_vfio_disconnect_container(container->fd); close(container->fd); g_free(container); -- 2.4.0.rc3.8.gfb3e7d5