linux-mips
[Top] [All Lists]

[PATCH v3 13/16] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioct

To: kvm@vger.kernel.org
Subject: [PATCH v3 13/16] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_fpu
From: Christoffer Dall <cdall@kernel.org>
Date: Mon, 4 Dec 2017 21:35:35 +0100
Cc: Andrew Jones <drjones@redhat.com>, Christoffer Dall <christoffer.dall@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Radim Krčmář <rkrcmar@redhat.com>, Marc Zyngier <marc.zyngier@arm.com>, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, James Hogan <jhogan@kernel.org>, linux-mips@linux-mips.org, Paul Mackerras <paulus@ozlabs.org>, kvm-ppc@vger.kernel.org, Christian Borntraeger <borntraeger@de.ibm.com>, Cornelia Huck <cohuck@redhat.com>, linux-s390@vger.kernel.org
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=/sNphlMbDKiBIPVVmKYnzJtUTOvcCdWKJRmCkp2sPiM=; b=Nmc6iqaEKdu5Hdp4B5yzpdUuFxFm2p2hvoG7wnOxBCjreTYVuM5SerPbgwacQNkjzf txyAuBwsbZ+etzg8fCl2Dsg/3BYCgOGLJvCbcRFPNxgj43yIJFMKJ+k1H8kjwE6nasq8 27FLr7sb5zyGapwjSl8gvs9hF0islUOft1oBuamehtP5+6dAL0Tp2n3BsFtV5wbzHeZ2 tuqrug5gHWY9b94bnH2FN+mfzHzpNC/IFG6cQz3rXit5DZr1mPu6wnBJOmO/Tbgo1psG IAWGl2D1VEJfL4xd0PiPTCC0khPmuURyFz1B62yhK2MlxlmfVHeFhLviKCsCiPHFWa0M S0EA==
In-reply-to: <20171204203538.8370-1-cdall@kernel.org>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20171204203538.8370-1-cdall@kernel.org>
Sender: linux-mips-bounce@linux-mips.org
From: Christoffer Dall <christoffer.dall@linaro.org>

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>
---
 arch/s390/kvm/kvm-s390.c | 15 ++++++++++++---
 arch/x86/kvm/x86.c       |  8 ++++++--
 virt/kvm/kvm_main.c      |  2 --
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 88dcb89656be..43278f334ce3 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2752,15 +2752,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)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 19b70e016858..95a329580c8b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7698,8 +7698,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;
@@ -7710,6 +7713,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;
 }
 
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 73ad70af6b2d..06751bbecd58 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2689,9 +2689,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
                        fpu = NULL;
                        goto out;
                }
-               vcpu_load(vcpu);
                r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
-               vcpu_put(vcpu);
                break;
        }
        default:
-- 
2.14.2


<Prev in Thread] Current Thread [Next in Thread>