* [PATCH] dma-direct: reject highmem pages from dma_alloc_from_contiguous
@ 2018-10-14 18:14 Christoph Hellwig
2018-10-22 9:41 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2018-10-14 18:14 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel
dma_alloc_from_contiguous can return highmem pages depending on the
setup, which a plain non-remapping DMA allocator can't handle. Detect
this case and try the normal page allocator instead.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/direct.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 87a6bc2a96c0..46fbaa49125b 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -126,6 +126,18 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
if (gfpflags_allow_blocking(gfp)) {
page = dma_alloc_from_contiguous(dev, count, page_order,
gfp & __GFP_NOWARN);
+ if (page && PageHighMem(page)) {
+ /*
+ * Depending on the cma= arguments and per-arch setup
+ * dma_alloc_from_contiguous could return highmem
+ * pages. Without remapping there is no way to return
+ * them here, so log an error and fail.
+ */
+ dev_info(dev, "Ignoring highmem page from CMA.\n");
+ dma_release_from_contiguous(dev, page, count);
+ page = NULL;
+ }
+
if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
dma_release_from_contiguous(dev, page, count);
page = NULL;
--
2.19.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] dma-direct: reject highmem pages from dma_alloc_from_contiguous
2018-10-14 18:14 [PATCH] dma-direct: reject highmem pages from dma_alloc_from_contiguous Christoph Hellwig
@ 2018-10-22 9:41 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2018-10-22 9:41 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel
Any comments?
On Sun, Oct 14, 2018 at 08:14:47PM +0200, Christoph Hellwig wrote:
> dma_alloc_from_contiguous can return highmem pages depending on the
> setup, which a plain non-remapping DMA allocator can't handle. Detect
> this case and try the normal page allocator instead.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/direct.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 87a6bc2a96c0..46fbaa49125b 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -126,6 +126,18 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
> if (gfpflags_allow_blocking(gfp)) {
> page = dma_alloc_from_contiguous(dev, count, page_order,
> gfp & __GFP_NOWARN);
> + if (page && PageHighMem(page)) {
> + /*
> + * Depending on the cma= arguments and per-arch setup
> + * dma_alloc_from_contiguous could return highmem
> + * pages. Without remapping there is no way to return
> + * them here, so log an error and fail.
> + */
> + dev_info(dev, "Ignoring highmem page from CMA.\n");
> + dma_release_from_contiguous(dev, page, count);
> + page = NULL;
> + }
> +
> if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
> dma_release_from_contiguous(dev, page, count);
> page = NULL;
> --
> 2.19.1
>
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
---end quoted text---
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-22 9:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-14 18:14 [PATCH] dma-direct: reject highmem pages from dma_alloc_from_contiguous Christoph Hellwig
2018-10-22 9:41 ` Christoph Hellwig
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).