Skip to contentSkip to conversation

Kconfig: Add SPL_SYS_MALLOC_CLEAR_ON_INIT

PATCH Superseded Shengyu Qu 2 participants 5 messages Aug 23, 2023 1 message not in the archive RISC-V

v5 of 6 Superseded Latest is v6 →

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 v5 1/3 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.

---
 Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
Kconfig +11 -0
index 91170bf8d2..588acbaf9b 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.38.1.windows.1
#2 lore raw
Quoted 18 lines · Shengyu Qu

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

---
 Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
Kconfig +1 -0
index 91170bf8d2..588acbaf9b 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

Kconfig if EXPERT · line 385

Quoted 10 lines
Kconfig +10 -0
+	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.
+

Please fix the whitespace here.

Signature · 1 line
Tom
author
#3 lore raw

PATCH v5 2/3 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.38.1.windows.1
author
#5 lore raw

PATCH v5 3/3 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.38.1.windows.1