[RFC PATCH 1/3] dma-buf: keep the DMA flags in the DMABUF_DEBUG copy
From: Karl Mehltretter
Date: Mon Oct 05 2026 - 02:45:42 EST
With DMABUF_DEBUG, dma_buf_map_attachment() hands the importer a copy
of the sg_table that keeps only sg_dma_address() and sg_dma_len(). The
dma_flags (SG_DMA_BUS_ADDRESS, SG_DMA_SWIOTLB) are dropped.
The flags describe the DMA side of an entry, which is the side
importers may use. Copy them as well.
This is not a bug fix. No importer reads the flags today. Their only
readers are dma-iommu, dma-direct and iommu_map_sg(), which are not
supposed to see an importer's copy at all. The warn mode added in the
next patch keeps its marker in dma_flags and lets importers that do
get there continue. They should then see the same flags as without
DMABUF_DEBUG.
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
Notes:
Built alone on x86_64 with NEED_SG_DMA_FLAGS=y (dma-buf.o, W=1). The
KUnit test in patch 3 checks the flags in the copy. It passes on x86_64
under QEMU in strict and in warn mode.
drivers/dma-buf/dma-buf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 4c9add51f9ef..b3d311acb883 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -904,6 +904,10 @@ static int dma_buf_wrap_sg_table(struct sg_table **sg_table)
sg_assign_page(to_sg, NULL);
sg_dma_address(to_sg) = sg_dma_address(from_sg);
sg_dma_len(to_sg) = sg_dma_len(from_sg);
+#ifdef CONFIG_NEED_SG_DMA_FLAGS
+ /* the flags describe the DMA side, e.g. SG_DMA_BUS_ADDRESS */
+ to_sg->dma_flags = from_sg->dma_flags;
+#endif
to_sg = sg_next(to_sg);
}
--
2.53.0