rivosinc / salus

Risc-V hypervisor for TEE development
92 stars 25 forks source link

Check for stack overflow in trap handler #296

Closed glg-rv closed 1 year ago

glg-rv commented 1 year ago

This change adds support for having a trap handler (that panics) in case the kernel stack is exhausted.

RISC-V lacking double fault, we check the stack pointer at the entry of the trap handler. When this happens, we switch to an emergency frame. Since this is a panic frame, we have only one for all CPUs, and we use a simple spinlock to allocate it in case two CPUs run out of stack at the same time.

I couldn't find a way to not clobber one register of the frame, and having to choose I went for T1. I don't think this is important, the most important data we get from such a failure is: IP and stack pointer.