Skip to content

Commit 2536617

Browse files
rleonmszyprow
authored andcommitted
dma-direct: prevent SWIOTLB path when DMA_ATTR_REQUIRE_COHERENT is set
DMA_ATTR_REQUIRE_COHERENT indicates that SWIOTLB must not be used. Ensure the SWIOTLB path is declined whenever the DMA direct path is selected. 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-5-1dde90a7f08b@nvidia.com
1 parent e6a58fa commit 2536617

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

kernel/dma/direct.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static inline dma_addr_t dma_direct_map_phys(struct device *dev,
8484
dma_addr_t dma_addr;
8585

8686
if (is_swiotlb_force_bounce(dev)) {
87-
if (attrs & DMA_ATTR_MMIO)
87+
if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT))
8888
return DMA_MAPPING_ERROR;
8989

9090
return swiotlb_map(dev, phys, size, dir, attrs);
@@ -98,7 +98,8 @@ static inline dma_addr_t dma_direct_map_phys(struct device *dev,
9898
dma_addr = phys_to_dma(dev, phys);
9999
if (unlikely(!dma_capable(dev, dma_addr, size, true)) ||
100100
dma_kmalloc_needs_bounce(dev, size, dir)) {
101-
if (is_swiotlb_active(dev))
101+
if (is_swiotlb_active(dev) &&
102+
!(attrs & DMA_ATTR_REQUIRE_COHERENT))
102103
return swiotlb_map(dev, phys, size, dir, attrs);
103104

104105
goto err_overflow;
@@ -123,7 +124,7 @@ static inline void dma_direct_unmap_phys(struct device *dev, dma_addr_t addr,
123124
{
124125
phys_addr_t phys;
125126

126-
if (attrs & DMA_ATTR_MMIO)
127+
if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT))
127128
/* nothing to do: uncached and no swiotlb */
128129
return;
129130

0 commit comments

Comments
 (0)