Skip to content

Commit 211ceca

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: entry: Simplify tramp_alias macro and tramp_exit routine
The tramp_alias macro constructs the virtual alias of a symbol in the trampoline text mapping, based on its kernel text address, and does so in a way that is more convoluted than necessary. So let's simplify that. Also, now that the address of the vector table is kept in a per-CPU variable, there is no need to defer the load and the assignment of VBAR_EL1 to tramp_exit(). This means we can use a PC-relative reference to the per-CPU variable instead of storing its absolute address in a global variable in the trampoline rodata. And given that tramp_alias no longer needs a temp register, this means we can restore X30 earlier as well, and only leave X29 for tramp_exit() to restore. While at it, give some related symbols static linkage, considering that they are only referenced from the object file that defines them. Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 0936243 commit 211ceca

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

arch/arm64/kernel/entry.S

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@
101101
.org .Lventry_start\@ + 128 // Did we overflow the ventry slot?
102102
.endm
103103

104-
.macro tramp_alias, dst, sym, tmp
105-
mov_q \dst, TRAMP_VALIAS
106-
adr_l \tmp, \sym
107-
add \dst, \dst, \tmp
108-
adr_l \tmp, .entry.tramp.text
109-
sub \dst, \dst, \tmp
104+
.macro tramp_alias, dst, sym
105+
.set .Lalias\@, TRAMP_VALIAS + \sym - .entry.tramp.text
106+
movz \dst, :abs_g2_s:.Lalias\@
107+
movk \dst, :abs_g1_nc:.Lalias\@
108+
movk \dst, :abs_g0_nc:.Lalias\@
110109
.endm
111110

112111
/*
@@ -436,8 +435,13 @@ alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0
436435
alternative_else_nop_endif
437436
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
438437
msr far_el1, x29
439-
tramp_alias x30, tramp_exit_native, x29
440-
br x30
438+
439+
ldr_this_cpu x30, this_cpu_vector, x29
440+
tramp_alias x29, tramp_exit
441+
msr vbar_el1, x30 // install vector table
442+
ldr lr, [sp, #S_LR] // restore x30
443+
add sp, sp, #PT_REGS_SIZE // restore sp
444+
br x29
441445
#endif
442446
.else
443447
ldr lr, [sp, #S_LR]
@@ -728,20 +732,6 @@ alternative_else_nop_endif
728732
.org 1b + 128 // Did we overflow the ventry slot?
729733
.endm
730734

731-
.macro tramp_exit, regsize = 64
732-
tramp_data_read_var x30, this_cpu_vector
733-
get_this_cpu_offset x29
734-
ldr x30, [x30, x29]
735-
736-
msr vbar_el1, x30
737-
ldr lr, [sp, #S_LR]
738-
tramp_unmap_kernel x29
739-
mrs x29, far_el1
740-
add sp, sp, #PT_REGS_SIZE // restore sp
741-
eret
742-
sb
743-
.endm
744-
745735
.macro generate_tramp_vector, kpti, bhb
746736
.Lvector_start\@:
747737
.space 0x400
@@ -762,7 +752,7 @@ alternative_else_nop_endif
762752
*/
763753
.pushsection ".entry.tramp.text", "ax"
764754
.align 11
765-
SYM_CODE_START_NOALIGN(tramp_vectors)
755+
SYM_CODE_START_LOCAL_NOALIGN(tramp_vectors)
766756
#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
767757
generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_LOOP
768758
generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_FW
@@ -771,9 +761,12 @@ SYM_CODE_START_NOALIGN(tramp_vectors)
771761
generate_tramp_vector kpti=1, bhb=BHB_MITIGATION_NONE
772762
SYM_CODE_END(tramp_vectors)
773763

774-
SYM_CODE_START(tramp_exit_native)
775-
tramp_exit
776-
SYM_CODE_END(tramp_exit_native)
764+
SYM_CODE_START_LOCAL(tramp_exit)
765+
tramp_unmap_kernel x29
766+
mrs x29, far_el1 // restore x29
767+
eret
768+
sb
769+
SYM_CODE_END(tramp_exit)
777770
.popsection // .entry.tramp.text
778771
#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
779772

@@ -1067,7 +1060,7 @@ alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0
10671060
alternative_else_nop_endif
10681061

10691062
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1070-
tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x3
1063+
tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline
10711064
br x5
10721065
#endif
10731066
SYM_CODE_END(__sdei_asm_handler)

0 commit comments

Comments
 (0)