Skip to content

Commit 636e657

Browse files
rleonmszyprow
authored andcommitted
iommu/dma: add support for DMA_ATTR_REQUIRE_COHERENT attribute
Add support for the DMA_ATTR_REQUIRE_COHERENT attribute to the exported functions. This attribute indicates that the SWIOTLB path must not be used and that no sync operations should be performed. Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20260316-dma-debug-overlap-v3-6-1dde90a7f08b@nvidia.com
1 parent 2536617 commit 636e657

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

drivers/iommu/dma-iommu.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
12111211
*/
12121212
if (dev_use_swiotlb(dev, size, dir) &&
12131213
iova_unaligned(iovad, phys, size)) {
1214-
if (attrs & DMA_ATTR_MMIO)
1214+
if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT))
12151215
return DMA_MAPPING_ERROR;
12161216

12171217
phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs);
@@ -1223,7 +1223,8 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
12231223
arch_sync_dma_for_device(phys, size, dir);
12241224

12251225
iova = __iommu_dma_map(dev, phys, size, prot, dma_mask);
1226-
if (iova == DMA_MAPPING_ERROR && !(attrs & DMA_ATTR_MMIO))
1226+
if (iova == DMA_MAPPING_ERROR &&
1227+
!(attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)))
12271228
swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
12281229
return iova;
12291230
}
@@ -1233,7 +1234,7 @@ void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle,
12331234
{
12341235
phys_addr_t phys;
12351236

1236-
if (attrs & DMA_ATTR_MMIO) {
1237+
if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) {
12371238
__iommu_dma_unmap(dev, dma_handle, size);
12381239
return;
12391240
}
@@ -1945,9 +1946,21 @@ int dma_iova_link(struct device *dev, struct dma_iova_state *state,
19451946
if (WARN_ON_ONCE(iova_start_pad && offset > 0))
19461947
return -EIO;
19471948

1949+
/*
1950+
* DMA_IOVA_USE_SWIOTLB is set on state after some entry
1951+
* took SWIOTLB path, which we were supposed to prevent
1952+
* for DMA_ATTR_REQUIRE_COHERENT attribute.
1953+
*/
1954+
if (WARN_ON_ONCE((state->__size & DMA_IOVA_USE_SWIOTLB) &&
1955+
(attrs & DMA_ATTR_REQUIRE_COHERENT)))
1956+
return -EOPNOTSUPP;
1957+
1958+
if (!dev_is_dma_coherent(dev) && (attrs & DMA_ATTR_REQUIRE_COHERENT))
1959+
return -EOPNOTSUPP;
1960+
19481961
if (dev_use_swiotlb(dev, size, dir) &&
19491962
iova_unaligned(iovad, phys, size)) {
1950-
if (attrs & DMA_ATTR_MMIO)
1963+
if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT))
19511964
return -EPERM;
19521965

19531966
return iommu_dma_iova_link_swiotlb(dev, state, phys, offset,

0 commit comments

Comments
 (0)