Skip to content

Commit

Permalink
iommu/amd: Make amd_iommu_devtable_lock a spin_lock
Browse files Browse the repository at this point in the history
Before commit 0bb6e24 ("iommu/amd: Support IOMMU_DOMAIN_DMA type
allocation") amd_iommu_devtable_lock had a read_lock() user but now
there are none. In fact, after the mentioned commit we had only
write_lock() user of the lock. Since there is no reason to keep it as
writer lock, change its type to a spin_lock.
I *think* that we might even be able to remove the lock because all its
current user seem to have their own protection.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Sebastian Andrzej Siewior authored and Joerg Roedel committed Mar 29, 2018
1 parent 993ca6e commit 2cd1083
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions drivers/iommu/amd_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
*/
#define AMD_IOMMU_PGSIZES ((~0xFFFUL) & ~(2ULL << 38))

static DEFINE_RWLOCK(amd_iommu_devtable_lock);
static DEFINE_SPINLOCK(amd_iommu_devtable_lock);
static DEFINE_SPINLOCK(pd_bitmap_lock);
static DEFINE_SPINLOCK(iommu_table_lock);

Expand Down Expand Up @@ -2097,9 +2097,9 @@ static int attach_device(struct device *dev,
}

skip_ats_check:
write_lock_irqsave(&amd_iommu_devtable_lock, flags);
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
ret = __attach_device(dev_data, domain);
write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);

/*
* We might boot into a crash-kernel here. The crashed kernel
Expand Down Expand Up @@ -2149,9 +2149,9 @@ static void detach_device(struct device *dev)
domain = dev_data->domain;

/* lock device table */
write_lock_irqsave(&amd_iommu_devtable_lock, flags);
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);
__detach_device(dev_data);
write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);

if (!dev_is_pci(dev))
return;
Expand Down Expand Up @@ -2814,15 +2814,15 @@ static void cleanup_domain(struct protection_domain *domain)
struct iommu_dev_data *entry;
unsigned long flags;

write_lock_irqsave(&amd_iommu_devtable_lock, flags);
spin_lock_irqsave(&amd_iommu_devtable_lock, flags);

while (!list_empty(&domain->dev_list)) {
entry = list_first_entry(&domain->dev_list,
struct iommu_dev_data, list);
__detach_device(entry);
}

write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
spin_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
}

static void protection_domain_free(struct protection_domain *domain)
Expand Down

0 comments on commit 2cd1083

Please sign in to comment.