diff mbox series

common: spl: Warn about overflow of SRAM stack

Message ID 20230607042841.2906576-1-vigneshr@ti.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series common: spl: Warn about overflow of SRAM stack | expand

Commit Message

Vignesh Raghavendra June 7, 2023, 4:28 a.m. UTC
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.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---

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(+)

Comments

Kamlesh Gurudasani June 7, 2023, 5 a.m. UTC | #1
Vignesh Raghavendra <vigneshr@ti.com> writes:

> 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.
>
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> ---
>
> 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(+)
Reviewed-by: Kamlesh Gurudasani <kamlesh@ti.com>
Tom Rini June 7, 2023, 4:55 p.m. UTC | #2
On Wed, Jun 07, 2023 at 09:58:41AM +0530, Vignesh Raghavendra wrote:
> 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.
> 
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> ---
> 
> 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(+)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 72078a8ebc8e..9a9c8fad7673 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -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

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".
diff mbox series

Patch

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 72078a8ebc8e..9a9c8fad7673 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -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
 }