Skip to content

Commit 30579c8

Browse files
committed
x86/sev: Do the C-bit verification only on the BSP
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) <bp@alien8.de> Acked-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/20231130132601.10317-1-bp@alien8.de
1 parent a39b6ac commit 30579c8

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

arch/x86/kernel/head_64.S

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ SYM_CODE_START_NOALIGN(startup_64)
114114

115115
/* Form the CR3 value being sure to include the CR3 modifier */
116116
addq $(early_top_pgt - __START_KERNEL_map), %rax
117+
118+
#ifdef CONFIG_AMD_MEM_ENCRYPT
119+
mov %rax, %rdi
120+
mov %rax, %r14
121+
122+
addq phys_base(%rip), %rdi
123+
124+
/*
125+
* For SEV guests: Verify that the C-bit is correct. A malicious
126+
* hypervisor could lie about the C-bit position to perform a ROP
127+
* attack on the guest by writing to the unencrypted stack and wait for
128+
* the next RET instruction.
129+
*/
130+
call sev_verify_cbit
131+
132+
/*
133+
* Restore CR3 value without the phys_base which will be added
134+
* below, before writing %cr3.
135+
*/
136+
mov %r14, %rax
137+
#endif
138+
117139
jmp 1f
118140
SYM_CODE_END(startup_64)
119141

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

195-
/*
196-
* For SEV guests: Verify that the C-bit is correct. A malicious
197-
* hypervisor could lie about the C-bit position to perform a ROP
198-
* attack on the guest by writing to the unencrypted stack and wait for
199-
* the next RET instruction.
200-
*/
201-
movq %rax, %rdi
202-
call sev_verify_cbit
203-
204217
/*
205218
* Switch to new page-table
206219
*

0 commit comments

Comments
 (0)