KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated
authorVitaly Kuznetsov <vkuznets@redhat.com>
Fri, 25 Mar 2022 13:21:40 +0000 (14:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:08:25 +0000 (09:08 +0200)
commit b1e34d325397a33d97d845e312d7cf2a8b646b44 upstream.

Setting non-zero values to SYNIC/STIMER MSRs activates certain features,
this should not happen when KVM_CAP_HYPERV_SYNIC{,2} was not activated.

Note, it would've been better to forbid writing anything to SYNIC/STIMER
MSRs, including zeroes, however, at least QEMU tries clearing
HV_X64_MSR_STIMER0_CONFIG without SynIC. HV_X64_MSR_EOM MSR is somewhat
'special' as writing zero there triggers an action, this also should not
happen when SynIC wasn't activated.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20220325132140.25650-4-vkuznets@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/hyperv.c

index 2fba82b06c2d5d0448705098bb3806b938b84035..5497eeef4e70e5ff9d1e5a3735d46a1e23421d46 100644 (file)
@@ -260,6 +260,9 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
        case HV_X64_MSR_EOM: {
                int i;
 
+               if (!synic->active)
+                       break;
+
                for (i = 0; i < ARRAY_SIZE(synic->sint); i++)
                        kvm_hv_notify_acked_sint(vcpu, i);
                break;
@@ -520,6 +523,12 @@ static int stimer_start(struct kvm_vcpu_hv_stimer *stimer)
 static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
                             bool host)
 {
+       struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer);
+       struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu);
+
+       if (!synic->active && (!host || config))
+               return 1;
+
        trace_kvm_hv_stimer_set_config(stimer_to_vcpu(stimer)->vcpu_id,
                                       stimer->index, config, host);
 
@@ -534,6 +543,12 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
 static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
                            bool host)
 {
+       struct kvm_vcpu *vcpu = stimer_to_vcpu(stimer);
+       struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu);
+
+       if (!synic->active && (!host || count))
+               return 1;
+
        trace_kvm_hv_stimer_set_count(stimer_to_vcpu(stimer)->vcpu_id,
                                      stimer->index, count, host);