[PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory

Vladimir Kondratiev posted 1 patch 4 weeks ago
There is a newer version of this series
kernel/dma/pool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory
Posted by Vladimir Kondratiev 4 weeks ago
If system have no 32-bit memory, GFP_DMA32 pool allocation will
obviously fail, so skip it.

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 kernel/dma/pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index ee45dee33d49..f38170f6635b 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -209,7 +209,7 @@ static int __init dma_atomic_pool_init(void)
 		if (!atomic_pool_dma)
 			ret = -ENOMEM;
 	}
-	if (IS_ENABLED(CONFIG_ZONE_DMA32)) {
+	if (IS_ENABLED(CONFIG_ZONE_DMA32) && phys_ram_base < BIT_ULL(32)) {
 		atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
 						GFP_KERNEL | GFP_DMA32);
 		if (!atomic_pool_dma32)

base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
-- 
2.43.0
Re: [PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory
Posted by kernel test robot 3 weeks, 6 days ago
Hi Vladimir,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7d0a66e4bb9081d75c82ec4957c50034cb0ea449]

url:    https://github.com/intel-lab-lkp/linux/commits/Vladimir-Kondratiev/dma-pool-don-t-allocate-DMA32-pool-if-no-32-bit-memory/20260111-232732
base:   7d0a66e4bb9081d75c82ec4957c50034cb0ea449
patch link:    https://lore.kernel.org/r/20260111152632.2133580-1-vladimir.kondratiev%40mobileye.com
patch subject: [PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory
config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20260112/202601120747.TAMpIDnI-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601120747.TAMpIDnI-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601120747.TAMpIDnI-lkp@intel.com/

All errors (new ones prefixed by >>):

>> kernel/dma/pool.c:212:39: error: use of undeclared identifier 'phys_ram_base'; did you mean 'phys_base'?
     212 |         if (IS_ENABLED(CONFIG_ZONE_DMA32) && phys_ram_base < BIT_ULL(32)) {
         |                                              ^~~~~~~~~~~~~
         |                                              phys_base
   arch/x86/include/asm/page_64.h:15:22: note: 'phys_base' declared here
      15 | extern unsigned long phys_base;
         |                      ^
   1 error generated.


vim +212 kernel/dma/pool.c

   186	
   187	static int __init dma_atomic_pool_init(void)
   188	{
   189		int ret = 0;
   190	
   191		/*
   192		 * If coherent_pool was not used on the command line, default the pool
   193		 * sizes to 128KB per 1GB of memory, min 128KB, max MAX_PAGE_ORDER.
   194		 */
   195		if (!atomic_pool_size) {
   196			unsigned long pages = totalram_pages() / (SZ_1G / SZ_128K);
   197			pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES);
   198			atomic_pool_size = max_t(size_t, pages << PAGE_SHIFT, SZ_128K);
   199		}
   200		INIT_WORK(&atomic_pool_work, atomic_pool_work_fn);
   201	
   202		atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,
   203							    GFP_KERNEL);
   204		if (!atomic_pool_kernel)
   205			ret = -ENOMEM;
   206		if (has_managed_dma()) {
   207			atomic_pool_dma = __dma_atomic_pool_init(atomic_pool_size,
   208							GFP_KERNEL | GFP_DMA);
   209			if (!atomic_pool_dma)
   210				ret = -ENOMEM;
   211		}
 > 212		if (IS_ENABLED(CONFIG_ZONE_DMA32) && phys_ram_base < BIT_ULL(32)) {
   213			atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
   214							GFP_KERNEL | GFP_DMA32);
   215			if (!atomic_pool_dma32)
   216				ret = -ENOMEM;
   217		}
   218	
   219		dma_atomic_pool_debugfs_init();
   220		return ret;
   221	}
   222	postcore_initcall(dma_atomic_pool_init);
   223	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
[PATCH v2] dma-pool: don't allocate DMA32 pool if no 32-bit memory
Posted by Vladimir Kondratiev 3 weeks, 6 days ago
If system have no 32-bit memory, GFP_DMA32 pool allocation will
obviously fail, so skip it.

Changes in v2: use arch-independent "memblock_start_of_DRAM" to get
DRAM base address

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 kernel/dma/pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index ee45dee33d49..ecd77a0272f2 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -209,7 +209,7 @@ static int __init dma_atomic_pool_init(void)
 		if (!atomic_pool_dma)
 			ret = -ENOMEM;
 	}
