Skip to content

Commit 45e528d

Browse files
committed
iommu/amd: Check for busy devices earlier in attach_device()
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: 92d420e ("iommu/amd: Relax locking in dma_ops path") Reviewed-by: Filippo Sironi <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent f6c0bfc commit 45e528d

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,23 +2072,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
20722072
domain->dev_cnt -= 1;
20732073
}
20742074

2075-
/*
2076-
* If a device is not yet associated with a domain, this function makes the
2077-
* device visible in the domain
2078-
*/
2079-
static int __attach_device(struct iommu_dev_data *dev_data,
2080-
struct protection_domain *domain)
2081-
{
2082-
if (dev_data->domain != NULL)
2083-
return -EBUSY;
2084-
2085-
/* Attach alias group root */
2086-
do_attach(dev_data, domain);
2087-
2088-
return 0;
2089-
}
2090-
2091-
20922075
static void pdev_iommuv2_disable(struct pci_dev *pdev)
20932076
{
20942077
pci_disable_ats(pdev);
@@ -2174,6 +2157,10 @@ static int attach_device(struct device *dev,
21742157

21752158
dev_data = get_dev_data(dev);
21762159

2160+
ret = -EBUSY;
2161+
if (dev_data->domain != NULL)
2162+
goto out;
2163+
21772164
if (!dev_is_pci(dev))
21782165
goto skip_ats_check;
21792166

@@ -2198,7 +2185,9 @@ static int attach_device(struct device *dev,
21982185
}
21992186

22002187
skip_ats_check:
2201-
ret = __attach_device(dev_data, domain);
2188+
ret = 0;
2189+
2190+
do_attach(dev_data, domain);
22022191

22032192
/*
22042193
* We might boot into a crash-kernel here. The crashed kernel

0 commit comments

Comments
 (0)