public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-direct: Set SG_DMA_SWIOTLB flag for dma-direct
@ 2024-05-03 18:37 T.J. Mercier
  2024-05-04  8:53 ` Petr Tesařík
  2024-05-06  5:29 ` Christoph Hellwig
  0 siblings, 2 replies; 19+ messages in thread
From: T.J. Mercier @ 2024-05-03 18:37 UTC (permalink / raw)
  To: tjmercier, Christoph Hellwig, Marek Szyprowski, Robin Murphy
  Cc: isaacmanjarres, iommu, linux-kernel

As of commit 861370f49ce4 ("iommu/dma: force bouncing if the size is
not cacheline-aligned") sg_dma_mark_swiotlb is called when
dma_map_sgtable takes the IOMMU path and uses SWIOTLB for some portion
of a scatterlist. It is never set for the direct path, so drivers
cannot always rely on sg_dma_is_swiotlb to return correctly after
calling dma_map_sgtable. Fix this by calling sg_dma_mark_swiotlb in the
direct path like it is in the IOMMU path.

Signed-off-by: T.J. Mercier <tjmercier@google.com>
---
 kernel/dma/direct.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 4d543b1e9d57..52f0dcb25ca2 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -12,7 +12,7 @@
 #include <linux/pfn.h>
 #include <linux/vmalloc.h>
 #include <linux/set_memory.h>
-#include <linux/slab.h>
+#include <linux/swiotlb.h>
 #include "direct.h"
 
 /*
@@ -497,6 +497,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 			goto out_unmap;
 		}
 		sg_dma_len(sg) = sg->length;
+		if (is_swiotlb_buffer(dev, dma_to_phys(dev, sg->dma_address)))
+			sg_dma_mark_swiotlb(sg);
 	}
 
 	return nents;
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-05-09 18:32 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-03 18:37 [PATCH] dma-direct: Set SG_DMA_SWIOTLB flag for dma-direct T.J. Mercier
2024-05-04  8:53 ` Petr Tesařík
2024-05-09 13:28   ` Robin Murphy
2024-05-06  5:29 ` Christoph Hellwig
2024-05-06 16:00   ` T.J. Mercier
2024-05-06 16:02     ` Christoph Hellwig
2024-05-06 16:10       ` T.J. Mercier
2024-05-06 16:19         ` Christoph Hellwig
2024-05-06 16:39           ` T.J. Mercier
2024-05-07  5:43             ` Christoph Hellwig
2024-05-07 20:07               ` T.J. Mercier
2024-05-08 11:33                 ` Christoph Hellwig
2024-05-09 12:54                   ` Robin Murphy
2024-05-09 18:26                     ` T.J. Mercier
2024-05-08 17:19                 ` Catalin Marinas
2024-05-08 20:14                   ` T.J. Mercier
2024-05-09  7:49                     ` Catalin Marinas
2024-05-09 13:06                       ` Christoph Hellwig
2024-05-09 18:32                         ` T.J. Mercier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox