x86/decompressor: Only call the trampoline when changing paging levels
authorArd Biesheuvel <ardb@kernel.org>
Mon, 7 Aug 2023 16:27:10 +0000 (18:27 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 7 Aug 2023 18:48:09 +0000 (20:48 +0200)
commitf97b67a773cd84bd8b55c0a0ec32448a87fc56bb
tree962837b9038ab088edc420a4a2c3569a9d398575
parent64ef578b6b6866bec012544416946533444036c8
x86/decompressor: Only call the trampoline when changing paging levels

Since the current and desired number of paging levels are known when the
trampoline is being prepared, avoid calling the trampoline at all if it
is clear that calling it is not going to result in a change to the
number of paging levels.

Given that the CPU is already running in long mode, the PAE and LA57
settings are necessarily consistent with the currently active page
tables, and other fields in CR4 will be initialized by the startup code
in the kernel proper. So limit the manipulation of CR4 to toggling the
LA57 bit, which is the only thing that really needs doing at this point
in the boot. This also means that there is no need to pass the value of
l5_required to toggle_la57(), as it will not be called unless CR4.LA57
needs to toggle.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/r/20230807162720.545787-14-ardb@kernel.org
arch/x86/boot/compressed/head_64.S
arch/x86/boot/compressed/pgtable_64.c