@@ -444,9 +444,14 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
{
- int r = -EINTR;
+ int r;
sigset_t sigsaved;
+ r = vcpu_load(vcpu);
+ if (r)
+ return r;
+ kvm_vcpu_run_adjust_pid(vcpu);
+
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
@@ -456,6 +461,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
vcpu->mmio_needed = 0;
}
+ r = -EINTR;
if (run->immediate_exit)
goto out;
@@ -483,6 +489,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
+ vcpu_put(vcpu);
return r;
}
@@ -1410,6 +1410,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
int r;
sigset_t sigsaved;
+ r = vcpu_load(vcpu);
+ if (r)
+ return r;
+ kvm_vcpu_run_adjust_pid(vcpu);
+
if (vcpu->mmio_needed) {
vcpu->mmio_needed = 0;
if (!vcpu->mmio_is_write)
@@ -1424,7 +1429,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
r = kvmppc_emulate_mmio_vsx_loadstore(vcpu, run);
if (r == RESUME_HOST) {
vcpu->mmio_needed = 1;
- return r;
+ goto out;
}
}
#endif
@@ -1460,6 +1465,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
+out:
+ vcpu_put(vcpu);
return r;
}
@@ -3378,9 +3378,15 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
if (kvm_run->immediate_exit)
return -EINTR;
+ rc = vcpu_load(vcpu);
+ if (rc)
+ return rc;
+ kvm_vcpu_run_adjust_pid(vcpu);
+
if (guestdbg_exit_pending(vcpu)) {
kvm_s390_prepare_debug_exit(vcpu);
- return 0;
+ rc = 0;
+ goto out;
}
if (vcpu->sigset_active)
@@ -3391,7 +3397,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
} else if (is_vcpu_stopped(vcpu)) {
pr_err_ratelimited("can't run stopped vcpu %d\n",
vcpu->vcpu_id);
- return -EINVAL;
+ rc = -EINVAL;
+ goto out;
}
sync_regs(vcpu, kvm_run);
@@ -3422,6 +3429,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
vcpu->stat.exit_userspace++;
+out:
+ vcpu_put(vcpu);
return rc;
}
@@ -7225,6 +7225,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
int r;
sigset_t sigsaved;
+ r = vcpu_load(vcpu);
+ if (r)
+ return r;
+ kvm_vcpu_run_adjust_pid(vcpu);
+
fpu__initialize(fpu);
if (vcpu->sigset_active)
@@ -7274,6 +7279,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
+ vcpu_put(vcpu);
return r;
}
@@ -620,18 +620,25 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
if (unlikely(!kvm_vcpu_initialized(vcpu)))
return -ENOEXEC;
- ret = kvm_vcpu_first_run_init(vcpu);
+ ret = vcpu_load(vcpu);
if (ret)
return ret;
+ kvm_vcpu_run_adjust_pid(vcpu);
+
+ ret = kvm_vcpu_first_run_init(vcpu);
+ if (ret)
+ goto out;
if (run->exit_reason == KVM_EXIT_MMIO) {
ret = kvm_handle_mmio_return(vcpu, vcpu->run);
if (ret)
- return ret;
+ goto out;
}
- if (run->immediate_exit)
- return -EINTR;
+ if (run->immediate_exit) {
+ ret = -EINTR;
+ goto out;
+ }
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
@@ -768,6 +775,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
if (vcpu->sigset_active)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
+
+out:
+ vcpu_put(vcpu);
return ret;
}
@@ -2549,12 +2549,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EINVAL;
if (arg)
goto out;
- r = vcpu_load(vcpu);
- if (r)
- goto out;
- kvm_vcpu_run_adjust_pid(vcpu);
r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
- vcpu_put(vcpu);
trace_kvm_userspace_exit(vcpu->run->exit_reason, r);
break;
}
Move vcpu_load() and vcpu_put() into the architecture specific implementations of kvm_arch_vcpu_ioctl_run(). We take care to call kvm_vcpu_run_adjust_pid() in every implementation after having successfully called vcpu_load(). Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> --- arch/mips/kvm/mips.c | 9 ++++++++- arch/powerpc/kvm/powerpc.c | 9 ++++++++- arch/s390/kvm/kvm-s390.c | 13 +++++++++++-- arch/x86/kvm/x86.c | 6 ++++++ virt/kvm/arm/arm.c | 18 ++++++++++++++---- virt/kvm/kvm_main.c | 5 ----- 6 files changed, 47 insertions(+), 13 deletions(-)