Skip to content

Commit fc65d0a

Browse files
anadavjoergroedel
authored andcommitted
iommu/amd: Selective flush on unmap
Recent patch attempted to enable selective page flushes on AMD IOMMU but neglected to adapt amd_iommu_iotlb_sync() to use the selective flushes. Adapt amd_iommu_iotlb_sync() to use selective flushes and change amd_iommu_unmap() to collect the flushes. As a defensive measure, to avoid potential issues as those that the Intel IOMMU driver encountered recently, flush the page-walk caches by always setting the "pde" parameter. This can be removed later. Cc: Joerg Roedel <[email protected]> Cc: Will Deacon <[email protected]> Cc: Jiajun Cao <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Lu Baolu <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Nadav Amit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ee974d9 commit fc65d0a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,12 +2060,17 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
20602060
{
20612061
struct protection_domain *domain = to_pdomain(dom);
20622062
struct io_pgtable_ops *ops = &domain->iop.iop.ops;
2063+
size_t r;
20632064

20642065
if ((amd_iommu_pgtable == AMD_IOMMU_V1) &&
20652066
(domain->iop.mode == PAGE_MODE_NONE))
20662067
return 0;
20672068

2068-
return (ops->unmap) ? ops->unmap(ops, iova, page_size, gather) : 0;
2069+
r = (ops->unmap) ? ops->unmap(ops, iova, page_size, gather) : 0;
2070+
2071+
iommu_iotlb_gather_add_page(dom, gather, iova, page_size);
2072+
2073+
return r;
20692074
}
20702075

20712076
static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
@@ -2168,7 +2173,13 @@ static void amd_iommu_flush_iotlb_all(struct iommu_domain *domain)
21682173
static void amd_iommu_iotlb_sync(struct iommu_domain *domain,
21692174
struct iommu_iotlb_gather *gather)
21702175
{
2171-
amd_iommu_flush_iotlb_all(domain);
2176+
struct protection_domain *dom = to_pdomain(domain);
2177+
unsigned long flags;
2178+
2179+
spin_lock_irqsave(&dom->lock, flags);
2180+
__domain_flush_pages(dom, gather->start, gather->end - gather->start, 1);
2181+
amd_iommu_domain_flush_complete(dom);
2182+
spin_unlock_irqrestore(&dom->lock, flags);
21722183
}
21732184

21742185
static int amd_iommu_def_domain_type(struct device *dev)

0 commit comments

Comments
 (0)