Skip to content

Commit 67ffbce

Browse files
LuBaolugregkh
authored andcommitted
iommu/vt-d: Optimize iotlb_sync_map for non-caching/non-RWBF modes
commit 12724ce upstream. The iotlb_sync_map iommu ops allows drivers to perform necessary cache flushes when new mappings are established. For the Intel iommu driver, this callback specifically serves two purposes: - To flush caches when a second-stage page table is attached to a device whose iommu is operating in caching mode (CAP_REG.CM==1). - To explicitly flush internal write buffers to ensure updates to memory- resident remapping structures are visible to hardware (CAP_REG.RWBF==1). However, in scenarios where neither caching mode nor the RWBF flag is active, the cache_tag_flush_range_np() helper, which is called in the iotlb_sync_map path, effectively becomes a no-op. Despite being a no-op, cache_tag_flush_range_np() involves iterating through all cache tags of the iommu's attached to the domain, protected by a spinlock. This unnecessary execution path introduces overhead, leading to a measurable I/O performance regression. On systems with NVMes under the same bridge, performance was observed to drop from approximately ~6150 MiB/s down to ~4985 MiB/s. Introduce a flag in the dmar_domain structure. This flag will only be set when iotlb_sync_map is required (i.e., when CM or RWBF is set). The cache_tag_flush_range_np() is called only for domains where this flag is set. This flag, once set, is immutable, given that there won't be mixed configurations in real-world scenarios where some IOMMUs in a system operate in caching mode while others do not. Theoretically, the immutability of this flag does not impact functionality. Reported-by: Ioanna Alifieraki <[email protected]> Closes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2115738 Link: https://lore.kernel.org/r/[email protected] Fixes: 129dab6 ("iommu/vt-d: Use cache_tag_flush_range_np() in iotlb_sync_map") Cc: [email protected] Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a9dd296 commit 67ffbce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,18 @@ static int domain_setup_first_level(struct intel_iommu *iommu,
17951795
(pgd_t *)pgd, flags, old);
17961796
}
17971797

1798+
static bool domain_need_iotlb_sync_map(struct dmar_domain *domain,
1799+
struct intel_iommu *iommu)
1800+
{
1801+
if (cap_caching_mode(iommu->cap) && !domain->use_first_level)
1802+
return true;
1803+
1804+
if (rwbf_quirk || cap_rwbf(iommu->cap))
1805+
return true;
1806+
1807+
return false;
1808+
}
1809+
17981810
static int dmar_domain_attach_device(struct dmar_domain *domain,
17991811
struct device *dev)
18001812
{
@@ -1832,6 +1844,8 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
18321844
if (ret)
18331845
goto out_block_translation;
18341846

1847+
domain->iotlb_sync_map |= domain_need_iotlb_sync_map(domain, iommu);
1848+
18351849
return 0;
18361850

18371851
out_block_translation:
@@ -3953,7 +3967,10 @@ static bool risky_device(struct pci_dev *pdev)
39533967
static int intel_iommu_iotlb_sync_map(struct iommu_domain *domain,
39543968
unsigned long iova, size_t size)
39553969
{
3956-
cache_tag_flush_range_np(to_dmar_domain(domain), iova, iova + size - 1);
3970+
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
3971+
3972+
if (dmar_domain->iotlb_sync_map)
3973+
cache_tag_flush_range_np(dmar_domain, iova, iova + size - 1);
39573974

39583975
return 0;
39593976
}

drivers/iommu/intel/iommu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ struct dmar_domain {
614614
u8 has_mappings:1; /* Has mappings configured through
615615
* iommu_map() interface.
616616
*/
617+
u8 iotlb_sync_map:1; /* Need to flush IOTLB cache or write
618+
* buffer when creating mappings.
619+
*/
617620

618621
spinlock_t lock; /* Protect device tracking lists */
619622
struct list_head devices; /* all devices' list */

0 commit comments

Comments
 (0)