* [PATCH] dma-mapping: use exact allocation for DMA pages
@ 2026-09-01 8:53 Qingfang Deng
2026-09-02 9:33 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Qingfang Deng @ 2026-09-01 8:53 UTC (permalink / raw)
To: Robin Murphy, Joerg Roedel (AMD),
Will Deacon, Marek Szyprowski, iommu, linux-kernel
Cc: Qingfang Deng
DMA page allocation fallbacks use alloc_pages_node() with get_order(size),
wasting the unused tail for non-power-of-two requests.
Use alloc_pages_exact_nid() and free_pages_exact() so that a buddy
fallback retains only requested pages.
Signed-off-by: Qingfang Deng <qingfang.deng@linux.dev>
---
drivers/iommu/dma-iommu.c | 10 ++++++----
include/linux/dma-map-ops.h | 2 +-
kernel/dma/contiguous.c | 6 +++---
kernel/dma/direct.c | 8 +++++---
kernel/dma/ops_helpers.c | 11 +++++++----
5 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 58c624513cd4..8f262c83802c 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1628,10 +1628,12 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size,
void *cpu_addr;
page = dma_alloc_contiguous(dev, alloc_size, gfp);
- if (!page)
- page = alloc_pages_node(node, gfp, get_order(alloc_size));
- if (!page)
- return NULL;
+ if (!page) {
+ cpu_addr = alloc_pages_exact_nid(node, alloc_size, gfp);
+ if (!cpu_addr)
+ return NULL;
+ page = virt_to_page(cpu_addr);
+ }
if (!coherent || PageHighMem(page)) {
pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 8fae2b7deb20..3ef3003713a6 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -143,7 +143,7 @@ static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
static inline void dma_free_contiguous(struct device *dev, struct page *page,
size_t size)
{
- __free_pages(page, get_order(size));
+ free_pages_exact(page_address(page), size);
}
#endif /* CONFIG_DMA_CMA*/
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 66093460584e..90937dc7c627 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -451,8 +451,8 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
*
* This function releases memory allocated by dma_alloc_contiguous(). As the
* cma_release returns false when provided pages do not belong to contiguous
- * area and true otherwise, this function then does a fallback __free_pages()
- * upon a false-return.
+ * area and true otherwise, this function then does a fallback
+ * free_pages_exact() upon a false-return.
*/
void dma_free_contiguous(struct device *dev, struct page *page, size_t size)
{
@@ -476,7 +476,7 @@ void dma_free_contiguous(struct device *dev, struct page *page, size_t size)
}
/* not in any cma, free from buddy */
- __free_pages(page, get_order(size));
+ free_pages_exact(page_address(page), size);
}
/*
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index da665ca22d5c..ea64453d7370 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -120,6 +120,7 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
int node = dev_to_node(dev);
struct page *page;
u64 phys_limit;
+ void *va;
WARN_ON_ONCE(!PAGE_ALIGNED(size));
@@ -133,9 +134,9 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
dma_free_contiguous(dev, page, size);
}
- while ((page = alloc_pages_node(node, gfp, get_order(size)))
- && !dma_coherent_ok(dev, page_to_phys(page), size)) {
- __free_pages(page, get_order(size));
+ while ((va = alloc_pages_exact_nid(node, size, gfp)) &&
+ !dma_coherent_ok(dev, virt_to_phys(va), size)) {
+ free_pages_exact(va, size);
if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
phys_limit < DMA_BIT_MASK(64) &&
@@ -146,6 +147,7 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
else
return NULL;
}
+ page = va ? virt_to_page(va) : NULL;
return page;
}
diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
index 6b5f9208d31c..5cdf3f60cf47 100644
--- a/kernel/dma/ops_helpers.c
+++ b/kernel/dma/ops_helpers.c
@@ -67,10 +67,13 @@ struct page *dma_common_alloc_pages(struct device *dev, size_t size,
phys_addr_t phys;
page = dma_alloc_contiguous(dev, size, gfp);
- if (!page)
- page = alloc_pages_node(dev_to_node(dev), gfp, get_order(size));
- if (!page)
- return NULL;
+ if (!page) {
+ void *va = alloc_pages_exact_nid(dev_to_node(dev), size, gfp);
+
+ if (!va)
+ return NULL;
+ page = virt_to_page(va);
+ }
phys = page_to_phys(page);
if (use_dma_iommu(dev))
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: use exact allocation for DMA pages
2026-09-01 8:53 [PATCH] dma-mapping: use exact allocation for DMA pages Qingfang Deng
@ 2026-09-02 9:33 ` kernel test robot
2026-09-02 10:47 ` kernel test robot
2026-09-02 11:18 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-09-02 9:33 UTC (permalink / raw)
To: Qingfang Deng, Robin Murphy, Joerg Roedel (AMD),
Will Deacon, Marek Szyprowski, iommu, linux-kernel
Cc: oe-kbuild-all, Qingfang Deng
Hi Qingfang,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v7.3-rc1 next-20260901]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Qingfang-Deng/dma-mapping-use-exact-allocation-for-DMA-pages/20260901-165347
base: linus/master
patch link: https://lore.kernel.org/r/20260901085348.53140-1-qingfang.deng%40linux.dev
patch subject: [PATCH] dma-mapping: use exact allocation for DMA pages
config: alpha-allnoconfig (https://download.01.org/0day-ci/archive/20260902/202609021750.Ifwj5NHl-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260902/202609021750.Ifwj5NHl-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/202609021750.Ifwj5NHl-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: vmlinux: 'saved_config' is COMMON symbol
>> WARNING: modpost: vmlinux: section mismatch in reference: __dma_direct_alloc_pages.isra.0+0xcc (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __dma_direct_alloc_pages.isra.0+0xe0 (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
>> WARNING: modpost: vmlinux: section mismatch in reference: dma_common_alloc_pages+0x10 (section: .text.unlikely) -> alloc_pages_exact_nid_noprof (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: dma_common_alloc_pages+0x50 (section: .text.unlikely) -> alloc_pages_exact_nid_noprof (section: .init.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: use exact allocation for DMA pages
2026-09-01 8:53 [PATCH] dma-mapping: use exact allocation for DMA pages Qingfang Deng
2026-09-02 9:33 ` kernel test robot
@ 2026-09-02 10:47 ` kernel test robot
2026-09-02 11:18 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-09-02 10:47 UTC (permalink / raw)
To: Qingfang Deng, Robin Murphy, Joerg Roedel (AMD),
Will Deacon, Marek Szyprowski, iommu, linux-kernel
Cc: oe-kbuild-all, Qingfang Deng
Hi Qingfang,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v7.3-rc1 next-20260901]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Qingfang-Deng/dma-mapping-use-exact-allocation-for-DMA-pages/20260901-165347
base: linus/master
patch link: https://lore.kernel.org/r/20260901085348.53140-1-qingfang.deng%40linux.dev
patch subject: [PATCH] dma-mapping: use exact allocation for DMA pages
config: xtensa-allnoconfig (https://download.01.org/0day-ci/archive/20260902/202609021852.48BS9Wph-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260902/202609021852.48BS9Wph-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/202609021852.48BS9Wph-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux: section mismatch in reference: check_ram_in_range_map+0xc0 (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: __dma_direct_alloc_pages.isra.0+0xab (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: try_to_run_init_process+0x24 (section: .text.unlikely) -> initcall_level_names (section: .init.data)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: use exact allocation for DMA pages
2026-09-01 8:53 [PATCH] dma-mapping: use exact allocation for DMA pages Qingfang Deng
2026-09-02 9:33 ` kernel test robot
2026-09-02 10:47 ` kernel test robot
@ 2026-09-02 11:18 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-09-02 11:18 UTC (permalink / raw)
To: Qingfang Deng, Robin Murphy, Joerg Roedel (AMD),
Will Deacon, Marek Szyprowski, iommu, linux-kernel
Cc: llvm, oe-kbuild-all, Qingfang Deng
Hi Qingfang,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v7.3-rc1 next-20260901]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Qingfang-Deng/dma-mapping-use-exact-allocation-for-DMA-pages/20260901-165347
base: linus/master
patch link: https://lore.kernel.org/r/20260901085348.53140-1-qingfang.deng%40linux.dev
patch subject: [PATCH] dma-mapping: use exact allocation for DMA pages
config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20260902/202609021920.kdbedjPR-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260902/202609021920.kdbedjPR-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/202609021920.kdbedjPR-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: vmlinux: section mismatch in reference: __dma_direct_alloc_pages+0xdd (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
>> WARNING: modpost: vmlinux: section mismatch in reference: dma_common_alloc_pages+0x17 (section: .text) -> alloc_pages_exact_nid_noprof (section: .init.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-02 11:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-01 8:53 [PATCH] dma-mapping: use exact allocation for DMA pages Qingfang Deng
2026-09-02 9:33 ` kernel test robot
2026-09-02 10:47 ` kernel test robot
2026-09-02 11:18 ` kernel test robot
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®