Patchwork [v4,1/5] kvm: vmx: Set IA32_TSC_AUX for legacy mode guests

login
register
mail settings
Submitter Jim Mattson
Date Dec. 5, 2018, 11:28 p.m.
Message ID <20181205232902.1431-2-jmattson@google.com>
Download mbox | patch
Permalink /patch/673591/
State New
Headers show

Comments

Jim Mattson - Dec. 5, 2018, 11:28 p.m.
RDTSCP is supported in legacy mode as well as long mode. The
IA32_TSC_AUX MSR should be set to the correct guest value before
entering any guest that supports RDTSCP.

Fixes: 4e47c7a6d714 ("KVM: VMX: Add instruction rdtscp support for guest")
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
---
 arch/x86/kvm/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Christopherson, Sean J - Dec. 6, 2018, 4:19 p.m.
On Wed, Dec 05, 2018 at 03:28:58PM -0800, Jim Mattson wrote:
> RDTSCP is supported in legacy mode as well as long mode. The
> IA32_TSC_AUX MSR should be set to the correct guest value before
> entering any guest that supports RDTSCP.

Not that it matters, but even the 64-bit case was wrong since it
was being gated by the (vmx->vcpu.arch.efer & EFER_SCE) check.

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

> 
> Fixes: 4e47c7a6d714 ("KVM: VMX: Add instruction rdtscp support for guest")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> Reviewed-by: Marc Orr <marcorr@google.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> ---
>  arch/x86/kvm/vmx.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index c379d0bfdcba9..ad1753e8a85e5 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3436,9 +3436,6 @@ static void setup_msrs(struct vcpu_vmx *vmx)
>  		index = __find_msr_index(vmx, MSR_CSTAR);
>  		if (index >= 0)
>  			move_msr_up(vmx, index, save_nmsrs++);
> -		index = __find_msr_index(vmx, MSR_TSC_AUX);
> -		if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
> -			move_msr_up(vmx, index, save_nmsrs++);
>  		/*
>  		 * MSR_STAR is only needed on long mode guests, and only
>  		 * if efer.sce is enabled.
> @@ -3451,6 +3448,9 @@ static void setup_msrs(struct vcpu_vmx *vmx)
>  	index = __find_msr_index(vmx, MSR_EFER);
>  	if (index >= 0 && update_transition_efer(vmx, index))
>  		move_msr_up(vmx, index, save_nmsrs++);
> +	index = __find_msr_index(vmx, MSR_TSC_AUX);
> +	if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
> +		move_msr_up(vmx, index, save_nmsrs++);
>  
>  	vmx->save_nmsrs = save_nmsrs;
>  	vmx->guest_msrs_dirty = true;
> -- 
> 2.20.0.rc1.387.gf8505762e3-goog
>
Christopherson, Sean J - Dec. 6, 2018, 6:17 p.m.
On Thu, Dec 06, 2018 at 08:19:23AM -0800, Sean Christopherson wrote:
> On Wed, Dec 05, 2018 at 03:28:58PM -0800, Jim Mattson wrote:
> > RDTSCP is supported in legacy mode as well as long mode. The
> > IA32_TSC_AUX MSR should be set to the correct guest value before
> > entering any guest that supports RDTSCP.
> 
> Not that it matters, but even the 64-bit case was wrong since it
> was being gated by the (vmx->vcpu.arch.efer & EFER_SCE) check.

Never mind, I was looking at it with your last patch applied...

> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> > 
> > Fixes: 4e47c7a6d714 ("KVM: VMX: Add instruction rdtscp support for guest")
> > Signed-off-by: Jim Mattson <jmattson@google.com>
> > Reviewed-by: Peter Shier <pshier@google.com>
> > Reviewed-by: Marc Orr <marcorr@google.com>
> > Reviewed-by: Liran Alon <liran.alon@oracle.com>
> > ---
> >  arch/x86/kvm/vmx.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> > index c379d0bfdcba9..ad1753e8a85e5 100644
> > --- a/arch/x86/kvm/vmx.c
> > +++ b/arch/x86/kvm/vmx.c
> > @@ -3436,9 +3436,6 @@ static void setup_msrs(struct vcpu_vmx *vmx)
> >  		index = __find_msr_index(vmx, MSR_CSTAR);
> >  		if (index >= 0)
> >  			move_msr_up(vmx, index, save_nmsrs++);
> > -		index = __find_msr_index(vmx, MSR_TSC_AUX);
> > -		if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
> > -			move_msr_up(vmx, index, save_nmsrs++);
> >  		/*
> >  		 * MSR_STAR is only needed on long mode guests, and only
> >  		 * if efer.sce is enabled.
> > @@ -3451,6 +3448,9 @@ static void setup_msrs(struct vcpu_vmx *vmx)
> >  	index = __find_msr_index(vmx, MSR_EFER);
> >  	if (index >= 0 && update_transition_efer(vmx, index))
> >  		move_msr_up(vmx, index, save_nmsrs++);
> > +	index = __find_msr_index(vmx, MSR_TSC_AUX);
> > +	if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
> > +		move_msr_up(vmx, index, save_nmsrs++);
> >  
> >  	vmx->save_nmsrs = save_nmsrs;
> >  	vmx->guest_msrs_dirty = true;
> > -- 
> > 2.20.0.rc1.387.gf8505762e3-goog
> >

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index c379d0bfdcba9..ad1753e8a85e5 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3436,9 +3436,6 @@  static void setup_msrs(struct vcpu_vmx *vmx)
 		index = __find_msr_index(vmx, MSR_CSTAR);
 		if (index >= 0)
 			move_msr_up(vmx, index, save_nmsrs++);
-		index = __find_msr_index(vmx, MSR_TSC_AUX);
-		if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
-			move_msr_up(vmx, index, save_nmsrs++);
 		/*
 		 * MSR_STAR is only needed on long mode guests, and only
 		 * if efer.sce is enabled.
@@ -3451,6 +3448,9 @@  static void setup_msrs(struct vcpu_vmx *vmx)
 	index = __find_msr_index(vmx, MSR_EFER);
 	if (index >= 0 && update_transition_efer(vmx, index))
 		move_msr_up(vmx, index, save_nmsrs++);
+	index = __find_msr_index(vmx, MSR_TSC_AUX);
+	if (index >= 0 && guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP))
+		move_msr_up(vmx, index, save_nmsrs++);
 
 	vmx->save_nmsrs = save_nmsrs;
 	vmx->guest_msrs_dirty = true;