Commit 8a32dd60 authored by Christoffer Dall's avatar Christoffer Dall Committed by Paolo Bonzini

KVM: Prepare for moving vcpu_load/vcpu_put into arch specific code

In preparation for moving calls to vcpu_load() and vcpu_put() into the
architecture specific implementations of the KVM vcpu ioctls, move the
calls in the main kvm_vcpu_ioctl() dispatcher function to each case
of the ioctl select statement.  This allows us to move the vcpu_load()
and vcpu_put() calls into architecture specific implementations of vcpu
ioctls, one by one.
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ec7660cc
...@@ -2556,13 +2556,13 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2556,13 +2556,13 @@ static long kvm_vcpu_ioctl(struct file *filp,
if (mutex_lock_killable(&vcpu->mutex)) if (mutex_lock_killable(&vcpu->mutex))
return -EINTR; return -EINTR;
vcpu_load(vcpu);
switch (ioctl) { switch (ioctl) {
case KVM_RUN: { case KVM_RUN: {
struct pid *oldpid; struct pid *oldpid;
r = -EINVAL; r = -EINVAL;
if (arg) if (arg)
goto out; goto out;
vcpu_load(vcpu);
oldpid = rcu_access_pointer(vcpu->pid); oldpid = rcu_access_pointer(vcpu->pid);
if (unlikely(oldpid != current->pids[PIDTYPE_PID].pid)) { if (unlikely(oldpid != current->pids[PIDTYPE_PID].pid)) {
/* The thread running this VCPU changed. */ /* The thread running this VCPU changed. */
...@@ -2574,6 +2574,7 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2574,6 +2574,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
put_pid(oldpid); put_pid(oldpid);
} }
r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
vcpu_put(vcpu);
trace_kvm_userspace_exit(vcpu->run->exit_reason, r); trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
break; break;
} }
...@@ -2584,7 +2585,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2584,7 +2585,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL); kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL);
if (!kvm_regs) if (!kvm_regs)
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs); r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs);
vcpu_put(vcpu);
if (r) if (r)
goto out_free1; goto out_free1;
r = -EFAULT; r = -EFAULT;
...@@ -2604,7 +2607,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2604,7 +2607,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = PTR_ERR(kvm_regs); r = PTR_ERR(kvm_regs);
goto out; goto out;
} }
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs); r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
vcpu_put(vcpu);
kfree(kvm_regs); kfree(kvm_regs);
break; break;
} }
...@@ -2613,7 +2618,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2613,7 +2618,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -ENOMEM; r = -ENOMEM;
if (!kvm_sregs) if (!kvm_sregs)
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs); r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs);
vcpu_put(vcpu);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
...@@ -2629,13 +2636,17 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2629,13 +2636,17 @@ static long kvm_vcpu_ioctl(struct file *filp,
kvm_sregs = NULL; kvm_sregs = NULL;
goto out; goto out;
} }
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs); r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs);
vcpu_put(vcpu);
break; break;
} }
case KVM_GET_MP_STATE: { case KVM_GET_MP_STATE: {
struct kvm_mp_state mp_state; struct kvm_mp_state mp_state;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_get_mpstate(vcpu, &mp_state); r = kvm_arch_vcpu_ioctl_get_mpstate(vcpu, &mp_state);
vcpu_put(vcpu);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
...@@ -2650,7 +2661,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2650,7 +2661,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&mp_state, argp, sizeof(mp_state))) if (copy_from_user(&mp_state, argp, sizeof(mp_state)))
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state); r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state);
vcpu_put(vcpu);
break; break;
} }
case KVM_TRANSLATE: { case KVM_TRANSLATE: {
...@@ -2659,7 +2672,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2659,7 +2672,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&tr, argp, sizeof(tr))) if (copy_from_user(&tr, argp, sizeof(tr)))
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_translate(vcpu, &tr); r = kvm_arch_vcpu_ioctl_translate(vcpu, &tr);
vcpu_put(vcpu);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
...@@ -2674,7 +2689,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2674,7 +2689,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&dbg, argp, sizeof(dbg))) if (copy_from_user(&dbg, argp, sizeof(dbg)))
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg); r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg);
vcpu_put(vcpu);
break; break;
} }
case KVM_SET_SIGNAL_MASK: { case KVM_SET_SIGNAL_MASK: {
...@@ -2705,7 +2722,9 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2705,7 +2722,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -ENOMEM; r = -ENOMEM;
if (!fpu) if (!fpu)
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu); r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu);
vcpu_put(vcpu);
if (r) if (r)
goto out; goto out;
r = -EFAULT; r = -EFAULT;
...@@ -2721,14 +2740,17 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2721,14 +2740,17 @@ static long kvm_vcpu_ioctl(struct file *filp,
fpu = NULL; fpu = NULL;
goto out; goto out;
} }
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu); r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
vcpu_put(vcpu);
break; break;
} }
default: default:
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl(filp, ioctl, arg); r = kvm_arch_vcpu_ioctl(filp, ioctl, arg);
vcpu_put(vcpu);
} }
out: out:
vcpu_put(vcpu);
mutex_unlock(&vcpu->mutex); mutex_unlock(&vcpu->mutex);
kfree(fpu); kfree(fpu);
kfree(kvm_sregs); kfree(kvm_sregs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment