Skip to content

Commit 3b122a5

Browse files
anadavjoergroedel
authored andcommitted
iommu/amd: Sync once for scatter-gather operations
On virtual machines, software must flush the IOTLB after each page table entry update. The iommu_map_sg() code iterates through the given scatter-gather list and invokes iommu_map() for each element in the scatter-gather list, which calls into the vendor IOMMU driver through iommu_ops callback. As the result, a single sg mapping may lead to multiple IOTLB flushes. Fix this by adding amd_iotlb_sync_map() callback and flushing at this point after all sg mappings we set. This commit is followed and inspired by commit 933fcd0 ("iommu/vt-d: Add iotlb_sync_map callback"). 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 fe6d269 commit 3b122a5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,16 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,
20282028
return ret;
20292029
}
20302030

2031+
static void amd_iommu_iotlb_sync_map(struct iommu_domain *dom,
2032+
unsigned long iova, size_t size)
2033+
{
2034+
struct protection_domain *domain = to_pdomain(dom);
2035+
struct io_pgtable_ops *ops = &domain->iop.iop.ops;
2036+
2037+
if (ops->map)
2038+
domain_flush_np_cache(domain, iova, size);
2039+
}
2040+
20312041
static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
20322042
phys_addr_t paddr, size_t page_size, int iommu_prot,
20332043
gfp_t gfp)
@@ -2046,10 +2056,8 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
20462056
if (iommu_prot & IOMMU_WRITE)
20472057
prot |= IOMMU_PROT_IW;
20482058

2049-
if (ops->map) {
2059+
if (ops->map)
20502060
ret = ops->map(ops, iova, paddr, page_size, prot, gfp);
2051-
domain_flush_np_cache(domain, iova, page_size);
2052-
}
20532061

20542062
return ret;
20552063
}
@@ -2229,6 +2237,7 @@ const struct iommu_ops amd_iommu_ops = {
22292237
.attach_dev = amd_iommu_attach_device,
22302238
.detach_dev = amd_iommu_detach_device,
22312239
.map = amd_iommu_map,
2240+
.iotlb_sync_map = amd_iommu_iotlb_sync_map,
22322241
.unmap = amd_iommu_unmap,
22332242
.iova_to_phys = amd_iommu_iova_to_phys,
22342243
.probe_device = amd_iommu_probe_device,

0 commit comments

Comments
 (0)