Skip to contentSkip to conversation

common: spl: Warn about overflow of SRAM stack

PATCH In review Vignesh Raghavendra 3 participants 3 messages Jun 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: spl: Warn about overflow of SRAM stack

If early stack usage is exactly same as SIZE_LIMIT_PROVIDE_STACK, then its most likely to have overflowed beyond this limit and corrupted any regions beyond stack. Warn about this to the user.

---

I found this useful when debugging slient corruption of code/data leading to random failures post relocation.

 common/spl/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
common/spl/spl.c +7 -0
index 72078a8ebc8e..9a9c8fad7673 100644
@@ -950,6 +950,13 @@ __weak void spl_relocate_stack_check(void)
 	}
 	printf("SPL initial stack usage: %lu bytes\n",
 	       CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i);
+
+	/*
+	 * If we used up all of the SIZE_LIMIT_PROVIDE_STACK, then here is high
+	 * possibility of stack overflow, warn the user accordingly
+	 */
+	if (!i)
+		printf("SPL possible initial stack overflow detected!!\n");
 #endif
 }
 
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Vignesh Raghavendra

If early stack usage is exactly same as SIZE_LIMIT_PROVIDE_STACK, then its most likely to have overflowed beyond this limit and corrupted any regions beyond stack. Warn about this to the user.

Quoted 8 lines

---

I found this useful when debugging slient corruption of code/data leading to random failures post relocation.

 common/spl/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
#2 lore raw
In reply to Vignesh Raghavendra
Quoted 19 lines · Vignesh Raghavendra

If early stack usage is exactly same as SIZE_LIMIT_PROVIDE_STACK, then its most likely to have overflowed beyond this limit and corrupted any regions beyond stack. Warn about this to the user.

---

I found this useful when debugging slient corruption of code/data leading to random failures post relocation.

 common/spl/spl.c | 7 +++++++
 1 file changed, 7 insertions(+)
common/spl/spl.c +0 -0
index 72078a8ebc8e..9a9c8fad7673 100644
@@ -950,6 +950,13 @@ __weak void spl_relocate_stack_check(void)
 	}

common/spl/spl.c __weak void spl_relocate_stack_check(void) · line 960

Quoted 10 lines
common/spl/spl.c +7 -0
 	printf("SPL initial stack usage: %lu bytes\n",
 	       CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i);
+
+	/*
+	 * If we used up all of the SIZE_LIMIT_PROVIDE_STACK, then here is high
+	 * possibility of stack overflow, warn the user accordingly
+	 */
+	if (!i)
+		printf("SPL possible initial stack overflow detected!!\n");
 #endif

Since we're already inside of CONFIG_SPL_SYS_REPORT_STACK_F_USAGE being enabled, we should rework the previous print to include something like "%lu bytes free".

Signature · 1 line
Tom