LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC] dma-direct: Try reallocation with GFP_DMA32 if possible
Date: Mon, 16 Apr 2018 17:18:19 +0200	[thread overview]
Message-ID: <20180416151819.27520-1-tiwai@suse.de> (raw)

As the recent swiotlb bug revealed, we seem to have given up the
direct DMA allocation too early and felt back to swiotlb allocation.
The reason is that swiotlb allocator expected that dma_direct_alloc()
would try harder to get pages even below 64bit DMA mask with
GFP_DMA32, but the function doesn't do that but only deals with
GFP_DMA case.

This patch adds a similar fallback reallocation with GFP_DMA32 as
we've done with GFP_DMA.  The condition is that the coherent mask is
smaller than 64bit (i.e. some address limitation), and neither GFP_DMA
nor GFP_DMA32 is set beforehand.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

---

This is a resend of a test patch included in the previous thread
("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").

 lib/dma-direct.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/dma-direct.c b/lib/dma-direct.c
index bbfb229aa067..970d39155618 100644
--- a/lib/dma-direct.c
+++ b/lib/dma-direct.c
@@ -84,6 +84,13 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
 		__free_pages(page, page_order);
 		page = NULL;
 
+		if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
+		    dev->coherent_dma_mask < DMA_BIT_MASK(64) &&
+		    !(gfp & (GFP_DMA32 | GFP_DMA))) {
+			gfp |= GFP_DMA32;
+			goto again;
+		}
+
 		if (IS_ENABLED(CONFIG_ZONE_DMA) &&
 		    dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
 		    !(gfp & GFP_DMA)) {
-- 
2.16.3

             reply	other threads:[~2018-04-16 15:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 15:18 Takashi Iwai [this message]
2018-04-20  9:47 ` Christoph Hellwig
2018-04-20  9:58   ` Takashi Iwai
2018-04-20 10:06     ` 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=20180416151819.27520-1-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH RFC] dma-direct: Try reallocation with GFP_DMA32 if possible' \
    /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

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