From patchwork Tue Feb 27 11:33:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10245009 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 9220060362 for ; Tue, 27 Feb 2018 12:08:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D9FD287A7 for ; Tue, 27 Feb 2018 12:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 707E928878; Tue, 27 Feb 2018 12:08: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 E97CF287A7 for ; Tue, 27 Feb 2018 12:08: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=+sPMjE4ZRmC57EApUJBI3+5tFLvtr4sKqggwqKfjpSg=; b=O74Tv6p1y9lv9VDr14qrAaHd5g u1AcBVU2pnTWtdQMp4MbPAEAw2RKzMNa66I67iYw3dDFSa2EmuO+02d0Bs8XabsTAwwairkl35JWB aoWrZGHki6TizuMuujz5Fo0LzedN2Rxh8DIDXtd/TkqGVI94MZ6z3w9vkNS3A03u6/+t6xumsaCQ3 UMm+JgStBb/DX8NFwe0wIlnxqHXyuWKOVlrVHMKzlJmyxbIs269EMpJaTyQ1HOtkCn1wUXKv6ViVe 0FJYdO5Rn4LTC29uyrWUtn4Pmy4OwTSDgXyUvxMKze4aKyaTFEL0RmUgTvaIe8dAU2DOyKizRiT6A jkklnQXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqe3W-0003bJ-Kd; Tue, 27 Feb 2018 12:08:26 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdX8-0006Zv-11 for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:35:11 +0000 Received: by mail-wm0-x241.google.com with SMTP id q83so23499756wme.5 for ; Tue, 27 Feb 2018 03:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nqee9bak77kzOqLPMAFJqzIWKAvRVxHQ0fsoi0i1FjQ=; b=aVknU/LQSmLD0Yp+Ukwl3tM8T8op0/olHhw27uIQkyJXNY5w7Fl5jGHGgYIgeyi+Q+ eRM0LdoMKr4szRkRjwfLo2wFVII1sg0p5GkmIUNvCIWsUWoRk85cX6kYh+w73OHFmJr7 atJCRJvTNv1Rtdisf5ET3EJ8TG/5wIxoWYTh+//awwHPBEQ3cehVajoZb+Ver7MW1Fcl GtawskpfzGwdyGQ7hoiWIRa8Fnpv+ync2/0Rh97z1OeCdU4vN1+MHQVZGZM9+kQx+apV YcNKUzrnVxDNjheFA7OFVdluUyO9uWfCKSg4YXrShGVDEnbaVPwwM2F9PkctSBJZSrZS kTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Nqee9bak77kzOqLPMAFJqzIWKAvRVxHQ0fsoi0i1FjQ=; b=trYL6paMin+QE4fIu1lgxYlfNZtl4vh7bxT9AFHQKfpJDwhyzF+FoinCx5LAPkV8W3 GHl2ubrfkrBMuDgzIt53jBHNsUKrROaZxBFJBi88Aaza092FnWpI9/VaJq/F4N0PbpQj guIhxhu5xk1LAl4fL2hVcrbU4gQJqjWUI6EVbFXWhCRDJ++AMTTv6GviFKjQbTtt8tqz pq24XrsTsRHF3auir9PyiCxfMLEzi4mptjTWYz3ZBEIjkrmbYW6sRTwhbu0rsO8V1mWU Xsr5IDntnDvV1RS4l/N3IWoNPqx8hmewmU/axF9lprpw2/UWr+nm/B/fmiQI0usSKKFu Dbcw== X-Gm-Message-State: APf1xPAvTVjmOASSDibnBrQz1qoWNAcqbTA+vCmSUaRmjDgq0x4pszO2 2seTm7Mtlv+YH+uBEkK/KPKzUQ== X-Google-Smtp-Source: AH8x225KYt7Qfj7E9+F5rggoCNdOUDj84Pc6xQJy9Q2uwi2dM1xMYqCy0pCVBy5O0bdbT40VSNMnPg== X-Received: by 10.80.149.161 with SMTP id w30mr18275622eda.229.1519731286648; Tue, 27 Feb 2018 03:34:46 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.34.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:34:45 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 10/40] KVM: arm64: Slightly improve debug save/restore functions Date: Tue, 27 Feb 2018 12:33:59 +0100 Message-Id: <20180227113429.637-11-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_033458_892272_E3BFA69E X-CRM114-Status: GOOD ( 15.44 ) 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: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Dave Martin , Shih-Wei Li 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 From: Christoffer Dall The debug save/restore functions can be improved by using the has_vhe() static key instead of the instruction alternative. Using the static key uses the same paradigm as we're going to use elsewhere, it makes the code more readable, and it generates slightly better code (no stack setups and function calls unless necessary). We also use a static key on the restore path, because it will be marginally faster than loading a value from memory. Finally, we don't have to conditionally clear the debug dirty flag if it's set, we can just clear it. Reviewed-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- Notes: Changes since v1: - Change dot to comma in comment - Rename __debug_restore_spe to __debug_restore_spe_nvhe arch/arm64/kvm/hyp/debug-sr.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c index d958cd63a547..74f71fb5e36d 100644 --- a/arch/arm64/kvm/hyp/debug-sr.c +++ b/arch/arm64/kvm/hyp/debug-sr.c @@ -66,11 +66,6 @@ default: write_debug(ptr[0], reg, 0); \ } -static void __hyp_text __debug_save_spe_vhe(u64 *pmscr_el1) -{ - /* The vcpu can run. but it can't hide. */ -} - static void __hyp_text __debug_save_spe_nvhe(u64 *pmscr_el1) { u64 reg; @@ -103,11 +98,7 @@ static void __hyp_text __debug_save_spe_nvhe(u64 *pmscr_el1) dsb(nsh); } -static hyp_alternate_select(__debug_save_spe, - __debug_save_spe_nvhe, __debug_save_spe_vhe, - ARM64_HAS_VIRT_HOST_EXTN); - -static void __hyp_text __debug_restore_spe(u64 pmscr_el1) +static void __hyp_text __debug_restore_spe_nvhe(u64 pmscr_el1) { if (!pmscr_el1) return; @@ -168,17 +159,24 @@ void __hyp_text __debug_cond_save_host_state(struct kvm_vcpu *vcpu) { __debug_save_state(vcpu, &vcpu->arch.host_debug_state.regs, kern_hyp_va(vcpu->arch.host_cpu_context)); - __debug_save_spe()(&vcpu->arch.host_debug_state.pmscr_el1); + + /* + * Non-VHE: Disable and flush SPE data generation + * VHE: The vcpu can run, but it can't hide. + */ + if (!has_vhe()) + __debug_save_spe_nvhe(&vcpu->arch.host_debug_state.pmscr_el1); } void __hyp_text __debug_cond_restore_host_state(struct kvm_vcpu *vcpu) { - __debug_restore_spe(vcpu->arch.host_debug_state.pmscr_el1); + if (!has_vhe()) + __debug_restore_spe_nvhe(vcpu->arch.host_debug_state.pmscr_el1); + __debug_restore_state(vcpu, &vcpu->arch.host_debug_state.regs, kern_hyp_va(vcpu->arch.host_cpu_context)); - if (vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) - vcpu->arch.debug_flags &= ~KVM_ARM64_DEBUG_DIRTY; + vcpu->arch.debug_flags &= ~KVM_ARM64_DEBUG_DIRTY; } u32 __hyp_text __kvm_get_mdcr_el2(void)