From patchwork Thu Feb 15 21:03:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10223629 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 3E02360467 for ; Thu, 15 Feb 2018 21:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DEE029511 for ; Thu, 15 Feb 2018 21:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 216C629529; Thu, 15 Feb 2018 21:09:49 +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 A828029511 for ; Thu, 15 Feb 2018 21:09:48 +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=4yXQ3xKITm/kVzbVzjfX+SXfEL79JJSfzwBi9zMqyp8=; b=ke5ueA2cBYoRZGqRhj8Sma+6Ir ipPEjWohzke54RdKqfvb2OtSWrHjyQqVR8GFGX+06I5ZeYvRRYalbXno4cesA9XQht3KDb3Qx5FyR wp0S2BXfqhzMDweaU6OlRl4IM0K1mvMqjdyiUW1fWLwbVevUGkjdtOa4sQwZe0aCUnvtZDG7Blkfe tFnCGKGHJbQOfCw5bkZl7cwSHO9rqoudM8i7o6WZbvlx8X783D5HSu4xaZZMXY8i3k0QE8a26ln2X cMqJNy7zgsDUgCsZE3xLiQfte2UtEGS8Cz/tFzVdDLNHItn+a/hDTHZFUFHW0U3NUWom6hzw57wEH 24vzcQ3A==; 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 1emQml-0005Ur-PI; Thu, 15 Feb 2018 21:09:43 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQhI-0008G9-3c for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2018 21:04:23 +0000 Received: by mail-wm0-x244.google.com with SMTP id v123so3293325wmd.5 for ; Thu, 15 Feb 2018 13:04:02 -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=qp0J45FlSj3Lg/Jc4Q7zNObB+wrNx/ObajqtM+f6mHc=; b=HSgsppChAkCebN/2LIETmc2w6gu3t53JzKtczIs8TyJ+1l0TCCUTbHogDVhQXFakDd xuYbhCvUYw/nbioue3NmIbVR5TvIzvc/0XPCZh0BtTcyTT8YjxtTLbEdc2mvRq5hTBcY l4g1O+1IhWwBLdVj4wkoPZfEbfhF2ghmULUs0= 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=qp0J45FlSj3Lg/Jc4Q7zNObB+wrNx/ObajqtM+f6mHc=; b=iTaT2NhJUrYfsJARkyLifneF1+bJE/hpEJjuTpkgThrm2c61vif/WWvnNOEuK5dR6d rjD+l6Pk+y9BYOiTrWnIxBC32Nl0NSADAdJ89VpKsTLSUIIunQch/tthwLTfTnEsMhfz SiCmq/GhUY6iCwQtLaVTAsh7l8jTHNc7w/ZcTt5GJ+xz5EU402NtRM/bK5FHNd+l3kMe ES7Jq6AEJBUBNIXqaxAT9Vw6pNu+WYcpl64ljXTAe22Xb41POi9is1iG8V3VnovaZrsC dqbOZaNVpSCeVkXuOtGYT/n9Zd5TCbs01Zczm6zmRxOuyru1ZYeAx2SuPqGbstAh7S4o erdg== X-Gm-Message-State: APf1xPB5Fyzn3D0FnqsU0SZL7RVwL1NbwwkMGYr1YVTpMZeoZ69lYwU2 BRtEiMBots2lIwgXfut8A0QBcA== X-Google-Smtp-Source: AH8x2242gtGftNJqkaMD4WlzddJvxLcpnR0f9HLni/7niA3t/XeXmA3YLKY7y36mwm4YRedXhQhtZw== X-Received: by 10.80.168.227 with SMTP id k90mr5062016edc.249.1518728641537; Thu, 15 Feb 2018 13:04:01 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id p55sm8220030edc.15.2018.02.15.13.03.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Feb 2018 13:04:00 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 10/40] KVM: arm64: Slightly improve debug save/restore functions Date: Thu, 15 Feb 2018 22:03:02 +0100 Message-Id: <20180215210332.8648-11-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180215210332.8648-1-christoffer.dall@linaro.org> References: <20180215210332.8648-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180215_130404_359683_54728B25 X-CRM114-Status: GOOD ( 14.82 ) 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 , Christoffer Dall , 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 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 Signed-off-by: Christoffer Dall Reviewed-by: Andrew Jones --- 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)