[PATCH v6 5/8] dma: swiotlb: Centralize minimal pool sizing

From: Aneesh Kumar K.V (Arm)

Date: Thu Sep 24 2026 - 02:11:01 EST


A default SWIOTLB pool used only for unaligned kmalloc bouncing can be
smaller than one required for limited DMA addressing. Arm64 and RISC-V
currently implement this sizing independently, using 1 MiB of SWIOTLB
space per GiB of RAM.

The SWIOTLB core now identifies this case with SWIOTLB_POOL_MINIMAL.
Size that policy in swiotlb_adjust_pool_size() and remove the
architecture-specific adjustments.

Explicit swiotlb= sizing remains unchanged because swiotlb_adjust_size()
preserves a user-configured size.

Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Paul Walmsley <pjw@xxxxxxxxxx>
Cc: Palmer Dabbelt <palmer@xxxxxxxxxxx>
Cc: Albert Ou <aou@xxxxxxxxxxxxxxxxx>
Cc: Alexandre Ghiti <alex@xxxxxxxx>
Cc: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Cc: Robin Murphy <robin.murphy@xxxxxxx>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
---
arch/arm64/mm/init.c | 11 -----------
arch/riscv/mm/init.c | 4 ----
kernel/dma/swiotlb.c | 9 ++++++++-
3 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index f55ebe57b8e1..95075b5c8207 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -340,17 +340,6 @@ void __init arch_mm_preinit(void)
{
unsigned int flags = SWIOTLB_VERBOSE;

- if (max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
- /*
- * If no bouncing needed for ZONE_DMA, reduce the swiotlb
- * buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
- */
- unsigned long size =
- DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
-
- swiotlb_adjust_size(min(swiotlb_default_pool_size(), size));
- }
-
if (max_pfn > PFN_DOWN(arm64_dma_phys_limit))
flags |= SWIOTLB_INIT_ADDRESSING_LIMIT;

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 2562cf45a8f2..96856114b387 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -183,10 +183,6 @@ void __init arch_mm_preinit(void)
* memory when DRAM starts above dma32_phys_limit. Allocate
* ~1 MB per 1 GB of RAM.
*/
- unsigned long size =
- DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
- swiotlb_adjust_size(min(swiotlb_default_pool_size(), size));
- swiotlb = true;
swiotlb_flags |= SWIOTLB_ANY;
}

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 8ae315b2d0e7..75ee63cd354e 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -469,9 +469,14 @@ static bool __init swiotlb_kmalloc_needs_bounce(void)
static void __init
swiotlb_adjust_pool_size(enum swiotlb_pool_policy policy)
{
+ unsigned long size;
+
switch (policy) {
case SWIOTLB_POOL_MINIMAL:
- return;
+ /* Use 1MB per 1GB of RAM for kmalloc() bouncing. */
+ size = DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
+ size = min(swiotlb_default_pool_size(), size);
+ break;
case SWIOTLB_POOL_CC_GUEST:
return;
case SWIOTLB_POOL_NONE:
@@ -481,6 +486,8 @@ swiotlb_adjust_pool_size(enum swiotlb_pool_policy policy)
default:
return;
}
+
+ swiotlb_adjust_size(size);
}

static enum swiotlb_pool_policy __init
--
2.43.0