Skip to contentSkip to conversation

iommu: Avoid unnecessary cache invalidations

PATCH Applied Lu Baolu 3 participants 3 messages Oct 26, 2023 – Oct 27, 2023 IOMMU

lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 iommu: Avoid unnecessary cache invalidations

The iommu_create_device_direct_mappings() only needs to flush the caches when the mappings are changed in the affected domain. This is not true for non-DMA domains, or for devices attached to the domain that have no reserved regions. To avoid unnecessary cache invalidations, add a check before iommu_flush_iotlb_all().

Fixes a48ce36e2786 ("iommu: Prevent RESV_DIRECT devices from blocking domains")
---
 drivers/iommu/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +2 -1
index 00d0a2b5d7dc..0cb676590bfa 100644
@@ -1114,7 +1114,8 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
 
 	}
 
-	iommu_flush_iotlb_all(domain);
+	if (!list_empty(&mappings) && iommu_is_dma_domain(domain))
+		iommu_flush_iotlb_all(domain);
 
 out:
 	iommu_put_resv_regions(dev, &mappings);
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Lu Baolu

The iommu_create_device_direct_mappings() only needs to flush the caches when the mappings are changed in the affected domain. This is not true for non-DMA domains, or for devices attached to the domain that have no reserved regions. To avoid unnecessary cache invalidations, add a check before iommu_flush_iotlb_all().

This also fixes a boot failure on Sapphire Rapids built with CONFIG_IOMMU_DEFAULT_PASSTHROUGH=y or the equivalent via kernel command line parameters.

Quoted 3 lines
Fixes a48ce36e2786 ("iommu: Prevent RESV_DIRECT devices from blocking domains")
Quoted 22 lines

---
drivers/iommu/iommu.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +2 -1
index 00d0a2b5d7dc..0cb676590bfa 100644
@@ -1114,7 +1114,8 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
 
 	}
 
-	iommu_flush_iotlb_all(domain);
+	if (!list_empty(&mappings) && iommu_is_dma_domain(domain))
+		iommu_flush_iotlb_all(domain);
 

out:

	iommu_put_resv_regions(dev, &mappings);
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw
In reply to Lu Baolu
Quoted 11 lines · Lu Baolu

The iommu_create_device_direct_mappings() only needs to flush the caches when the mappings are changed in the affected domain. This is not true for non-DMA domains, or for devices attached to the domain that have no reserved regions. To avoid unnecessary cache invalidations, add a check before iommu_flush_iotlb_all().

Fixes a48ce36e2786 ("iommu: Prevent RESV_DIRECT devices from blocking domains")
---
 drivers/iommu/iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks.