KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_fpu
authorChristoffer Dall <christoffer.dall@linaro.org>
Mon, 4 Dec 2017 20:35:35 +0000 (21:35 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 14 Dec 2017 08:26:57 +0000 (09:26 +0100)
Move vcpu_load() and vcpu_put() into the architecture specific
implementations of kvm_arch_vcpu_ioctl_set_fpu().

Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/x86.c
virt/kvm/kvm_main.c

index 39327888bb064564caedd06f86cebc3bed399070..3bd2f83e1fa981679752e48eab9db3285c17349d 100644 (file)
@@ -2749,15 +2749,24 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
 
 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
-       if (test_fp_ctl(fpu->fpc))
-               return -EINVAL;
+       int ret = 0;
+
+       vcpu_load(vcpu);
+
+       if (test_fp_ctl(fpu->fpc)) {
+               ret = -EINVAL;
+               goto out;
+       }
        vcpu->run->s.regs.fpc = fpu->fpc;
        if (MACHINE_HAS_VX)
                convert_fp_to_vx((__vector128 *) vcpu->run->s.regs.vrs,
                                 (freg_t *) fpu->fprs);
        else
                memcpy(vcpu->run->s.regs.fprs, &fpu->fprs, sizeof(fpu->fprs));
-       return 0;
+
+out:
+       vcpu_put(vcpu);
+       return ret;
 }
 
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
index 846d292ea33b3cf04165dae3aaa441eda5662de8..981b61531ab746a2d0489d7f5f47e3231a3c64d1 100644 (file)
@@ -7722,8 +7722,11 @@ int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 
 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 {
-       struct fxregs_state *fxsave =
-                       &vcpu->arch.guest_fpu.state.fxsave;
+       struct fxregs_state *fxsave;
+
+       vcpu_load(vcpu);
+
+       fxsave = &vcpu->arch.guest_fpu.state.fxsave;
 
        memcpy(fxsave->st_space, fpu->fpr, 128);
        fxsave->cwd = fpu->fcw;
@@ -7734,6 +7737,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
        fxsave->rdp = fpu->last_dp;
        memcpy(fxsave->xmm_space, fpu->xmm, sizeof fxsave->xmm_space);
 
+       vcpu_put(vcpu);
        return 0;
 }
 
index 5791aa687233d08e55d7b792ba1c39298bb56c76..ca0ec9fb72ce9aacb93a7ae4f007323568335b94 100644 (file)
@@ -2720,9 +2720,7 @@ out_free1:
                        fpu = NULL;
                        goto out;
                }
-               vcpu_load(vcpu);
                r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
-               vcpu_put(vcpu);
                break;
        }
        default: