Skip to content

Commit

Permalink
dma-mapping: Don't clear GFP_ZERO in dma_alloc_attrs
Browse files Browse the repository at this point in the history
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: 57bf5a8 ("dma-mapping: clear harmful GFP_* flags in common code")
Reported-by: Evgeniy Didin <[email protected]>
Reported-by: Sebastian Ott <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Tested-by: Evgeniy Didin <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
Christoph Hellwig authored and KAGA-KOKO committed Mar 28, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ea2301b commit e89f5b3
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 2 additions & 6 deletions include/linux/dma-mapping.h
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions lib/dma-direct.c
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e89f5b3

Please sign in to comment.