KVM: x86: disallow multiple KVM_CREATE_IRQCHIP
[deliverable/linux.git] / arch / x86 / kvm / x86.c
index 58c5cddf363d9150ccd835ec17eb416d140683ac..97f6f9565ac9cba10426e98b63b273967a585971 100644 (file)
@@ -2362,25 +2362,39 @@ long kvm_arch_vm_ioctl(struct file *filp,
                if (r)
                        goto out;
                break;
-       case KVM_CREATE_IRQCHIP:
+       case KVM_CREATE_IRQCHIP: {
+               struct kvm_pic *vpic;
+
+               mutex_lock(&kvm->lock);
+               r = -EEXIST;
+               if (kvm->arch.vpic)
+                       goto create_irqchip_unlock;
                r = -ENOMEM;
-               kvm->arch.vpic = kvm_create_pic(kvm);
-               if (kvm->arch.vpic) {
+               vpic = kvm_create_pic(kvm);
+               if (vpic) {
                        r = kvm_ioapic_init(kvm);
                        if (r) {
-                               kfree(kvm->arch.vpic);
-                               kvm->arch.vpic = NULL;
-                               goto out;
+                               kfree(vpic);
+                               goto create_irqchip_unlock;
                        }
                } else
-                       goto out;
+                       goto create_irqchip_unlock;
+               smp_wmb();
+               kvm->arch.vpic = vpic;
+               smp_wmb();
                r = kvm_setup_default_irq_routing(kvm);
                if (r) {
+                       mutex_lock(&kvm->irq_lock);
                        kfree(kvm->arch.vpic);
                        kfree(kvm->arch.vioapic);
-                       goto out;
+                       kvm->arch.vpic = NULL;
+                       kvm->arch.vioapic = NULL;
+                       mutex_unlock(&kvm->irq_lock);
                }
+       create_irqchip_unlock:
+               mutex_unlock(&kvm->lock);
                break;
+       }
        case KVM_CREATE_PIT:
                u.pit_config.flags = KVM_PIT_SPEAKER_DUMMY;
                goto create_pit;
@@ -4525,11 +4539,6 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason)
                kvm_set_rflags(vcpu, eflags & ~X86_EFLAGS_NT);
        }
 
-       /* set back link to prev task only if NT bit is set in eflags
-          note that old_tss_sel is not used afetr this point */
-       if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE)
-               old_tss_sel = 0xffff;
-
        /* set back link to prev task only if NT bit is set in eflags
           note that old_tss_sel is not used afetr this point */
        if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE)
@@ -4596,8 +4605,10 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 
        mmu_reset_needed |= vcpu->arch.cr4 != sregs->cr4;
        kvm_x86_ops->set_cr4(vcpu, sregs->cr4);
-       if (!is_long_mode(vcpu) && is_pae(vcpu))
+       if (!is_long_mode(vcpu) && is_pae(vcpu)) {
                load_pdptrs(vcpu, vcpu->arch.cr3);
+               mmu_reset_needed = 1;
+       }
 
        if (mmu_reset_needed)
                kvm_mmu_reset_context(vcpu);
This page took 0.024668 seconds and 5 git commands to generate.