From patchwork Thu Dec 7 17:06:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10100167 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 B1BEB60360 for ; Thu, 7 Dec 2017 17:07:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CCCE204FE for ; Thu, 7 Dec 2017 17:07:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91B51284DE; Thu, 7 Dec 2017 17:07:02 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 371A0204FE for ; Thu, 7 Dec 2017 17:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756222AbdLGRG4 (ORCPT ); Thu, 7 Dec 2017 12:06:56 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:46876 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756601AbdLGRGy (ORCPT ); Thu, 7 Dec 2017 12:06:54 -0500 Received: by mail-wm0-f68.google.com with SMTP id r78so14369214wme.5 for ; Thu, 07 Dec 2017 09:06:53 -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=uEPRgDdQf+3M2n4mbga6VsFIpONdqnLLvWyHfBDVfJY=; b=eFsg4/9njysbuTZXPKwvMkmdnOLPZakzMvISU9Sv04THJN1pun4KR7N2HFDv7h/i5C nNaxcvhQHi/QQYhKZdiM6qYLeGgNr99dnj1ZzekHiC+SfBB/q4mf+VWwcC66QhqBRkmT PKV643uNcA380k4vUWVNm+hhWfBMecI1T0HKA= 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=uEPRgDdQf+3M2n4mbga6VsFIpONdqnLLvWyHfBDVfJY=; b=hyqznydvAa6lPViRoRc+9CsDXDmgi0v2rjKOZZv999FwkA8H59iEWVKCgqBZ2oM/2+ dt6zAvBjlhWiAfVmLDpSPgNmch0sgEzA85bTvDQfQNr8SkPOExT8X9Cx6aUnNVoTsmmT P9tEtYPKLWLKlGpChHi/vA0AmX69sO2Kfvo4kUPlPejWeNF7AQMTiiEaONdwfbX0RX5i 4X6gr6nPSgrB8BWTWLEKr5dCpAp9+mwB3BttomxZEJgfYkEpkW2bYYKEulfYzBiQYDo0 o2SvFktUjrY+kB2f13iI/mTQC7JKjQ4zQtvZeKzxuVCwx1ktnY3SWU4uL7qYhF18oEwa j6Sg== X-Gm-Message-State: AJaThX4k4ZMGhedMMXCpURM2aAjRhUDDK0qczQWp3FLDGJdk0P8b7Hf+ bHRwUOflQmjSmfr7pt3B1zBmXQ== X-Google-Smtp-Source: AGs4zMa8/tC6x1TujsopY+bGQEhnD/ZfBtkw/yZrPPBrO8O0BFezr4Pr90AbVtkUAEScBCnGY38PeQ== X-Received: by 10.80.213.210 with SMTP id g18mr40793521edj.75.1512666413226; Thu, 07 Dec 2017 09:06:53 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a16sm2868270edd.19.2017.12.07.09.06.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 09:06:52 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Shih-Wei Li , Andrew Jones , Christoffer Dall Subject: [PATCH v2 08/36] KVM: arm64: Slightly improve debug save/restore functions Date: Thu, 7 Dec 2017 18:06:02 +0100 Message-Id: <20171207170630.592-9-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207170630.592-1-christoffer.dall@linaro.org> References: <20171207170630.592-1-christoffer.dall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- 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 406829b6a43e..81b8ad44f9e0 100644 --- a/arch/arm64/kvm/hyp/debug-sr.c +++ b/arch/arm64/kvm/hyp/debug-sr.c @@ -65,11 +65,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; @@ -99,11 +94,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; @@ -164,17 +155,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)