Skip to content

Commit dd3dced

Browse files
Nicolin ChenChristoph Hellwig
authored andcommitted
dma-contiguous: fix !CONFIG_DMA_CMA version of dma_{alloc, free}_contiguous()
Commit fdaeec198ada ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers") adds a pair of new helper functions so as to abstract code in the dma-direct (and other places in the future), however it breaks QEMU boot feature using x86_64 defconfig. That's because x86_64 defconfig has CONFIG_DMA_CMA=n so those two newly introduced helper functions are empty in their !CONFIG_DMA_CMA version, while previously the platform independent dma-direct code had fallback alloc_pages_node() and __free_pages(). So this patch fixes it by adding alloc_pages_node() and __free_pages() in the !CONFIG_DMA_CMA version of the two helper functions. Tested with below QEMU command: qemu-system-x86_64 -m 512m \ -drive file=images/x86_64/rootfs.ext4,format=raw,if=ide \ -append 'console=ttyS0 root=/dev/sda' -nographic \ -kernel arch/x86_64/boot/bzImage with the rootfs from the below link: https://github.com/ClangBuiltLinux/continuous-integration/raw/master/images/x86_64/rootfs.ext4 Fixes: fdaeec198ada ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers") Reported-by: Nathan Chancellor <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent bd2e756 commit dd3dced

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

include/linux/dma-contiguous.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#ifdef __KERNEL__
5151

5252
#include <linux/device.h>
53+
#include <linux/mm.h>
5354

5455
struct cma;
5556
struct page;
@@ -155,15 +156,20 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
155156
return false;
156157
}
157158

159+
/* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
158160
static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
159161
gfp_t gfp)
160162
{
161-
return NULL;
163+
int node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
164+
size_t align = get_order(PAGE_ALIGN(size));
165+
166+
return alloc_pages_node(node, gfp, align);
162167
}
163168

164169
static inline void dma_free_contiguous(struct device *dev, struct page *page,
165170
size_t size)
166171
{
172+
__free_pages(page, get_order(size));
167173
}
168174

169175
#endif

0 commit comments

Comments
 (0)