From patchwork Fri Jan 12 12:07:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160501 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 3EB1E602D8 for ; Fri, 12 Jan 2018 12:12:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22027289D2 for ; Fri, 12 Jan 2018 12:12:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16932289D4; Fri, 12 Jan 2018 12:12:35 +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 93B91289D2 for ; Fri, 12 Jan 2018 12:12:34 +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=4v3pp7bm8VWVplOw3x3qJfW6wHiDQZYQU1/FG5YclJE=; b=KcQJ8rU/JmNt25eOPxUsKTMm9A mBN1d6IdFOZ/tIWop+ivO0M6+Qly+J7vLgv45Q+PD7EWGmIAuLpitTZM+bn3Ort0XIgGh6IP5eOGy PMgVWGzZWFkb8ppTLMRVNwmP1Umk4gomuVhG7eoHtLsNAgpxP3SWZ6GsTGTmjHzmRM2Kh7m/1WWcO TiQEnZ7eWJk6c1/iCQmKNp/CZ66cSPOF9Wk9FCVsDBrz1INuLWWZjN5PPhrfIUtNJs5aXpdQq1FYh Vod45wpLS0DEJC+s6SWnJAX0fc9zsvvliVodKt66R5Lr4ckdp4sbOrz2I58NqH8wW/4d5ICNa/lE0 Am3mfWfg==; 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 1eZyCG-0006Pm-35; Fri, 12 Jan 2018 12:12:32 +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 1eZy8B-0000EM-RZ for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:23 +0000 Received: by mail-wm0-x241.google.com with SMTP id x4so2105553wmc.0 for ; Fri, 12 Jan 2018 04:08:09 -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=EFGJVu4BIjQz2VyB29HqEoTXfbzUoQQPJttv0I43vM8=; b=ME8jhk7b0mj8METyMGW+TTECLwp8TzYQfBJGUnV32QkOxVbEf6abndO5MlBdaxalTU VxKqASQ/quCoXEW6eWl4MuKsQgb3xi0b+U63VL/INY0bGn+v3ikkmrFVECxgJYjivgSY uzNozn3i+/f3wtKuqB+7b9LqwHjhRsBZqIHLo= 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=EFGJVu4BIjQz2VyB29HqEoTXfbzUoQQPJttv0I43vM8=; b=q0yKGu9AT7YG9qc+7qf9+/uKhWQSleKe3Qv5+CLa3qZPbeoZAnszabE+8za31r4V3i t7XRKyrX85d5uYc1PFHi5fP5mTtE8/xOwJCPrMESqTZy9TJSqtv8f5/oxNS8Tcan5cEO MmYJCI3JRWIVWMqVMG/0p8F8HaDrddP70j/E472Y6Y8OhyXdkEMUDSyYf88m0ZCHNRcs l6XYschdnW+Q9rpFOGFhmX6Y53gJyCunKj8PigXRCXpzYBS7cXPLUMq/yXVjDL/mRk7j YgV/fWI8a1gAXD+jXjHVCZfmLs290eyWCZzWwQG0Q/1y6YoktxUpNe5QMS6BA/e5wAX5 KvQw== X-Gm-Message-State: AKwxytdMwTzFdbPH0xpjQDNMpadAJq5hCK33dfGNfZpx3/aP10SGnfJU /BgLKSaiBtV1We5iI/Azb+YgAA== X-Google-Smtp-Source: ACJfBos0wj2LzUQA/zHuvBUxkfwq+hI7t17xmXlY+p0ycpTpuB6IkX6uIX6EaFgZwnFQV8OwpNUuLg== X-Received: by 10.80.169.67 with SMTP id m3mr15135231edc.274.1515758888358; Fri, 12 Jan 2018 04:08:08 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f16sm13489705edj.65.2018.01.12.04.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:07 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 11/41] KVM: arm64: Slightly improve debug save/restore functions Date: Fri, 12 Jan 2018 13:07:17 +0100 Message-Id: <20180112120747.27999-12-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180112120747.27999-1-christoffer.dall@linaro.org> References: <20180112120747.27999-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180112_040820_037771_D2B16D68 X-CRM114-Status: GOOD ( 14.28 ) 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. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- 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)