Skip to contentSkip to conversation

x86: fix DMA CMA on x86

PATCH New Akinobu Mita 1 participant 3 messages Apr 20, 2014 x86

lore
Share & tools
lore
#0 lore raw

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(-)
Cc Marek Szyprowski <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Don Dutile <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <andi-Vw/[email protected]>
Cc iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Signature · 1 line
1.8.3.2
#1 lore raw

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.

Cc Marek Szyprowski <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Don Dutile <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <andi-Vw/[email protected]>
Cc iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
---
 arch/x86/kernel/pci-dma.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c +6 -1
index a0ffe44..f15bf8d 100644
@@ -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
#2 lore raw

PATCH 2/2 x86: avoid duplicated memset in dma_generic_alloc_coherent()

In reply to Akinobu Mita

This 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.

Cc Marek Szyprowski <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Don Dutile <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Andi Kleen <andi-Vw/[email protected]>
Cc iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
---
 arch/x86/kernel/pci-dma.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/pci-dma.c +1 -0
index f15bf8d..a25e202 100644
@@ -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