From patchwork Mon Dec 4 20:35:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9A8D60327 for ; Mon, 4 Dec 2017 20:36:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBC55290AA for ; Mon, 4 Dec 2017 20:36:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0911293F1; Mon, 4 Dec 2017 20:36:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D5FC290AA for ; Mon, 4 Dec 2017 20:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qwFvlf6LzXOdfayJEGb/q8dsjn1EKOVcGnhi9SXA+oM=; b=FQH0LaQH6d9DP9U63DicdfRl5e 2varfd0V4pUhFf7Zjeu2VgyytKJfLzJMsK0XcOBnhPNl1RgoJlyaDL7rofjiRNUMRk5w5IpftnVP/ 9ip1xWXOMWiRGL9Y8bD3Fx34ccu/csoRKIEOh/FPBO3vmEPgv8cdbEquR4kWi9ZLubAYckAUQC1qU kPnhmg+cZLXzntf35DmPjx27gafveem6tu5FAZSAhr7jDmKBAXql/NADi9WHRdpj/7mndl3RuVxWd crNOVx+SbJorFdN1u/53kJSG+BO+cJTw4Kvyfq6Lad17/oHV2hOL3MoiGl4tvnux7/QecfokU4m2p THALNwAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLxTh-0006dR-Bj; Mon, 04 Dec 2017 20:36:37 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLxTG-0006C0-UW for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 20:36:15 +0000 Received: by mail-wm0-x243.google.com with SMTP id y82so16157396wmg.1 for ; Mon, 04 Dec 2017 12:35:59 -0800 (PST) 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=av+QFbSSrODWlW8ibViZv5MIzeuxutucuP1Fj2b4Bjc=; b=aQ52aevwRj2dUdIn2wESr23Ptly6NjOVrZfoEfYikfprlCe5I2JPO4etW8OWN2HGlP Ge8fAZ34zgbW2tVSh8Odf16oOuIsavZq6GJY1Jp2DeLw16suvwk9chhh1i0HvZcr6SyM eg2KekoOWMOTHgFEkusW07Y5X+kd4Kk/8B/sD8ndwpy/r/OPaOp7pjIYfHiP96Z+8tkP 1RANOWjffbgJU8j6ylMG5t4DpWk5iRAAimT1nMH1dY4xOD3sXFpYZ/G1KLSOI5GFc3Bx UxLPpVfRO5TpqnfUBNeQCeDBakOl18EjG0iMSJPGfa7vECPxLGYPPAM8tDN/9wOLBbyT VC3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=av+QFbSSrODWlW8ibViZv5MIzeuxutucuP1Fj2b4Bjc=; b=Udch1owR8xTAMbPOXAaGPtWWTBTOobWimb59DQ780HVnATvbVPdwra+T7w1TEK+ZxW VD58z/0+a4bIv/AewALPluHBVzU/wNWpwL1AKMCFrdBe92rR9kMGf+qvhsegUZx1pHpn XO9QLEpOjSzrEug4j9zkWDc4AlZ1/WOecueNjvP07jSdAtz3SQd7lFGCVf6OANk712G+ +sRQC/vFIDTTegAPHqPgA9GGVxFvEXhrZIGuM6WYhpPr2QnPkdf/0aYWMElXJpPPArF6 lZFDLnHEzOPWJAEW4+JNDJPGB+RiA8y1JVDuQahBLuQS9X0qeeNpUYM7K1bAYjgePj+b IFrw== X-Gm-Message-State: AJaThX6p3w+Vt8t+ToKvxHttxDMaE7x//N1vRKMCWfDbr1LgdP2l4ZTA Vf4EJv+xX5IrIKESIyfksU+GNg== X-Google-Smtp-Source: AGs4zMZZfTSx6V6cq8gtgpyYjoKkfPKtPlQtiPg3/7ypFfZ6CYOJ+GhigZUrx85J6Tw2oflYoQPI7g== X-Received: by 10.80.137.244 with SMTP id h49mr32741040edh.303.1512419758100; Mon, 04 Dec 2017 12:35:58 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id k42sm8434943edb.94.2017.12.04.12.35.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:35:57 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH v3 07/16] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_sregs Date: Mon, 4 Dec 2017 21:35:29 +0100 Message-Id: <20171204203538.8370-8-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204203538.8370-1-cdall@kernel.org> References: <20171204203538.8370-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_123611_231195_485119CC X-CRM114-Status: GOOD ( 12.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, Andrew Jones , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Marc Zyngier , James Hogan , Cornelia Huck , kvm-ppc@vger.kernel.org, Paul Mackerras , Christian Borntraeger , linux-arm-kernel@lists.infradead.org, Paolo Bonzini , linux-s390@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall Move vcpu_load() and vcpu_put() into the architecture specific implementations of kvm_arch_vcpu_ioctl_set_sregs(). Signed-off-by: Christoffer Dall Reviewed-by: David Hildenbrand Reviewed-by: Cornelia Huck --- arch/powerpc/kvm/book3s.c | 8 +++++++- arch/powerpc/kvm/booke.c | 15 +++++++++++---- arch/s390/kvm/kvm-s390.c | 4 ++++ arch/x86/kvm/x86.c | 13 ++++++++++--- virt/kvm/kvm_main.c | 2 -- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 6cc2377549f7..047651622cb8 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -496,7 +496,13 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) { - return vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); + int ret; + + vcpu_load(vcpu); + ret = vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); + vcpu_put(vcpu); + + return ret; } int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index f647e121070e..cdf0be02c95a 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1632,18 +1632,25 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, { int ret; + vcpu_load(vcpu); + + ret = -EINVAL; if (vcpu->arch.pvr != sregs->pvr) - return -EINVAL; + goto out; ret = set_sregs_base(vcpu, sregs); if (ret < 0) - return ret; + goto out; ret = set_sregs_arch206(vcpu, sregs); if (ret < 0) - return ret; + goto out; + + ret = vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); - return vcpu->kvm->arch.kvm_ops->set_sregs(vcpu, sregs); +out: + vcpu_put(vcpu); + return ret; } int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 18011fc4ac49..d95b4f15e52b 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2729,8 +2729,12 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) { + vcpu_load(vcpu); + memcpy(&vcpu->run->s.regs.acrs, &sregs->acrs, sizeof(sregs->acrs)); memcpy(&vcpu->arch.sie_block->gcr, &sregs->crs, sizeof(sregs->crs)); + + vcpu_put(vcpu); return 0; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 20a5f6776eea..a31a80aee0b9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7500,15 +7500,19 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, int mmu_reset_needed = 0; int pending_vec, max_bits, idx; struct desc_ptr dt; + int ret; + + vcpu_load(vcpu); + ret = -EINVAL; if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) && (sregs->cr4 & X86_CR4_OSXSAVE)) - return -EINVAL; + goto out; apic_base_msr.data = sregs->apic_base; apic_base_msr.host_initiated = true; if (kvm_set_apic_base(vcpu, &apic_base_msr)) - return -EINVAL; + goto out; dt.size = sregs->idt.limit; dt.address = sregs->idt.base; @@ -7574,7 +7578,10 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, kvm_make_request(KVM_REQ_EVENT, vcpu); - return 0; + ret = 0; +out: + vcpu_put(vcpu); + return ret; } int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 779c03e39fa4..19cf2d11f80f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2597,9 +2597,7 @@ static long kvm_vcpu_ioctl(struct file *filp, kvm_sregs = NULL; goto out; } - vcpu_load(vcpu); r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs); - vcpu_put(vcpu); break; } case KVM_GET_MP_STATE: {