public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Samiullah Khawaja <skhawaja@google.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	 Robin Murphy <robin.murphy@arm.com>,
	Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
	 Allen Hubbe <allenbh@gmail.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	 ntb@lists.linux.dev
Subject: Re: [PATCH v2 5/6] dma-debug: Feed DMA attribute for unmapping flows too
Date: Wed, 6 May 2026 18:06:45 +0000	[thread overview]
Message-ID: <afuDLtR6Q1W2_VO5@google.com> (raw)
In-Reply-To: <20260501-dma-attrs-debug-v2-5-8dbac75cd501@nvidia.com>

On Fri, May 01, 2026 at 09:35:09AM +0300, Leon Romanovsky wrote:
>From: Leon Romanovsky <leonro@nvidia.com>
>
>There are multiple unmapping flows which didn't provide DMA attributes,
>which limited DMA debug code to compare the mapping and unmapping
>attributes. Let's fix it.
>
>Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>---
> kernel/dma/debug.c   | 13 ++++++++-----
> kernel/dma/debug.h   | 19 +++++++++++--------
> kernel/dma/mapping.c |  8 ++++----
> 3 files changed, 23 insertions(+), 17 deletions(-)
>
>diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
>index f07e6a1e9fbab..3dfed51c3d9aa 100644
>--- a/kernel/dma/debug.c
>+++ b/kernel/dma/debug.c
>@@ -1307,8 +1307,8 @@ void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
> }
> EXPORT_SYMBOL(debug_dma_mapping_error);
>
>-void debug_dma_unmap_phys(struct device *dev, dma_addr_t dma_addr,
>-			  size_t size, int direction)
>+void debug_dma_unmap_phys(struct device *dev, dma_addr_t dma_addr, size_t size,
>+			  int direction, unsigned long attrs)
> {
> 	struct dma_debug_entry ref = {
> 		.type           = dma_debug_phy,
>@@ -1316,6 +1316,7 @@ void debug_dma_unmap_phys(struct device *dev, dma_addr_t dma_addr,
> 		.dev_addr       = dma_addr,
> 		.size           = size,
> 		.direction      = direction,
>+		.attrs          = attrs,
> 	};
>
> 	if (unlikely(dma_debug_disabled()))
>@@ -1381,7 +1382,7 @@ static int get_nr_mapped_entries(struct device *dev,
> }
>
> void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
>-			int nelems, int dir)
>+			int nelems, int dir, unsigned long attrs)
> {
> 	struct scatterlist *s;
> 	int mapped_ents = 0, i;
>@@ -1399,6 +1400,7 @@ void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
> 			.size           = sg_dma_len(s),
> 			.direction      = dir,
> 			.sg_call_ents   = nelems,
>+			.attrs          = attrs,
> 		};
>
> 		if (mapped_ents && i >= mapped_ents)
>@@ -1454,8 +1456,8 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
> 	add_dma_entry(entry);
> }
>
>-void debug_dma_free_coherent(struct device *dev, size_t size,
>-			 void *virt, dma_addr_t dma_addr)
>+void debug_dma_free_coherent(struct device *dev, size_t size, void *virt,
>+			     dma_addr_t dma_addr, unsigned long attrs)
> {
> 	struct dma_debug_entry ref = {
> 		.type           = dma_debug_coherent,
>@@ -1463,6 +1465,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
> 		.dev_addr       = dma_addr,
> 		.size           = size,
> 		.direction      = DMA_BIDIRECTIONAL,
>+		.attrs          = attrs,
> 	};
>
> 	/* handle vmalloc and linear addresses */
>diff --git a/kernel/dma/debug.h b/kernel/dma/debug.h
>index 24b8610850fbd..13e384633c32a 100644
>--- a/kernel/dma/debug.h
>+++ b/kernel/dma/debug.h
>@@ -14,21 +14,22 @@ extern void debug_dma_map_phys(struct device *dev, phys_addr_t phys,
> 			       unsigned long attrs);
>
> extern void debug_dma_unmap_phys(struct device *dev, dma_addr_t addr,
>-				 size_t size, int direction);
>+				 size_t size, int direction,
>+				 unsigned long attrs);
>
> extern void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
> 			     int nents, int mapped_ents, int direction,
> 			     unsigned long attrs);
>
> extern void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
>-			       int nelems, int dir);
>+			       int nelems, int dir, unsigned long attrs);
>
> extern void debug_dma_alloc_coherent(struct device *dev, size_t size,
> 				     dma_addr_t dma_addr, void *virt,
> 				     unsigned long attrs);
>
>-extern void debug_dma_free_coherent(struct device *dev, size_t size,
>-				    void *virt, dma_addr_t addr);
>+extern void debug_dma_free_coherent(struct device *dev, size_t size, void *virt,
>+				    dma_addr_t addr, unsigned long attrs);
>
> extern void debug_dma_sync_single_for_cpu(struct device *dev,
> 					  dma_addr_t dma_handle, size_t size,
>@@ -59,7 +60,8 @@ static inline void debug_dma_map_phys(struct device *dev, phys_addr_t phys,
> }
>
> static inline void debug_dma_unmap_phys(struct device *dev, dma_addr_t addr,
>-					size_t size, int direction)
>+					size_t size, int direction,
>+					unsigned long attrs)
> {
> }
>
>@@ -70,8 +72,8 @@ static inline void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
> }
>
> static inline void debug_dma_unmap_sg(struct device *dev,
>-				      struct scatterlist *sglist,
>-				      int nelems, int dir)
>+				      struct scatterlist *sglist, int nelems,
>+				      int dir, unsigned long attrs)
> {
> }
>
>@@ -82,7 +84,8 @@ static inline void debug_dma_alloc_coherent(struct device *dev, size_t size,
> }
>
> static inline void debug_dma_free_coherent(struct device *dev, size_t size,
>-					   void *virt, dma_addr_t addr)
>+					   void *virt, dma_addr_t addr,
>+					   unsigned long attrs)
> {
> }
>
>diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
>index 6cbefbd4158c8..f010b3cc0ece4 100644
>--- a/kernel/dma/mapping.c
>+++ b/kernel/dma/mapping.c
>@@ -225,7 +225,7 @@ void dma_unmap_phys(struct device *dev, dma_addr_t addr, size_t size,
> 	else if (ops->unmap_phys)
> 		ops->unmap_phys(dev, addr, size, dir, attrs);
> 	trace_dma_unmap_phys(dev, addr, size, dir, attrs);
>-	debug_dma_unmap_phys(dev, addr, size, dir);
>+	debug_dma_unmap_phys(dev, addr, size, dir, attrs);
> }
> EXPORT_SYMBOL_GPL(dma_unmap_phys);
>
>@@ -351,7 +351,7 @@ void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
>
> 	BUG_ON(!valid_dma_direction(dir));
> 	trace_dma_unmap_sg(dev, sg, nents, dir, attrs);
>-	debug_dma_unmap_sg(dev, sg, nents, dir);
>+	debug_dma_unmap_sg(dev, sg, nents, dir, attrs);
> 	if (dma_map_direct(dev, ops) ||
> 	    arch_dma_unmap_sg_direct(dev, sg, nents))
> 		dma_direct_unmap_sg(dev, sg, nents, dir, attrs);
>@@ -693,7 +693,7 @@ void dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
> 	if (!cpu_addr)
> 		return;
>
>-	debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
>+	debug_dma_free_coherent(dev, size, cpu_addr, dma_handle, attrs);
> 	if (dma_alloc_direct(dev, ops) || arch_dma_free_direct(dev, dma_handle))
> 		dma_direct_free(dev, size, cpu_addr, dma_handle, attrs);
> 	else if (use_dma_iommu(dev))
>@@ -840,7 +840,7 @@ void dma_free_noncontiguous(struct device *dev, size_t size,
> 		struct sg_table *sgt, enum dma_data_direction dir)
> {
> 	trace_dma_free_sgt(dev, sgt, size, dir);
>-	debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir);
>+	debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir, 0);
>
> 	if (use_dma_iommu(dev))
> 		iommu_dma_free_noncontiguous(dev, size, sgt, dir);
>
>-- 
>2.53.0
>
>

