Skip to content

Commit 6f01a73

Browse files
niklas88joergroedel
authored andcommitted
iommu/virtio: Add ops->flush_iotlb_all and enable deferred flush
Add ops->flush_iotlb_all operation to enable virtio-iommu for the dma-iommu deferred flush scheme. This results in a significant increase in performance in exchange for a window in which devices can still access previously IOMMU mapped memory when running with CONFIG_IOMMU_DEFAULT_DMA_LAZY. The previous strict behavior can be achieved with iommu.strict=1 on the kernel command line or CONFIG_IOMMU_DEFAULT_DMA_STRICT. Link: https://lore.kernel.org/lkml/20230802123612.GA6142@myrica/ Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Link: https://lore.kernel.org/r/20231120-viommu-sync-map-v3-2-50a57ecf78b5@linux.ibm.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 00271ca commit 6f01a73

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/iommu/virtio-iommu.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,19 @@ static int viommu_iotlb_sync_map(struct iommu_domain *domain,
926926
return viommu_sync_req(vdomain->viommu);
927927
}
928928

929+
static void viommu_flush_iotlb_all(struct iommu_domain *domain)
930+
{
931+
struct viommu_domain *vdomain = to_viommu_domain(domain);
932+
933+
/*
934+
* May be called before the viommu is initialized including
935+
* while creating direct mapping
936+
*/
937+
if (!vdomain->nr_endpoints)
938+
return;
939+
viommu_sync_req(vdomain->viommu);
940+
}
941+
929942
static void viommu_get_resv_regions(struct device *dev, struct list_head *head)
930943
{
931944
struct iommu_resv_region *entry, *new_entry, *msi = NULL;
@@ -1051,6 +1064,8 @@ static bool viommu_capable(struct device *dev, enum iommu_cap cap)
10511064
switch (cap) {
10521065
case IOMMU_CAP_CACHE_COHERENCY:
10531066
return true;
1067+
case IOMMU_CAP_DEFERRED_FLUSH:
1068+
return true;
10541069
default:
10551070
return false;
10561071
}
@@ -1071,6 +1086,7 @@ static struct iommu_ops viommu_ops = {
10711086
.map_pages = viommu_map_pages,
10721087
.unmap_pages = viommu_unmap_pages,
10731088
.iova_to_phys = viommu_iova_to_phys,
1089+
.flush_iotlb_all = viommu_flush_iotlb_all,
10741090
.iotlb_sync = viommu_iotlb_sync,
10751091
.iotlb_sync_map = viommu_iotlb_sync_map,
10761092
.free = viommu_domain_free,

0 commit comments

Comments
 (0)