]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
ccaf3472b86acd83db513a3a9a9340ccd3657622
[thirdparty/kernel/stable-queue.git] /
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
5
6 From: Maxim Levitsky <mlevitsk@redhat.com>
7
8 commit e910a53fb4f20aa012e46371ffb4c32c8da259b4 upstream.
9
10 If nested tsc scaling is disabled, MSR_AMD64_TSC_RATIO should
11 never have non default value.
12
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.
16
17 Fixes: 5228eb96a487 ("KVM: x86: nSVM: implement nested TSC scaling")
18 Cc: stable@vger.kernel.org
19
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>
24 ---
25 arch/x86/kvm/svm/svm.c | 19 +++++++++++++++++--
26 1 file changed, 17 insertions(+), 2 deletions(-)
27
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 *
31 u64 data = msr->data;
32 switch (ecx) {
33 case MSR_AMD64_TSC_RATIO:
34 - if (!msr->host_initiated && !svm->tsc_scaling_enabled)
35 - return 1;
36 +
37 + if (!svm->tsc_scaling_enabled) {
38 +
39 + if (!msr->host_initiated)
40 + return 1;
41 + /*
42 + * In case TSC scaling is not enabled, always
43 + * leave this MSR at the default value.
44 + *
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.
48 + */
49 + if (data != 0 && data != svm->tsc_ratio_msr)
50 + return 1;
51 + break;
52 + }
53
54 if (data & TSC_RATIO_RSVD)
55 return 1;