Skip to content

Commit

Permalink
dma-mapping: clear harmful GFP_* flags in common code
Browse files Browse the repository at this point in the history
Lift the code from x86 so that we behave consistently.  In the future we
should probably warn if any of these is set.

Signed-off-by: Christoph Hellwig <[email protected]>
Acked-by: Jesper Nilsson <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]> [m68k]
  • Loading branch information
Christoph Hellwig committed Jan 15, 2018
1 parent 205e1b7 commit 57bf5a8
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 31 deletions.
3 changes: 0 additions & 3 deletions arch/cris/arch-v32/drivers/pci/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ static void *v32_dma_alloc(struct device *dev, size_t size,
{
void *ret;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);

if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
gfp |= GFP_DMA;

Expand Down
3 changes: 0 additions & 3 deletions arch/h8300/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ static void *dma_alloc(struct device *dev, size_t size,
{
void *ret;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);

if (dev == NULL || (*dev->dma_mask < 0xffffffff))
gfp |= GFP_DMA;
ret = (void *)__get_free_pages(gfp, get_order(size));
Expand Down
2 changes: 0 additions & 2 deletions arch/m68k/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ static void *m68k_dma_alloc(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
{
void *ret;
/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);

if (dev == NULL || (*dev->dma_mask < 0xffffffff))
gfp |= GFP_DMA;
Expand Down
3 changes: 0 additions & 3 deletions arch/mips/cavium-octeon/dma-octeon.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ static void *octeon_dma_alloc_coherent(struct device *dev, size_t size,
{
void *ret;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);

if (IS_ENABLED(CONFIG_ZONE_DMA) && dev == NULL)
gfp |= __GFP_DMA;
else if (IS_ENABLED(CONFIG_ZONE_DMA) &&
Expand Down
3 changes: 0 additions & 3 deletions arch/mips/loongson64/common/dma-swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ static void *loongson_dma_alloc_coherent(struct device *dev, size_t size,
{
void *ret;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);

if ((IS_ENABLED(CONFIG_ISA) && dev == NULL) ||
(IS_ENABLED(CONFIG_ZONE_DMA) &&
dev->coherent_dma_mask < DMA_BIT_MASK(32)))
Expand Down
3 changes: 0 additions & 3 deletions arch/mips/mm/dma-default.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ static gfp_t massage_gfp_flags(const struct device *dev, gfp_t gfp)
{
gfp_t dma_flag;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);

#ifdef CONFIG_ISA
if (dev == NULL)
dma_flag = __GFP_DMA;
Expand Down
3 changes: 0 additions & 3 deletions arch/mips/netlogic/common/nlm-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ static char *nlm_swiotlb;
static void *nlm_dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
{
/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);

#ifdef CONFIG_ZONE_DMA32
if (dev->coherent_dma_mask <= DMA_BIT_MASK(32))
gfp |= __GFP_DMA32;
Expand Down
3 changes: 0 additions & 3 deletions arch/mn10300/mm/dma-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ static void *mn10300_dma_alloc(struct device *dev, size_t size,
goto done;
}

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);

if (dev == NULL || dev->coherent_dma_mask < 0xffffffff)
gfp |= GFP_DMA;

Expand Down
3 changes: 0 additions & 3 deletions arch/nios2/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ static void *nios2_dma_alloc(struct device *dev, size_t size,
{
void *ret;

/* ignore region specifiers */
gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);

/* optimized page clearing */
gfp |= __GFP_ZERO;

Expand Down
3 changes: 0 additions & 3 deletions arch/powerpc/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ void *__dma_nommu_alloc_coherent(struct device *dev, size_t size,
};
#endif /* CONFIG_FSL_SOC */

/* ignore region specifiers */
flag &= ~(__GFP_HIGHMEM);

page = alloc_pages_node(node, flag, get_order(size));
if (page == NULL)
return NULL;
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/kernel/pci-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,

dma_mask = dma_alloc_coherent_mask(dev, flag);

flag &= ~__GFP_ZERO;
again:
page = NULL;
/* CMA can be used only in the context which permits sleeping */
Expand Down Expand Up @@ -139,7 +138,6 @@ bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp)
if (!*dev)
*dev = &x86_dma_fallback_dev;

*gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
*gfp = dma_alloc_coherent_gfp_flags(*dev, *gfp);

if (!is_device_dma_capable(*dev))
Expand Down
7 changes: 7 additions & 0 deletions include/linux/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ 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);

if (!arch_dma_alloc_attrs(&dev, &flag))
return NULL;
if (!ops->alloc)
Expand Down

0 comments on commit 57bf5a8

Please sign in to comment.