-
-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aarch64: handle exceptions on dedicated stack
This patch changes exception handling mechanism to use dedicated exception stack instead of the default stack provided for kernel and application threads. This is critical to support Golang apps which are known to use tiny stacks in coroutines and exception handler of svc instruction cannnot use single byte of the application stack in such case. Having separate exception stack has other benefits for debugging and will allow future implementation of "lazy" stacks. This also makes aarch64 port similar to x64 where we use dedicated stacks as well. To support dedicated stacks, we take advantage of the fact that at every exception level but EL0 there are two stack registers available - SP_ELx and SP_EL0. OSv runs at the exception level EL1 and in boot.S selects EP_EL1 to be used by default. The SP effectively is an alias to one of the two stack registers and can be changed by setting the system register SPSel (stack selector). This patch changes all exception handlers (both synchrounous and asynchronous (interrupts)) in entry.S to switch to the new exception stack before pushing a frame by setting the SPSel to #0 which makes SP point to SP_EL0. We have to switch to SP_EL0 even in the case of the nested exception when we are on SP_EL0 as per ARM specification the SP is always reset to SP_ELx (in our case SP_EL1) after taking an exception. The typical case of nested exception is handling of a page fault where we enable exceptions downstream in the page fault handler (arch/aarch64/mmu.cc) and it may be interrupted by an asynchronous exception like a timer one. To that end we also add the exception handlers for curr_el_sp0 which system invokes when code is running with SP pointing to SP_EL0. Finally, we also change the context switch code in sched.S to make it save not only default stack register but explicitly save SP_EL0 and SP_EL1 and SPSel for old thread and then restore those from arch_thread_state for new thread. This makes context switch slightly more expensive and has been measured to add around 5% of overhead. This patch effectively enhances OSv to allow runing Golang apps on AArch64. Fixes #1155 Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
- Loading branch information
Showing
5 changed files
with
78 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters