From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bx7m7-000615-Cx for qemu-devel@nongnu.org; Thu, 20 Oct 2016 03:28:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bx7m3-0001Qe-E7 for qemu-devel@nongnu.org; Thu, 20 Oct 2016 03:28:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bx7m3-0001QN-98 for qemu-devel@nongnu.org; Thu, 20 Oct 2016 03:28:23 -0400 Date: Thu, 20 Oct 2016 15:28:18 +0800 From: Peter Xu Message-ID: <20161020072818.GH15168@pxdev.xzpeter.org> References: <1476719064-9242-1-git-send-email-bd.aviv@gmail.com> <1476719064-9242-4-git-send-email-bd.aviv@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1476719064-9242-4-git-send-email-bd.aviv@gmail.com> Subject: Re: [Qemu-devel] [PATCH v4 RESEND 3/3] IOMMU: enable intel_iommu map and unmap notifiers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aviv B.D" Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" , Alex Williamson , Jan Kiszka On Mon, Oct 17, 2016 at 06:44:24PM +0300, Aviv B.D wrote: [...] > @@ -2000,8 +2065,10 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, > IOMMUNotifierFlag new) > { > VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu); > + IntelIOMMUState *s = vtd_as->iommu_state; > + IntelIOMMUNotifierNode *node = NULL; > > - if (new & IOMMU_NOTIFIER_MAP) { > + if (!s->cache_mode_enabled && new & IOMMU_NOTIFIER_MAP) { > error_report("Device at bus %s addr %02x.%d requires iommu " > "notifier which is currently not supported by " > "intel-iommu emulation", Here after the patch works, we can modify the warning message into something like: "We need to set cache_mode=1 for intel-iommu to enable device assignment with IOMMU protection." > @@ -2009,6 +2076,27 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, > PCI_FUNC(vtd_as->devfn)); > exit(1); > } > + > + /* Add new ndoe if no mapping was exising before this call */ > + if (old == IOMMU_NOTIFIER_NONE) { > + node = g_malloc0(sizeof(*node)); > + node->vtd_as = vtd_as; > + node->notifier_flag = new; > + QLIST_INSERT_HEAD(&s->notifiers_list, node, next); > + return; > + } > + > + /* update notifier node with new flags */ > + QLIST_FOREACH(node, &s->notifiers_list, next) { Though in this case it is safe, I would still suggest we use QLIST_FOREACH_SAFE here. > + if (node->vtd_as == vtd_as) { > + if (new == IOMMU_NOTIFIER_NONE) { > + QLIST_REMOVE(node, next); Memory leak here? Thanks, -- peterx