Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[cascardo/linux.git] / virt / kvm / kvm_main.c
index 61b31a5..cc081cc 100644 (file)
@@ -148,6 +148,7 @@ int vcpu_load(struct kvm_vcpu *vcpu)
        put_cpu();
        return 0;
 }
+EXPORT_SYMBOL_GPL(vcpu_load);
 
 void vcpu_put(struct kvm_vcpu *vcpu)
 {
@@ -157,6 +158,7 @@ void vcpu_put(struct kvm_vcpu *vcpu)
        preempt_enable();
        mutex_unlock(&vcpu->mutex);
 }
+EXPORT_SYMBOL_GPL(vcpu_put);
 
 static void ack_flush(void *_completed)
 {
@@ -2997,7 +2999,7 @@ static long kvm_vm_ioctl(struct file *filp,
                if (copy_from_user(&routing, argp, sizeof(routing)))
                        goto out;
                r = -EINVAL;
-               if (routing.nr >= KVM_MAX_IRQ_ROUTES)
+               if (routing.nr > KVM_MAX_IRQ_ROUTES)
                        goto out;
                if (routing.flags)
                        goto out;
@@ -3104,6 +3106,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
 {
        int r;
        struct kvm *kvm;
+       struct file *file;
 
        kvm = kvm_create_vm(type);
        if (IS_ERR(kvm))
@@ -3115,17 +3118,25 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
                return r;
        }
 #endif
-       r = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR | O_CLOEXEC);
+       r = get_unused_fd_flags(O_CLOEXEC);
        if (r < 0) {
                kvm_put_kvm(kvm);
                return r;
        }
+       file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
+       if (IS_ERR(file)) {
+               put_unused_fd(r);
+               kvm_put_kvm(kvm);
+               return PTR_ERR(file);
+       }
 
        if (kvm_create_vm_debugfs(kvm, r) < 0) {
-               kvm_put_kvm(kvm);
+               put_unused_fd(r);
+               fput(file);
                return -ENOMEM;
        }
 
+       fd_install(r, file);
        return r;
 }
 
@@ -3200,12 +3211,13 @@ static void hardware_enable_nolock(void *junk)
        }
 }
 
-static void hardware_enable(void)
+static int kvm_starting_cpu(unsigned int cpu)
 {
        raw_spin_lock(&kvm_count_lock);
        if (kvm_usage_count)
                hardware_enable_nolock(NULL);
        raw_spin_unlock(&kvm_count_lock);
+       return 0;
 }
 
 static void hardware_disable_nolock(void *junk)
@@ -3218,12 +3230,13 @@ static void hardware_disable_nolock(void *junk)
        kvm_arch_hardware_disable();
 }
 
-static void hardware_disable(void)
+static int kvm_dying_cpu(unsigned int cpu)
 {
        raw_spin_lock(&kvm_count_lock);
        if (kvm_usage_count)
                hardware_disable_nolock(NULL);
        raw_spin_unlock(&kvm_count_lock);
+       return 0;
 }
 
 static void hardware_disable_all_nolock(void)
@@ -3264,21 +3277,6 @@ static int hardware_enable_all(void)
        return r;
 }
 
-static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
-                          void *v)
-{
-       val &= ~CPU_TASKS_FROZEN;
-       switch (val) {
-       case CPU_DYING:
-               hardware_disable();
-               break;
-       case CPU_STARTING:
-               hardware_enable();
-               break;
-       }
-       return NOTIFY_OK;
-}
-
 static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
                      void *v)
 {
@@ -3569,10 +3567,6 @@ out_unlock:
 }
 EXPORT_SYMBOL_GPL(kvm_io_bus_get_dev);
 
-static struct notifier_block kvm_cpu_notifier = {
-       .notifier_call = kvm_cpu_hotplug,
-};
-
 static int kvm_debugfs_open(struct inode *inode, struct file *file,
                           int (*get)(void *, u64 *), int (*set)(void *, u64),
                           const char *fmt)
@@ -3823,7 +3817,8 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
                        goto out_free_1;
        }
 
-       r = register_cpu_notifier(&kvm_cpu_notifier);
+       r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_STARTING, "AP_KVM_STARTING",
+                                     kvm_starting_cpu, kvm_dying_cpu);
        if (r)
                goto out_free_2;
        register_reboot_notifier(&kvm_reboot_notifier);
@@ -3877,7 +3872,7 @@ out_free:
        kmem_cache_destroy(kvm_vcpu_cache);
 out_free_3:
        unregister_reboot_notifier(&kvm_reboot_notifier);
-       unregister_cpu_notifier(&kvm_cpu_notifier);
+       cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
 out_free_2:
 out_free_1:
        kvm_arch_hardware_unsetup();
@@ -3900,7 +3895,7 @@ void kvm_exit(void)
        kvm_async_pf_deinit();
        unregister_syscore_ops(&kvm_syscore_ops);
        unregister_reboot_notifier(&kvm_reboot_notifier);
-       unregister_cpu_notifier(&kvm_cpu_notifier);
+       cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING);
        on_each_cpu(hardware_disable_nolock, NULL, 1);
        kvm_arch_hardware_unsetup();
        kvm_arch_exit();