Skip to content

Commit de7eab3

Browse files
tiwaiChristoph Hellwig
authored andcommitted
dma-direct: try reallocation with GFP_DMA32 if possible
As the recent swiotlb bug revealed, we seem to have given up the direct DMA allocation too early and felt back to swiotlb allocation. The reason is that swiotlb allocator expected that dma_direct_alloc() would try harder to get pages even below 64bit DMA mask with GFP_DMA32, but the function doesn't do that but only deals with GFP_DMA case. This patch adds a similar fallback reallocation with GFP_DMA32 as we've done with GFP_DMA. The condition is that the coherent mask is smaller than 64bit (i.e. some address limitation), and neither GFP_DMA nor GFP_DMA32 is set beforehand. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 698733f commit de7eab3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/dma-direct.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
8484
__free_pages(page, page_order);
8585
page = NULL;
8686

87+
if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
88+
dev->coherent_dma_mask < DMA_BIT_MASK(64) &&
89+
!(gfp & (GFP_DMA32 | GFP_DMA))) {
90+
gfp |= GFP_DMA32;
91+
goto again;
92+
}
93+
8794
if (IS_ENABLED(CONFIG_ZONE_DMA) &&
8895
dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
8996
!(gfp & GFP_DMA)) {

0 commit comments

Comments
 (0)