From patchwork Mon Dec 4 20:35:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091569 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 7DF336035E for ; Mon, 4 Dec 2017 20:49:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F5A52879A for ; Mon, 4 Dec 2017 20:49:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 645F1288B7; Mon, 4 Dec 2017 20:49:17 +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 CF47B2879A for ; Mon, 4 Dec 2017 20:49:16 +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=3gFefb2PimP+IIJC5ecLHb1Am4nJ47IeEaCFXcHyORM=; b=PBPkPwD0u0Xr+flJtX3Jobw1Xb eqGVpzX5GFPH6jYqLaZUE+2wtRmet+/PT697fuayHT9xCzdLghLebJfQOJTeYs1dG+rfbLy6RRMzP Gi9SXf6AjPyuLnnoo97gO/jTOKLpRexuBrGMfG7jRTAMHKc2YNEHcA0JH6D+yDzwcSGrwrsE/Nhy5 umpvj8uQcf9ZFRCgYCiclSS2lFcXVXP45zeskZkcDoOldzASEw9cQTO2KLC6BcfjDsLpKhCmxJudx LC79woz5jHO/cr3fQ0XGQ0JEko+3J6D5WAQ4UHLLPsl8h5UMQrRNpNFLBUnhl8ypl9ddNzPQqF2XI NAt087ig==; 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 1eLxft-0007Gt-LS; Mon, 04 Dec 2017 20:49:13 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLxTN-0006CJ-PE for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 20:36:30 +0000 Received: by mail-wm0-x244.google.com with SMTP id f206so10419790wmf.5 for ; Mon, 04 Dec 2017 12:36:02 -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=PCJeEI2Yc8eiVyqKh4MGBqD1y7hf4RhVqlmbDFQkW50=; b=L/27JIj8ivYzOkTEbEPfmNSxG/eOz4PIRW87oe2BHXhrLnm768+gWS/IRczHyzcSpT WUxgl79PgWJzL6zhLrKFNmMD796WKky0vlJ6dJHosLtC+wwDPYNyymOa+3XM/C3ZuAPB VD8eFo2v8Gl7QvIENnQND94dsDIlcXGPOPujiE8hmMJAgYhyGjgW03b7g12p/fzZTxBF IBk0SfouaZKudG+K7ZB/DuJVjewz25O6+dVgjwMdQoLcowckG6A6f8s5q/WvXdSWo3Mt hdwW+0NHNycvCWhmjGUXDvaBstKCjxeTeSYcbp0wNJjAY8CQmGwwnw1JkGjEguWx0FiV 20wQ== 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=PCJeEI2Yc8eiVyqKh4MGBqD1y7hf4RhVqlmbDFQkW50=; b=GDOm8lqpflDic9biXxceQc6ghhYBPwC+WYzrA8Cro2068YyASScgHZbvl+Czqffyig t2EvEnbCxHWZabs5Q3hc7w8kSXJ0YoqrYvC/GfE1sLQ5KUVhs6fNd0sSl5oH5QajsQHT 9FZhu7Yn3K+/6REaxgNF6OXlH/Jn+hEj3N/Dr77f0vX5JadqS69LXrwXO+fjtW2QkKf/ oYlupuQL0xM9t7rMNb/siUTIA+W7jgKoSMblyAgj/4khJjPXzsoqHiELcWJ206rDNIet jSSJPbO+SBpkJXz7gPhdK46qod/OgEhm4E+J07xU8Ie0Q3CMQEQEDeQNPNXu/Xeg06if QMcg== X-Gm-Message-State: AJaThX7pvpn29JF03ZRY+nVIG3YRHccqyjJxOHFUB93aADKvQZzpYQZW u+Q2/J8WVzLzeytxRXt3htelAg== X-Google-Smtp-Source: AGs4zMZW4CzxkQ4hvAivBjN05kmbWIiPsnYygwCEQVxvM5FF9DfMeHCTbQrAKllLen+7bbljVBfELw== X-Received: by 10.80.173.20 with SMTP id y20mr31785286edc.23.1512419761091; Mon, 04 Dec 2017 12:36:01 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:36:00 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH v3 09/16] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_mpstate Date: Mon, 4 Dec 2017 21:35:31 +0100 Message-Id: <20171204203538.8370-10-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_123618_474374_80A73342 X-CRM114-Status: GOOD ( 13.26 ) 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_mpstate(). Reviewed-by: David Hildenbrand Signed-off-by: Christoffer Dall Reviewed-by: Cornelia Huck --- arch/s390/kvm/kvm-s390.c | 3 +++ arch/x86/kvm/x86.c | 14 +++++++++++--- virt/kvm/arm/arm.c | 9 +++++++-- virt/kvm/kvm_main.c | 2 -- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 396fc3db6d63..8fade858c790 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2853,6 +2853,8 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, { int rc = 0; + vcpu_load(vcpu); + /* user space knows about this interface - let it control the state */ vcpu->kvm->arch.user_cpu_state_ctrl = 1; @@ -2870,6 +2872,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, rc = -ENXIO; } + vcpu_put(vcpu); return rc; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9bf62c336aa5..8e67428af01b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7456,15 +7456,19 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, struct kvm_mp_state *mp_state) { + int ret = -EINVAL; + + vcpu_load(vcpu); + if (!lapic_in_kernel(vcpu) && mp_state->mp_state != KVM_MP_STATE_RUNNABLE) - return -EINVAL; + goto out; /* INITs are latched while in SMM */ if ((is_smm(vcpu) || vcpu->arch.smi_pending) && (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED || mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED)) - return -EINVAL; + goto out; if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) { vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; @@ -7472,7 +7476,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, } else vcpu->arch.mp_state = mp_state->mp_state; kvm_make_request(KVM_REQ_EVENT, vcpu); - return 0; + + ret = 0; +out: + vcpu_put(vcpu); + return ret; } int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index a7171701df44..9a3acbcf542c 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -395,6 +395,10 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, struct kvm_mp_state *mp_state) { + int ret = 0; + + vcpu_load(vcpu); + switch (mp_state->mp_state) { case KVM_MP_STATE_RUNNABLE: vcpu->arch.power_off = false; @@ -403,10 +407,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, vcpu_power_off(vcpu); break; default: - return -EINVAL; + ret = -EINVAL; } - return 0; + vcpu_put(vcpu); + return ret; } /** diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index eac3c29697db..f3600052adbb 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2618,9 +2618,7 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -EFAULT; if (copy_from_user(&mp_state, argp, sizeof(mp_state))) goto out; - vcpu_load(vcpu); r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state); - vcpu_put(vcpu); break; } case KVM_TRANSLATE: {