From patchwork Mon Jul 6 18:35:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 491758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C5B8F140DBC for ; Tue, 7 Jul 2015 04:38:19 +1000 (AEST) Received: from localhost ([::1]:52452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCBHV-0000kl-SI for incoming@patchwork.ozlabs.org; Mon, 06 Jul 2015 14:38:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCBEv-0004jZ-HH for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:35:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCBEu-0003M9-5l for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:35:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCBEu-0003M1-0n for qemu-devel@nongnu.org; Mon, 06 Jul 2015 14:35:36 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 99A988B137 for ; Mon, 6 Jul 2015 18:35:35 +0000 (UTC) Received: from gimli.home (ovpn-113-190.phx2.redhat.com [10.3.113.190]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t66IZZSo025701; Mon, 6 Jul 2015 14:35:35 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 06 Jul 2015 12:35:35 -0600 Message-ID: <20150706183534.15635.34945.stgit@gimli.home> In-Reply-To: <20150706183311.15635.76314.stgit@gimli.home> References: <20150706183311.15635.76314.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/11] vfio: Unregister IOMMU notifiers when container is destroyed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alexey Kardashevskiy 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 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 Reviewed-by: David Gibson Signed-off-by: Alex Williamson --- hw/vfio/common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b1045da..85ee9b0 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);