[PATCH 5/5] iommu/amd: Hold the domain lock when calling domain_flush_tlb[_pde]

From: Filippo Sironi
Date: Tue Sep 10 2019 - 13:50:09 EST


From: Wei Wang <wawei@xxxxxxxxx>

domain_flush_tlb[_pde] traverses the device list, which is protected by
the domain lock.

Signed-off-by: Wei Wang <wawei@xxxxxxxxx>
Signed-off-by: Filippo Sironi <sironi@xxxxxxxxx>
---
drivers/iommu/amd_iommu.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3714ae5ded31..f5df23acd1c7 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -1806,7 +1806,11 @@ static void free_gcr3_table(struct protection_domain *domain)

static void dma_ops_domain_flush_tlb(struct dma_ops_domain *dom)
{
+ unsigned long flags;
+
+ spin_lock_irqsave(&dom->domain.lock, flags);
domain_flush_tlb(&dom->domain);
+ spin_unlock_irqrestore(&dom->domain.lock, flags);
domain_flush_complete(&dom->domain);
}

@@ -2167,7 +2171,9 @@ static int attach_device(struct device *dev,
* left the caches in the IOMMU dirty. So we have to flush
* here to evict all dirty stuff.
*/
+ spin_lock_irqsave(&domain->lock, flags);
domain_flush_tlb_pde(domain);
+ spin_unlock_irqrestore(&domain->lock, flags);

domain_flush_complete(domain);

@@ -3245,8 +3251,11 @@ static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain,
static void amd_iommu_flush_iotlb_all(struct iommu_domain *domain)
{
struct protection_domain *dom = to_pdomain(domain);
+ unsigned long flags;

+ spin_lock_irqsave(&dom->lock, flags);
domain_flush_tlb_pde(dom);
+ spin_unlock_irqrestore(&dom->lock, flags);
domain_flush_complete(dom);
}

--
2.7.4