public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	x86@kernel.org, "Radim Krčmář" <rkrcmar@redhat.com>,
	"KarimAllah Ahmed" <karahmed@amazon.de>,
	"David Woodhouse" <dwmw@amazon.co.uk>,
	"Jim Mattson" <jmattson@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/3] KVM: x86: use native MSR ops for SPEC_CTRL
Date: Thu, 22 Feb 2018 12:07:17 -0500	[thread overview]
Message-ID: <20180222170717.GP31483@char.us.oracle.com> (raw)
In-Reply-To: <1519249297-73718-2-git-send-email-pbonzini@redhat.com>

On Wed, Feb 21, 2018 at 10:41:35PM +0100, Paolo Bonzini wrote:
> Having a paravirt indirect call in the IBRS restore path is not a
> good idea, since we are trying to protect from speculative execution
> of bogus indirect branch targets.  It is also slower, so use
> native_wrmsrl on the vmentry path too.

But it gets replaced during patching. As in once the machine boots
the assembler changes from:

	callq 	*0xfffflbah

to
	wrmsr

? I don't think you need this patch.

> 
> Fixes: d28b387fb74da95d69d2615732f50cceb38e9a4d
> Cc: x86@kernel.org
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: KarimAllah Ahmed <karahmed@amazon.de>
> Cc: David Woodhouse <dwmw@amazon.co.uk>
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 7 ++++---
>  arch/x86/kvm/vmx.c | 7 ++++---
>  2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index b3e488a74828..1598beeda11c 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -49,6 +49,7 @@
>  #include <asm/debugreg.h>
>  #include <asm/kvm_para.h>
>  #include <asm/irq_remapping.h>
> +#include <asm/microcode.h>
>  #include <asm/nospec-branch.h>
>  
>  #include <asm/virtext.h>
> @@ -5355,7 +5356,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  	 * being speculatively taken.
>  	 */
>  	if (svm->spec_ctrl)
> -		wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
> +		native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
>  
>  	asm volatile (
>  		"push %%" _ASM_BP "; \n\t"
> @@ -5465,10 +5466,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  	 * save it.
>  	 */
>  	if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))
> -		rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
> +		svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
>  
>  	if (svm->spec_ctrl)
> -		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
> +		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
>  
>  	/* 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 67b028d8e726..5caeb8dc5bda 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -51,6 +51,7 @@
>  #include <asm/apic.h>
>  #include <asm/irq_remapping.h>
>  #include <asm/mmu_context.h>
> +#include <asm/microcode.h>
>  #include <asm/nospec-branch.h>
>  
>  #include "trace.h"
> @@ -9453,7 +9454,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
>  	 * being speculatively taken.
>  	 */
>  	if (vmx->spec_ctrl)
> -		wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
> +		native_wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
>  
>  	vmx->__launched = vmx->loaded_vmcs->launched;
>  	asm(
> @@ -9589,10 +9590,10 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
>  	 * save it.
>  	 */
>  	if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))
> -		rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
> +		vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
>  
>  	if (vmx->spec_ctrl)
> -		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
> +		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
>  
>  	/* Eliminate branch target predictions from guest mode */
>  	vmexit_fill_RSB();
> -- 
> 1.8.3.1
> 
> 

  parent reply	other threads:[~2018-02-22 17:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21 21:41 [PATCH 0/3] x86/pti: KVM: fixes and optimizations for IBRS Paolo Bonzini
2018-02-21 21:41 ` [PATCH 1/3] KVM: x86: use native MSR ops for SPEC_CTRL Paolo Bonzini
2018-02-21 23:49   ` Jim Mattson
2018-02-22 17:07   ` Konrad Rzeszutek Wilk [this message]
2018-02-23  9:37     ` Paolo Bonzini
2018-02-23 17:22       ` Konrad Rzeszutek Wilk
2018-02-23 17:35         ` Paolo Bonzini
2018-02-23 17:55           ` Konrad Rzeszutek Wilk
2018-02-21 21:41 ` [PATCH 2/3] KVM: nVMX: fix wrong condition for SPEC_CTRL and PRED_CMD MSRs Paolo Bonzini
2018-02-22  0:07   ` Jim Mattson
2018-02-22  9:39     ` Paolo Bonzini
2018-02-21 21:41 ` [PATCH 3/3] KVM: VMX: mark RDMSR path as unlikely Paolo Bonzini
2018-02-22  0:25   ` Jim Mattson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180222170717.GP31483@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=dwmw@amazon.co.uk \
    --cc=jmattson@google.com \
    --cc=karahmed@amazon.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox