Skip to content

Commit 6022907

Browse files
committed
x86/sev: Do the C-bit verification only on the BSP
JIRA: https://issues.redhat.com/browse/RHEL-39439 commit 30579c8 Author: Borislav Petkov (AMD) <bp@alien8.de> Date: Thu Nov 30 14:26:01 2023 +0100 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 Signed-off-by: Bandan Das <bsd@redhat.com>
1 parent a28ef91 commit 6022907

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

arch/x86/kernel/head_64.S

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

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

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

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

0 commit comments

Comments
 (0)