LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] swiotlb: Some regression fixes
@ 2018-04-15  9:08 Takashi Iwai
  2018-04-15  9:08 ` [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA Takashi Iwai
  2018-04-15  9:08 ` [PATCH 2/2] swiotlb: Fix dma_supported() to consider direct allocation Takashi Iwai
  0 siblings, 2 replies; 4+ messages in thread
From: Takashi Iwai @ 2018-04-15  9:08 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: iommu, linux-kernel

Hi,

this is a couple of small regression fixes I stumbled on recently.
The first one is a trivial one, and it was already posted in another
thread ("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").


thanks,

Takashi

===

Takashi Iwai (2):
  dma-direct: Don't repeat allocation for no-op GFP_DMA
  swiotlb: Fix dma_supported() to consider direct allocation

 lib/dma-direct.c | 3 ++-
 lib/swiotlb.c    | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.16.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA
  2018-04-15  9:08 [PATCH 0/2] swiotlb: Some regression fixes Takashi Iwai
@ 2018-04-15  9:08 ` Takashi Iwai
  2018-04-23 12:54   ` Christoph Hellwig
  2018-04-15  9:08 ` [PATCH 2/2] swiotlb: Fix dma_supported() to consider direct allocation Takashi Iwai
  1 sibling, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2018-04-15  9:08 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: iommu, linux-kernel

When an allocation with lower dma_coherent mask fails,
dma_direct_alloc() retries the allocation with GFP_DMA.  But, it's
useless for architectures that has no ZONE_DMA, obviously.

Fix it by adding the check of CONFIG_ZONE_DMA before retrying the
allocation.

Fixes: 95f183916d4b ("dma-direct: retry allocations using GFP_DMA for small masks")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 lib/dma-direct.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] swiotlb: Fix dma_supported() to consider direct allocation
  2018-04-15  9:08 [PATCH 0/2] swiotlb: Some regression fixes Takashi Iwai
  2018-04-15  9:08 ` [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA Takashi Iwai
@ 2018-04-15  9:08 ` Takashi Iwai
  1 sibling, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2018-04-15  9:08 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: iommu, linux-kernel

Along with the recent change to use the common swiotlb dma_ops, x86
also takes over the swiotlb_dma_supported().  This caused a regression
when a low bit DMA mask is set; e.g. parport_pc driver now fails to
set the 24bit DMA mask:

  parport_pc parport_pc.956: Unable to set coherent dma mask: disabling DMA

It's because swiotlb_dma_supported() only checks the swiotlb range,
and the 24bit DMA mask is below io_tlb_end.  OTOH, in the past kernel
versions, x86's swiotlb dma_supported() was NULL, which was
effectively evaluated as the direct DMA, hence the lower DMA mask was
allowed.

This patch fixes the regression by extending swiotlb_dma_supported()
to check the direct DMA at first for covering the primary allocation
before swiotlb.

Fixes: 6e4bf5867783 ("x86/dma: Use generic swiotlb_ops")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 lib/swiotlb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index de7cc540450f..a81502ea79e7 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -1042,6 +1042,10 @@ swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)
 int
 swiotlb_dma_supported(struct device *hwdev, u64 mask)
 {
+#ifdef CONFIG_DMA_DIRECT_OPS
+	if (dma_direct_supported(hwdev, mask))
+		return 1;
+#endif
 	return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask;
 }
 
-- 
2.16.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA
  2018-04-15  9:08 ` [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA Takashi Iwai
@ 2018-04-23 12:54   ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2018-04-23 12:54 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Christoph Hellwig, iommu, linux-kernel

Thanks,

applied to the dma-mapping tree for 4.17.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-23 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-15  9:08 [PATCH 0/2] swiotlb: Some regression fixes Takashi Iwai
2018-04-15  9:08 ` [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA Takashi Iwai
2018-04-23 12:54   ` Christoph Hellwig
2018-04-15  9:08 ` [PATCH 2/2] swiotlb: Fix dma_supported() to consider direct allocation Takashi Iwai

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