From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754274AbbHEPbf (ORCPT ); Wed, 5 Aug 2015 11:31:35 -0400 Received: from 8bytes.org ([81.169.241.247]:43089 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753141AbbHEPTX (ORCPT ); Wed, 5 Aug 2015 11:19:23 -0400 From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: David Woodhouse , Alex Williamson , linux-kernel@vger.kernel.org, Joerg Roedel , jroedel@suse.de Subject: [PATCH 12/26] iommu/vt-d: Simplify domain_remove_one_dev_info() Date: Wed, 5 Aug 2015 17:18:43 +0200 Message-Id: <1438787937-7340-13-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438787937-7340-1-git-send-email-joro@8bytes.org> References: <1438787937-7340-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Simplify this function as much as possible with the new iommu_refcnt field. Signed-off-by: Joerg Roedel --- drivers/iommu/intel-iommu.c | 50 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index ae2343c..f59b4ef 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -4587,52 +4587,34 @@ static void iommu_detach_dependent_devices(struct intel_iommu *iommu, static void domain_remove_one_dev_info(struct dmar_domain *domain, struct device *dev) { - struct device_domain_info *info, *tmp; + struct device_domain_info *info; struct intel_iommu *iommu; unsigned long flags; - bool found = false; u8 bus, devfn; iommu = device_to_iommu(dev, &bus, &devfn); if (!iommu) return; - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry_safe(info, tmp, &domain->devices, link) { - if (info->iommu == iommu && info->bus == bus && - info->devfn == devfn) { - unlink_domain_info(info); - spin_unlock_irqrestore(&device_domain_lock, flags); - - iommu_disable_dev_iotlb(info); - iommu_detach_dev(iommu, info->bus, info->devfn); - iommu_detach_dependent_devices(iommu, dev); - free_devinfo_mem(info); - - spin_lock_irqsave(&device_domain_lock, flags); - - if (found) - break; - else - continue; - } + info = dev->archdata.iommu; - /* - * If there is no other devices under the same iommu owned by - * this domain, clear this iommu in iommu_refcnt update iommu - * count and coherency. - */ - if (info->iommu == iommu) - found = true; - } + if (WARN_ON(!info)) + return; + spin_lock_irqsave(&device_domain_lock, flags); + unlink_domain_info(info); spin_unlock_irqrestore(&device_domain_lock, flags); - if (found == 0) { - domain_detach_iommu(domain, iommu); - if (!domain_type_is_vm_or_si(domain)) - iommu_detach_domain(domain, iommu); - } + iommu_disable_dev_iotlb(info); + iommu_detach_dev(iommu, info->bus, info->devfn); + iommu_detach_dependent_devices(iommu, dev); + free_devinfo_mem(info); + domain_detach_iommu(domain, iommu); + + spin_lock_irqsave(&domain->iommu_lock, flags); + if (!domain->iommu_refcnt[iommu->seq_id]) + iommu_detach_domain(domain, iommu); + spin_unlock_irqrestore(&domain->iommu_lock, flags); } static int md_domain_init(struct dmar_domain *domain, int guest_width) -- 1.9.1