* [PATCH] KVM: SVM: let alternatives handle the cases when rsb filling is required
@ 2024-06-21 12:07 Amit Shah
2024-06-21 12:51 ` Borislav Petkov
0 siblings, 1 reply; 3+ messages in thread
From: Amit Shah @ 2024-06-21 12:07 UTC (permalink / raw)
To: x86, kvm, linux-kernel
Cc: amit.shah, seanjc, pbonzini, tglx, mingo, bp, dave.hansen, hpa,
kim.phillips, david.kaplan
From: Amit Shah <amit.shah@amd.com>
This patch removes superfluous RSB filling after a VMEXIT when the CPU
already has flushed the RSB after a VMEXIT.
The initial implementation for adding RETPOLINES added an ALTERNATIVES
implementation for filling the RSB after a VMEXIT in
commit 117cc7a908c836 ("x86/retpoline: Fill return stack buffer on vmexit")
Later, X86_FEATURE_RSB_VMEXIT was added in
commit 2b129932201673 ("x86/speculation: Add RSB VM Exit protections")
The AutoIBRS (on AMD CPUs) feature implementation added in
commit e7862eda309ecf ("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>
---
arch/x86/kvm/svm/vmenter.S | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/svm/vmenter.S b/arch/x86/kvm/svm/vmenter.S
index a0c8eb37d3e1..2ed80aea3bb1 100644
--- a/arch/x86/kvm/svm/vmenter.S
+++ b/arch/x86/kvm/svm/vmenter.S
@@ -209,10 +209,8 @@ SYM_FUNC_START(__svm_vcpu_run)
7: vmload %_ASM_AX
8:
-#ifdef CONFIG_MITIGATION_RETPOLINE
/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
- FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
-#endif
+ FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
/* Clobbers RAX, RCX, RDX. */
RESTORE_HOST_SPEC_CTRL
@@ -348,10 +346,8 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run)
2: cli
-#ifdef CONFIG_MITIGATION_RETPOLINE
/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
- FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
-#endif
+ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
/* Clobbers RAX, RCX, RDX, consumes RDI (@svm) and RSI (@spec_ctrl_intercepted). */
RESTORE_HOST_SPEC_CTRL
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: SVM: let alternatives handle the cases when rsb filling is required
2024-06-21 12:07 [PATCH] KVM: SVM: let alternatives handle the cases when rsb filling is required Amit Shah
@ 2024-06-21 12:51 ` Borislav Petkov
0 siblings, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2024-06-21 12:51 UTC (permalink / raw)
To: Amit Shah
Cc: x86, kvm, linux-kernel, amit.shah, seanjc, pbonzini, tglx, mingo,
dave.hansen, hpa, kim.phillips, david.kaplan
On Fri, Jun 21, 2024 at 02:07:43PM +0200, Amit Shah wrote:
> From: Amit Shah <amit.shah@amd.com>
>
> This patch removes superfluous RSB filling after a VMEXIT when the CPU
s/This patch removes/Remove/
> already has flushed the RSB after a VMEXIT.
... because AutoIBRS flushes the RSB on VMEXIT."
I'd like to be stated clearly that AutoIBRS does that.
Otherwise, looks ok to me.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] KVM: SVM: let alternatives handle the cases when RSB filling is required
@ 2024-08-06 10:52 Amit Shah
0 siblings, 0 replies; 3+ messages in thread
From: Amit Shah @ 2024-08-06 10:52 UTC (permalink / raw)
To: seanjc, pbonzini, x86, kvm, linux-kernel
Cc: amit.shah, tglx, mingo, bp, dave.hansen, hpa, kim.phillips,
david.kaplan
From: Amit Shah <amit.shah@amd.com>
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 117cc7a908c836 ("x86/retpoline: Fill return stack buffer on vmexit")
Later, X86_FEATURE_RSB_VMEXIT was added in
commit 2b129932201673 ("x86/speculation: Add RSB VM Exit protections")
The AutoIBRS (on AMD CPUs) feature implementation added in
commit e7862eda309ecf ("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>
---
v3:
- Add a comment mentioning SVM does not need RSB_VMEXIT_LITE unlike
VMX.
v2:
- tweak commit message re: Boris's comments.
arch/x86/kvm/svm/vmenter.S | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/svm/vmenter.S b/arch/x86/kvm/svm/vmenter.S
index a0c8eb37d3e1..69d9825ebdd9 100644
--- a/arch/x86/kvm/svm/vmenter.S
+++ b/arch/x86/kvm/svm/vmenter.S
@@ -209,10 +209,14 @@ SYM_FUNC_START(__svm_vcpu_run)
7: vmload %_ASM_AX
8:
-#ifdef CONFIG_MITIGATION_RETPOLINE
- /* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
- FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
-#endif
+ /*
+ * IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET!
+ *
+ * Unlike VMX, AMD does not have the hardware bug that necessitates
+ * RSB_VMEXIT_LITE
+ */
+
+ FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
/* Clobbers RAX, RCX, RDX. */
RESTORE_HOST_SPEC_CTRL
@@ -348,10 +352,14 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run)
2: cli
-#ifdef CONFIG_MITIGATION_RETPOLINE
- /* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
- FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RETPOLINE
-#endif
+ /*
+ * IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET!
+ *
+ * Unlike VMX, AMD does not have the hardware bug that necessitates
+ * RSB_VMEXIT_LITE
+ */
+
+ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
/* Clobbers RAX, RCX, RDX, consumes RDI (@svm) and RSI (@spec_ctrl_intercepted). */
RESTORE_HOST_SPEC_CTRL
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-06 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-21 12:07 [PATCH] KVM: SVM: let alternatives handle the cases when rsb filling is required Amit Shah
2024-06-21 12:51 ` Borislav Petkov
-- strict thread matches above, loose matches on Subject: below --
2024-08-06 10:52 [PATCH] KVM: SVM: let alternatives handle the cases when RSB " Amit Shah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox