1 From e910a53fb4f20aa012e46371ffb4c32c8da259b4 Mon Sep 17 00:00:00 2001
2 From: Maxim Levitsky <mlevitsk@redhat.com>
3 Date: Wed, 23 Feb 2022 13:56:49 +0200
4 Subject: KVM: x86: nSVM: disallow userspace setting of MSR_AMD64_TSC_RATIO to non default value when tsc scaling disabled
6 From: Maxim Levitsky <mlevitsk@redhat.com>
8 commit e910a53fb4f20aa012e46371ffb4c32c8da259b4 upstream.
10 If nested tsc scaling is disabled, MSR_AMD64_TSC_RATIO should
11 never have non default value.
13 Due to way nested tsc scaling support was implmented in qemu,
14 it would set this msr to 0 when nested tsc scaling was disabled.
15 Ignore that value for now, as it causes no harm.
17 Fixes: 5228eb96a487 ("KVM: x86: nSVM: implement nested TSC scaling")
18 Cc: stable@vger.kernel.org
20 Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
21 Message-Id: <20220223115649.319134-1-mlevitsk@redhat.com>
22 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 arch/x86/kvm/svm/svm.c | 19 +++++++++++++++++--
26 1 file changed, 17 insertions(+), 2 deletions(-)
28 --- a/arch/x86/kvm/svm/svm.c
29 +++ b/arch/x86/kvm/svm/svm.c
30 @@ -2903,8 +2903,23 @@ static int svm_set_msr(struct kvm_vcpu *
33 case MSR_AMD64_TSC_RATIO:
34 - if (!msr->host_initiated && !svm->tsc_scaling_enabled)
37 + if (!svm->tsc_scaling_enabled) {
39 + if (!msr->host_initiated)
42 + * In case TSC scaling is not enabled, always
43 + * leave this MSR at the default value.
45 + * Due to bug in qemu 6.2.0, it would try to set
46 + * this msr to 0 if tsc scaling is not enabled.
47 + * Ignore this value as well.
49 + if (data != 0 && data != svm->tsc_ratio_msr)
54 if (data & TSC_RATIO_RSVD)