Skip to contentSkip to conversation

dma-direct: Try reallocation with GFP_DMA32 if possible

RFC PATCH In review Takashi Iwai 2 participants 4 messages Apr 16, 2018 – Apr 20, 2018 Library code

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 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.

---

This is a resend of a test patch included in the previous thread ("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").

 lib/dma-direct.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/dma-direct.c +7 -0
index bbfb229aa067..970d39155618 100644
@@ -84,6 +84,13 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
 		__free_pages(page, page_order);
 		page = NULL;
 
+		if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
+		    dev->coherent_dma_mask < DMA_BIT_MASK(64) &&
+		    !(gfp & (GFP_DMA32 | GFP_DMA))) {
+			gfp |= GFP_DMA32;
+			goto again;
+		}
+
 		if (IS_ENABLED(CONFIG_ZONE_DMA) &&
 		    dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
 		    !(gfp & GFP_DMA)) {
Signature · 1 line
2.16.3
#1 lore raw
Quoted 12 lines · Takashi Iwai

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.

Quoted 6 lines

---

This is a resend of a test patch included in the previous thread ("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").

I like the patch, but as-is it doesn't apply. Can you resend it against latest Linus' tree?

#2 lore raw
Quoted 16 lines · Christoph Hellwig
Quoted 14 lines · Takashi Iwai

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.

Quoted 7 lines
Quoted 4 lines

---

This is a resend of a test patch included in the previous thread ("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").

I like the patch, but as-is it doesn't apply. Can you resend it against latest Linus' tree?

It's because it's written on the tree with another fix patch I sent beforehand ("[PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA").

Could you check that one at first? I'm fine to rebase and resubmit this one, if still preferred, though.

thanks,

Takashi

#3 lore raw
Quoted 6 lines · Takashi Iwai

It's because it's written on the tree with another fix patch I sent beforehand ("[PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA").

Could you check that one at first? I'm fine to rebase and resubmit this one, if still preferred, though.

That one looks fine, too. I'll add it to my patch queue.