mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask
@ 2024-03-13 12:19 John Hsu
  2024-03-13 12:43 ` Robin Murphy
  0 siblings, 1 reply; 2+ messages in thread
From: John Hsu @ 2024-03-13 12:19 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: surenb, John Hsu, Chinwen Chang, Casper Li, Kuan-Ying Lee, iommu,
	linux-kernel, linux-arm-kernel, linux-mediatek

From: JohnHsu <john.hsu@mediatek.com>

The dma_direct_alloc() may return null in some cases. For example, the
allocated page is not addressable for the device's coherent_dma_mask,
and the allocated page will be assigned to null.

This patch can WARN_ON_ONCE() when the returned page is null in
dma_direct_alloc. It helps the developers position the root cause of
allocation failure rapidly.

Signed-off-by: JohnHsu <john.hsu@mediatek.com>
---
 kernel/dma/direct.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 9596ae1aa0da..a73b8ad1ef9e 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -156,6 +156,8 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
 		}
 	}
 
+	WARN_ON_ONCE(!page);
+
 	return page;
 }
 
-- 
2.18.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask
  2024-03-13 12:19 [PATCH] direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask John Hsu
@ 2024-03-13 12:43 ` Robin Murphy
  0 siblings, 0 replies; 2+ messages in thread
From: Robin Murphy @ 2024-03-13 12:43 UTC (permalink / raw)
  To: John Hsu, Christoph Hellwig, Marek Szyprowski, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: surenb, Chinwen Chang, Casper Li, Kuan-Ying Lee, iommu,
	linux-kernel, linux-arm-kernel, linux-mediatek

On 2024-03-13 12:19 pm, John Hsu wrote:
> From: JohnHsu <john.hsu@mediatek.com>
> 
> The dma_direct_alloc() may return null in some cases. For example, the
> allocated page is not addressable for the device's coherent_dma_mask,
> and the allocated page will be assigned to null.
> 
> This patch can WARN_ON_ONCE() when the returned page is null in
> dma_direct_alloc. It helps the developers position the root cause of
> allocation failure rapidly.

No. Failure to allocate a buffer can happen for any number of reasons, 
it is not specific to dma-direct, and in some cases it is even expected, 
hence why DMA_ATTR_NO_WARN exists. And either way it's still not a 
condition worthy of panicking when panic_on_warn is in use.

Sure, this may well be a handy development hack for debugging a 
particular driver which isn't handling failure correctly, but it is not 
suitable for mainline.

Thanks,
Robin.

> Signed-off-by: JohnHsu <john.hsu@mediatek.com>
> ---
>   kernel/dma/direct.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 9596ae1aa0da..a73b8ad1ef9e 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -156,6 +156,8 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
>   		}
>   	}
>   
> +	WARN_ON_ONCE(!page);
> +
>   	return page;
>   }
>   

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-13 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-13 12:19 [PATCH] direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask John Hsu
2024-03-13 12:43 ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®