From patchwork Sat Nov 25 20:57:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10075175 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 09A4660353 for ; Sat, 25 Nov 2017 21:16:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF50628FEB for ; Sat, 25 Nov 2017 21:15:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E312428FED; Sat, 25 Nov 2017 21:15:59 +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 63AC528FEB for ; Sat, 25 Nov 2017 21:15:58 +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=WIc7CoV19WVYqULYhs6dSJoyexkOYAAEJQBrPzOCoV0=; b=gl8fp+fiOF8NRMzqzFX6ElTK6h M3pH/i4XkMgEzx0VeSzbcuxSGKlabrLb1XWKODVYVceuTPg6hGuhTvfMRQlAykpQl33yVu03Bf56U anI5Y+5v8bhbaT6JUZgihxhwph3CcqwgV7VDVyI9S/2jYEO+LWJyWRUuSYh7q4dyp26+qykqmDTno LLpmgQrmXx1nKyHYk2ZCzoICMkGjLb/weqILvn2g1xjg43h6cbuKOjOFzfGpvCvAb4NmRf8AVoxiK vaXIe3y7whk0qxg4gtCSxiYSx5mg9F8oQC9ZzW6s1fSPs1tZWoX3fvxKtr/TutDIb3Hmi/sIXqrNV IST3O1LQ==; 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 1eIhnq-0007i8-Hs; Sat, 25 Nov 2017 21:15:58 +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 1eIhWG-00059x-Ih for linux-arm-kernel@lists.infradead.org; Sat, 25 Nov 2017 20:57:57 +0000 Received: by mail-wm0-x243.google.com with SMTP id b189so28063886wmd.5 for ; Sat, 25 Nov 2017 12:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x5Fl7ZbU8WHXQH0NNsg7YpG7IqvScDT5k45o/NtmXJ0=; b=IQUkbuDAvQmVZIXM+rl8ssKYDNqAmd/7F8eeJFBcoaUTkhaWKquT+UwP+actdj8f0p K2gM8W1wXMaumhxPyGw4ok93aYBu9ZGzJqO+DjqbTGgc3Fh+Fek1tOV2ETL+T5bmbOTK Pej6OWy1Gax+qo1blUv0XVunfTVRMMqF5q7wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x5Fl7ZbU8WHXQH0NNsg7YpG7IqvScDT5k45o/NtmXJ0=; b=Rm1WVwAthYZgYaPaGb0wWO16rqQPMIHfhZXMkgOYlH6ZZKrvJTWb8NKn4JbcDcK9qU eP50F++Wsca2L0YFcoVOp8w0x2WqGONe3M7XsygTHDsBGu79+NYGW6+U3uNW0Kn1c7Ip K1hZY1gjnQC38AMurcwaicZ3nB96F+z3At0UPTp6Gs44xuI1nnjmCC+8ToVnkIAlvq2o bscD/o+Hpi1AREEB3w3HHbKHZcgk8ZSTkVXF4b9JQDoBbyaB1w82Gm9xMve/rbTv6gYx NuQE7Qu99G2eTItU3Ts8u8cWHBm1/QXNlQ9meiogmUlO6NXYkLWZQpiSwh6nYHsHWs5g 1F7A== X-Gm-Message-State: AJaThX5/QVRl0myJJpQ1UuJXYzc4/07qvnWCT0+QRVf0lVVndYr0SQlk PslOgGcBw3r+lWZNMIBiFxX3YQ== X-Google-Smtp-Source: AGs4zMYHXXL4EqCPPpXTzA7/PzDgPg5b9lMzwkTOcOaoDmWEJ0LudnOIacS5iDPVFlOLjayAO5elMg== X-Received: by 10.28.159.15 with SMTP id i15mr12563282wme.58.1511643447145; Sat, 25 Nov 2017 12:57:27 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id z37sm15157577wrc.31.2017.11.25.12.57.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Nov 2017 12:57:26 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH 09/15] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_mpstate Date: Sat, 25 Nov 2017 21:57:12 +0100 Message-Id: <20171125205718.7731-10-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171125205718.7731-1-christoffer.dall@linaro.org> References: <20171125205718.7731-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171125_125749_400420_1E489388 X-CRM114-Status: GOOD ( 13.34 ) 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 , Christian Borntraeger , kvm-ppc@vger.kernel.org, Alexander Graf , 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 Move vcpu_load() and vcpu_put() into the architecture specific implementations of kvm_arch_vcpu_ioctl_set_mpstate(). Signed-off-by: Christoffer Dall --- arch/s390/kvm/kvm-s390.c | 7 ++++++- arch/x86/kvm/x86.c | 17 ++++++++++++++--- virt/kvm/arm/arm.c | 11 +++++++++-- virt/kvm/kvm_main.c | 4 ---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index ccaf5088b73e..aa76d2988178 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2870,7 +2870,11 @@ 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 rc = 0; + int rc; + + rc = vcpu_load(vcpu); + if (rc) + return rc; /* user space knows about this interface - let it control the state */ vcpu->kvm->arch.user_cpu_state_ctrl = 1; @@ -2889,6 +2893,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 71f0572a4e4a..1a4fa1f2fa46 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7446,15 +7446,22 @@ 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; + + ret = vcpu_load(vcpu); + if (ret) + return ret; + + ret = -EINVAL; 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; @@ -7462,7 +7469,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 4f36e6dd4d5e..631d04d87b25 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -399,6 +399,12 @@ 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; + + ret = vcpu_load(vcpu); + if (ret) + return ret; + switch (mp_state->mp_state) { case KVM_MP_STATE_RUNNABLE: vcpu->arch.power_off = false; @@ -407,10 +413,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 8b7c821e0244..bcfdb4800e44 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2626,11 +2626,7 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -EFAULT; if (copy_from_user(&mp_state, argp, sizeof(mp_state))) goto out; - r = vcpu_load(vcpu); - if (r) - goto out; r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state); - vcpu_put(vcpu); break; } case KVM_TRANSLATE: {