Reviewed-by: Samiullah Khawaja <skhawaja@google.com>

  reply	other threads:[~2026-05-06 18:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01  6:35 [PATCH v2 0/6] Add DMA attributes tracking Leon Romanovsky
2026-05-01  6:35 ` [PATCH v2 1/6] ntb: Store original DMA address for future release Leon Romanovsky
2026-05-01 17:00   ` Dave Jiang
2026-05-01  6:35 ` [PATCH v2 2/6] ntb: Use consistent DMA attributes when freeing DMA mappings Leon Romanovsky
2026-05-01 17:00   ` Dave Jiang
2026-05-01  6:35 ` [PATCH v2 3/6] dma-debug: Remove unused DMA attribute parameter Leon Romanovsky
2026-05-06 17:47   ` Samiullah Khawaja
2026-05-01  6:35 ` [PATCH v2 4/6] dma-debug: Record DMA attributes in debug entry Leon Romanovsky
2026-05-06 17:53   ` Samiullah Khawaja
2026-05-01  6:35 ` [PATCH v2 5/6] dma-debug: Feed DMA attribute for unmapping flows too Leon Romanovsky
2026-05-06 18:06   ` Samiullah Khawaja [this message]
2026-05-01  6:35 ` [PATCH v2 6/6] dma-debug: Ensure mappings are created and released with matching attributes Leon Romanovsky
2026-05-06 18:16   ` Samiullah Khawaja

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afuDLtR6Q1W2_VO5@google.com \
    --to=skhawaja@google.com \
    --cc=allenbh@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jdmason@kudzu.us \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=ntb@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox