Skip to contentSkip to conversation

Kconfig: Add SPL_SYS_MALLOC_CLEAR_ON_INIT

PATCH In review Shengyu Qu 3 participants 7 messages Aug 24, 2023 – Sep 4, 2023 1 message not in the archive RISC-V

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Shengyu Qu

author
#1 lore raw

PATCH v6 1/4 Kconfig: Add SPL_SYS_MALLOC_CLEAR_ON_INIT

Add SPL version of SYS_MALLOC_CLEAR_ON_INIT, this would help devices that need to clear ram before use to work correctly.

---
Changes since v5:
- Fix whitespace

---
 Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
Kconfig +11 -0
index 91170bf8d2..6ba605a564 100644
@@ -372,6 +372,17 @@ if EXPERT
 	  When disabling this, please check if malloc calls, maybe
 	  should be replaced by calloc - if one expects zeroed memory.
 
+config SPL_SYS_MALLOC_CLEAR_ON_INIT
+	bool "Init with zeros the memory reserved for malloc (slow) in SPL"
+	depends on SPL
+	default SYS_MALLOC_CLEAR_ON_INIT
+	help
+	  Same as SYS_MALLOC_CLEAR_ON_INIT, but for SPL. It's possible to
+	  Enable it without SYS_MALLOC_CLEAR_ON_INIT. It's useful for boards
+	  that must have particular memory regions zero'ed before first use.
+	  If SYS_SPL_MALLOC_START is configured to be in such region, this
+	  option should be enabled.
+
 config SYS_MALLOC_DEFAULT_TO_INIT
 	bool "Default malloc to init while reserving the memory for it"
 	help
Signature · 1 line
2.42.0
author
#3 lore raw

PATCH v6 2/4 dlmalloc: Add support for SPL_SYS_MALLOC_CLEAR_ON_INIT

In reply to a message not in the archive

To support SPL_SYS_MALLOC_CLEAR_ON_INIT, we have to modify #ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
to #if CONFIG_IS_ENABLED(SYS_MALLOC_CLEAR_ON_INIT)

---
 common/dlmalloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/dlmalloc.c +3 -3
index 0f9b7262d5..dcecdb8623 100644
@@ -631,7 +631,7 @@ void mem_malloc_init(ulong start, ulong size)
 
 	debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start,
 	      mem_malloc_end);
-#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
+#if CONFIG_IS_ENABLED(SYS_MALLOC_CLEAR_ON_INIT)
 	memset((void *)mem_malloc_start, 0x0, size);
 #endif
 	malloc_bin_reloc();
@@ -2153,7 +2153,7 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
 
 
   /* check if expand_top called, in which case don't need to clear */
-#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
+#if CONFIG_IS_ENABLED(SYS_MALLOC_CLEAR_ON_INIT)
 #if MORECORE_CLEARS
   mchunkptr oldtop = top;
   INTERNAL_SIZE_T oldtopsize = chunksize(top);
@@ -2184,7 +2184,7 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
 
     csz = chunksize(p);
 
-#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
+#if CONFIG_IS_ENABLED(SYS_MALLOC_CLEAR_ON_INIT)
 #if MORECORE_CLEARS
     if (p == oldtop && csz > oldtopsize)
     {
Signature · 1 line
2.42.0
author
#4 lore raw

PATCH v6 3/4 riscv: cpu: jh7110: Imply SPL_SYS_MALLOC_CLEAR_ON_INIT

In reply to a message not in the archive

Starfive JH7110 needs to clear L2 LIM to zero before use or ECC error would be triggered. Currently, we use DDR ram for SPL malloc arena on Visionfive 2 board in defconfig, but it's also possible to use L2 LIM as SPL malloc arena. To avoid triggering ECC error in this scenario, we imply SPL_SYS_MALLOC_CLEAR_ON_INIT as default.

---
 arch/riscv/cpu/jh7110/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/cpu/jh7110/Kconfig +1 -0
index 8469ee7de5..e5549a01b8 100644
@@ -28,3 +28,4 @@ config STARFIVE_JH7110
 	imply SPL_LOAD_FIT
 	imply SPL_OPENSBI
 	imply SPL_RISCV_ACLINT
+	imply SPL_SYS_MALLOC_CLEAR_ON_INIT
Signature · 1 line
2.42.0
Reviewed-by on v6 3/4
#5 lore raw

Re: [PATCH v6 3/4] riscv: cpu: jh7110: Imply SPL_SYS_MALLOC_CLEAR_ON_INIT

Quoted 11 lines · Shengyu Qu

Starfive JH7110 needs to clear L2 LIM to zero before use or ECC error would be triggered. Currently, we use DDR ram for SPL malloc arena on Visionfive 2 board in defconfig, but it's also possible to use L2 LIM as SPL malloc arena. To avoid triggering ECC error in this scenario, we imply SPL_SYS_MALLOC_CLEAR_ON_INIT as default.

---
 arch/riscv/cpu/jh7110/Kconfig | 1 +
 1 file changed, 1 insertion(+)
author
#6 lore raw

PATCH v6 4/4 configs: starfive: Disable SYS_MALLOC_CLEAR_ON_INIT by default

In reply to a message not in the archive

SPL_SYS_MALLOC_CLEAR_ON_INIT would enable SYS_MALLOC_CLEAR_ON_INIT by default, but that's not need on JH7110, so disable that.

---
 configs/starfive_visionfive2_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/starfive_visionfive2_defconfig +2 -0
index e9b63e5b84..efe3c2205a 100644
@@ -58,6 +58,8 @@ CONFIG_SYS_SPL_MALLOC=y
 CONFIG_HAS_CUSTOM_SPL_MALLOC_START=y
 CONFIG_CUSTOM_SYS_SPL_MALLOC_ADDR=0x80000000
 CONFIG_SYS_SPL_MALLOC_SIZE=0x400000
+# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
+CONFIG_SPL_SYS_MALLOC_CLEAR_ON_INIT=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=0x2
 CONFIG_SPL_I2C=y
Signature · 1 line
2.42.0
Reviewed-by on v6 4/4
#7 lore raw

Re: [PATCH v6 4/4] configs: starfive: Disable SYS_MALLOC_CLEAR_ON_INIT by default

Quoted 7 lines · Shengyu Qu

SPL_SYS_MALLOC_CLEAR_ON_INIT would enable SYS_MALLOC_CLEAR_ON_INIT by default, but that's not need on JH7110, so disable that.

---
 configs/starfive_visionfive2_defconfig | 2 ++
 1 file changed, 2 insertions(+)