]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dma-debug: Feed DMA attribute for unmapping flows too
authorLeon Romanovsky <leonro@nvidia.com>
Fri, 1 May 2026 06:35:09 +0000 (09:35 +0300)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 8 May 2026 20:28:19 +0000 (22:28 +0200)
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>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20260501-dma-attrs-debug-v2-5-8dbac75cd501@nvidia.com
kernel/dma/debug.c
kernel/dma/debug.h
kernel/dma/mapping.c

index f07e6a1e9fbabfd51e9b075fb8f443fab6ff7234..3dfed51c3d9aab6100a32cae68184052be2c444c 100644 (file)
@@ -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 */
index 24b8610850fbddb8d8b6ea3ebaa5e71343676011..13e384633c32af12977ca518e01ae5dbad267a27 100644 (file)
@@ -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)
 {
 }
 
index 6cbefbd4158c868d9227abff05c7909dbe78e561..f010b3cc0ece4259c6bb4a40e3b8450eb8ec0752 100644 (file)
@@ -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);