> On 25. Sep 2019, at 06:22, Joerg Roedel <j...@8bytes.org> wrote:
>
> From: Joerg Roedel <jroe...@suse.de>
>
> Check early in attach_device whether the device is already attached to a
> domain. This also simplifies the code path so that __attach_device() can
> be removed.
>
> Fixes: 92d420ec028d ("iommu/amd: Relax locking in dma_ops path")
> Signed-off-by: Joerg Roedel <jroe...@suse.de>
> ---
> drivers/iommu/amd_iommu.c | 25 +++++++------------------
> 1 file changed, 7 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
> index 2919168577ff..459247c32dc0 100644
> --- a/drivers/iommu/amd_iommu.c
> +++ b/drivers/iommu/amd_iommu.c
> @@ -2072,23 +2072,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
> domain->dev_cnt -= 1;
> }
>
> -/*
> - * 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);
> @@ -2174,6 +2157,10 @@ static int attach_device(struct device *dev,
>
> dev_data = get_dev_data(dev);
>
> + ret = -EBUSY;
> + if (dev_data->domain != NULL)
> + goto out;
> +
> if (!dev_is_pci(dev))
> goto skip_ats_check;
>
> @@ -2198,7 +2185,9 @@ static int attach_device(struct device *dev,
> }
>
> skip_ats_check:
> - ret = __attach_device(dev_data, domain);
> + ret = 0;
> +
> + do_attach(dev_data, domain);
>
> /*
> * We might boot into a crash-kernel here. The crashed kernel
> --
> 2.17.1
>
Reviewed-by: Filippo Sironi <sir...@amazon.de>
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu