Skip to content

Commit 4440337

Browse files
amit3ssean-jc
authored andcommitted
KVM: SVM: let alternatives handle the cases when RSB filling is required
Remove superfluous RSB filling after a VMEXIT when the CPU already has flushed the RSB after a VMEXIT when AutoIBRS is enabled. The initial implementation for adding RETPOLINES added an ALTERNATIVES implementation for filling the RSB after a VMEXIT in commit 117cc7a ("x86/retpoline: Fill return stack buffer on vmexit"). Later, X86_FEATURE_RSB_VMEXIT was added in commit 9756bba ("x86/speculation: Fill RSB on vmexit for IBRS") to handle stuffing the RSB if RETPOLINE=y *or* KERNEL_IBRS=y, i.e. to also stuff the RSB if the kernel is configured to do IBRS mitigations on entry/exit. The AutoIBRS (on AMD) feature implementation added in commit e7862ed ("x86/cpu: Support AMD Automatic IBRS") used the already-implemented logic for EIBRS in spectre_v2_determine_rsb_fill_type_on_vmexit() -- but did not update the code at VMEXIT to act on the mode selected in that function -- resulting in VMEXITs continuing to clear the RSB when RETPOLINES are enabled, despite the presence of AutoIBRS. Signed-off-by: Amit Shah <amit.shah@amd.com> Link: https://lore.kernel.org/r/20240807123531.69677-1-amit@kernel.org [sean: massage changeloge, drop comment about AMD not needing RSB_VMEXIT_LITE] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 32071fa commit 4440337

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

arch/x86/kvm/svm/vmenter.S

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ SYM_FUNC_START(__svm_vcpu_run)
209209
7: vmload %_ASM_AX
210210
8:
211211

212-
#ifdef CONFIG_MITIGATION_RETPOLINE
213212
/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
214-
FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
215-
#endif
213+
FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
216214

217215
/* Clobbers RAX, RCX, RDX. */
218216
RESTORE_HOST_SPEC_CTRL
@@ -348,10 +346,8 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run)
348346

349347
2: cli
350348

351-
#ifdef CONFIG_MITIGATION_RETPOLINE
352349
/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
353-
FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
354-
#endif
350+
FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
355351

356352
/* Clobbers RAX, RCX, RDX, consumes RDI (@svm) and RSI (@spec_ctrl_intercepted). */
357353
RESTORE_HOST_SPEC_CTRL

0 commit comments

Comments
 (0)