Skip to content

Commit b1e34d3

Browse files
vittyvkbonzini
authored andcommitted
KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated
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>
1 parent 00b5f37 commit b1e34d3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

arch/x86/kvm/hyperv.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
239239
struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
240240
int ret;
241241

242-
if (!synic->active && !host)
242+
if (!synic->active && (!host || data))
243243
return 1;
244244

245245
trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
@@ -285,6 +285,9 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
285285
case HV_X64_MSR_EOM: {
286286
int i;
287287

288+
if (!synic->active)
289+
break;
290+
288291
for (i = 0; i < ARRAY_SIZE(synic->sint); i++)
289292
kvm_hv_notify_acked_sint(vcpu, i);
290293
break;
@@ -664,7 +667,7 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
664667
struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
665668
struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
666669

667-
if (!synic->active && !host)
670+
if (!synic->active && (!host || config))
668671
return 1;
669672

670673
if (unlikely(!host && hv_vcpu->enforce_cpuid && new_config.direct_mode &&
@@ -693,7 +696,7 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
693696
struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
694697
struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
695698

696-
if (!synic->active && !host)
699+
if (!synic->active && (!host || count))
697700
return 1;
698701

699702
trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,

0 commit comments

Comments
 (0)