From patchwork Mon Mar 6 02:33:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 9604989 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 C8DF660234 for ; Mon, 6 Mar 2017 02:34:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E62A627813 for ; Mon, 6 Mar 2017 02:34:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAE1427D0C; Mon, 6 Mar 2017 02:34:13 +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 [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 5735527813 for ; Mon, 6 Mar 2017 02:34:13 +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: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:In-Reply-To: References:List-Owner; bh=qsw3VKn08dDdy60qbGUEEBDelCOcBCAfxAcrq6RP9zQ=; b=e5/ JlcdIRM6WjAsMvuijh6sudbNMCQpARVEbTVR4C4ZcuvtXY9937DN5CgUQ3YNdNVLJn0SRzBV3eKR7 HoevZQVkNXXm60lrovCxh1wK1M2LlNx5sfhnwi//xg7XlQQF8M9EEZxw5EUYsKKrvoz5Ab5c7cObG wb6ZS+tXio54/lGW6HHNbhETXRdaC29Ue/UnIP1SUwYSppFLnxM/DgFYPt9pZwWiPs0qEFS3ZA1/B lqjuIWj1MC4xEAClAThPobTN6MhamHKoPdiUV9IKM2eVcdbAJAwjIKDLeLUkR6uASe28orxR9z5pI JqJebYNAYIPOu+dqHb4jpam0+HfSS/w==; 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 1ckiTQ-0008SI-J8; Mon, 06 Mar 2017 02:34:08 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckiT1-0008Qj-QB for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 02:33:45 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7240360733; Mon, 6 Mar 2017 02:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1488767603; bh=XFSTjXMsv3HGk24ZtyC8DhUtgRomCruNNDrZEu1x/f4=; h=From:To:Cc:Subject:Date:From; b=han2RXY3A0wgMr0mWnwheDHDMqfCvxnPf+PyGr4nNZABxOemO0PFQs/yNrbv6tkIq qMnSAt+k8MqXY/5/aEekzTccbYqhBaVkxb8NI2rOjr5XcrrJ1987/oN4hR+Hnf12IA wOsfKeXOXJBImrAAaXxXkaA9nyiXqd52kEekaeqE= Received: from shankerd-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E8A556034D; Mon, 6 Mar 2017 02:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1488767601; bh=XFSTjXMsv3HGk24ZtyC8DhUtgRomCruNNDrZEu1x/f4=; h=From:To:Cc:Subject:Date:From; b=nK/k3U52+EN/rzKbJadMBk8qYhLVo74D0UUs6eHf9AyybojcOMvkB+mwYoo6NW73X 5QRx20APDroLRGgIk6Vlpna6pt+IN4XFPiHbq97+ymjKohLdlewGXHLtKXmdOGgO0c Tkx+hJqFjAi6VQuObmC3iIsfW3M9PIw1fONfBEcc= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E8A556034D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org From: Shanker Donthineni To: Marc Zyngier , Christoffer Dall Subject: [PATCH v2] arm64: kvm: Use has_vhe() instead of hyp_alternate_select() Date: Sun, 5 Mar 2017 20:33:18 -0600 Message-Id: <1488767598-2055-1-git-send-email-shankerd@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170305_183343_898119_32EF77ED X-CRM114-Status: GOOD ( 15.97 ) 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: Vikram Sethi , kvm , Catalin Marinas , Will Deacon , linux-kernel , Shanker Donthineni , kvmarm , linux-arm-kernel 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 Now all the cpu_hwcaps features have their own static keys. We don't need a separate function hyp_alternate_select() to patch the vhe/nvhe code. We can achieve the same functionality by using has_vhe(). It improves the code readability, uses the jump label instructions, and also compiler generates the better code with a fewer instructions. Signed-off-by: Shanker Donthineni --- v2: removed 'Change-Id: Ia8084189833f2081ff13c392deb5070c46a64038' from commit arch/arm64/kvm/hyp/debug-sr.c | 12 ++++++---- arch/arm64/kvm/hyp/switch.c | 50 +++++++++++++++++++----------------------- arch/arm64/kvm/hyp/sysreg-sr.c | 23 +++++++++---------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c index f5154ed..e5642c2 100644 --- a/arch/arm64/kvm/hyp/debug-sr.c +++ b/arch/arm64/kvm/hyp/debug-sr.c @@ -109,9 +109,13 @@ 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_save_spe(u64 *pmscr_el1) +{ + if (has_vhe()) + __debug_save_spe_vhe(pmscr_el1); + else + __debug_save_spe_nvhe(pmscr_el1); +} static void __hyp_text __debug_restore_spe(u64 pmscr_el1) { @@ -180,7 +184,7 @@ 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); + __debug_save_spe(&vcpu->arch.host_debug_state.pmscr_el1); } void __hyp_text __debug_cond_restore_host_state(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index aede165..c5c77b8 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -33,13 +33,9 @@ static bool __hyp_text __fpsimd_enabled_vhe(void) return !!(read_sysreg(cpacr_el1) & CPACR_EL1_FPEN); } -static hyp_alternate_select(__fpsimd_is_enabled, - __fpsimd_enabled_nvhe, __fpsimd_enabled_vhe, - ARM64_HAS_VIRT_HOST_EXTN); - bool __hyp_text __fpsimd_enabled(void) { - return __fpsimd_is_enabled()(); + return has_vhe() ? __fpsimd_enabled_vhe() : __fpsimd_enabled_nvhe(); } static void __hyp_text __activate_traps_vhe(void) @@ -63,9 +59,10 @@ static void __hyp_text __activate_traps_nvhe(void) write_sysreg(val, cptr_el2); } -static hyp_alternate_select(__activate_traps_arch, - __activate_traps_nvhe, __activate_traps_vhe, - ARM64_HAS_VIRT_HOST_EXTN); +static void __hyp_text __activate_traps_arch(void) +{ + has_vhe() ? __activate_traps_vhe() : __activate_traps_nvhe(); +} static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) { @@ -97,7 +94,7 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) write_sysreg(0, pmselr_el0); write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0); write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); - __activate_traps_arch()(); + __activate_traps_arch(); } static void __hyp_text __deactivate_traps_vhe(void) @@ -127,9 +124,10 @@ static void __hyp_text __deactivate_traps_nvhe(void) write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); } -static hyp_alternate_select(__deactivate_traps_arch, - __deactivate_traps_nvhe, __deactivate_traps_vhe, - ARM64_HAS_VIRT_HOST_EXTN); +static void __hyp_text __deactivate_traps_arch(void) +{ + has_vhe() ? __deactivate_traps_vhe() : __deactivate_traps_nvhe(); +} static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) { @@ -142,7 +140,7 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) if (vcpu->arch.hcr_el2 & HCR_VSE) vcpu->arch.hcr_el2 = read_sysreg(hcr_el2); - __deactivate_traps_arch()(); + __deactivate_traps_arch(); write_sysreg(0, hstr_el2); write_sysreg(0, pmuserenr_el0); } @@ -183,20 +181,14 @@ static void __hyp_text __vgic_restore_state(struct kvm_vcpu *vcpu) __vgic_v2_restore_state(vcpu); } -static bool __hyp_text __true_value(void) +static bool __check_arm_834220(void) { - return true; -} + if (cpus_have_const_cap(ARM64_WORKAROUND_834220)) + return true; -static bool __hyp_text __false_value(void) -{ return false; } -static hyp_alternate_select(__check_arm_834220, - __false_value, __true_value, - ARM64_WORKAROUND_834220); - static bool __hyp_text __translate_far_to_hpfar(u64 far, u64 *hpfar) { u64 par, tmp; @@ -251,7 +243,7 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) * resolve the IPA using the AT instruction. */ if (!(esr & ESR_ELx_S1PTW) && - (__check_arm_834220()() || (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) { + (__check_arm_834220() || (esr & ESR_ELx_FSC_TYPE) == FSC_PERM)) { if (!__translate_far_to_hpfar(far, &hpfar)) return false; } else { @@ -406,9 +398,13 @@ static void __hyp_text __hyp_call_panic_vhe(u64 spsr, u64 elr, u64 par) (void *)read_sysreg(tpidr_el2)); } -static hyp_alternate_select(__hyp_call_panic, - __hyp_call_panic_nvhe, __hyp_call_panic_vhe, - ARM64_HAS_VIRT_HOST_EXTN); +static void __hyp_text __hyp_call_panic(u64 spsr, u64 elr, u64 par) +{ + if (has_vhe()) + __hyp_call_panic_vhe(spsr, elr, par); + else + __hyp_call_panic_nvhe(spsr, elr, par); +} void __hyp_text __noreturn __hyp_panic(void) { @@ -428,7 +424,7 @@ void __hyp_text __noreturn __hyp_panic(void) } /* Call panic for real */ - __hyp_call_panic()(spsr, elr, par); + __hyp_call_panic(spsr, elr, par); unreachable(); } diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index 9341376..2a6cb27 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -21,9 +21,6 @@ #include #include -/* Yes, this does nothing, on purpose */ -static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { } - /* * Non-VHE: Both host and guest must save everything. * @@ -68,13 +65,15 @@ static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt) ctxt->gp_regs.spsr[KVM_SPSR_EL1]= read_sysreg_el1(spsr); } -static hyp_alternate_select(__sysreg_call_save_host_state, - __sysreg_save_state, __sysreg_do_nothing, - ARM64_HAS_VIRT_HOST_EXTN); +static void __hyp_text __sysreg_call_save_host_state(struct kvm_cpu_context *ctxt) +{ + if (!has_vhe()) + __sysreg_save_state(ctxt); +} void __hyp_text __sysreg_save_host_state(struct kvm_cpu_context *ctxt) { - __sysreg_call_save_host_state()(ctxt); + __sysreg_call_save_host_state(ctxt); __sysreg_save_common_state(ctxt); } @@ -121,13 +120,15 @@ static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt) write_sysreg_el1(ctxt->gp_regs.spsr[KVM_SPSR_EL1],spsr); } -static hyp_alternate_select(__sysreg_call_restore_host_state, - __sysreg_restore_state, __sysreg_do_nothing, - ARM64_HAS_VIRT_HOST_EXTN); +static void __hyp_text __sysreg_call_restore_host_state(struct kvm_cpu_context *ctxt) +{ + if (!has_vhe()) + __sysreg_restore_state(ctxt); +} void __hyp_text __sysreg_restore_host_state(struct kvm_cpu_context *ctxt) { - __sysreg_call_restore_host_state()(ctxt); + __sysreg_call_restore_host_state(ctxt); __sysreg_restore_common_state(ctxt); }