Skip to contentSkip to conversation

dma-contiguous: CMA: give precedence to cmdline

PATCH In review Nicolas Saenz Julienne 3 participants 4 messages Jan 10, 2020 – Jan 30, 2020 DMA mapping helpers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-contiguous: CMA: give precedence to cmdline

Although the device tree might contain a reserved-memory DT node dedicated as the default CMA pool, users might want to change CMA's parameters using the kernel command line for debugging purposes and whatnot. Honor this by bypassing the reserved memory CMA setup, which will ultimately end up freeing the memblock and allow the command line CMA configuration routine to run.

---

NOTE: Tested this on arm and arm64 with the Raspberry Pi 4.

 kernel/dma/contiguous.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/dma/contiguous.c +8 -1
index daa4e6eefdde..8bc6f2d670f9 100644
@@ -302,9 +302,16 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
 	phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
 	phys_addr_t mask = align - 1;
 	unsigned long node = rmem->fdt_node;
+	bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);
 	struct cma *cma;
 	int err;
 
+	if (size_cmdline != -1 && default_cma) {
+		pr_info("Reserved memory: bypass %s node, using cmdline CMA params instead\n",
+			rmem->name);
+		return -EBUSY;
+	}
+
 	if (!of_get_flat_dt_prop(node, "reusable", NULL) ||
 	    of_get_flat_dt_prop(node, "no-map", NULL))
 		return -EINVAL;
@@ -322,7 +329,7 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
 	/* Architecture specific contiguous memory fixup. */
 	dma_contiguous_early_fixup(rmem->base, rmem->size);
 
-	if (of_get_flat_dt_prop(node, "linux,cma-default", NULL))
+	if (default_cma)
 		dma_contiguous_set_default(cma);
 
 	rmem->ops = &rmem_cma_ops;
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Nicolas,

Quoted 38 lines · Nicolas Saenz Julienne

Although the device tree might contain a reserved-memory DT node dedicated as the default CMA pool, users might want to change CMA's parameters using the kernel command line for debugging purposes and whatnot. Honor this by bypassing the reserved memory CMA setup, which will ultimately end up freeing the memblock and allow the command line CMA configuration routine to run.

---

NOTE: Tested this on arm and arm64 with the Raspberry Pi 4.

  kernel/dma/contiguous.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
kernel/dma/contiguous.c +7 -0
index daa4e6eefdde..8bc6f2d670f9 100644
@@ -302,9 +302,16 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
  	phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order);
  	phys_addr_t mask = align - 1;
  	unsigned long node = rmem->fdt_node;
+	bool default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);
  	struct cma *cma;
  	int err;
 
+	if (size_cmdline != -1 && default_cma) {
+		pr_info("Reserved memory: bypass %s node, using cmdline CMA params instead\n",
+			rmem->name);
+		return -EBUSY;
+	}
+
  	if (!of_get_flat_dt_prop(node, "reusable", NULL) ||
  	    of_get_flat_dt_prop(node, "no-map", NULL))
  		return -EINVAL;

kernel/dma/contiguous.c static int __init rmem_cma_setup(struct reserved_mem *rmem) · line 335

Quoted 8 lines
kernel/dma/contiguous.c +1 -1
@@ -322,7 +329,7 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
  	/* Architecture specific contiguous memory fixup. */
  	dma_contiguous_early_fixup(rmem->base, rmem->size);
 
-	if (of_get_flat_dt_prop(node, "linux,cma-default", NULL))
+	if (default_cma)
  		dma_contiguous_set_default(cma);
 
  	rmem->ops = &rmem_cma_ops;

For what it's worth,

Phil

#3 lore raw
Quoted 1 line · Christoph Hellwig

I've picked this up for Linux 5.6, sorry for the delay.

Thanks!