Skip to content

Commit 1567570

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/startup_64: Drop long return to initial_code pointer
Since 866b556 ("x86/head/64: Install startup GDT") the primary startup sequence sets the code segment register (CS) to __KERNEL_CS before calling into the startup code shared between primary and secondary boot. This means a simple indirect call is sufficient here. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240129180502.4069817-24-ardb+git@google.com
1 parent 41bccc9 commit 1567570

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

arch/x86/kernel/head_64.S

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -428,39 +428,10 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
428428
movq %r15, %rdi
429429

430430
.Ljump_to_C_code:
431-
/*
432-
* Jump to run C code and to be on a real kernel address.
433-
* Since we are running on identity-mapped space we have to jump
434-
* to the full 64bit address, this is only possible as indirect
435-
* jump. In addition we need to ensure %cs is set so we make this
436-
* a far return.
437-
*
438-
* Note: do not change to far jump indirect with 64bit offset.
439-
*
440-
* AMD does not support far jump indirect with 64bit offset.
441-
* AMD64 Architecture Programmer's Manual, Volume 3: states only
442-
* JMP FAR mem16:16 FF /5 Far jump indirect,
443-
* with the target specified by a far pointer in memory.
444-
* JMP FAR mem16:32 FF /5 Far jump indirect,
445-
* with the target specified by a far pointer in memory.
446-
*
447-
* Intel64 does support 64bit offset.
448-
* Software Developer Manual Vol 2: states:
449-
* FF /5 JMP m16:16 Jump far, absolute indirect,
450-
* address given in m16:16
451-
* FF /5 JMP m16:32 Jump far, absolute indirect,
452-
* address given in m16:32.
453-
* REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
454-
* address given in m16:64.
455-
*/
456-
pushq $.Lafter_lret # put return address on stack for unwinder
457431
xorl %ebp, %ebp # clear frame pointer
458-
movq initial_code(%rip), %rax
459-
pushq $__KERNEL_CS # set correct cs
460-
pushq %rax # target address in negative space
461-
lretq
462-
.Lafter_lret:
463-
ANNOTATE_NOENDBR
432+
ANNOTATE_RETPOLINE_SAFE
433+
callq *initial_code(%rip)
434+
ud2
464435
SYM_CODE_END(secondary_startup_64)
465436

466437
#include "verify_cpu.S"

0 commit comments

Comments
 (0)