Skip to content

Commit ffcb754

Browse files
author
Christoph Hellwig
committed
dma-mapping: reject __GFP_COMP in dma_alloc_attrs
DMA allocations can never be turned back into a page pointer, so requesting compound pages doesn't make sense and it can't even be supported at all by various backends. Reject __GFP_COMP with a warning in dma_alloc_attrs, and stop clearing the flag in the arm dma ops and dma-iommu. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
1 parent 3306877 commit ffcb754

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

arch/arm/mm/dma-mapping.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,6 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
564564
if (mask < 0xffffffffULL)
565565
gfp |= GFP_DMA;
566566

567-
/*
568-
* Following is a work-around (a.k.a. hack) to prevent pages
569-
* with __GFP_COMP being passed to split_page() which cannot
570-
* handle them. The real problem is that this flag probably
571-
* should be 0 on ARM as it is not supported on this
572-
* platform; see CONFIG_HUGETLBFS.
573-
*/
574-
gfp &= ~(__GFP_COMP);
575567
args.gfp = gfp;
576568

577569
*handle = DMA_MAPPING_ERROR;
@@ -1093,15 +1085,6 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
10931085
return __iommu_alloc_simple(dev, size, gfp, handle,
10941086
coherent_flag, attrs);
10951087

1096-
/*
1097-
* Following is a work-around (a.k.a. hack) to prevent pages
1098-
* with __GFP_COMP being passed to split_page() which cannot
1099-
* handle them. The real problem is that this flag probably
1100-
* should be 0 on ARM as it is not supported on this
1101-
* platform; see CONFIG_HUGETLBFS.
1102-
*/
1103-
gfp &= ~(__GFP_COMP);
1104-
11051088
pages = __iommu_alloc_buffer(dev, size, gfp, attrs, coherent_flag);
11061089
if (!pages)
11071090
return NULL;

drivers/iommu/dma-iommu.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,6 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev,
744744
/* IOMMU can map any pages, so himem can also be used here */
745745
gfp |= __GFP_NOWARN | __GFP_HIGHMEM;
746746

747-
/* It makes no sense to muck about with huge pages */
748-
gfp &= ~__GFP_COMP;
749-
750747
while (count) {
751748
struct page *page = NULL;
752749
unsigned int order_size;

kernel/dma/mapping.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
498498

499499
WARN_ON_ONCE(!dev->coherent_dma_mask);
500500

501+
/*
502+
* DMA allocations can never be turned back into a page pointer, so
503+
* requesting compound pages doesn't make sense (and can't even be
504+
* supported at all by various backends).
505+
*/
506+
if (WARN_ON_ONCE(flag & __GFP_COMP))
507+
return NULL;
508+
501509
if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
502510
return cpu_addr;
503511

0 commit comments

Comments
 (0)