[PATCH 2/3] mm_zone: Generalise has_managed_dma()

Robin Murphy posted 3 patches 3 weeks, 4 days ago
[PATCH 2/3] mm_zone: Generalise has_managed_dma()
Posted by Robin Murphy 3 weeks, 4 days ago
It would be useful to be able to check for potential DMA pages beyond
just ZONE_DMA - generalise the existing has_managed_dma() function to
allow checking other zones too.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 include/linux/mmzone.h | 9 +++++----
 mm/page_alloc.c        | 8 ++------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 75ef7c9f9307..fc5d6c88d2f0 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1648,14 +1648,15 @@ static inline int is_highmem(const struct zone *zone)
 	return is_highmem_idx(zone_idx(zone));
 }
 
-#ifdef CONFIG_ZONE_DMA
-bool has_managed_dma(void);
-#else
+bool has_managed_zone(enum zone_type zone);
 static inline bool has_managed_dma(void)
 {
+#ifdef CONFIG_ZONE_DMA
+	return has_managed_zone(ZONE_DMA);
+#else
 	return false;
-}
 #endif
+}
 
 
 #ifndef CONFIG_NUMA
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 822e05f1a964..36ccc85c5073 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7418,20 +7418,16 @@ bool put_page_back_buddy(struct page *page)
 }
 #endif
 
-#ifdef CONFIG_ZONE_DMA
-bool has_managed_dma(void)
+bool has_managed_zone(enum zone_type zone)
 {
 	struct pglist_data *pgdat;
 
 	for_each_online_pgdat(pgdat) {
-		struct zone *zone = &pgdat->node_zones[ZONE_DMA];
-
-		if (managed_zone(zone))
+		if (managed_zone(&pgdat->node_zones[zone]))
 			return true;
 	}
 	return false;
 }
-#endif /* CONFIG_ZONE_DMA */
 
 #ifdef CONFIG_UNACCEPTED_MEMORY
 
-- 
2.34.1
Re: [PATCH 2/3] mm_zone: Generalise has_managed_dma()
Posted by Mike Rapoport 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 03:46:37PM +0000, Robin Murphy wrote:
> It would be useful to be able to check for potential DMA pages beyond
> just ZONE_DMA - generalise the existing has_managed_dma() function to
> allow checking other zones too.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  include/linux/mmzone.h | 9 +++++----
>  mm/page_alloc.c        | 8 ++------
>  2 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 75ef7c9f9307..fc5d6c88d2f0 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1648,14 +1648,15 @@ static inline int is_highmem(const struct zone *zone)
>  	return is_highmem_idx(zone_idx(zone));
>  }
>  
> -#ifdef CONFIG_ZONE_DMA
> -bool has_managed_dma(void);
> -#else
> +bool has_managed_zone(enum zone_type zone);
>  static inline bool has_managed_dma(void)
>  {
> +#ifdef CONFIG_ZONE_DMA
> +	return has_managed_zone(ZONE_DMA);
> +#else
>  	return false;
> -}
>  #endif
> +}
>  
>  
>  #ifndef CONFIG_NUMA
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 822e05f1a964..36ccc85c5073 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7418,20 +7418,16 @@ bool put_page_back_buddy(struct page *page)
>  }
>  #endif
>  
> -#ifdef CONFIG_ZONE_DMA
> -bool has_managed_dma(void)
> +bool has_managed_zone(enum zone_type zone)
>  {
>  	struct pglist_data *pgdat;
>  
>  	for_each_online_pgdat(pgdat) {
> -		struct zone *zone = &pgdat->node_zones[ZONE_DMA];
> -
> -		if (managed_zone(zone))
> +		if (managed_zone(&pgdat->node_zones[zone]))
>  			return true;
>  	}
>  	return false;
>  }
> -#endif /* CONFIG_ZONE_DMA */
>  
>  #ifdef CONFIG_UNACCEPTED_MEMORY
>  
> -- 
> 2.34.1
> 

-- 
Sincerely yours,
Mike.
Re: [PATCH 2/3] mm_zone: Generalise has_managed_dma()
Posted by David Hildenbrand (Red Hat) 3 weeks, 4 days ago
On 1/12/26 16:46, Robin Murphy wrote:
> It would be useful to be able to check for potential DMA pages beyond
> just ZONE_DMA - generalise the existing has_managed_dma() function to
> allow checking other zones too.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>

-- 
Cheers

David