public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	stable@vger.kernel.org, Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH] KVM: SVM: fix trashing of MSR_TSC_AUX
Date: Fri, 15 Jul 2016 14:15:28 +0200	[thread overview]
Message-ID: <20160715121528.GA3273@potion> (raw)
In-Reply-To: <1467812596-18903-1-git-send-email-pbonzini@redhat.com>

2016-07-06 15:43+0200, Paolo Bonzini:
> I don't know what I was thinking when I wrote commit 46896c73c1a4 ("KVM:
> svm: add support for RDTSCP", 2015-11-12); I missed write_rdtscp_aux which
> obviously uses MSR_TSC_AUX.
> 
> Therefore we do need to save/restore MSR_TSC_AUX in svm_vcpu_run.

Hm, MSR_TSC_AUX is in host_save_user_msrs[], so we save it on every
svm_vcpu_load() and restore on svm_vcpu_put().  Linux does not use
RDTSCP and every transition to userspace has svm_vcpu_put() in between.

We also still do "wrmsrl(MSR_TSC_AUX, svm->tsc_aux);" in svm_set_msr()
and can switch to userspace without performing svm_vcpu_run() first.

Was this patch fixing the host userspace or something in the guest?

Thanks.

> Cc: stable@vger.kernel.org
> Cc: Borislav Petkov <bp@alien8.de>
> Fixes: 46896c73c1a4 ("KVM: svm: add support for RDTSCP")
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 16ef31b87452..44f6368f8b45 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -43,6 +43,7 @@
>  #include <asm/kvm_para.h>
>  
>  #include <asm/virtext.h>
> +#include <asm/vgtod.h>
>  #include "trace.h"
>  
>  #define __ex(x) __kvm_handle_fault_on_reboot(x)
> @@ -1530,9 +1531,6 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>  			wrmsrl(MSR_AMD64_TSC_RATIO, tsc_ratio);
>  		}
>  	}
> -	/* This assumes that the kernel never uses MSR_TSC_AUX */
> -	if (static_cpu_has(X86_FEATURE_RDTSCP))
> -		wrmsrl(MSR_TSC_AUX, svm->tsc_aux);
>  
>  	avic_vcpu_load(vcpu, cpu);
>  }
> @@ -4474,6 +4472,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  	svm->vmcb->save.cr2 = vcpu->arch.cr2;
>  
>  	clgi();
> +	if (static_cpu_has(X86_FEATURE_RDTSCP))
> +		wrmsrl(MSR_TSC_AUX, svm->tsc_aux);
>  
>  	local_irq_enable();
>  
> @@ -4550,6 +4550,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  #endif
>  		);
>  
> +	if (static_cpu_has(X86_FEATURE_RDTSCP))
> +		wrmsrl(MSR_TSC_AUX, __getcpu());
>  #ifdef CONFIG_X86_64
>  	wrmsrl(MSR_GS_BASE, svm->host.gs_base);
>  #else
> -- 
> 1.8.3.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-07-15 12:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 13:43 [PATCH] KVM: SVM: fix trashing of MSR_TSC_AUX Paolo Bonzini
2016-07-06 14:18 ` Borislav Petkov
2016-07-06 14:29   ` Paolo Bonzini
2016-07-07 10:41     ` Borislav Petkov
2016-07-07 11:01       ` Paolo Bonzini
2016-07-07 11:47         ` Borislav Petkov
2016-07-07 12:28           ` Paolo Bonzini
2016-07-07 12:47             ` Borislav Petkov
2016-07-07 13:16               ` Paolo Bonzini
2016-07-07 16:01                 ` Borislav Petkov
2016-07-07 16:17                   ` Paolo Bonzini
2016-07-07 16:27                   ` Eduardo Habkost
2016-07-07 17:04                     ` Borislav Petkov
2016-07-07 17:43                       ` Eduardo Habkost
2016-07-08 11:09                         ` Borislav Petkov
2016-07-08 11:15                           ` Paolo Bonzini
2016-07-08 12:55                             ` Borislav Petkov
2016-07-06 15:00 ` kbuild test robot
2016-07-15 12:15 ` Radim Krčmář [this message]
2016-07-15 12:30   ` Paolo Bonzini

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=20160715121528.GA3273@potion \
    --to=rkrcmar@redhat.com \
    --cc=bp@alien8.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.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