From patchwork Sat Nov 25 20:57:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10075153 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 5B7D460383 for ; Sat, 25 Nov 2017 20:58:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C727286EC for ; Sat, 25 Nov 2017 20:58:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40C9F28B53; Sat, 25 Nov 2017 20:58:10 +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 BA5A6286EC for ; Sat, 25 Nov 2017 20:58:09 +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=Z4hho1jNDRdTkdmuzU6q25UlIV9K0pdNSwrMHqopp1Y=; b=Dfso9aM5JiiCaUej815ZxWIRZS cjgV9iEWkEDbpQRGb9HqvfTEWmOeOXwv+nKrAe69y7PW7N9QXXwkRvI2Z8b3elIU/wqERvQ4y2CBM 9S29/c70wOKedtaG3HCrEzJvzO3SmHeEcUIZpMyFQc3jXu/Mq95DxXPOvTLav50TmSV/OFGGstnyt 4K1x8BWE5SDzmB68jp3WxD7HLt44KEe0RFHz4MXIu28kQy4CXjI/CCY5PtNwnqhlO95w22nwoty+x pEgacrSikvRs9tQjEK2FgLXhCFYEE5bLUEjWGeYgvH3dzWhIdCidLFYN3CdkAjL6KYrMmUKSzVaDl BkQ60QXQ==; 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 1eIhWO-0005TJ-Vf; Sat, 25 Nov 2017 20:57:57 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eIhW3-0004tw-7M for linux-arm-kernel@lists.infradead.org; Sat, 25 Nov 2017 20:57:37 +0000 Received: by mail-wr0-x242.google.com with SMTP id y42so23043509wrd.3 for ; Sat, 25 Nov 2017 12:57:14 -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=V3Vm+6ixly0ib2qMFBLoowg7G+ZdIZG9b7wCLe/d1AM=; b=R99SEGxEvSBqQLuepATEK3sLqKur2HXnHU31MIq/bpsChrIuXm2P8cvFYe9hFlpGyC YVcFonDdf/abbUzLfT0u92mXpxrplAekGP0YTIpDqqghFqu/n3NyVi5z76vHNx+OTlud 9fsaiynwxt1xN6g0GkvoCLyoqEXfr+bj34Mqw= 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=V3Vm+6ixly0ib2qMFBLoowg7G+ZdIZG9b7wCLe/d1AM=; b=uIsfnnTMkNIXMbs4jg50uB4ypb8FS3ux26T4cPReP3c2rJ/9NYRxWovBvprm9QTxOm sSh1EnyinKgtQJ0l0vE45ZAEs2unXTrWBYycU86OGAgTEGGr9V0AWzZKEsFDxWqYa1aq IksFAKpNZkd0SipTh6bAyAlQrrhPrMpt7eMv+/eL5R33ktsIcXO7ZOfxa1s1wLD5m/+i +GKgzviSgFItzE+MCtES09HjJRZTBbhFGLTSbm6YVp0ck/QZAvBDV97p/5VwXmMV0wMV 2khqhqpo1QIee2k8HJI7HHDX45j5Gk8loqzHfwJg8ohinoj0ejTiHOWN2/jq0zPjL+i8 Qjug== X-Gm-Message-State: AJaThX64Pcus7dn0i70ERL+i6GYqFwYpj1ntKXDhr9XAxHIOthkjYKvu VLmDrfyzf8StUuBykuFqJzMGFg== X-Google-Smtp-Source: AGs4zMa76xrf/tEpClZTJRAaiWxp2GgHtbESLQHWUKGIWwlBZjmhvCUw6oJnvio824F8fWPwcXVqnA== X-Received: by 10.223.150.46 with SMTP id b43mr21007257wra.5.1511643433303; Sat, 25 Nov 2017 12:57:13 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Nov 2017 12:57:12 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH 01/15] KVM: Prepare for moving vcpu_load/vcpu_put into arch specific code Date: Sat, 25 Nov 2017 21:57:04 +0100 Message-Id: <20171125205718.7731-2-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_125735_423368_6440CA63 X-CRM114-Status: GOOD ( 12.94 ) 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 In preparation for moving calls to vcpu_load() and vcpu_put() into the architecture specific implementations of the KVM vcpu ioctls, move the calls in the main kvm_vcpu_ioctl() dispatcher function to each case of the ioctl select statement. This allows us to move the vcpu_load() and vcpu_put() calls into architecture specific implementations of vcpu ioctls, one by one. Signed-off-by: Christoffer Dall --- virt/kvm/kvm_main.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9deb5a245b83..fafafcc38b5a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2528,16 +2528,15 @@ static long kvm_vcpu_ioctl(struct file *filp, return kvm_arch_vcpu_ioctl(filp, ioctl, arg); #endif - - r = vcpu_load(vcpu); - if (r) - return r; switch (ioctl) { case KVM_RUN: { struct pid *oldpid; r = -EINVAL; if (arg) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; oldpid = rcu_access_pointer(vcpu->pid); if (unlikely(oldpid != current->pids[PIDTYPE_PID].pid)) { /* The thread running this VCPU changed. */ @@ -2549,6 +2548,7 @@ static long kvm_vcpu_ioctl(struct file *filp, put_pid(oldpid); } r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); + vcpu_put(vcpu); trace_kvm_userspace_exit(vcpu->run->exit_reason, r); break; } @@ -2559,7 +2559,11 @@ static long kvm_vcpu_ioctl(struct file *filp, kvm_regs = kzalloc(sizeof(struct kvm_regs), GFP_KERNEL); if (!kvm_regs) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_get_regs(vcpu, kvm_regs); + vcpu_put(vcpu); if (r) goto out_free1; r = -EFAULT; @@ -2579,7 +2583,11 @@ static long kvm_vcpu_ioctl(struct file *filp, r = PTR_ERR(kvm_regs); goto out; } + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs); + vcpu_put(vcpu); kfree(kvm_regs); break; } @@ -2588,7 +2596,11 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -ENOMEM; if (!kvm_sregs) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_get_sregs(vcpu, kvm_sregs); + vcpu_put(vcpu); if (r) goto out; r = -EFAULT; @@ -2604,13 +2616,21 @@ 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: { struct kvm_mp_state mp_state; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_get_mpstate(vcpu, &mp_state); + vcpu_put(vcpu); if (r) goto out; r = -EFAULT; @@ -2625,7 +2645,11 @@ 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: { @@ -2634,7 +2658,11 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -EFAULT; if (copy_from_user(&tr, argp, sizeof(tr))) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_translate(vcpu, &tr); + vcpu_put(vcpu); if (r) goto out; r = -EFAULT; @@ -2649,7 +2677,11 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -EFAULT; if (copy_from_user(&dbg, argp, sizeof(dbg))) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg); + vcpu_put(vcpu); break; } case KVM_SET_SIGNAL_MASK: { @@ -2680,7 +2712,11 @@ static long kvm_vcpu_ioctl(struct file *filp, r = -ENOMEM; if (!fpu) goto out; + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_get_fpu(vcpu, fpu); + vcpu_put(vcpu); if (r) goto out; r = -EFAULT; @@ -2696,14 +2732,21 @@ static long kvm_vcpu_ioctl(struct file *filp, fpu = NULL; goto out; } + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu); + vcpu_put(vcpu); break; } default: + r = vcpu_load(vcpu); + if (r) + goto out; r = kvm_arch_vcpu_ioctl(filp, ioctl, arg); + vcpu_put(vcpu); } out: - vcpu_put(vcpu); kfree(fpu); kfree(kvm_sregs); return r;