Skip to content

Commit 78d5f0f

Browse files
anadavDavid Woodhouse
authored andcommitted
intel-iommu: Avoid global flushes with caching mode.
While it may be efficient on real hardware, emulation of global invalidations is very expensive as all shadow entries must be examined. This patch changes the behaviour when caching mode is enabled (which is the case when IOMMU emulation takes place). In this case, page specific invalidation is used instead. Signed-off-by: Nadav Amit <[email protected]> Signed-off-by: David Woodhouse <[email protected]>
1 parent 8265363 commit 78d5f0f

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/pci/intel-iommu.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,15 +2647,24 @@ static void flush_unmaps(void)
26472647
if (!deferred_flush[i].next)
26482648
continue;
26492649

2650-
iommu->flush.flush_iotlb(iommu, 0, 0, 0,
2650+
/* In caching mode, global flushes turn emulation expensive */
2651+
if (!cap_caching_mode(iommu->cap))
2652+
iommu->flush.flush_iotlb(iommu, 0, 0, 0,
26512653
DMA_TLB_GLOBAL_FLUSH);
26522654
for (j = 0; j < deferred_flush[i].next; j++) {
26532655
unsigned long mask;
26542656
struct iova *iova = deferred_flush[i].iova[j];
2655-
2656-
mask = ilog2(mm_to_dma_pfn(iova->pfn_hi - iova->pfn_lo + 1));
2657-
iommu_flush_dev_iotlb(deferred_flush[i].domain[j],
2658-
(uint64_t)iova->pfn_lo << PAGE_SHIFT, mask);
2657+
struct dmar_domain *domain = deferred_flush[i].domain[j];
2658+
2659+
/* On real hardware multiple invalidations are expensive */
2660+
if (cap_caching_mode(iommu->cap))
2661+
iommu_flush_iotlb_psi(iommu, domain->id,
2662+
iova->pfn_lo, iova->pfn_hi - iova->pfn_lo + 1, 0);
2663+
else {
2664+
mask = ilog2(mm_to_dma_pfn(iova->pfn_hi - iova->pfn_lo + 1));
2665+
iommu_flush_dev_iotlb(deferred_flush[i].domain[j],
2666+
(uint64_t)iova->pfn_lo << PAGE_SHIFT, mask);
2667+
}
26592668
__free_iova(&deferred_flush[i].domain[j]->iovad, iova);
26602669
}
26612670
deferred_flush[i].next = 0;

0 commit comments

Comments
 (0)