public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools
@ 2026-01-28 13:35 ` Sai Sree Kartheek Adivi
  2026-01-28 14:05   ` Robin Murphy
  2026-01-29  9:26   ` Marek Szyprowski
  0 siblings, 2 replies; 3+ messages in thread
From: Sai Sree Kartheek Adivi @ 2026-01-28 13:35 UTC (permalink / raw)
  To: m.szyprowski, robin.murphy, iommu, linux-kernel; +Cc: vigneshr

Currently, dma_alloc_from_pool() unconditionally warns and dumps a stack
trace when an allocation fails, with the message "Failed to get suitable
pool".

This conflates two distinct failure modes:
1. Configuration error: No atomic pool is available for the requested
   DMA mask (a fundamental system setup issue)
2. Resource Exhaustion: A suitable pool exists but is currently full (a
   recoverable runtime state)

This lack of distinction prevents drivers from using __GFP_NOWARN to
suppress error messages during temporary pressure spikes, such as when
awaiting synchronous reclaim of descriptors.

Refactor the error handling to distinguish these cases:
- If no suitable pool is found, keep the unconditional WARN regarding
  the missing pool.
- If a pool was found but is exhausted, respect __GFP_NOWARN and update
  the warning message to explicitly state "DMA pool exhausted".

Fixes: 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings")
Signed-off-by: Sai Sree Kartheek Adivi <s-adivi@ti.com>
---

Changes from v2 to v3:
- Distinguish between "no suitable pool is found" and "pool is
  exhausted" cases.
Link: https://lore.kernel.org/all/20260112104749.4132641-1-s-adivi@ti.com/

 kernel/dma/pool.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index c5da29ad010c4..2b2fbb7092429 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -277,15 +277,20 @@ struct page *dma_alloc_from_pool(struct device *dev, size_t size,
 {
 	struct gen_pool *pool = NULL;
 	struct page *page;
+	bool pool_found = false;
 
 	while ((pool = dma_guess_pool(pool, gfp))) {
+		pool_found = true;
 		page = __dma_alloc_from_pool(dev, size, pool, cpu_addr,
 					     phys_addr_ok);
 		if (page)
 			return page;
 	}
 
-	WARN(1, "Failed to get suitable pool for %s\n", dev_name(dev));
+	if (pool_found)
+		WARN(!(gfp & __GFP_NOWARN), "DMA pool exhausted for %s\n", dev_name(dev));
+	else
+		WARN(1, "Failed to get suitable pool for %s\n", dev_name(dev));
 	return NULL;
 }
 
-- 
2.34.1


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

* Re: [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools
  2026-01-28 13:35 ` [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools Sai Sree Kartheek Adivi
@ 2026-01-28 14:05   ` Robin Murphy
  2026-01-29  9:26   ` Marek Szyprowski
  1 sibling, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2026-01-28 14:05 UTC (permalink / raw)
  To: Sai Sree Kartheek Adivi, m.szyprowski, iommu, linux-kernel; +Cc: vigneshr

On 2026-01-28 1:35 pm, Sai Sree Kartheek Adivi wrote:
> Currently, dma_alloc_from_pool() unconditionally warns and dumps a stack
> trace when an allocation fails, with the message "Failed to get suitable
> pool".
> 
> This conflates two distinct failure modes:
> 1. Configuration error: No atomic pool is available for the requested
>     DMA mask (a fundamental system setup issue)
> 2. Resource Exhaustion: A suitable pool exists but is currently full (a
>     recoverable runtime state)
> 
> This lack of distinction prevents drivers from using __GFP_NOWARN to
> suppress error messages during temporary pressure spikes, such as when
> awaiting synchronous reclaim of descriptors.
> 
> Refactor the error handling to distinguish these cases:
> - If no suitable pool is found, keep the unconditional WARN regarding
>    the missing pool.
> - If a pool was found but is exhausted, respect __GFP_NOWARN and update
>    the warning message to explicitly state "DMA pool exhausted".

Great writeup!

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings")
> Signed-off-by: Sai Sree Kartheek Adivi <s-adivi@ti.com>
> ---
> 
> Changes from v2 to v3:
> - Distinguish between "no suitable pool is found" and "pool is
>    exhausted" cases.
> Link: https://lore.kernel.org/all/20260112104749.4132641-1-s-adivi@ti.com/
> 
>   kernel/dma/pool.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index c5da29ad010c4..2b2fbb7092429 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -277,15 +277,20 @@ struct page *dma_alloc_from_pool(struct device *dev, size_t size,
>   {
>   	struct gen_pool *pool = NULL;
>   	struct page *page;
> +	bool pool_found = false;
>   
>   	while ((pool = dma_guess_pool(pool, gfp))) {
> +		pool_found = true;
>   		page = __dma_alloc_from_pool(dev, size, pool, cpu_addr,
>   					     phys_addr_ok);
>   		if (page)
>   			return page;
>   	}
>   
> -	WARN(1, "Failed to get suitable pool for %s\n", dev_name(dev));
> +	if (pool_found)
> +		WARN(!(gfp & __GFP_NOWARN), "DMA pool exhausted for %s\n", dev_name(dev));
> +	else
> +		WARN(1, "Failed to get suitable pool for %s\n", dev_name(dev));
>   	return NULL;
>   }
>   


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

* Re: [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools
  2026-01-28 13:35 ` [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools Sai Sree Kartheek Adivi
  2026-01-28 14:05   ` Robin Murphy
@ 2026-01-29  9:26   ` Marek Szyprowski
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Szyprowski @ 2026-01-29  9:26 UTC (permalink / raw)
  To: Sai Sree Kartheek Adivi, robin.murphy, iommu, linux-kernel; +Cc: vigneshr

On 28.01.2026 14:35, Sai Sree Kartheek Adivi wrote:
> Currently, dma_alloc_from_pool() unconditionally warns and dumps a stack
> trace when an allocation fails, with the message "Failed to get suitable
> pool".
>
> This conflates two distinct failure modes:
> 1. Configuration error: No atomic pool is available for the requested
>     DMA mask (a fundamental system setup issue)
> 2. Resource Exhaustion: A suitable pool exists but is currently full (a
>     recoverable runtime state)
>
> This lack of distinction prevents drivers from using __GFP_NOWARN to
> suppress error messages during temporary pressure spikes, such as when
> awaiting synchronous reclaim of descriptors.
>
> Refactor the error handling to distinguish these cases:
> - If no suitable pool is found, keep the unconditional WARN regarding
>    the missing pool.
> - If a pool was found but is exhausted, respect __GFP_NOWARN and update
>    the warning message to explicitly state "DMA pool exhausted".
>
> Fixes: 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings")
> Signed-off-by: Sai Sree Kartheek Adivi <s-adivi@ti.com>

Applied to dma-mapping-fixes. Thanks!


Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

end of thread, other threads:[~2026-01-29  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20260128133621eucas1p22cd752b033c780f52b6fee2dfaec1593@eucas1p2.samsung.com>
2026-01-28 13:35 ` [PATCH v3] dma/pool: distinguish between missing and exhausted atomic pools Sai Sree Kartheek Adivi
2026-01-28 14:05   ` Robin Murphy
2026-01-29  9:26   ` Marek Szyprowski

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