x86: fix DMA CMA on x86
cover x86: fix DMA CMA on x86
This series includes two fixes for dma_generic_alloc_coherent(), based on top of the patchset 'enhance DMA CMA on x86' which has been added in -mm tree.
Akinobu Mita (2):
x86: fix dma_generic_alloc_coherent() when CONFIG_DMA_CMA is enabled
x86: avoid duplicated memset in dma_generic_alloc_coherent()
arch/x86/kernel/pci-dma.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.2
PATCH 1/2 x86: fix dma_generic_alloc_coherent() when CONFIG_DMA_CMA is enabled
dma_generic_alloc_coherent() firstly attempts to allocate by dma_alloc_from_contiguous() if CONFIG_DMA_CMA is enabled. But the memory region allocated by it may not fit within the device's DMA mask. This change makes it fall back to usual alloc_pages_node() allocation for such cases.
--- arch/x86/kernel/pci-dma.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c +6 -1
@@ -100,8 +100,13 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, again: page =NULL ;/* CMA can be used only in the context which permits sleeping */ -if (flag & __GFP_WAIT) +if (flag & __GFP_WAIT) { page =dma_alloc_from_contiguous (dev, count,get_order (size)); +if (page &&page_to_phys (page) + size > dma_mask) { +dma_release_from_contiguous (dev, page, count); + page =NULL ; + } + }/* fallback */ if (!page) page =alloc_pages_node (dev_to_node (dev), flag,get_order (size));
Signature · 1 line
1.8.3.2
PATCH 2/2 x86: avoid duplicated memset in dma_generic_alloc_coherent()
In reply to Akinobu MitaThis patch fixes duplicated memset that is introduced by the patch x86-make-dma_alloc_coherent-return-zeroed-memory-if-cma-is-enabled.patch in -mm tree, and this change should be folded into it.
If dma_generic_alloc_coherent() is called with __GFP_ZERO, it does a duplicated memset to the memory area allocated by alloc_pages_node() with __GFP_ZERO. This change fixes that inefficiency by clearing __GFP_ZERO bit in gfp flages before calling alloc_pages_node(). Note that dma_generic_alloc_coherent() always returns zeroed memory.
--- arch/x86/kernel/pci-dma.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/pci-dma.c +1 -0
@@ -97,6 +97,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, dma_mask =dma_alloc_coherent_mask (dev, flag); + flag &= ~__GFP_ZERO; again: page =NULL ;/* CMA can be used only in the context which permits sleeping */
Signature · 1 line
1.8.3.2