]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/dmapool.c: avoid duplicate memset within dma_pool_alloc
authorLiu Song <liusong@linux.alibaba.com>
Mon, 18 Jul 2022 06:28:10 +0000 (14:28 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 17 Aug 2022 20:58:35 +0000 (13:58 -0700)
In "dma_alloc_from_dev_coherent" and "dma_direct_alloc",
the allocated memory is explicitly set to 0.

A helper function "use_dev_coherent_memory" is introduced here to
determine whether the memory is allocated by "dma_alloc_from_dev_coherent".

And use "get_dma_ops" to determine whether the memory is allocated by
"dma_direct_alloc".

After this modification, memory allocated using "dma_pool_zalloc" can avoid
duplicate memset.

Link: https://lkml.kernel.org/r/1658125690-76930-1-git-send-email-liusong@linux.alibaba.com
Signed-off-by: Liu Song <liusong@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/dma-map-ops.h
mm/dmapool.c

index d678afeb8a13a3a54380a959d14f79bca9c23d8e..0749245dad6020ec1372123043df10fbfc6a92e6 100644 (file)
@@ -183,6 +183,10 @@ int dma_alloc_from_dev_coherent(struct device *dev, ssize_t size,
 int dma_release_from_dev_coherent(struct device *dev, int order, void *vaddr);
 int dma_mmap_from_dev_coherent(struct device *dev, struct vm_area_struct *vma,
                void *cpu_addr, size_t size, int *ret);
+static inline bool use_dev_coherent_memory(struct device *dev)
+{
+       return dev->dma_mem ? true : false;
+}
 #else
 static inline int dma_declare_coherent_memory(struct device *dev,
                phys_addr_t phys_addr, dma_addr_t device_addr, size_t size)
@@ -194,6 +198,7 @@ static inline int dma_declare_coherent_memory(struct device *dev,
 #define dma_release_from_dev_coherent(dev, order, vaddr) (0)
 #define dma_mmap_from_dev_coherent(dev, vma, vaddr, order, ret) (0)
 static inline void dma_release_coherent_memory(struct device *dev) { }
+#define use_dev_coherent_memory(dev) (0)
 #endif /* CONFIG_DMA_DECLARE_COHERENT */
 
 #ifdef CONFIG_DMA_GLOBAL_POOL
index a7eb5d0eb2da7362050a578f24d2026d107dd5ce..6e0353027ae258032269e7778ca933f7b35736de 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
+#include <linux/dma-map-ops.h>
 #include <linux/dmapool.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
@@ -372,7 +373,9 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
 #endif
        spin_unlock_irqrestore(&pool->lock, flags);
 
-       if (want_init_on_alloc(mem_flags))
+       if (want_init_on_alloc(mem_flags) &&
+               !use_dev_coherent_memory(pool->dev) &&
+               get_dma_ops(pool->dev))
                memset(retval, 0, pool->size);
 
        return retval;