-	if (IS_ENABLED(CONFIG_ZONE_DMA32)) {
+	if (IS_ENABLED(CONFIG_ZONE_DMA32) && memblock_start_of_DRAM() < BIT_ULL(32)) {
 		atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
 						GFP_KERNEL | GFP_DMA32);
 		if (!atomic_pool_dma32)

base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
-- 
2.43.0
Re: [PATCH v2] dma-pool: don't allocate DMA32 pool if no 32-bit memory
Posted by Robin Murphy 3 weeks, 6 days ago
On 2026-01-12 6:58 am, Vladimir Kondratiev wrote:
> If system have no 32-bit memory, GFP_DMA32 pool allocation will
> obviously fail, so skip it.

Note that the rest of the code doesn't quite work right if 
CONFIG_ZONE_DMA32 is enabled but atomic_pool_dma32 is NULL - seems such 
a setup wasn't really anticipated. Funnily enough, I also recently wrote 
a patch series to improve this more generally, but hadn't got round to 
writing a cover letter yet - lemme finish that up and post it...

Thanks,
Robin.

> Changes in v2: use arch-independent "memblock_start_of_DRAM" to get
> DRAM base address
> 
> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
> ---
>   kernel/dma/pool.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index ee45dee33d49..ecd77a0272f2 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -209,7 +209,7 @@ static int __init dma_atomic_pool_init(void)
>   		if (!atomic_pool_dma)
>   			ret = -ENOMEM;
>   	}
> -	if (IS_ENABLED(CONFIG_ZONE_DMA32)) {
> +	if (IS_ENABLED(CONFIG_ZONE_DMA32) && memblock_start_of_DRAM() < BIT_ULL(32)) {
>   		atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
>   						GFP_KERNEL | GFP_DMA32);
>   		if (!atomic_pool_dma32)
> 
> base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
Re: [PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory
Posted by kernel test robot 4 weeks ago
Hi Vladimir,

kernel test robot noticed the following build errors:

[auto build test ERROR on 7d0a66e4bb9081d75c82ec4957c50034cb0ea449]

url:    https://github.com/intel-lab-lkp/linux/commits/Vladimir-Kondratiev/dma-pool-don-t-allocate-DMA32-pool-if-no-32-bit-memory/20260111-232732
base:   7d0a66e4bb9081d75c82ec4957c50034cb0ea449
patch link:    https://lore.kernel.org/r/20260111152632.2133580-1-vladimir.kondratiev%40mobileye.com
patch subject: [PATCH] dma-pool: don't allocate DMA32 pool if no 32-bit memory
config: arc-randconfig-001-20260111 (https://download.01.org/0day-ci/archive/20260112/202601120212.Wm3uFeKw-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601120212.Wm3uFeKw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601120212.Wm3uFeKw-lkp@intel.com/

All errors (new ones prefixed by >>):

   kernel/dma/pool.c: In function 'dma_atomic_pool_init':
>> kernel/dma/pool.c:212:39: error: 'phys_ram_base' undeclared (first use in this function); did you mean 'phys_to_page'?
     if (IS_ENABLED(CONFIG_ZONE_DMA32) && phys_ram_base < BIT_ULL(32)) {
                                          ^~~~~~~~~~~~~
                                          phys_to_page
   kernel/dma/pool.c:212:39: note: each undeclared identifier is reported only once for each function it appears in


vim +212 kernel/dma/pool.c

   186	
   187	static int __init dma_atomic_pool_init(void)
   188	{
   189		int ret = 0;
   190	
   191		/*
   192		 * If coherent_pool was not used on the command line, default the pool
   193		 * sizes to 128KB per 1GB of memory, min 128KB, max MAX_PAGE_ORDER.
   194		 */
   195		if (!atomic_pool_size) {
   196			unsigned long pages = totalram_pages() / (SZ_1G / SZ_128K);
   197			pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES);
   198			atomic_pool_size = max_t(size_t, pages << PAGE_SHIFT, SZ_128K);
   199		}
   200		INIT_WORK(&atomic_pool_work, atomic_pool_work_fn);
   201	
   202		atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,
   203							    GFP_KERNEL);
   204		if (!atomic_pool_kernel)
   205			ret = -ENOMEM;
   206		if (has_managed_dma()) {
   207			atomic_pool_dma = __dma_atomic_pool_init(atomic_pool_size,
   208							GFP_KERNEL | GFP_DMA);
   209			if (!atomic_pool_dma)
   210				ret = -ENOMEM;
   211		}
 > 212		if (IS_ENABLED(CONFIG_ZONE_DMA32) && phys_ram_base < BIT_ULL(32)) {
   213			atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
   214							GFP_KERNEL | GFP_DMA32);
   215			if (!atomic_pool_dma32)
   216				ret = -ENOMEM;
   217		}
   218	
   219		dma_atomic_pool_debugfs_init();
   220		return ret;
   221	}
   222	postcore_initcall(dma_atomic_pool_init);
   223	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki