@@ -376,6 +376,22 @@ static int iommu_completion_wait(struct amd_iommu *iommu)
376376 return 0 ;
377377}
378378
379+ static void iommu_flush_complete (struct protection_domain * domain )
380+ {
381+ int i ;
382+
383+ for (i = 0 ; i < amd_iommus_present ; ++ i ) {
384+ if (!domain -> dev_iommu [i ])
385+ continue ;
386+
387+ /*
388+ * Devices of this domain are behind this IOMMU
389+ * We need to wait for completion of all commands.
390+ */
391+ iommu_completion_wait (amd_iommus [i ]);
392+ }
393+ }
394+
379395/*
380396 * Command send function for invalidating a device table entry
381397 */
@@ -1758,7 +1774,7 @@ static dma_addr_t map_page(struct device *dev, struct page *page,
17581774 if (addr == DMA_ERROR_CODE )
17591775 goto out ;
17601776
1761- iommu_completion_wait ( iommu );
1777+ iommu_flush_complete ( domain );
17621778
17631779out :
17641780 spin_unlock_irqrestore (& domain -> lock , flags );
@@ -1791,7 +1807,7 @@ static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
17911807
17921808 __unmap_single (iommu , domain -> priv , dma_addr , size , dir );
17931809
1794- iommu_completion_wait ( iommu );
1810+ iommu_flush_complete ( domain );
17951811
17961812 spin_unlock_irqrestore (& domain -> lock , flags );
17971813}
@@ -1863,7 +1879,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
18631879 goto unmap ;
18641880 }
18651881
1866- iommu_completion_wait ( iommu );
1882+ iommu_flush_complete ( domain );
18671883
18681884out :
18691885 spin_unlock_irqrestore (& domain -> lock , flags );
@@ -1914,7 +1930,7 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist,
19141930 s -> dma_address = s -> dma_length = 0 ;
19151931 }
19161932
1917- iommu_completion_wait ( iommu );
1933+ iommu_flush_complete ( domain );
19181934
19191935 spin_unlock_irqrestore (& domain -> lock , flags );
19201936}
@@ -1969,7 +1985,7 @@ static void *alloc_coherent(struct device *dev, size_t size,
19691985 goto out_free ;
19701986 }
19711987
1972- iommu_completion_wait ( iommu );
1988+ iommu_flush_complete ( domain );
19731989
19741990 spin_unlock_irqrestore (& domain -> lock , flags );
19751991
@@ -2010,7 +2026,7 @@ static void free_coherent(struct device *dev, size_t size,
20102026
20112027 __unmap_single (iommu , domain -> priv , dma_addr , size , DMA_BIDIRECTIONAL );
20122028
2013- iommu_completion_wait ( iommu );
2029+ iommu_flush_complete ( domain );
20142030
20152031 spin_unlock_irqrestore (& domain -> lock , flags );
20162032
0 commit comments