KVM: x86: decouple irqchip_in_kernel() and pic_irqchip()
[linux-2.6-block.git] / arch / x86 / kvm / x86.c
index 51ccfe08e32ff0570517fda01277dc0085721e94..0630ab438bd5bf95c84d4efea57f509e2ad4cfe2 100644 (file)
@@ -3070,6 +3070,8 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
        memset(&events->reserved, 0, sizeof(events->reserved));
 }
 
+static void kvm_set_hflags(struct kvm_vcpu *vcpu, unsigned emul_flags);
+
 static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
                                              struct kvm_vcpu_events *events)
 {
@@ -3106,10 +3108,13 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
                vcpu->arch.apic->sipi_vector = events->sipi_vector;
 
        if (events->flags & KVM_VCPUEVENT_VALID_SMM) {
+               u32 hflags = vcpu->arch.hflags;
                if (events->smi.smm)
-                       vcpu->arch.hflags |= HF_SMM_MASK;
+                       hflags |= HF_SMM_MASK;
                else
-                       vcpu->arch.hflags &= ~HF_SMM_MASK;
+                       hflags &= ~HF_SMM_MASK;
+               kvm_set_hflags(vcpu, hflags);
+
                vcpu->arch.smi_pending = events->smi.pending;
                if (events->smi.smm_inside_nmi)
                        vcpu->arch.hflags |= HF_SMM_INSIDE_NMI_MASK;
@@ -3889,7 +3894,7 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
                        goto split_irqchip_unlock;
                /* Pairs with irqchip_in_kernel. */
                smp_wmb();
-               kvm->arch.irqchip_split = true;
+               kvm->arch.irqchip_mode = KVM_IRQCHIP_SPLIT;
                kvm->arch.nr_reserved_ioapic_pins = cap->args[0];
                r = 0;
 split_irqchip_unlock:
@@ -3956,7 +3961,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
 
                mutex_lock(&kvm->lock);
                r = -EEXIST;
-               if (kvm->arch.vpic)
+               if (irqchip_in_kernel(kvm))
                        goto create_irqchip_unlock;
                r = -EINVAL;
                if (kvm->created_vcpus)
@@ -3983,8 +3988,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
                        mutex_unlock(&kvm->slots_lock);
                        goto create_irqchip_unlock;
                }
-               /* Write kvm->irq_routing before kvm->arch.vpic.  */
+               /* Write kvm->irq_routing before enabling irqchip_in_kernel. */
                smp_wmb();
+               kvm->arch.irqchip_mode = KVM_IRQCHIP_KERNEL;
                kvm->arch.vpic = vpic;
        create_irqchip_unlock:
                mutex_unlock(&kvm->lock);