Commit 6b20dc16 authored by Lukas Auer's avatar Lukas Auer Committed by Andes
Browse files

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
Reported-by: default avatarAurelien Jarno <>
Signed-off-by: default avatarLukas Auer <>
Tested-by: default avatarDavid Abdurachmanov <>
Tested-by: default avatarAurelien Jarno <>
Reviewed-by: default avatarRick Chen <>
parent 0c5c3f29
......@@ -224,7 +224,7 @@ config XIP
default 13
default 14
default "arch/riscv/cpu/"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment