Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752853AbbG1R4U (ORCPT ); Tue, 28 Jul 2015 13:56:20 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:56689 "EHLO e06smtp17.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751775AbbG1R4S (ORCPT ); Tue, 28 Jul 2015 13:56:18 -0400 X-Helo: d06dlp01.portsmouth.uk.ibm.com X-MailFrom: gerald.schaefer@de.ibm.com X-RcptTo: linux-pci@vger.kernel.org From: Gerald Schaefer To: Joerg Roedel Cc: Alex Williamson , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-pci@vger.kernel.org, Sebastian Ott , Martin Schwidefsky , Gerald Schaefer Subject: [RFC PATCH 1/1] iommu: Detach device from domain when removed from group Date: Tue, 28 Jul 2015 19:55:56 +0200 Message-Id: <1438106156-51847-2-git-send-email-gerald.schaefer@de.ibm.com> X-Mailer: git-send-email 2.3.8 In-Reply-To: <1438106156-51847-1-git-send-email-gerald.schaefer@de.ibm.com> References: <1438106156-51847-1-git-send-email-gerald.schaefer@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15072817-0029-0000-0000-000005A79317 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1745 Lines: 49 This patch adds a call to __iommu_detach_device() to the iommu_group_remove_device() function, which will trigger a missing detach_dev callback in (at least) the following scenario: When a user completes the VFIO_SET_IOMMU ioctl for a vfio-pci device, and the corresponding device is removed thereafter (before any other ioctl like VFIO_GROUP_GET_DEVICE_FD), then the detach_dev callback of the underlying IOMMU API is never called. This also fixes an asymmetry with iommu_group_add_device() and iommu_group_remove_device(), where the former did an "attach_dev" but the latter did no "detach_dev". Signed-off-by: Gerald Schaefer --- drivers/iommu/iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f286090..82ac8b3 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -447,6 +447,9 @@ rename: } EXPORT_SYMBOL_GPL(iommu_group_add_device); +static void __iommu_detach_device(struct iommu_domain *domain, + struct device *dev); + /** * iommu_group_remove_device - remove a device from it's current group * @dev: device to be removed @@ -466,6 +469,8 @@ void iommu_group_remove_device(struct device *dev) IOMMU_GROUP_NOTIFY_DEL_DEVICE, dev); mutex_lock(&group->mutex); + if (group->domain) + __iommu_detach_device(group->domain, dev); list_for_each_entry(tmp_device, &group->devices, list) { if (tmp_device->dev == dev) { device = tmp_device; -- 2.3.8 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/