Skip to contentSkip to conversation

arm64: fix CONFIG_ZONE_DMA on systems with no 32-bit addressable DRAM

PATCH In review Mark Salter 3 participants 3 messages Jun 23, 2014 – Jun 27, 2014 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: fix CONFIG_ZONE_DMA on systems with no 32-bit addressable DRAM

Commit 2d5a5612bc (arm64: Limit the CMA buffer to 32-bit if ZONE_DMA) forces the CMA buffer to be 32-bit addressable if CONFIG_ZONE_DMA is defined. This breaks CMA on platforms with no 32-bit addressable DRAM. This patch checks to make sure there is 32-bit addressable DRAM before setting the 32-bit limit. If there is none, no limit is placed on the CMA buffer. This allows a single kernel (with CONFIG_ZONE_DMA defined) to support platforms requiring the 32-bit limit and platforms with no 32-bit limit.

---
 arch/arm64/mm/init.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm64/mm/init.c +10 -1
index c5415e2..2925576 100644
@@ -149,8 +149,17 @@ void __init arm64_memblock_init(void)
 	early_init_fdt_scan_reserved_mem();
 
 	/* 4GB maximum for 32-bit only capable devices */
-	if (IS_ENABLED(CONFIG_ZONE_DMA))
+	if (IS_ENABLED(CONFIG_ZONE_DMA)) {
 		dma_phys_limit = dma_to_phys(NULL, DMA_BIT_MASK(32)) + 1;
+		/*
+		 * If platform doesn't have DRAM within the dma_phys_limit,
+		 * remove the limit altogether. This allows one kernel (with
+		 * CONFIG_ZONE_DMA defined) to support platforms with 32-bit
+		 * only devices and platforms with no 32-bit DRAM.
+		 */
+		if (dma_phys_limit <= memblock_start_of_DRAM())
+			dma_phys_limit = 0;
+	}
 	dma_contiguous_reserve(dma_phys_limit);
 
 	memblock_allow_resize();
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 27 lines · Mark Salter

Commit 2d5a5612bc (arm64: Limit the CMA buffer to 32-bit if ZONE_DMA) forces the CMA buffer to be 32-bit addressable if CONFIG_ZONE_DMA is defined. This breaks CMA on platforms with no 32-bit addressable DRAM. This patch checks to make sure there is 32-bit addressable DRAM before setting the 32-bit limit. If there is none, no limit is placed on the CMA buffer. This allows a single kernel (with CONFIG_ZONE_DMA defined) to support platforms requiring the 32-bit limit and platforms with no 32-bit limit.

---
 arch/arm64/mm/init.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm64/mm/init.c +3 -1
index c5415e2..2925576 100644
@@ -149,8 +149,17 @@ void __init arm64_memblock_init(void)
 	early_init_fdt_scan_reserved_mem();
 
 	/* 4GB maximum for 32-bit only capable devices */
-	if (IS_ENABLED(CONFIG_ZONE_DMA))
+	if (IS_ENABLED(CONFIG_ZONE_DMA)) {
 		dma_phys_limit = dma_to_phys(NULL, DMA_BIT_MASK(32)) + 1;
+		/*
+		 * If platform doesn't have DRAM within the dma_phys_limit,

arch/arm64/mm/init.c void __init arm64_memblock_init(void) · line 165

Quoted 10 lines
arch/arm64/mm/init.c +7 -0
+		 * remove the limit altogether. This allows one kernel (with
+		 * CONFIG_ZONE_DMA defined) to support platforms with 32-bit
+		 * only devices and platforms with no 32-bit DRAM.
+		 */
+		if (dma_phys_limit <= memblock_start_of_DRAM())
+			dma_phys_limit = 0;
+	}
 	dma_contiguous_reserve(dma_phys_limit);
 
 	memblock_allow_resize();

It is a shame that we have very similar logic, all dependent on memblock_start_of_DRAM(), in both zone_sizes_init() and arm64_memblock_init() and the latter having to be called before the former. I assume there's no way to make this cleaner in the bootstrap code so the dma_to_phys(NULL, DMA_BIT_MASK(32)) + 1 limit can be handled properly in a single location?

maintainer
#2 lore raw
Quoted 38 lines · David Rientjes
Quoted 36 lines · Mark Salter

Commit 2d5a5612bc (arm64: Limit the CMA buffer to 32-bit if ZONE_DMA) forces the CMA buffer to be 32-bit addressable if CONFIG_ZONE_DMA is defined. This breaks CMA on platforms with no 32-bit addressable DRAM. This patch checks to make sure there is 32-bit addressable DRAM before setting the 32-bit limit. If there is none, no limit is placed on the CMA buffer. This allows a single kernel (with CONFIG_ZONE_DMA defined) to support platforms requiring the 32-bit limit and platforms with no 32-bit limit.

---
 arch/arm64/mm/init.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm64/mm/init.c +10 -1
index c5415e2..2925576 100644
@@ -149,8 +149,17 @@ void __init arm64_memblock_init(void)
 	early_init_fdt_scan_reserved_mem();
 
 	/* 4GB maximum for 32-bit only capable devices */
-	if (IS_ENABLED(CONFIG_ZONE_DMA))
+	if (IS_ENABLED(CONFIG_ZONE_DMA)) {
 		dma_phys_limit = dma_to_phys(NULL, DMA_BIT_MASK(32)) + 1;
+		/*
+		 * If platform doesn't have DRAM within the dma_phys_limit,
+		 * remove the limit altogether. This allows one kernel (with
+		 * CONFIG_ZONE_DMA defined) to support platforms with 32-bit
+		 * only devices and platforms with no 32-bit DRAM.
+		 */
+		if (dma_phys_limit <= memblock_start_of_DRAM())
+			dma_phys_limit = 0;
+	}
 	dma_contiguous_reserve(dma_phys_limit);
 
Quoted 8 lines

arch/arm64/mm/init.c void __init arm64_memblock_init(void) · line 165

Quoted 1 line
arch/arm64/mm/init.c +0 -0
 	memblock_allow_resize();

It is a shame that we have very similar logic, all dependent on memblock_start_of_DRAM(), in both zone_sizes_init() and arm64_memblock_init() and the latter having to be called before the former. I assume there's no way to make this cleaner in the bootstrap code so the dma_to_phys(NULL, DMA_BIT_MASK(32)) + 1 limit can be handled properly in a single location?

Probably and I suggested something along the lines of only calculating it once in reply to the "[PATCH] arm64: make CONFIG_ZONE_DMA user settable" message. I'll follow up on the other thread (Mark considers there's a penalty issue with all memory in the DMA zone).

Signature · 1 line
Catalin