Skip to content

Commit

Permalink
x86/sev: Do the C-bit verification only on the BSP
Browse files Browse the repository at this point in the history
There's no need to do it on every AP.

The C-bit value read on the BSP and also verified there, is used
everywhere from now on.

No functional changes - just a bit faster booting APs.

Signed-off-by: Borislav Petkov (AMD) <[email protected]>
Acked-by: Tom Lendacky <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
bp3tk0v committed Dec 13, 2023
1 parent a39b6ac commit 30579c8
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions arch/x86/kernel/head_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ SYM_CODE_START_NOALIGN(startup_64)

/* Form the CR3 value being sure to include the CR3 modifier */
addq $(early_top_pgt - __START_KERNEL_map), %rax

#ifdef CONFIG_AMD_MEM_ENCRYPT
mov %rax, %rdi
mov %rax, %r14

addq phys_base(%rip), %rdi

/*
* For SEV guests: Verify that the C-bit is correct. A malicious
* hypervisor could lie about the C-bit position to perform a ROP
* attack on the guest by writing to the unencrypted stack and wait for
* the next RET instruction.
*/
call sev_verify_cbit

/*
* Restore CR3 value without the phys_base which will be added
* below, before writing %cr3.
*/
mov %r14, %rax
#endif

jmp 1f
SYM_CODE_END(startup_64)

Expand Down Expand Up @@ -192,15 +214,6 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
/* Setup early boot stage 4-/5-level pagetables. */
addq phys_base(%rip), %rax

/*
* For SEV guests: Verify that the C-bit is correct. A malicious
* hypervisor could lie about the C-bit position to perform a ROP
* attack on the guest by writing to the unencrypted stack and wait for
* the next RET instruction.
*/
movq %rax, %rdi
call sev_verify_cbit

/*
* Switch to new page-table
*
Expand Down

0 comments on commit 30579c8

Please sign in to comment.