Skip to content

Commit 8e334d7

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: smp: unify task and sp setup
Once we enable the MMU, we have to initialize: * SP_EL0 to point at the active task * SP to point at the active task's stack * SCS_SP to point at the active task's shadow stack For all tasks (including init_task), this information can be derived from the task's task_struct. Let's unify __primary_switched and __secondary_switched to consistently acquire this information from the relevant task_struct. At the same time, let's fold this together with initializing a task's final frame. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: James Morse <james.morse@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Suzuki Poulose <suzuki.poulose@arm.com> Cc: Will Deacon <will@kernel.org> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20210520115031.18509-6-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 3305e7f commit 8e334d7

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

arch/arm64/kernel/head.S

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,24 @@ SYM_FUNC_START_LOCAL(__create_page_tables)
395395
SYM_FUNC_END(__create_page_tables)
396396

397397
/*
398+
* Initialize CPU registers with task-specific and cpu-specific context.
399+
*
398400
* Create a final frame record at task_pt_regs(current)->stackframe, so
399401
* that the unwinder can identify the final frame record of any task by
400402
* its location in the task stack. We reserve the entire pt_regs space
401403
* for consistency with user tasks and kthreads.
402404
*/
403-
.macro setup_final_frame
405+
.macro init_cpu_task tsk, tmp
406+
msr sp_el0, \tsk
407+
408+
ldr \tmp, [\tsk, #TSK_STACK]
409+
add sp, \tmp, #THREAD_SIZE
404410
sub sp, sp, #PT_REGS_SIZE
411+
405412
stp xzr, xzr, [sp, #S_STACKFRAME]
406413
add x29, sp, #S_STACKFRAME
414+
415+
scs_load \tsk, \tmp
407416
.endm
408417

409418
/*
@@ -412,22 +421,16 @@ SYM_FUNC_END(__create_page_tables)
412421
* x0 = __PHYS_OFFSET
413422
*/
414423
SYM_FUNC_START_LOCAL(__primary_switched)
415-
adrp x4, init_thread_union
416-
add sp, x4, #THREAD_SIZE
417-
adr_l x5, init_task
418-
msr sp_el0, x5 // Save thread_info
424+
adr_l x4, init_task
425+
init_cpu_task x4, x5
419426

420427
adr_l x8, vectors // load VBAR_EL1 with virtual
421428
msr vbar_el1, x8 // vector table address
422429
isb
423430

424-
stp xzr, x30, [sp, #-16]!
431+
stp x29, x30, [sp, #-16]!
425432
mov x29, sp
426433

427-
#ifdef CONFIG_SHADOW_CALL_STACK
428-
adr_l scs_sp, init_shadow_call_stack // Set shadow call stack
429-
#endif
430-
431434
str_l x21, __fdt_pointer, x5 // Save FDT pointer
432435

433436
ldr_l x4, kimage_vaddr // Save the offset between
@@ -459,8 +462,7 @@ SYM_FUNC_START_LOCAL(__primary_switched)
459462
0:
460463
#endif
461464
bl switch_to_vhe // Prefer VHE if possible
462-
add sp, sp, #16
463-
setup_final_frame
465+
ldp x29, x30, [sp], #16
464466
bl start_kernel
465467
ASM_BUG()
466468
SYM_FUNC_END(__primary_switched)
@@ -648,12 +650,7 @@ SYM_FUNC_START_LOCAL(__secondary_switched)
648650
ldr x2, [x0, #CPU_BOOT_TASK]
649651
cbz x2, __secondary_too_slow
650652

651-
ldr x1, [x2, #TSK_STACK]
652-
add sp, x1, #THREAD_SIZE
653-
654-
msr sp_el0, x2
655-
scs_load x2, x3
656-
setup_final_frame
653+
init_cpu_task x2, x1
657654

658655
#ifdef CONFIG_ARM64_PTR_AUTH
659656
ptrauth_keys_init_cpu x2, x3, x4, x5

0 commit comments

Comments
 (0)