When device is already attached to a domain, there is no need to execute the domain_flush_tlb_pde(). Therefore move the check if the domain is set into attach_device().
Signed-off-by: Anna-Maria Gleixner <anna-ma...@linutronix.de> --- drivers/iommu/amd_iommu.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 38ec7cae0024..f9207e5b5901 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1878,8 +1878,11 @@ static void clear_dte_entry(u16 devid) amd_iommu_apply_erratum_63(devid); } -static void do_attach(struct iommu_dev_data *dev_data, - struct protection_domain *domain) +/* + * This function makes the device visible in the domain + */ +static void __attach_device(struct iommu_dev_data *dev_data, + struct protection_domain *domain) { struct amd_iommu *iommu; u16 alias; @@ -1932,23 +1935,6 @@ static void __detach_device(struct iommu_dev_data *dev_data) device_flush_dte(dev_data); } -/* - * If a device is not yet associated with a domain, this function makes the - * device visible in the domain - */ -static int __attach_device(struct iommu_dev_data *dev_data, - struct protection_domain *domain) -{ - if (dev_data->domain != NULL) - return -EBUSY; - - /* Attach alias group root */ - do_attach(dev_data, domain); - - return 0; -} - - static void pdev_iommuv2_disable(struct pci_dev *pdev) { pci_disable_ats(pdev); @@ -2045,7 +2031,6 @@ static int attach_device(struct device *dev, struct pci_dev *pdev; struct iommu_dev_data *dev_data; unsigned long flags; - int ret; dev_data = get_dev_data(dev); @@ -2073,8 +2058,11 @@ static int attach_device(struct device *dev, skip_ats_check: + if (dev_data->domain != NULL) + return -EBUSY; + spin_lock_irqsave(&domain->lock, flags); - ret = __attach_device(dev_data, domain); + __attach_device(dev_data, domain); spin_unlock_irqrestore(&domain->lock, flags); /* @@ -2084,7 +2072,7 @@ static int attach_device(struct device *dev, */ domain_flush_tlb_pde(domain); - return ret; + return 0; } /* -- 2.15.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu