All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] riscv: increase stack size to avoid a stack overflow during distro boot
@ 2019-10-20 18:53 Lukas Auer
       [not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA412B7F6@ATCPCS16.andestech.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Auer @ 2019-10-20 18:53 UTC (permalink / raw)
  To: u-boot

This fixes a problem, where booting Linux using distro boot will
sometimes lead to an invalid instruction exception on the main hart. The
secondary harts are not affected and boot Linux successfully. The root
cause of this problem is a stack overflow on the main hart.

With distro boot, the current default stack size of 8KiB on RISC-V is
not sufficient and will cause a stack overflow. The stacks are allocated
sequentially. In the case of a stack overflow the stack of the main hart
can reach into that of another hart and be corrupted.

The stack overflow previously did not cause any problems, because only
stack frames, which are not used anymore since the hart enters Linux,
were corrupted. Starting with GCC 9, the stack usage has decreased. Now,
only the most recent stack frame overflows into the stack of a secondary
hart and is corrupted. The illegal instruction exception is caused by
the secondary hart overwriting the return address in the stack frame of
the main hart with an address that does not include valid code.

Increase the default stack size of each hart to 16KiB to avoid this
problem.

Reported-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
Tested-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
Tested-by: Aurelien Jarno <aurelien@aurel32.net>
---

 arch/riscv/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 01975d7c60..85e15ebffa 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -224,7 +224,7 @@ config XIP
 
 config STACK_SIZE_SHIFT
 	int
-	default 13
+	default 14
 
 config SPL_LDSCRIPT
 	default "arch/riscv/cpu/u-boot-spl.lds"
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] riscv: increase stack size to avoid a stack overflow during distro boot
       [not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA412B7F6@ATCPCS16.andestech.com>
@ 2019-10-25  1:10   ` Rick Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Rick Chen @ 2019-10-25  1:10 UTC (permalink / raw)
  To: u-boot

> > From: Lukas Auer [mailto:lukas.auer at aisec.fraunhofer.de]
> > Sent: Monday, October 21, 2019 2:54 AM
> > To: u-boot at lists.denx.de
> > Cc: Alistair Francis; Anup Patel; Bin Meng; Atish Patra; Lukas Auer; Aurelien
> > Jarno; David Abdurachmanov; Rick Jian-Zhi Chen(陳建志)
> > Subject: [PATCH] riscv: increase stack size to avoid a stack overflow during
> > distro boot
> >
> > This fixes a problem, where booting Linux using distro boot will sometimes
> > lead to an invalid instruction exception on the main hart. The secondary harts
> > are not affected and boot Linux successfully. The root cause of this problem is
> > a stack overflow on the main hart.
> >
> > With distro boot, the current default stack size of 8KiB on RISC-V is not
> > sufficient and will cause a stack overflow. The stacks are allocated sequentially.
> > In the case of a stack overflow the stack of the main hart can reach into that of
> > another hart and be corrupted.
> >
> > The stack overflow previously did not cause any problems, because only stack
> > frames, which are not used anymore since the hart enters Linux, were
> > corrupted. Starting with GCC 9, the stack usage has decreased. Now, only the
> > most recent stack frame overflows into the stack of a secondary hart and is
> > corrupted. The illegal instruction exception is caused by the secondary hart
> > overwriting the return address in the stack frame of the main hart with an
> > address that does not include valid code.
> >
> > Increase the default stack size of each hart to 16KiB to avoid this problem.
> >
> > Reported-by: Aurelien Jarno <aurelien@aurel32.net>
> > Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
> > Tested-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
> > Tested-by: Aurelien Jarno <aurelien@aurel32.net>
> > ---
> >
> >  arch/riscv/Kconfig | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index
> > 01975d7c60..85e15ebffa 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -224,7 +224,7 @@ config XIP
> >
> >  config STACK_SIZE_SHIFT
> >       int
> > -     default 13
> > +     default 14
> >
> >  config SPL_LDSCRIPT
> >       default "arch/riscv/cpu/u-boot-spl.lds"
> > --
> > 2.21.0
>

Reviewed-by: Rick Chen <rick@andestech.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-25  1:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20 18:53 [U-Boot] [PATCH] riscv: increase stack size to avoid a stack overflow during distro boot Lukas Auer
     [not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FA412B7F6@ATCPCS16.andestech.com>
2019-10-25  1:10   ` Rick Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.