All of lore.kernel.org
 help / color / mirror / Atom feed
* [MODERATED] [patch 04/11] [PATCH v2 04/10] Linux Patch #4
@ 2018-04-20  2:25 konrad.wilk
  2018-04-20 16:15 ` [MODERATED] " Borislav Petkov
  0 siblings, 1 reply; 7+ messages in thread
From: konrad.wilk @ 2018-04-20  2:25 UTC (permalink / raw)
  To: speck

A guest may modify the SPEC_CTRL MSR from the value used by the
kernel. Since we don't use IBRS, this means a value of zero
is what we need in the host.

But the 336996-Speculative-Execution-Side-Channel-Mitigations.pdf
refers to the other bits as reserved so we should respect the
boot time SPEC_CTRL value and use that.

This allows us to deal with future extensions to the SPEC_CTRL
interface if any at all.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
v2: New patch
---
 arch/x86/kvm/svm.c | 6 +++---
 arch/x86/kvm/vmx.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index be9c839e2c89..f666b4c21559 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -5401,7 +5401,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 	 * is no need to worry about the conditional branch over the wrmsr
 	 * being speculatively taken.
 	 */
-	if (svm->spec_ctrl)
+	if (svm->spec_ctrl || need_spec_ctrl_acc())
 		native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
 
 	asm volatile (
@@ -5514,8 +5514,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 	if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
 		svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
-	if (svm->spec_ctrl)
-		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+	if (svm->spec_ctrl || need_spec_ctrl_acc())
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, clear_spec_ctrl(SPEC_CTRL_IBRS));
 
 	/* Eliminate branch target predictions from guest mode */
 	vmexit_fill_RSB();
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 657c93409042..5ba310eefe2b 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -9466,7 +9466,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 	 * is no need to worry about the conditional branch over the wrmsr
 	 * being speculatively taken.
 	 */
-	if (vmx->spec_ctrl)
+	if (vmx->spec_ctrl || need_spec_ctrl_acc())
 		native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
 
 	vmx->__launched = vmx->loaded_vmcs->launched;
@@ -9605,8 +9605,8 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 	if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
 		vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
 
-	if (vmx->spec_ctrl)
-		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+	if (vmx->spec_ctrl || need_spec_ctrl_acc())
+		native_wrmsrl(MSR_IA32_SPEC_CTRL, clear_spec_ctrl(SPEC_CTRL_IBRS));
 
 	/* Eliminate branch target predictions from guest mode */
 	vmexit_fill_RSB();
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-04-22  5:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-20  2:25 [MODERATED] [patch 04/11] [PATCH v2 04/10] Linux Patch #4 konrad.wilk
2018-04-20 16:15 ` [MODERATED] " Borislav Petkov
2018-04-20 16:39   ` Konrad Rzeszutek Wilk
2018-04-20 17:03     ` Borislav Petkov
2018-04-20 17:17       ` Konrad Rzeszutek Wilk
2018-04-22  5:57         ` Jon Masters
2018-04-20 17:06     ` Jon Masters

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.