Skip to content

Commit e910a53

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: nSVM: disallow userspace setting of MSR_AMD64_TSC_RATIO to non default value when tsc scaling disabled
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: 5228eb9 ("KVM: x86: nSVM: implement nested TSC scaling") Cc: [email protected] Signed-off-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6f3c1fc commit e910a53

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,8 +2693,23 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
26932693
u64 data = msr->data;
26942694
switch (ecx) {
26952695
case MSR_AMD64_TSC_RATIO:
2696-
if (!msr->host_initiated && !svm->tsc_scaling_enabled)
2697-
return 1;
2696+
2697+
if (!svm->tsc_scaling_enabled) {
2698+
2699+
if (!msr->host_initiated)
2700+
return 1;
2701+
/*
2702+
* In case TSC scaling is not enabled, always
2703+
* leave this MSR at the default value.
2704+
*
2705+
* Due to bug in qemu 6.2.0, it would try to set
2706+
* this msr to 0 if tsc scaling is not enabled.
2707+
* Ignore this value as well.
2708+
*/
2709+
if (data != 0 && data != svm->tsc_ratio_msr)
2710+
return 1;
2711+
break;
2712+
}
26982713

26992714
if (data & TSC_RATIO_RSVD)
27002715
return 1;

0 commit comments

Comments
 (0)