From patchwork Sat Nov 25 20:57:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10075161 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 3402160383 for ; Sat, 25 Nov 2017 20:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B26C287E3 for ; Sat, 25 Nov 2017 20:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FD3728B53; Sat, 25 Nov 2017 20:59:32 +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 7881B28C1C for ; Sat, 25 Nov 2017 20:59:31 +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=OW7Ihyq6v7Zz1OhvJDyWIpk4a98PI/oVGhs0rUwf3T4=; b=vBCNrPMrofHN1OUAICX8KWkuFG laadFCr4Jhmi+dIODO6lfzi2MQnhVEsYG/mS685bE60fiP3Pru5I6ZqSA9kHdWV6GcBi4wwGkcNTc OxKZxXVwf23OT00POwl43OcIpBNK5gdq5EssTIjtmaHvZ55dVWnnItM56ecZZZQvUEhPTc20ccwO+ 0cZZTmCrZz+X1yGf8cxCHKze2rK/dWeIQYVwWRxkKoXKLlgZzvgIAbEpwQEFMVvOpR9trzpTBuVP8 TSRzgC9LY49F6UGr9nrOwMSgBWBEnwmkByf20/Yi/g8NyLdjpMmsqcS7a8htlZn+HXj3HRDpMiiX1 dOGEet8g==; 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 1eIhXu-0006h2-Ks; Sat, 25 Nov 2017 20:59:30 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eIhW6-000598-Rd for linux-arm-kernel@lists.infradead.org; Sat, 25 Nov 2017 20:57:48 +0000 Received: by mail-wr0-x241.google.com with SMTP id z75so21667309wrc.5 for ; Sat, 25 Nov 2017 12:57:18 -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=Dz8Vx95G1CWvoJM35PjdOdtHCmiqRzw2IUObyY4JeH4=; b=M8xSoEDaUVa3cV4NGpqvh5R78wuzp3JWdxPvjfIvixFHDm1QBd5quCEgeh21775/YS 2Xsj+aMQ/ouxb8k3Q6LbNf8LKieAZiVm5OKs/aPCxGYNl7S5clMC3scPYgf5vmdqjXfy YZTi9ONcSfbEgeIvFBd035a1ma9suso+cjNec= 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=Dz8Vx95G1CWvoJM35PjdOdtHCmiqRzw2IUObyY4JeH4=; b=rHpTlQfEM4M8AbIccPflMRY96d3+BqgNYDiNq0cqCdoIBbn6AThXP+YNYo0REa9rA1 tK8YJSfirPKEmoPZ4IVVwkVd8NK3NcjVhgXLAhv18k91nQViG1n4uMUFoVVZbuw4Qnse IS0cY6LB6cx2h3j9Fjaf+C08nUPv5dRX6W1hwu7W7zTn0I5mnRpbxJLXZRXfoKHz9vwO c65JiMf3EVgVeBe7LDuoqgzZUBNmKaDgqDmVHHK6clajpkfhs/EPRO9K7UDoNSPSxzF1 sfFnv/JjbFXC9zK9uKCynntcK+pWzo97Nu2mMcadrQR11OGLU1d5xIIDQKnLU4cilPhw SLbg== X-Gm-Message-State: AJaThX7X87hMlPglxtTFLYMC3jZW9YWCfHLQ7FBRve0bV+2Vnhl32IfV mWf87H0U1W7mAymAVoKgIPyP8g== X-Google-Smtp-Source: AGs4zMYqm3nIL/NvU55CCSdfuDHiO25cuXnhGksljq/BVfMBMs1u5TXzt3lCK1bKbAN49kwL6j01hg== X-Received: by 10.223.164.22 with SMTP id d22mr30855405wra.232.1511643436754; Sat, 25 Nov 2017 12:57:16 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Nov 2017 12:57:15 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH 03/15] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_run Date: Sat, 25 Nov 2017 21:57:06 +0100 Message-Id: <20171125205718.7731-4-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_125739_339634_1CC0C10A X-CRM114-Status: GOOD ( 14.54 ) 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_run(). We take care to call kvm_vcpu_run_adjust_pid() in every implementation after having successfully called vcpu_load(). Signed-off-by: Christoffer Dall --- arch/mips/kvm/mips.c | 9 ++++++++- arch/powerpc/kvm/powerpc.c | 9 ++++++++- arch/s390/kvm/kvm-s390.c | 13 +++++++++++-- arch/x86/kvm/x86.c | 6 ++++++ virt/kvm/arm/arm.c | 18 ++++++++++++++---- virt/kvm/kvm_main.c | 5 ----- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index d535edc01434..c93620e4b01f 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -444,9 +444,14 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) { - int r = -EINTR; + int r; sigset_t sigsaved; + r = vcpu_load(vcpu); + if (r) + return r; + kvm_vcpu_run_adjust_pid(vcpu); + if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); @@ -456,6 +461,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) vcpu->mmio_needed = 0; } + r = -EINTR; if (run->immediate_exit) goto out; @@ -483,6 +489,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL); + vcpu_put(vcpu); return r; } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 3480faaf1ef8..66e5c2445a87 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -1410,6 +1410,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) int r; sigset_t sigsaved; + r = vcpu_load(vcpu); + if (r) + return r; + kvm_vcpu_run_adjust_pid(vcpu); + if (vcpu->mmio_needed) { vcpu->mmio_needed = 0; if (!vcpu->mmio_is_write) @@ -1424,7 +1429,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) r = kvmppc_emulate_mmio_vsx_loadstore(vcpu, run); if (r == RESUME_HOST) { vcpu->mmio_needed = 1; - return r; + goto out; } } #endif @@ -1460,6 +1465,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL); +out: + vcpu_put(vcpu); return r; } diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 40d0a1a97889..aaeae92983a6 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -3378,9 +3378,15 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) if (kvm_run->immediate_exit) return -EINTR; + rc = vcpu_load(vcpu); + if (rc) + return rc; + kvm_vcpu_run_adjust_pid(vcpu); + if (guestdbg_exit_pending(vcpu)) { kvm_s390_prepare_debug_exit(vcpu); - return 0; + rc = 0; + goto out; } if (vcpu->sigset_active) @@ -3391,7 +3397,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) } else if (is_vcpu_stopped(vcpu)) { pr_err_ratelimited("can't run stopped vcpu %d\n", vcpu->vcpu_id); - return -EINVAL; + rc = -EINVAL; + goto out; } sync_regs(vcpu, kvm_run); @@ -3422,6 +3429,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) sigprocmask(SIG_SETMASK, &sigsaved, NULL); vcpu->stat.exit_userspace++; +out: + vcpu_put(vcpu); return rc; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 03869eb7fcd6..18e39666ada7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7225,6 +7225,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) int r; sigset_t sigsaved; + r = vcpu_load(vcpu); + if (r) + return r; + kvm_vcpu_run_adjust_pid(vcpu); + fpu__initialize(fpu); if (vcpu->sigset_active) @@ -7274,6 +7279,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL); + vcpu_put(vcpu); return r; } diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 01e575b9f78b..54d9aa533df9 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -620,18 +620,25 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (unlikely(!kvm_vcpu_initialized(vcpu))) return -ENOEXEC; - ret = kvm_vcpu_first_run_init(vcpu); + ret = vcpu_load(vcpu); if (ret) return ret; + kvm_vcpu_run_adjust_pid(vcpu); + + ret = kvm_vcpu_first_run_init(vcpu); + if (ret) + goto out; if (run->exit_reason == KVM_EXIT_MMIO) { ret = kvm_handle_mmio_return(vcpu, vcpu->run); if (ret) - return ret; + goto out; } - if (run->immediate_exit) - return -EINTR; + if (run->immediate_exit) { + ret = -EINTR; + goto out; + } if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); @@ -768,6 +775,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) if (vcpu->sigset_active) sigprocmask(SIG_SETMASK, &sigsaved, NULL); + +out: + vcpu_put(vcpu); return ret; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c9549d44c489..b6941320d6e5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2549,12 +2549,7 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -EINVAL; if (arg) goto out; - r = vcpu_load(vcpu); - if (r) - goto out; - kvm_vcpu_run_adjust_pid(vcpu); r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); - vcpu_put(vcpu); trace_kvm_userspace_exit(vcpu->run->exit_reason, r); break; }