From patchwork Sat Nov 25 20:57:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10075165 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 34C5D60383 for ; Sat, 25 Nov 2017 21:00:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 252DC28EA1 for ; Sat, 25 Nov 2017 21:00:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16DC728EE4; Sat, 25 Nov 2017 21:00:12 +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 9F18128EA1 for ; Sat, 25 Nov 2017 21:00:11 +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=oI+fDpJuv+IVX/fBDQ3+Z61+XzWueMCLn0tSwHgBlhs=; b=VZVpqUaMCJGekZbUDIXZFknHV8 2I7DqC0goCDbTYL+QPzfgIslKQwULAvQN68Bed6p2JJYZ4V0xlQHbakgnTZL40xC7Oy6ZWUMtgYJr fIJDNo1lFoYL8EWTebOJP8ONEQmKhdOPMvgIGKAFik9oGuBvnbdvwGIiIQh4V/x1UN3+Ahm8S4iSj g7+CxZGKwznxe28eqRg8N87QTRwn4Ljml3toX+CXznabCwBoxjnm2cN3oYQFScThnjuNrhLwuW7sT t2jkLVc+RwHh4XTpLZoxDV1jSORRYOnEdpCydVo9LfZ47Oc8B27b2V0solfVBGaDi4TDu51xuvdIJ AqIYYEfQ==; 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 1eIhYY-0007eY-UZ; Sat, 25 Nov 2017 21:00:10 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eIhW9-00059d-Lv for linux-arm-kernel@lists.infradead.org; Sat, 25 Nov 2017 20:57:51 +0000 Received: by mail-wm0-x241.google.com with SMTP id b189so27619826wmd.0 for ; Sat, 25 Nov 2017 12:57:24 -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=yBPDH1YJd3lnWwvJDXZnwgQMZySEthOe/5MAal9840U=; b=XP3kr4vTjBzRq0mjaknciSRaP7k6SqX3k3z9xuQRgo0hyH9rva7ETjRYDb/VcPkb/O hwiKD4XkYBjnTZy6tM5zS+FM1Qx6fTlviEIE/LQuAiSiZhobxyNj/YeuYjXnRTsO63ky bs9iowVCBJqj2HmaEf9Sw5LNZViXRfnAdUen4= 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=yBPDH1YJd3lnWwvJDXZnwgQMZySEthOe/5MAal9840U=; b=p/tpCHijbt6rR54RWdX/jNmxASIG10fGQR83vj5tgK6UVTjwxjfxLQLu0vYyiXtFgq vwDKK6h3fsNZ8aldtgrV8IUIOGpLapj7SYX3/+ugOeqKfL1t4G+HcVnneKDVPUVsTe0c 3a/dKIDvQlL1Z3jW3Pu9q12VvAPhNXYux9x0Z9T4zEIwiB1TCaypfHENSRCVznw2/gBw Lh7qb+AOnbegqB6tdkUW8EC1rtjUg1VgtP8zAbnhNEbC2Kqq5PxEsGNQj09I51eZlzlo q3Wp7OO0EOOx/TS2Q2YfHLFrpcHXUN2kLKhRIwaIm8u+h2SSQ0lhezO7K9KcJ/vIpGcw 3rUA== X-Gm-Message-State: AJaThX6Xa/94gWOCL/R13PWUyQHchodIXJhoxGCKh4Xruw5Qt7fMCdKs YOXqOonps5AzCWqWfjT7aQoqBw== X-Google-Smtp-Source: AGs4zMY1/OvIFFWfI4nW7FvUWUQbDlUKl6cYWdFiG0gsdtmWx78TCzdJWttcNrKuHpvE85C8xIRvng== X-Received: by 10.28.131.203 with SMTP id f194mr14113888wmd.39.1511643443502; Sat, 25 Nov 2017 12:57:23 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Nov 2017 12:57:22 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH 07/15] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_sregs Date: Sat, 25 Nov 2017 21:57:10 +0100 Message-Id: <20171125205718.7731-8-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_125742_234654_E0704EE8 X-CRM114-Status: GOOD ( 13.49 ) 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_sregs(). Signed-off-by: Christoffer Dall --- arch/powerpc/kvm/book3s.c | 10 +++++++++- arch/powerpc/kvm/booke.c | 17 +++++++++++++---- arch/s390/kvm/kvm-s390.c | 8 ++++++++ arch/x86/kvm/x86.c | 15 ++++++++++++--- virt/kvm/kvm_main.c | 4 ---- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index b7db75010843..63e68c24af0e 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -498,7 +498,15 @@ 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; + + ret = vcpu_load(vcpu); + if (ret) + return ret; + 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 d770f465cb9d..59d1d0bd6909 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1641,18 +1641,27 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, { int ret; + ret = vcpu_load(vcpu); + if (ret) + return ret; + + 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 93a19e7e4f59..51569cc97a07 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2738,8 +2738,16 @@ 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) { + int r; + + r = vcpu_load(vcpu); + if (r) + return r; + 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 7faa9479e8d8..1a701a2f25a3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7486,15 +7486,21 @@ 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; + + ret = vcpu_load(vcpu); + if (ret) + return ret; + 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; @@ -7560,7 +7566,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 dbfaf190fca3..f68f45e64967 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2605,11 +2605,7 @@ static long kvm_vcpu_ioctl(struct file *filp, kvm_sregs = NULL; goto out; } - r = vcpu_load(vcpu); - if (r) - goto out; r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs); - vcpu_put(vcpu); break; } case KVM_GET_MP_STATE: {