kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Haozhong Zhang <haozhong.zhang@intel.com>, kvm@vger.kernel.org
Cc: Gleb Natapov <gleb@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST
Date: Fri, 7 Aug 2015 13:27:52 +0200	[thread overview]
Message-ID: <55C49638.3060508@redhat.com> (raw)
In-Reply-To: <1438917872-23908-1-git-send-email-haozhong.zhang@intel.com>



On 07/08/2015 05:24, Haozhong Zhang wrote:
> When kvm_set_msr_common() handles a guest's write to
> MSR_IA32_TSC_ADJUST, it will calcuate an adjustment based on the data
> written by guest and then use it to adjust TSC offset by calling a
> call-back adjust_tsc_offset(). The 3rd parameter of adjust_tsc_offset()
> indicates whether the adjustment is in host TSC cycles or in guest TSC
> cycles. If SVM TSC scaling is enabled, adjust_tsc_offset()
> [i.e. svm_adjust_tsc_offset()] will first scale the adjustment;
> otherwise, it will just use the unscaled one. As the MSR write here
> comes from the guest, the adjustment is in guest TSC cycles. However,
> the current kvm_set_msr_common() uses it as a value in host TSC
> cycles (by using true as the 3rd parameter of adjust_tsc_offset()),
> which can result in an incorrect adjustment of TSC offset if SVM TSC
> scaling is enabled. This patch fixes this problem.
> 
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
>  arch/x86/kvm/x86.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 5ef2560..3cd6cd2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2105,7 +2105,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  		if (guest_cpuid_has_tsc_adjust(vcpu)) {
>  			if (!msr_info->host_initiated) {
>  				s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr;
> -				kvm_x86_ops->adjust_tsc_offset(vcpu, adj, true);
> +				adjust_tsc_offset_guest(vcpu, adj);
>  			}
>  			vcpu->arch.ia32_tsc_adjust_msr = data;
>  		}
> --
> 1.7.9.5
> 
> --
> 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
> 

Thanks, applied!

Paolo

      reply	other threads:[~2015-08-07 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  3:24 [PATCH] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST Haozhong Zhang
2015-08-07 11:27 ` Paolo Bonzini [this message]

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=55C49638.3060508@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gleb@kernel.org \
    --cc=haozhong.zhang@intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).