Skip to contentSkip to conversation

tip/x86/dma fix for arc and s390 (at least)

PATCH In review Christoph Hellwig 4 participants 5 messages Mar 28, 2018 – Apr 9, 2018

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Hi all,

this restores previous __GFP_ZERO passthrough behavior for now as arc and s390 rely on it. Needs more work to sort out the API mess in the long run.

#1 lore raw

PATCH 1/1 dma-mapping: don't clear GFP_ZERO in dma_alloc_attrs

Revert the clearing of __GFP_ZERO in dma_alloc_attrs and move it to dma_direct_alloc for now. While most common architectures always zero dma cohereny allocations (and x86 did so since day one) this is not documented and at least arc and s390 do not zero without the explicit __GFP_ZERO argument.

Fixes 57bf5a8963f8 ("dma-mapping: clear harmful GFP_* flags in common code")
---
 include/linux/dma-mapping.h | 8 ++------
 lib/dma-direct.c            | 3 +++
 2 files changed, 5 insertions(+), 6 deletions(-)
include/linux/dma-mapping.h +2 -6
index eb9eab4ecd6d..12fedcba9a9a 100644
@@ -518,12 +518,8 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size,
 	if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
 		return cpu_addr;
 
-	/*
-	 * Let the implementation decide on the zone to allocate from, and
-	 * decide on the way of zeroing the memory given that the memory
-	 * returned should always be zeroed.
-	 */
-	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);
+	/* let the implementation decide on the zone to allocate from: */
+	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);
 
 	if (!arch_dma_alloc_attrs(&dev, &flag))
 		return NULL;
lib/dma-direct.c +3 -0
index 1277d293d4da..c0bba30fef0a 100644
@@ -59,6 +59,9 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
 	struct page *page = NULL;
 	void *ret;
 
+	/* we always manually zero the memory once we are done: */
+	gfp &= ~__GFP_ZERO;
+
 	/* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */
 	if (dev->coherent_dma_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
 		gfp |= GFP_DMA;
Signature · 1 line
2.14.2
Tested-by on v1 1/1
#2 lore raw

Re: [PATCH] dma-mapping: don't clear GFP_ZERO in dma_alloc_attrs

Adding linux-snps and linux-arch mailing lists.

Quoted 5 lines

Revert the clearing of __GFP_ZERO in dma_alloc_attrs and move it to dma_direct_alloc for now.  While most common architectures always zero dma cohereny allocations (and x86 did so since day one) this is not documented and at least arc and s390 do not zero without the explicit __GFP_ZERO argument.

This patch fixed Ethernet issues on ARC HSDK.
https://www.spinics.net/lists/kernel/msg2762054.html

Quoted 39 lines
Fixes 57bf5a8963f8 ("dma-mapping: clear harmful GFP_* flags in common code")

---
 include/linux/dma-mapping.h | 8 ++------
 lib/dma-direct.c            | 3 +++

 2 files changed, 5 insertions(+), 6 deletions(-)
include/linux/dma-mapping.h +0 -0
index eb9eab4ecd6d..12fedcba9a9a 100644
@@ -518,12 +518,8 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  	if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
  		return cpu_addr;

include/linux/dma-mapping.h +2 -6
-	/*
-	 * Let the implementation decide on the zone to allocate from, and
-	 * decide on the way of zeroing the memory given that the memory
-	 * returned should always be zeroed.
-	 */
-	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);
+	/* let the implementation decide on the zone to allocate from: */
+	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);

  if (!arch_dma_alloc_attrs(&dev, &flag))
  return NULL;

lib/dma-direct.c +0 -0
index 1277d293d4da..c0bba30fef0a 100644
@@ -59,6 +59,9 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
  	struct page *page = NULL;
  	void *ret;

lib/dma-direct.c +3 -0
+	/* we always manually zero the memory once we are done: */
+	gfp &= ~__GFP_ZERO;
+
Quoted 3 lines

  /* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */ if (dev->coherent_dma_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)) gfp |= GFP_DMA;

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#4 lore raw

[tip:x86/dma] dma-mapping: Don't clear GFP_ZERO in dma_alloc_attrs

In reply to Christoph Hellwig
dma-mapping: Don't clear GFP_ZERO in dma_alloc_attrs
Commit-ID:  e89f5b37015309a8bdf0b21d08007580b92f92a4
Gitweb:     https://git.kernel.org/tip/e89f5b37015309a8bdf0b21d08007580b92f92a4
Author:     Christoph Hellwig <[email protected]>
AuthorDate: Wed, 28 Mar 2018 15:35:35 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Wed, 28 Mar 2018 17:34:23 +0200

dma-mapping: Don't clear GFP_ZERO in dma_alloc_attrs

Revert the clearing of __GFP_ZERO in dma_alloc_attrs and move it to dma_direct_alloc for now. While most common architectures always zero dma cohereny allocations (and x86 did so since day one) this is not documented and at least arc and s390 do not zero without the explicit __GFP_ZERO argument.

---
 include/linux/dma-mapping.h | 8 ++------
 lib/dma-direct.c            | 3 +++
 2 files changed, 5 insertions(+), 6 deletions(-)
include/linux/dma-mapping.h +2 -6
index eb9eab4ecd6d..12fedcba9a9a 100644
@@ -518,12 +518,8 @@ static inline void *dma_alloc_attrs(struct device *dev, size_t size,
 	if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
 		return cpu_addr;
 
-	/*
-	 * Let the implementation decide on the zone to allocate from, and
-	 * decide on the way of zeroing the memory given that the memory
-	 * returned should always be zeroed.
-	 */
-	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM | __GFP_ZERO);
+	/* let the implementation decide on the zone to allocate from: */
+	flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);
 
 	if (!arch_dma_alloc_attrs(&dev, &flag))
 		return NULL;
lib/dma-direct.c +3 -0
index 1277d293d4da..c0bba30fef0a 100644
@@ -59,6 +59,9 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
 	struct page *page = NULL;
 	void *ret;
 
+	/* we always manually zero the memory once we are done: */
+	gfp &= ~__GFP_ZERO;
+
 	/* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */
 	if (dev->coherent_dma_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
 		gfp |= GFP_DMA;