2323#include <asm/mmu.h>
2424#include <asm/processor.h>
2525#include <asm/ptrace.h>
26+ #include <asm/scs.h>
2627#include <asm/thread_info.h>
2728#include <asm/asm - uaccess.h>
2829#include <asm/unistd.h>
@@ -179,6 +180,8 @@ alternative_cb_end
179180 apply_ssbd 1 , x22 , x23
180181
181182 ptrauth_keys_install_kernel tsk , 1 , x20 , x22 , x23
183+
184+ scs_load tsk , x20
182185 .else
183186 add x21 , sp , #S_FRAME_SIZE
184187 get_current_task tsk
@@ -343,6 +346,8 @@ alternative_else_nop_endif
343346 msr cntkctl_el1 , x1
3443474 :
345348#endif
349+ scs_save tsk , x0
350+
346351 / * No kernel C function calls after this as user keys are set. * /
347352 ptrauth_keys_install_user tsk , x0 , x1 , x2
348353
@@ -388,6 +393,9 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
388393
389394 .macro irq_stack_entry
390395 mov x19 , sp // preserve the original sp
396+ #ifdef CONFIG_SHADOW_CALL_STACK
397+ mov x24 , x18 // preserve the original shadow stack
398+ #endif
391399
392400 / *
393401 * Compare sp with the base of the task stack.
@@ -405,15 +413,25 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
405413
406414 / * switch to the irq stack * /
407415 mov sp , x26
416+
417+ #ifdef CONFIG_SHADOW_CALL_STACK
418+ / * also switch to the irq shadow stack * /
419+ adr_this_ cpu x18 , irq_shadow_call_stack , x26
420+ #endif
421+
4084229998 :
409423 .endm
410424
411425 / *
412- * x19 should be preserved between irq_stack_entry and
413- * irq_stack_exit.
426+ * The callee - saved regs (x19 - x29) should be preserved between
427+ * irq_stack_entry and irq_stack_exit , but note th at kernel_entry
428+ * uses x20 - x23 to store data for later use.
414429 * /
415430 .macro irq_stack_exit
416431 mov sp , x19
432+ #ifdef CONFIG_SHADOW_CALL_STACK
433+ mov x18 , x24
434+ #endif
417435 .endm
418436
419437/ * GPRs used by entry code * /
@@ -901,6 +919,8 @@ SYM_FUNC_START(cpu_switch_to)
901919 mov sp , x9
902920 msr sp_el0 , x1
903921 ptrauth_keys_install_kernel x1 , 1 , x8 , x9 , x10
922+ scs_save x0 , x8
923+ scs_load x1 , x8
904924 ret
905925SYM_FUNC_END(cpu_switch_to)
906926NOKPROBE(cpu_switch_to)
0 commit comments