Skip to content

Commit a2cfbf0

Browse files
committed
dma-mapping: reject __GFP_COMP in dma_alloc_attrs
Bugzilla: https://bugzilla.redhat.com/2181354 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit ffcb754 Author: Christoph Hellwig <hch@lst.de> Date: Wed Nov 9 08:37:17 2022 +0100 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> (cherry picked from commit ffcb754) Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
1 parent 21db375 commit a2cfbf0

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
@@ -695,14 +695,6 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
695695
if (mask < 0xffffffffULL)
696696
gfp |= GFP_DMA;
697697

698-
/*
699-
* Following is a work-around (a.k.a. hack) to prevent pages
700-
* with __GFP_COMP being passed to split_page() which cannot
701-
* handle them. The real problem is that this flag probably
702-
* should be 0 on ARM as it is not supported on this
703-
* platform; see CONFIG_HUGETLBFS.
704-
*/
705-
gfp &= ~(__GFP_COMP);
706698
args.gfp = gfp;
707699

708700
*handle = DMA_MAPPING_ERROR;
@@ -1434,15 +1426,6 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,
14341426
return __iommu_alloc_simple(dev, size, gfp, handle,
14351427
coherent_flag, attrs);
14361428

1437-
/*
1438-
* Following is a work-around (a.k.a. hack) to prevent pages
1439-
* with __GFP_COMP being passed to split_page() which cannot
1440-
* handle them. The real problem is that this flag probably
1441-
* should be 0 on ARM as it is not supported on this
1442-
* platform; see CONFIG_HUGETLBFS.
1443-
*/
1444-
gfp &= ~(__GFP_COMP);
1445-
14461429
pages = __iommu_alloc_buffer(dev, size, gfp, attrs, coherent_flag);
14471430
if (!pages)
14481431
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
@@ -494,6 +494,14 @@ void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
494494

495495
WARN_ON_ONCE(!dev->coherent_dma_mask);
496496

497+
/*
498+
* DMA allocations can never be turned back into a page pointer, so
499+
* requesting compound pages doesn't make sense (and can't even be
500+
* supported at all by various backends).
501+
*/
502+
if (WARN_ON_ONCE(flag & __GFP_COMP))
503+
return NULL;
504+
497505
if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr))
498506
return cpu_addr;
499507

0 commit comments

Comments
 (0)