arm64: entry: Preserve/restore X29 even for compat tasks
authorArd Biesheuvel <ardb@kernel.org>
Tue, 18 Apr 2023 14:36:03 +0000 (16:36 +0200)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 25 May 2023 15:55:19 +0000 (16:55 +0100)
commit0936243cabf0caf46f1a42606325ab93cfa05a6a
treebd03ebe84cd1b345bd1393c876645323f1e52d3d
parent44c026a73be8038f03dbdeef028b642880cf1511
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>
arch/arm64/kernel/entry.S