Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Leon Romanovsky and committed by
Marek Szyprowski
636e6572 2536617f

+17 -4
+17 -4
drivers/iommu/dma-iommu.c
··· 1211 1211 */ 1212 1212 if (dev_use_swiotlb(dev, size, dir) && 1213 1213 iova_unaligned(iovad, phys, size)) { 1214 - if (attrs & DMA_ATTR_MMIO) 1214 + if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) 1215 1215 return DMA_MAPPING_ERROR; 1216 1216 1217 1217 phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs); ··· 1223 1223 arch_sync_dma_for_device(phys, size, dir); 1224 1224 1225 1225 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))) 1227 1228 swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); 1228 1229 return iova; 1229 1230 } ··· 1234 1233 { 1235 1234 phys_addr_t phys; 1236 1235 1237 - if (attrs & DMA_ATTR_MMIO) { 1236 + if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) { 1238 1237 __iommu_dma_unmap(dev, dma_handle, size); 1239 1238 return; 1240 1239 } ··· 1946 1945 if (WARN_ON_ONCE(iova_start_pad && offset > 0)) 1947 1946 return -EIO; 1948 1947 1948 + /* 1949 + * DMA_IOVA_USE_SWIOTLB is set on state after some entry 1950 + * took SWIOTLB path, which we were supposed to prevent 1951 + * for DMA_ATTR_REQUIRE_COHERENT attribute. 1952 + */ 1953 + if (WARN_ON_ONCE((state->__size & DMA_IOVA_USE_SWIOTLB) && 1954 + (attrs & DMA_ATTR_REQUIRE_COHERENT))) 1955 + return -EOPNOTSUPP; 1956 + 1957 + if (!dev_is_dma_coherent(dev) && (attrs & DMA_ATTR_REQUIRE_COHERENT)) 1958 + return -EOPNOTSUPP; 1959 + 1949 1960 if (dev_use_swiotlb(dev, size, dir) && 1950 1961 iova_unaligned(iovad, phys, size)) { 1951 - if (attrs & DMA_ATTR_MMIO) 1962 + if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) 1952 1963 return -EPERM; 1953 1964 1954 1965 return iommu_dma_iova_link_swiotlb(dev, state, phys, offset,