Skip to content

Commit 3a11905

Browse files
committed
iommu/amd: Remove amd_iommu_devtable_lock
The lock is not necessary because the device table does not contain shared state that needs protection. Locking is only needed on an individual entry basis, and that needs to happen on the iommu_dev_data level. 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 f15d9a9 commit 3a11905

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
*/
7171
#define AMD_IOMMU_PGSIZES ((~0xFFFUL) & ~(2ULL << 38))
7272

73-
static DEFINE_SPINLOCK(amd_iommu_devtable_lock);
7473
static DEFINE_SPINLOCK(pd_bitmap_lock);
7574

7675
/* List of all available dev_data structures */
@@ -2080,10 +2079,11 @@ static void do_detach(struct iommu_dev_data *dev_data)
20802079
static int __attach_device(struct iommu_dev_data *dev_data,
20812080
struct protection_domain *domain)
20822081
{
2082+
unsigned long flags;
20832083
int ret;
20842084

20852085
/* lock domain */
2086-
spin_lock(&domain->lock);
2086+
spin_lock_irqsave(&domain->lock, flags);
20872087

20882088
ret = -EBUSY;
20892089
if (dev_data->domain != NULL)
@@ -2097,7 +2097,7 @@ static int __attach_device(struct iommu_dev_data *dev_data,
20972097
out_unlock:
20982098

20992099
/* ready */
2100-
spin_unlock(&domain->lock);
2100+
spin_unlock_irqrestore(&domain->lock, flags);
21012101

21022102
return ret;
21032103
}
@@ -2181,7 +2181,6 @@ static int attach_device(struct device *dev,
21812181
{
21822182
struct pci_dev *pdev;
21832183
struct iommu_dev_data *dev_data;
2184-
unsigned long flags;
21852184
int ret;
21862185

21872186
dev_data = get_dev_data(dev);
@@ -2209,9 +2208,7 @@ static int attach_device(struct device *dev,
22092208
}
22102209

22112210
skip_ats_check:
2212-
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
22132211
ret = __attach_device(dev_data, domain);
2214-
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
22152212

22162213
/*
22172214
* We might boot into a crash-kernel here. The crashed kernel
@@ -2231,14 +2228,15 @@ static int attach_device(struct device *dev,
22312228
static void __detach_device(struct iommu_dev_data *dev_data)
22322229
{
22332230
struct protection_domain *domain;
2231+
unsigned long flags;
22342232

22352233
domain = dev_data->domain;
22362234

2237-
spin_lock(&domain->lock);
2235+
spin_lock_irqsave(&domain->lock, flags);
22382236

22392237
do_detach(dev_data);
22402238

2241-
spin_unlock(&domain->lock);
2239+
spin_unlock_irqrestore(&domain->lock, flags);
22422240
}
22432241

22442242
/*
@@ -2248,7 +2246,6 @@ static void detach_device(struct device *dev)
22482246
{
22492247
struct protection_domain *domain;
22502248
struct iommu_dev_data *dev_data;
2251-
unsigned long flags;
22522249

22532250
dev_data = get_dev_data(dev);
22542251
domain = dev_data->domain;
@@ -2262,10 +2259,7 @@ static void detach_device(struct device *dev)
22622259
if (WARN_ON(!dev_data->domain))
22632260
return;
22642261

2265-
/* lock device table */
2266-
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
22672262
__detach_device(dev_data);
2268-
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
22692263

22702264
if (!dev_is_pci(dev))
22712265
return;
@@ -2910,18 +2904,13 @@ int __init amd_iommu_init_dma_ops(void)
29102904
static void cleanup_domain(struct protection_domain *domain)
29112905
{
29122906
struct iommu_dev_data *entry;
2913-
unsigned long flags;
2914-
2915-
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
29162907

29172908
while (!list_empty(&domain->dev_list)) {
29182909
entry = list_first_entry(&domain->dev_list,
29192910
struct iommu_dev_data, list);
29202911
BUG_ON(!entry->domain);
29212912
__detach_device(entry);
29222913
}
2923-
2924-
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
29252914
}
29262915

29272916
static void protection_domain_free(struct protection_domain *domain)

0 commit comments

Comments
 (0)