Skip to content

Commit b28a8ee

Browse files
author
James Morse
committed
arm64: entry: Add macro for reading symbol addresses from the trampoline
The trampoline code needs to use the address of symbols in the wider kernel, e.g. vectors. PC-relative addressing wouldn't work as the trampoline code doesn't run at the address the linker expected. tramp_ventry uses a literal pool, unless CONFIG_RANDOMIZE_BASE is set, in which case it uses the data page as a literal pool because the data page can be unmapped when running in user-space, which is required for CPUs vulnerable to meltdown. Pull this logic out as a macro, instead of adding a third copy of it. Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: James Morse <[email protected]>
1 parent ba26892 commit b28a8ee

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

arch/arm64/kernel/entry.S

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ alternative_else_nop_endif
646646
sub \dst, \dst, PAGE_SIZE
647647
.endm
648648

649+
.macro tramp_data_read_var dst, var
650+
#ifdef CONFIG_RANDOMIZE_BASE
651+
tramp_data_page \dst
652+
add \dst, \dst, #:lo12:__entry_tramp_data_\var
653+
ldr \dst, [\dst]
654+
#else
655+
ldr \dst, =\var
656+
#endif
657+
.endm
649658

650659
#define BHB_MITIGATION_NONE 0
651660
#define BHB_MITIGATION_LOOP 1
@@ -676,13 +685,8 @@ alternative_else_nop_endif
676685
b .
677686
2:
678687
tramp_map_kernel x30
679-
#ifdef CONFIG_RANDOMIZE_BASE
680-
tramp_data_page x30
681688
alternative_insn isb, nop, ARM64_WORKAROUND_QCOM_FALKOR_E1003
682-
ldr x30, [x30]
683-
#else
684-
ldr x30, =vectors
685-
#endif
689+
tramp_data_read_var x30, vectors
686690
alternative_if_not ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM
687691
prfm plil1strm, [x30, #(1b - \vector_start)]
688692
alternative_else_nop_endif
@@ -765,7 +769,12 @@ SYM_CODE_END(tramp_exit_compat)
765769
.pushsection ".rodata", "a"
766770
.align PAGE_SHIFT
767771
SYM_DATA_START(__entry_tramp_data_start)
772+
__entry_tramp_data_vectors:
768773
.quad vectors
774+
#ifdef CONFIG_ARM_SDE_INTERFACE
775+
__entry_tramp_data___sdei_asm_handler:
776+
.quad __sdei_asm_handler
777+
#endif /* CONFIG_ARM_SDE_INTERFACE */
769778
SYM_DATA_END(__entry_tramp_data_start)
770779
.popsection // .rodata
771780
#endif /* CONFIG_RANDOMIZE_BASE */
@@ -932,14 +941,7 @@ SYM_CODE_START(__sdei_asm_entry_trampoline)
932941
* Remember whether to unmap the kernel on exit.
933942
*/
934943
1: str x4, [x1, #(SDEI_EVENT_INTREGS + S_SDEI_TTBR1)]
935-
936-
#ifdef CONFIG_RANDOMIZE_BASE
937-
tramp_data_page x4
938-
add x4, x4, #:lo12:__sdei_asm_trampoline_next_handler
939-
ldr x4, [x4]
940-
#else
941-
ldr x4, =__sdei_asm_handler
942-
#endif
944+
tramp_data_read_var x4, __sdei_asm_handler
943945
br x4
944946
SYM_CODE_END(__sdei_asm_entry_trampoline)
945947
NOKPROBE(__sdei_asm_entry_trampoline)
@@ -962,13 +964,6 @@ SYM_CODE_END(__sdei_asm_exit_trampoline)
962964
NOKPROBE(__sdei_asm_exit_trampoline)
963965
.ltorg
964966
.popsection // .entry.tramp.text
965-
#ifdef CONFIG_RANDOMIZE_BASE
966-
.pushsection ".rodata", "a"
967-
SYM_DATA_START(__sdei_asm_trampoline_next_handler)
968-
.quad __sdei_asm_handler
969-
SYM_DATA_END(__sdei_asm_trampoline_next_handler)
970-
.popsection // .rodata
971-
#endif /* CONFIG_RANDOMIZE_BASE */
972967
#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
973968

974969
/*

0 commit comments

Comments
 (0)