mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Maxim Levitsky <mlevitsk@redhat.com>, kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: nSVM: disallow userspace setting of MSR_AMD64_TSC_RATIO to non default value when tsc scaling disabled
Date: Thu, 24 Feb 2022 15:22:41 +0100	[thread overview]
Message-ID: <e459dbcc-3a43-bd20-6f78-1a9d712ae020@redhat.com> (raw)
In-Reply-To: <20220223115649.319134-1-mlevitsk@redhat.com>

On 2/23/22 12:56, Maxim Levitsky wrote:
> If nested tsc scaling is disabled, MSR_AMD64_TSC_RATIO should
> never have non default value.
> 
> Due to way nested tsc scaling support was implmented in qemu,
> it would set this msr to 0 when nested tsc scaling was disabled.
> Ignore that value for now, as it causes no harm.
> 
> 
> Fixes: 5228eb96a487 ("KVM: x86: nSVM: implement nested TSC scaling")
> Cc: stable@vger.kernel.org
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>   arch/x86/kvm/svm/svm.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)

Queued, thanks.

Paolo

> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 7038c76fa841..b80ad471776f 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -2705,8 +2705,23 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>   	u64 data = msr->data;
>   	switch (ecx) {
>   	case MSR_AMD64_TSC_RATIO:
> -		if (!msr->host_initiated && !svm->tsc_scaling_enabled)
> -			return 1;
> +
> +		if (!svm->tsc_scaling_enabled) {
> +
> +			if (!msr->host_initiated)
> +				return 1;
> +			/*
> +			 * In case TSC scaling is not enabled, always
> +			 * leave this MSR at the default value.
> +			 *
> +			 * Due to bug in qemu 6.2.0, it would try to set
> +			 * this msr to 0 if tsc scaling is not enabled.
> +			 * Ignore this value as well.
> +			 */
> +			if (data != 0 && data != svm->tsc_ratio_msr)
> +				return 1;
> +			break;
> +		}
>   
>   		if (data & TSC_RATIO_RSVD)
>   			return 1;


      reply	other threads:[~2022-02-24 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 11:56 Maxim Levitsky
2022-02-24 14:22 ` 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=e459dbcc-3a43-bd20-6f78-1a9d712ae020@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@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

all inboxes | Powered by JetHome®