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: 10244901 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 2D9A160208 for ; Tue, 27 Feb 2018 11:36:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 220D028843 for ; Tue, 27 Feb 2018 11:36:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16B1A28846; Tue, 27 Feb 2018 11:36:26 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 6C29E28843 for ; Tue, 27 Feb 2018 11:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932082AbeB0LgY (ORCPT ); Tue, 27 Feb 2018 06:36:24 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:53935 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753020AbeB0Ler (ORCPT ); Tue, 27 Feb 2018 06:34:47 -0500 Received: by mail-wm0-f65.google.com with SMTP id t74so23540319wme.3 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=VmB9b6c48+Wi4EZNmO2d9NXnXczHW8UhYaoY33bAlaJgH6vN2cerlfkLBWc8oEj/C1 vGEj8LZexKNdihsfjWS+aUDQcKSwTY1WP0sTHvhLf1ekccI++PYPynvNaK5Urd6eYyti lJEDPSHyKiwA8+XCxvbUdypBF0q831fNkFr6nh1JH6rzD/PW8MkDTYT1Zze708WIOhGz IEt4TN6ulbYel+6JTR5sPx6k185RsiQb7FajL28eqKz4xWuDByjdeGdKyV2AguZ2cT+7 MKexiSdsl6TD38pEgVk66xZsM3CB//EPI/iby4QMrymLcbgZr53Rp/h0Lh3JDIZng+2Q 3D4A== X-Gm-Message-State: APf1xPDNvLg+uIQQaAfVW286zDaKWqJ7H75aPAwxiQj3Zz+BfDfKu5Lc 7bmi2M1HvuYBvQjokJYzsmPYlw== 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 Cc: kvm@vger.kernel.org, Marc Zyngier , Andrew Jones , Shih-Wei Li , Dave Martin , Julien Grall , Tomasz Nowicki , Yury Norov 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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)