Skip to content

Commit 0936243

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: entry: Preserve/restore X29 even for compat tasks
Currently, the KPTI trampoline code for returning to user space takes care to only preserve X29 into FAR_EL1 for native tasks, as compat tasks don't have access to this register anyway, and so preserving it is not necessary. It also means it does not need to be restored, and so we have two code paths for returning back to user space: the native one that restores X29 from FAR_EL1, and the compat one that leaves X29 clobbered, containing the value of TTBR1_EL1, which carries a physical address pointing somewhere into the kernel image. This is needlessly complex, and given that FAR_EL1 becomes UNKNOWN after an exception return anway, the only benefit of avoiding the preserve and restore is that we can skip the system register write and read. So let's simplify this, and collapse the two code paths into one that always preserves X29 into FAR_EL1, and always restores it again after the TTBR switch. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20230418143604.1176437-2-ardb@kernel.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 44c026a commit 0936243

1 file changed

Lines changed: 0 additions & 10 deletions

File tree

arch/arm64/kernel/entry.S

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,9 @@ alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0
435435
eret
436436
alternative_else_nop_endif
437437
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
438-
bne 4f
439438
msr far_el1, x29
440439
tramp_alias x30, tramp_exit_native, x29
441440
br x30
442-
4:
443-
tramp_alias x30, tramp_exit_compat, x29
444-
br x30
445441
#endif
446442
.else
447443
ldr lr, [sp, #S_LR]
@@ -740,9 +736,7 @@ alternative_else_nop_endif
740736
msr vbar_el1, x30
741737
ldr lr, [sp, #S_LR]
742738
tramp_unmap_kernel x29
743-
.if \regsize == 64
744739
mrs x29, far_el1
745-
.endif
746740
add sp, sp, #PT_REGS_SIZE // restore sp
747741
eret
748742
sb
@@ -780,10 +774,6 @@ SYM_CODE_END(tramp_vectors)
780774
SYM_CODE_START(tramp_exit_native)
781775
tramp_exit
782776
SYM_CODE_END(tramp_exit_native)
783-
784-
SYM_CODE_START(tramp_exit_compat)
785-
tramp_exit 32
786-
SYM_CODE_END(tramp_exit_compat)
787777
.popsection // .entry.tramp.text
788778
#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
789779

0 commit comments

Comments
 (0)