From patchwork Sat Nov 25 20:57:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10075171 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 9A04460383 for ; Sat, 25 Nov 2017 21:01:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8911028F67 for ; Sat, 25 Nov 2017 21:01:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A3E428F53; Sat, 25 Nov 2017 21:01:23 +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 D172028F53 for ; Sat, 25 Nov 2017 21:01:22 +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=qTmlGe1NnGcRxL2jQKS+eYA7zGZ8NiNisOT8gnmqYFc=; b=iBHj5lfKcMdiMHsRBLToCmUlhH dvkKKmB8MeostACGF8fkr+w9c/C+oahSaZXSUsquba9RuAqoTNunRHHmijh+869kJOdyNztyihE79 yuL695VcB5GUxmCF2N/geABv8y7g03OxlpP6CUr+ITJP2Etw88Gap9C+jw17mvSWODifGaMaOTpST xK9KHUkN6aUi1So4TCOg3E3r9tznwcLGMkiOIndq/XUZa9bg1ZjSVLZSzj8H50Z1z0LYT9xv+YNv9 wSVE+veQTBg+LBOGP81S8WeGVC6zRKeqM1dfe+0vlFFPSPHF6MrGRCb5B8OvzjX8TsJ6WS74eLnMS skCkycrg==; 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 1eIhZb-00013h-8X; Sat, 25 Nov 2017 21:01:15 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eIhWK-0005AF-Rb for linux-arm-kernel@lists.infradead.org; Sat, 25 Nov 2017 20:58:00 +0000 Received: by mail-wr0-x243.google.com with SMTP id l22so22981521wrc.11 for ; Sat, 25 Nov 2017 12:57:32 -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=Jx3F3l4X8mPO2fUbPReyCvyFHiFtJpj35SNJzUecnR0=; b=e+Zu0KonvEN8e2dWBvjW8NeVYO7h2El0/cGIRrMBdZeC5O44Y2FeO5Yi2BtfLDZ5KD ieRTF3bbCUe0bdkc6QFp1QW8jPfI7CHfuoV3Q0Q4PTp/aZa1imAzZ8BQSqtXKooBtHBp +fW8dtpBKk/FGcKUBNvNDOTaM7KDm9+DURFKo= 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=Jx3F3l4X8mPO2fUbPReyCvyFHiFtJpj35SNJzUecnR0=; b=NIzelmbeEToaO+mKmJK7p5QeJK3CxQVEn2HcF/5eSuUD+RzIHgqYvaehVc6UqewUuM NxYb8TOtxpdyqlRABDjpbMazOol7RJB5832Yrz2z+IC2bKmnYoiqoUYTyUBFv19auD40 +TVRqYyBlC6acGmkXgcNt+IRZ4J+3hFj+zBSKCZO/TDmUUF1LFI7fO4Ggz7Y9mZrymb4 VCUJDZqX2ACAWjwi2xwkSXbbCY7iiEAL2/tTmKNrLtN6vz61kT/Yrrwn8h77C4TdWpdV Laa4Z8OK5bxCyp7sMhUDv7NoJ44srpnZo9N77JDBRUEqWty1d2u6ii3ezfYozmc20dfc COGA== X-Gm-Message-State: AJaThX4NiWRuXdMiFSU+nVoAC0gaCl/rOPC7o/CGLBgSow3uuOlag5nK qtgHVvKPJX1RWSpo9n4zt+DP1A== X-Google-Smtp-Source: AGs4zMamEliV1UyneIaE1O0iDnyddd3R9PMUvGEuDHZdif2YBin1at0XM3bg/uJnu7o7U680Hu5RQQ== X-Received: by 10.223.166.103 with SMTP id k94mr28303292wrc.22.1511643450825; Sat, 25 Nov 2017 12:57:30 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Nov 2017 12:57:29 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Subject: [PATCH 11/15] KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_guest_debug Date: Sat, 25 Nov 2017 21:57:14 +0100 Message-Id: <20171125205718.7731-12-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_125754_002060_B299A772 X-CRM114-Status: GOOD ( 14.67 ) 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_guest_debug(). Signed-off-by: Christoffer Dall --- arch/arm64/kvm/guest.c | 17 ++++++++++++++--- arch/powerpc/kvm/book3s.c | 6 ++++++ arch/powerpc/kvm/booke.c | 21 +++++++++++++++------ arch/s390/kvm/kvm-s390.c | 14 +++++++++++--- arch/x86/kvm/x86.c | 6 +++++- virt/kvm/kvm_main.c | 4 ---- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 5c7f657dd207..0375d1f977c8 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -361,10 +361,18 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) { + int ret; + + ret = vcpu_load(vcpu); + if (ret) + return ret; + trace_kvm_set_guest_debug(vcpu, dbg->control); - if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) - return -EINVAL; + if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) { + ret = -EINVAL; + goto out; + } if (dbg->control & KVM_GUESTDBG_ENABLE) { vcpu->guest_debug = dbg->control; @@ -378,7 +386,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, /* If not enabled clear all flags */ vcpu->guest_debug = 0; } - return 0; + +out: + vcpu_put(vcpu); + return ret; } int kvm_arm_vcpu_arch_set_attr(struct kvm_vcpu *vcpu, diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 63e68c24af0e..6d9885b6e77c 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -765,7 +765,13 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) { + int r; + + r = vcpu_load(vcpu); + if (r) + return r; vcpu->guest_debug = dbg->control; + vcpu_put(vcpu); return 0; } diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 8069d93bf654..fcc033a4d958 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -2031,12 +2031,17 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, { struct debug_reg *dbg_reg; int n, b = 0, w = 0; + int ret; + + ret = vcpu_load(vcpu); + if (ret) + return ret; if (!(dbg->control & KVM_GUESTDBG_ENABLE)) { vcpu->arch.dbg_reg.dbcr0 = 0; vcpu->guest_debug = 0; kvm_guest_protect_msr(vcpu, MSR_DE, false); - return 0; + goto out; } kvm_guest_protect_msr(vcpu, MSR_DE, true); @@ -2068,8 +2073,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, #endif if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) - return 0; + goto out; + ret = -EINVAL; for (n = 0; n < (KVMPPC_BOOKE_IAC_NUM + KVMPPC_BOOKE_DAC_NUM); n++) { uint64_t addr = dbg->arch.bp[n].addr; uint32_t type = dbg->arch.bp[n].type; @@ -2080,21 +2086,24 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, if (type & ~(KVMPPC_DEBUG_WATCH_READ | KVMPPC_DEBUG_WATCH_WRITE | KVMPPC_DEBUG_BREAKPOINT)) - return -EINVAL; + goto out; if (type & KVMPPC_DEBUG_BREAKPOINT) { /* Setting H/W breakpoint */ if (kvmppc_booke_add_breakpoint(dbg_reg, addr, b++)) - return -EINVAL; + goto out; } else { /* Setting H/W watchpoint */ if (kvmppc_booke_add_watchpoint(dbg_reg, addr, type, w++)) - return -EINVAL; + goto out; } } - return 0; + ret = 0; +out: + vcpu_put(vcpu); + return ret; } void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index aa76d2988178..ac26d95444c9 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2819,15 +2819,20 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) { - int rc = 0; + int rc; + + rc = vcpu_load(vcpu); + if (rc) + return rc; vcpu->guest_debug = 0; kvm_s390_clear_bp_data(vcpu); + rc = -EINVAL; if (dbg->control & ~VALID_GUESTDBG_FLAGS) - return -EINVAL; + goto out; if (!sclp.has_gpere) - return -EINVAL; + goto out; if (dbg->control & KVM_GUESTDBG_ENABLE) { vcpu->guest_debug = dbg->control; @@ -2847,6 +2852,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, atomic_andnot(CPUSTAT_P, &vcpu->arch.sie_block->cpuflags); } + rc = 0; +out: + vcpu_put(vcpu); return rc; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ae8685155d11..09135bd759a4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7596,6 +7596,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, unsigned long rflags; int i, r; + r = vcpu_load(vcpu); + if (r) + return r; + if (dbg->control & (KVM_GUESTDBG_INJECT_DB | KVM_GUESTDBG_INJECT_BP)) { r = -EBUSY; if (vcpu->arch.exception.pending) @@ -7641,7 +7645,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, r = 0; out: - + vcpu_put(vcpu); return r; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 173f98d9c58d..6b87c24c60da 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2650,11 +2650,7 @@ 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: {