public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Chris J Arges <chris.j.arges@canonical.com>, kvm@vger.kernel.org
Cc: Joerg Roedel <joro@8bytes.org>, Gleb Natapov <gleb@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kvm: svm: move WARN_ON in svm_adjust_tsc_offset
Date: Thu, 13 Nov 2014 11:56:19 +0100	[thread overview]
Message-ID: <54648E53.9080309@redhat.com> (raw)
In-Reply-To: <1415847657-22178-1-git-send-email-chris.j.arges@canonical.com>

On 13/11/2014 04:00, Chris J Arges wrote:
> When running the tsc_adjust kvm-unit-test on an AMD processor with the
> IA32_TSC_ADJUST feature enabled, the WARN_ON in svm_adjust_tsc_offset can be
> triggered. This WARN_ON checks for a negative adjustment in case __scale_tsc
> is called; however it may trigger unnecessary warnings.
> 
> This patch moves the WARN_ON to trigger only if __scale_tsc will actually be
> called from svm_adjust_tsc_offset. In addition make adj in kvm_set_msr_common
> s64 since this can have signed values.
> 
> Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
> ---
>  arch/x86/kvm/svm.c | 8 +++++---
>  arch/x86/kvm/x86.c | 2 +-
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index d4f3aaa..6b411ad 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1056,9 +1056,11 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment, bool ho
>  {
>  	struct vcpu_svm *svm = to_svm(vcpu);
>  
> -	WARN_ON(adjustment < 0);
> -	if (host)
> -		adjustment = svm_scale_tsc(vcpu, adjustment);
> +	if (host) {
> +		if (svm->tsc_ratio != TSC_RATIO_DEFAULT)
> +			WARN_ON(adjustment < 0);
> +		adjustment = svm_scale_tsc(vcpu, (u64)adjustment);
> +	}
>  
>  	svm->vmcb->control.tsc_offset += adjustment;
>  	if (is_guest_mode(vcpu))
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f85da5c..1cd1376 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2141,7 +2141,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  	case MSR_IA32_TSC_ADJUST:
>  		if (guest_cpuid_has_tsc_adjust(vcpu)) {
>  			if (!msr_info->host_initiated) {
> -				u64 adj = data - vcpu->arch.ia32_tsc_adjust_msr;
> +				s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr;
>  				kvm_x86_ops->adjust_tsc_offset(vcpu, adj, true);
>  			}
>  			vcpu->arch.ia32_tsc_adjust_msr = data;
> 

Applied, thanks!

Paolo

      reply	other threads:[~2014-11-13 10:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13  3:00 [PATCH] kvm: svm: move WARN_ON in svm_adjust_tsc_offset Chris J Arges
2014-11-13 10:56 ` 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=54648E53.9080309@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=chris.j.arges@canonical.com \
    --cc=gleb@kernel.org \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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