KVM: Consolidate arch specific vcpu ioctl locking
Avi Kivity [Thu, 13 May 2010 09:35:17 +0000 (12:35 +0300)]
Now that all arch specific ioctls have centralized locking, it is easy to
move it to the central dispatcher.

Signed-off-by: Avi Kivity <avi@redhat.com>

arch/powerpc/kvm/powerpc.c
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/x86.c
virt/kvm/kvm_main.c

index caeed7b..a1d8750 100644 (file)
@@ -512,17 +512,16 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
        void __user *argp = (void __user *)arg;
        long r;
 
-       if (ioctl == KVM_INTERRUPT) {
+       switch (ioctl) {
+       case KVM_INTERRUPT: {
                struct kvm_interrupt irq;
                r = -EFAULT;
                if (copy_from_user(&irq, argp, sizeof(irq)))
-                       goto out_nolock;
+                       goto out;
                r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
-               goto out_nolock;
+               goto out;
        }
 
-       vcpu_load(vcpu);
-       switch (ioctl) {
        case KVM_ENABLE_CAP:
        {
                struct kvm_enable_cap cap;
@@ -537,8 +536,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
        }
 
 out:
-       vcpu_put(vcpu);
-out_nolock:
        return r;
 }
 
index fd169f6..0cb0da7 100644 (file)
@@ -638,16 +638,16 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
        void __user *argp = (void __user *)arg;
        long r;
 
-       if (ioctl == KVM_S390_INTERRUPT) {
+       switch (ioctl) {
+       case KVM_S390_INTERRUPT: {
                struct kvm_s390_interrupt s390int;
 
+               r = -EFAULT;
                if (copy_from_user(&s390int, argp, sizeof(s390int)))
-                       return -EFAULT;
-               return kvm_s390_inject_vcpu(vcpu, &s390int);
+                       break;
+               r = kvm_s390_inject_vcpu(vcpu, &s390int);
+               break;
        }
-
-       vcpu_load(vcpu);
-       switch (ioctl) {
        case KVM_S390_STORE_STATUS:
                r = kvm_s390_vcpu_store_status(vcpu, arg);
                break;
@@ -666,7 +666,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
        default:
                r = -EINVAL;
        }
-       vcpu_put(vcpu);
        return r;
 }
 
index 999b017..4c2096f 100644 (file)
@@ -2298,7 +2298,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
        int r;
        struct kvm_lapic_state *lapic = NULL;
 
-       vcpu_load(vcpu);
        switch (ioctl) {
        case KVM_GET_LAPIC: {
                r = -EINVAL;
@@ -2496,7 +2495,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
                r = -EINVAL;
        }
 out:
-       vcpu_put(vcpu);
        kfree(lapic);
        return r;
 }
index e0fb098..35532c9 100644 (file)
@@ -1578,9 +1578,7 @@ out_free2:
                break;
        }
        default:
-               vcpu_put(vcpu);
                r = kvm_arch_vcpu_ioctl(filp, ioctl, arg);
-               vcpu_load(vcpu);
        }
 out:
        vcpu_put(vcpu);