From: Nicolin Chen <nicoleotsuka@gmail.com>
To: hch@lst.de, robin.murphy@arm.com, m.szyprowski@samsung.com,
natechancellor@gmail.com
Cc: vdumpa@nvidia.com, linux@armlinux.org.uk,
catalin.marinas@arm.com, will.deacon@arm.com, chris@zankel.net,
jcmvbkbc@gmail.com, joro@8bytes.org, dwmw2@infradead.org,
tony@atomide.com, akpm@linux-foundation.org,
sfr@canb.auug.org.au, treding@nvidia.com, keescook@chromium.org,
iamjoonsoo.kim@lge.com, wsa+renesas@sang-engineering.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-xtensa@linux-xtensa.org,
iommu@lists.linux-foundation.org, dann.frazier@canonical.com
Subject: [PATCH] dma-contiguous: Fix !CONFIG_DMA_CMA version of dma_{alloc,free}_contiguous()
Date: Wed, 29 May 2019 17:54:25 -0700 [thread overview]
Message-ID: <20190530005425.7184-1-nicoleotsuka@gmail.com> (raw)
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 <natechancellor@gmail.com>
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
include/linux/dma-contiguous.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h
index 428f3b7b1c42..c05d4e661489 100644
--- a/include/linux/dma-contiguous.h
+++ b/include/linux/dma-contiguous.h
@@ -50,6 +50,7 @@
#ifdef __KERNEL__
#include <linux/device.h>
+#include <linux/mm.h>
struct cma;
struct page;
@@ -155,15 +156,20 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return false;
}
+/* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
gfp_t gfp)
{
- return NULL;
+ int node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
+ size_t align = get_order(PAGE_ALIGN(size));
+
+ return alloc_pages_node(node, gfp, align);
}
static inline void dma_free_contiguous(struct device *dev, struct page *page,
size_t size)
{
+ __free_pages(page, get_order(size));
}
#endif
--
2.17.1
next reply other threads:[~2019-05-30 0:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-30 0:54 Nicolin Chen [this message]
2019-05-31 16:39 ` [PATCH] dma-contiguous: Fix !CONFIG_DMA_CMA version of dma_{alloc,free}_contiguous() Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190530005425.7184-1-nicoleotsuka@gmail.com \
--to=nicoleotsuka@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=chris@zankel.net \
--cc=dann.frazier@canonical.com \
--cc=dwmw2@infradead.org \
--cc=hch@lst.de \
--cc=iamjoonsoo.kim@lge.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jcmvbkbc@gmail.com \
--cc=joro@8bytes.org \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linux@armlinux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=natechancellor@gmail.com \
--cc=robin.murphy@arm.com \
--cc=sfr@canb.auug.org.au \
--cc=tony@atomide.com \
--cc=treding@nvidia.com \
--cc=vdumpa@nvidia.com \
--cc=will.deacon@arm.com \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).