swiotlb: Some regression fixes
cover swiotlb: Some regression fixes
Hi,
this is a couple of small regression fixes I stumbled on recently. The first one is a trivial one, and it was already posted in another thread ("swiotlb: Fix unexpected swiotlb_alloc_coherent() failures").
thanks,
Takashi
===
Takashi Iwai (2):
dma-direct: Don't repeat allocation for no-op GFP_DMA
swiotlb: Fix dma_supported() to consider direct allocation
lib/dma-direct.c | 3 ++- lib/swiotlb.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.16.3
PATCH 1/2 dma-direct: Don't repeat allocation for no-op GFP_DMA
When an allocation with lower dma_coherent mask fails, dma_direct_alloc() retries the allocation with GFP_DMA. But, it's useless for architectures that has no ZONE_DMA, obviously.
Fix it by adding the check of CONFIG_ZONE_DMA before retrying the allocation.
--- lib/dma-direct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dma-direct.c +2 -1
@@ -84,7 +84,8 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,__free_pages (page, page_order); page =NULL ; -if (dev->coherent_dma_mask <DMA_BIT_MASK (32 ) && +if (IS_ENABLED (CONFIG_ZONE_DMA ) && + dev->coherent_dma_mask <DMA_BIT_MASK (32 ) && !(gfp &GFP_DMA )) { gfp = (gfp & ~GFP_DMA32 ) |GFP_DMA ; goto again;
Signature · 1 line
2.16.3
Christoph Hellwig
AppliedRe: [PATCH 1/2] dma-direct: Don't repeat allocation for no-op GFP_DMA
Thanks,
applied to the dma-mapping tree for 4.17.
PATCH 2/2 swiotlb: Fix dma_supported() to consider direct allocation
In reply to Takashi IwaiAlong with the recent change to use the common swiotlb dma_ops, x86 also takes over the swiotlb_dma_supported(). This caused a regression when a low bit DMA mask is set; e.g. parport_pc driver now fails to set the 24bit DMA mask:
parport_pc parport_pc.956: Unable to set coherent dma mask: disabling DMA
It's because swiotlb_dma_supported() only checks the swiotlb range, and the 24bit DMA mask is below io_tlb_end. OTOH, in the past kernel versions, x86's swiotlb dma_supported() was NULL, which was effectively evaluated as the direct DMA, hence the lower DMA mask was allowed.
This patch fixes the regression by extending swiotlb_dma_supported() to check the direct DMA at first for covering the primary allocation before swiotlb.
--- lib/swiotlb.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/swiotlb.c +4 -0
@@ -1042,6 +1042,10 @@ swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)int swiotlb_dma_supported (struct device *hwdev,u64 mask) { +#ifdef CONFIG_DMA_DIRECT_OPS +if (dma_direct_supported (hwdev, mask)) +return 1 ; +#endif return __phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; }
Signature · 1 line
2.16.3