From patchwork Thu Oct 12 10:41:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001629 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 41A2960325 for ; Thu, 12 Oct 2017 10:49:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3328828D52 for ; Thu, 12 Oct 2017 10:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2810C28D6D; Thu, 12 Oct 2017 10:49:11 +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 AA4C028D52 for ; Thu, 12 Oct 2017 10:49:10 +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=8OfqEQOI/QGqWHJKjTkDnAfMmADHiEcFAWkzB2cZF9E=; b=kpazFRurpz0FcCdy0GLk+20Usi P3eHx396VD1Q795pqAjeILOJyySYi7ZdVBdCX1E8ZXEj+x7IfiiqmzSWDaprtXmsqGo3FUIraX0BI GXuFBYVN1+BzRzg4y1aU/LiZeIGa5eykhNWKDbIjw+XV0JOORYcMWKDfxJRbG2w5gsiS3ECKmbrz4 XrWpJ4Utw0qts4IPaDVS+ci6Fd1C8k42eh8DBCRPClEdXyBmbg0QK2wMYYJKrPXf7tA7MuVmmMlQW bKHp0u+SXRoNTUw30PYbVRwiVgrRGrjIuITh9weIEy7dYGjFvfpWjvUxzCyUEL2ZePS8GAmEfqlV4 Un72mSoA==; 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 1e2b33-0006Ey-RI; Thu, 12 Oct 2017 10:49:05 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awP-0007WQ-H0 for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:23 +0000 Received: by mail-wm0-x236.google.com with SMTP id t69so11960027wmt.2 for ; Thu, 12 Oct 2017 03:41:56 -0700 (PDT) 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=tQzgU8DXJfejK/8pSa51FE/6CqoR9vwEpvftrxvPisk=; b=KcF077rGuVCksSiMXZm4HddCkP2Uwa4nM6woZArWk1HXSRus/JkcOtRNB79KNnKtea UFiCamkRTL46It3z/RkoSafO7A+e0VTQ+dbXErVfJerYyZw62TJKk2WwSB3jZ2txSaDl jygI7makbFNIjoj9RnjZyVvOrSGHvO0TTbXxM= 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=tQzgU8DXJfejK/8pSa51FE/6CqoR9vwEpvftrxvPisk=; b=gpEeTSc4Y6EGCnsG9Nkv7l9HT0sWC4x4YjFNLvjfNc4fNdXd3Xb5xDO1SD90kwx35p k4DX5lQ7C9FrMdVNqqAROj1BpoTHcpuwtQYJLIa11lnv25i78vBfDdwkNIJyRT0xf+E/ ZA/sBnO+Btg0fGNxa77h4IlC69Nv9tHCJiV1eoas+AHKcm9lYaABf8simIj1D34CC8Bp Fnewgsh3iHdUXAJDVY1KjxpPNDQiVM6TcoA5fhekSN2DNUQGrvy5Y/DZn3RMNiOf4uRZ UphsNxZ9xUdYQ0WwAu+ar7x7Ldy2FBsUR0nYKoaeVZleshHy+kPRQq8Wz37dzKNQcyf/ UYHQ== X-Gm-Message-State: AMCzsaX7zFUE1xrAo5oR5EpQKZ6vDAjnNXF45GVRk1jkpB81L/HnBFH4 PekxGhMa0TWDxNpt2cyEbnIGxxh9gg8= X-Google-Smtp-Source: AOwi7QDPn5tbgbJTkhGfFpy20GChKBYqjLj4b8yhmHJKjJIpPmewMwn6ex8BhKii6RgP2dVMiAEM9A== X-Received: by 10.80.215.146 with SMTP id w18mr2342788edi.81.1507804915554; Thu, 12 Oct 2017 03:41:55 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id g49sm4798603edc.31.2017.10.12.03.41.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:41:54 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/37] KVM: arm64: Slightly improve debug save/restore functions Date: Thu, 12 Oct 2017 12:41:14 +0200 Message-Id: <20171012104141.26902-11-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171012104141.26902-1-christoffer.dall@linaro.org> References: <20171012104141.26902-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171012_034214_005351_DFCF79E4 X-CRM114-Status: GOOD ( 14.94 ) 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 , 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 --- arch/arm64/kvm/hyp/debug-sr.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c index 0fc0758..a2291b6 100644 --- a/arch/arm64/kvm/hyp/debug-sr.c +++ b/arch/arm64/kvm/hyp/debug-sr.c @@ -75,11 +75,6 @@ #define psb_csync() asm volatile("hint #17") -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; @@ -109,10 +104,6 @@ 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) { if (!pmscr_el1) @@ -174,17 +165,22 @@ 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(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)