From bf32bda4208ea71c05ac057c77fb124552ac907a Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Akinobu Mita Date: Wed, 4 Jun 2014 16:06:56 -0700 Subject: [PATCH 15/27] arch/x86/kernel/pci-dma.c: 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. Signed-off-by: Akinobu Mita Cc: Marek Szyprowski Cc: Konrad Rzeszutek Wilk Cc: David Woodhouse Cc: Don Dutile Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Andi Kleen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit 38f7ea5a082bbde9e64b7ece389f20e71a9806f4) Conflicts: arch/x86/kernel/pci-dma.c Signed-off-by: Jim Somerville --- arch/x86/kernel/pci-dma.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index 9d92ea8..dbc2c74 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -100,8 +100,13 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, flag &= ~__GFP_ZERO; again: page = NULL; - if (!(flag & GFP_ATOMIC)) + if (!(flag & GFP_ATOMIC)) { 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; + } + } if (!page) page = alloc_pages_node(dev_to_node(dev), flag, get_order(size)); if (!page) -- 1.8.3.1