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: 10100367 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 6428560325 for ; Thu, 7 Dec 2017 17:20:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3F725E13 for ; Thu, 7 Dec 2017 17:20:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F08128514; Thu, 7 Dec 2017 17:20:46 +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 4CEA825E13 for ; Thu, 7 Dec 2017 17:20:45 +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=M0ByUG7XRBDQkWGK5TzmY+/lzIx40MAtDojMPRp62zc=; b=GCUK8shdMm0Zrci0AxG5LHY9NP VwcXMEA2wXgJLuQsUm5tW+08keF7b+ntqoSedfsvvP0Admm6vqYDWh2lSkoxe8DFRcgdaTejQXSfP X2EWPNYmg+9FRkxt6fcnFdr5b/XYFlWaU0vNAimEDE/wwGQbLrAq9ByG185eL3NmvUUM6ULvmASRE 59x2+Zbv9UR/PgEet1v0lIFcwl84yyL990BwDaFbUZhTSYONP8NYZzZzPIdMv3rwN8HE1nxe5fpRf MSpB22dZPMmU+pUssTCBENG1Wp1Ghbb+lYv+wa5heg74slK21NHIdOJHctRz0NNVKTRPmw9z51A/6 qWyXqo9A==; 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 1eMzql-0001iV-Aj; Thu, 07 Dec 2017 17:20:43 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMzdf-0002sT-0q for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 17:07:15 +0000 Received: by mail-wm0-x244.google.com with SMTP id t8so14267782wmc.3 for ; Thu, 07 Dec 2017 09:06:54 -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=JetiLaMmQHQTTr/hLL3lNpY9XV5aoI2uo9F+snE7jIjgpI9y0mfZBFA6c7U+pkLcle DF1kK3JUlCtEdiK76nM/2O2Ccu1yc6TYHFIpXI/X7yLf+sb2iG8aj3Nr0YAg0HdljR07 bZa1iZSKkPYraJzZtTV4vW+CJnlaSwNpayGjpKp2XlqiyNtW6M8bnh2bV3RkYrxGqOi2 nMAtdUfAy4tVrhdReNzau5TFg0SDNkvzx00JCJqNl9s9azMDOOSMPuEZZ1UE8PhwWBB3 EJNOWnRRQKrTF+6yozOhlOOFDyJthaH0XAhFFjXij9kpFGqwLWRVZUmtStFd9hlcsUPI DIjw== X-Gm-Message-State: AJaThX6pfhpZGzrTsF5Il2S4mJstz21gewjRYUNnpfpmCVs2S3d43VuK VC0y/Fo8WZeOMXksLBYrFMz9aQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171207_090711_379433_7149E9E2 X-CRM114-Status: GOOD ( 15.16 ) 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: Marc Zyngier , Andrew Jones , Christoffer Dall , Shih-Wei Li , kvm@vger.kernel.org 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 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)