Skip to content

Commit 864bcaa

Browse files
Peter Zijlstrabp3tk0v
authored andcommitted
x86/cpu/kvm: Provide UNTRAIN_RET_VM
Similar to how it doesn't make sense to have UNTRAIN_RET have two untrain calls, it also doesn't make sense for VMEXIT to have an extra IBPB call. This cures VMEXIT doing potentially unret+IBPB or double IBPB. Also, the (SEV) VMEXIT case seems to have been overlooked. Redefine the meaning of the synthetic IBPB flags to: - ENTRY_IBPB -- issue IBPB on entry (was: entry + VMEXIT) - IBPB_ON_VMEXIT -- issue IBPB on VMEXIT And have 'retbleed=ibpb' set *BOTH* feature flags to ensure it retains the previous behaviour and issues IBPB on entry+VMEXIT. The new 'srso=ibpb_vmexit' option only sets IBPB_ON_VMEXIT. Create UNTRAIN_RET_VM specifically for the VMEXIT case, and have that check IBPB_ON_VMEXIT. All this avoids having the VMEXIT case having to check both ENTRY_IBPB and IBPB_ON_VMEXIT and simplifies the alternatives. Fixes: fb3bd91 ("x86/srso: Add a Speculative RAS Overflow mitigation") Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230814121149.109557833@infradead.org
1 parent e7c25c4 commit 864bcaa

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@
299299
#endif
300300
.endm
301301

302+
.macro UNTRAIN_RET_VM
303+
#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \
304+
defined(CONFIG_CALL_DEPTH_TRACKING) || defined(CONFIG_CPU_SRSO)
305+
VALIDATE_UNRET_END
306+
ALTERNATIVE_3 "", \
307+
CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \
308+
"call entry_ibpb", X86_FEATURE_IBPB_ON_VMEXIT, \
309+
__stringify(RESET_CALL_DEPTH), X86_FEATURE_CALL_DEPTH
310+
#endif
311+
.endm
312+
302313
.macro UNTRAIN_RET_FROM_CALL
303314
#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \
304315
defined(CONFIG_CALL_DEPTH_TRACKING)

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ static void __init retbleed_select_mitigation(void)
10541054

10551055
case RETBLEED_MITIGATION_IBPB:
10561056
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
1057+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
10571058
mitigate_smt = true;
10581059
break;
10591060

arch/x86/kvm/svm/vmenter.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ SYM_FUNC_START(__svm_vcpu_run)
222222
* because interrupt handlers won't sanitize 'ret' if the return is
223223
* from the kernel.
224224
*/
225-
UNTRAIN_RET
226-
227-
/* SRSO */
228-
ALTERNATIVE "", "call entry_ibpb", X86_FEATURE_IBPB_ON_VMEXIT
225+
UNTRAIN_RET_VM
229226

230227
/*
231228
* Clear all general purpose registers except RSP and RAX to prevent
@@ -362,7 +359,7 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run)
362359
* because interrupt handlers won't sanitize RET if the return is
363360
* from the kernel.
364361
*/
365-
UNTRAIN_RET
362+
UNTRAIN_RET_VM
366363

367364
/* "Pop" @spec_ctrl_intercepted. */
368365
pop %_ASM_BX

0 commit comments

Comments
 (0)