Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[linux-2.6-microblaze.git] / arch / x86 / kvm / hyperv.c
index a32f54a..123b677 100644 (file)
@@ -122,9 +122,13 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic *synic,
        else
                hv->synic_auto_eoi_used--;
 
-       __kvm_request_apicv_update(vcpu->kvm,
-                                  !hv->synic_auto_eoi_used,
-                                  APICV_INHIBIT_REASON_HYPERV);
+       /*
+        * Inhibit APICv if any vCPU is using SynIC's AutoEOI, which relies on
+        * the hypervisor to manually inject IRQs.
+        */
+       __kvm_set_or_clear_apicv_inhibit(vcpu->kvm,
+                                        APICV_INHIBIT_REASON_HYPERV,
+                                        !!hv->synic_auto_eoi_used);
 
        up_write(&vcpu->kvm->arch.apicv_update_lock);
 }
@@ -239,7 +243,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
        struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
        int ret;
 
-       if (!synic->active && !host)
+       if (!synic->active && (!host || data))
                return 1;
 
        trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
@@ -285,6 +289,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;
@@ -449,6 +456,9 @@ static int synic_set_irq(struct kvm_vcpu_hv_synic *synic, u32 sint)
        struct kvm_lapic_irq irq;
        int ret, vector;
 
+       if (KVM_BUG_ON(!lapic_in_kernel(vcpu), vcpu->kvm))
+               return -EINVAL;
+
        if (sint >= ARRAY_SIZE(synic->sint))
                return -EINVAL;
 
@@ -661,7 +671,7 @@ static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
        struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
        struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
 
-       if (!synic->active && !host)
+       if (!synic->active && (!host || config))
                return 1;
 
        if (unlikely(!host && hv_vcpu->enforce_cpuid && new_config.direct_mode &&
@@ -690,7 +700,7 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
        struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
        struct kvm_vcpu_hv_synic *synic = to_hv_synic(vcpu);
 
-       if (!synic->active && !host)
+       if (!synic->active && (!host || count))
                return 1;
 
        trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,