From patchwork Mon Sep 21 21:26:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 7234261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5F11B9F380 for ; Mon, 21 Sep 2015 21:29:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6DF93206F4 for ; Mon, 21 Sep 2015 21:29:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 744E720726 for ; Mon, 21 Sep 2015 21:29:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze8cU-0001R7-8k; Mon, 21 Sep 2015 21:27:30 +0000 Received: from mailout4.w2.samsung.com ([211.189.100.14] helo=usmailout4.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze8cP-0001IJ-2q for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2015 21:27:26 +0000 Received: from uscpsbgex2.samsung.com (u123.gpu85.samsung.co.kr [203.254.195.123]) by usmailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NV1007E4Q933L40@usmailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2015 17:27:03 -0400 (EDT) X-AuditID: cbfec37b-f79926d0000060e9-9a-560076272a14 Received: from usmmp2.samsung.com ( [203.254.195.78]) by uscpsbgex2.samsung.com (USCPEXMTA) with SMTP id BC.06.24809.72670065; Mon, 21 Sep 2015 17:27:03 -0400 (EDT) Received: from sisasmtp.sisa.samsung.com ([105.144.21.116]) by usmmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NV1001AVQ92YOD0@usmmp2.samsung.com>; Mon, 21 Sep 2015 17:27:03 -0400 (EDT) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.145.28.253) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.3.224.2; Mon, 21 Sep 2015 14:27:02 -0700 From: Mario Smarduch To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Subject: [RFT - PATCH 2/2] KVM/arm64: enable armv8 fp/simd lazy switch Date: Mon, 21 Sep 2015 14:26:23 -0700 Message-id: <1442870783-30752-3-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1442870783-30752-1-git-send-email-m.smarduch@samsung.com> References: <1442870783-30752-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 X-Originating-IP: [105.145.28.253] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNLMWRmVeSWpSXmKPExsVy+t9hP131MoYwg1evJSxevP7HaDFnaqHF x1PH2S02Pb7GavH3zj82B1aPNfPWMHrcubaHzeP8pjXMHpuX1Ht83iQXwBrFZZOSmpNZllqk b5fAlXFk/hPWgsUyFWs75jI3ME4W62Lk5JAQMJFY8/AXE4QtJnHh3nq2LkYuDiGBZYwS74/1 sEA4TUwSxzZsg3IuMko0vLjBAtLCJqArsf/eRnYQW0QgVGLK8tdgo5gFMiRmP/0HFhcWcJP4 2XUezGYRUJXo3HqUFcTmBYo/WdzKCrFaTuLksclgNqeAu0TvvTtg9UJANUf/fGWCqBeU+DH5 HtBeDqD5EhLPPytBlKhKbLv5nBEkLCGgJLFju/YERqFZSBpmITQsYGRaxShWWpxcUJyUnlph pFecmFtcmpeul5yfu4kREuTVOxjvfrU5xCjAwajEw5tY/j9UiDWxrLgy9xCjBAezkgjvcX6G MCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8dyTkQoUE0hNLUrNTUwtSi2CyTBycUg2Mempf4i5F f7JM+nPscYSIgNOch+IH8/asrVy6WGrts8j91/2+afCpMeXMmZ+yMplXcNLi0y6qu6+Gf3/F 73L10tWtHVqZEZNqNu77mCfHbOv34tS+bR4sXtJWMpPVJH5XTRRm7+p6UsPkt/Len+M9hjaz l708HTdD3ql+/6GpDYxaPdbrGevrlFiKMxINtZiLihMBDd8Zem4CAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150921_142725_320583_00456A47 X-CRM114-Status: GOOD ( 12.72 ) X-Spam-Score: -6.9 (------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Mario Smarduch Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enables arm64 lazy fp/simd switch. Removes the ARM constraint, and follows the same approach as armv7 version - found here https://lists.cs.columbia.edu/pipermail/kvmarm/2015-September/016518.html Signed-off-by: Mario Smarduch --- arch/arm/kvm/arm.c | 2 -- arch/arm64/kvm/hyp.S | 59 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 0acbb69..7260853 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -112,12 +112,10 @@ void kvm_arch_check_processor_compat(void *rtn) */ static void kvm_switch_fp_regs(struct kvm_vcpu *vcpu) { -#ifdef CONFIG_ARM if (vcpu->arch.vfp_lazy == 1) { kvm_call_hyp(__kvm_restore_host_vfp_state, vcpu); vcpu->arch.vfp_lazy = 0; } -#endif } /** diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index 39aa322..e412251 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -385,14 +385,6 @@ tbz \tmp, #KVM_ARM64_DEBUG_DIRTY_SHIFT, \target .endm -/* - * Branch to target if CPTR_EL2.TFP bit is set (VFP/SIMD trapping enabled) - */ -.macro skip_fpsimd_state tmp, target - mrs \tmp, cptr_el2 - tbnz \tmp, #CPTR_EL2_TFP_SHIFT, \target -.endm - .macro compute_debug_state target // Compute debug state: If any of KDE, MDE or KVM_ARM64_DEBUG_DIRTY // is set, we do a full save/restore cycle and disable trapping. @@ -433,10 +425,6 @@ mrs x5, ifsr32_el2 stp x4, x5, [x3] - skip_fpsimd_state x8, 3f - mrs x6, fpexc32_el2 - str x6, [x3, #16] -3: skip_debug_state x8, 2f mrs x7, dbgvcr32_el2 str x7, [x3, #24] @@ -495,8 +483,14 @@ isb 99: msr hcr_el2, x2 - mov x2, #CPTR_EL2_TTA + + mov x2, #0 + ldr x3, [x0, #VCPU_VFP_LAZY] + tbnz x3, #0, 98f + orr x2, x2, #CPTR_EL2_TFP +98: + mov x2, #CPTR_EL2_TTA msr cptr_el2, x2 mov x2, #(1 << 15) // Trap CP15 Cr=15 @@ -674,14 +668,10 @@ __restore_debug: ret __save_fpsimd: - skip_fpsimd_state x3, 1f save_fpsimd -1: ret __restore_fpsimd: - skip_fpsimd_state x3, 1f restore_fpsimd -1: ret switch_to_guest_fpsimd: push x4, lr @@ -693,6 +683,9 @@ switch_to_guest_fpsimd: mrs x0, tpidr_el2 + mov x2, #1 + str x2, [x0, #VCPU_VFP_LAZY] + ldr x2, [x0, #VCPU_HOST_CONTEXT] kern_hyp_va x2 bl __save_fpsimd @@ -768,7 +761,6 @@ __kvm_vcpu_return: add x2, x0, #VCPU_CONTEXT save_guest_regs - bl __save_fpsimd bl __save_sysregs skip_debug_state x3, 1f @@ -789,7 +781,6 @@ __kvm_vcpu_return: kern_hyp_va x2 bl __restore_sysregs - bl __restore_fpsimd /* Clear FPSIMD and Trace trapping */ msr cptr_el2, xzr @@ -868,6 +859,36 @@ ENTRY(__kvm_flush_vm_context) ret ENDPROC(__kvm_flush_vm_context) +/** + * kvm_switch_fp_regs() - switch guest/host VFP/SIMD registers + * @vcpu: pointer to vcpu structure. + * + */ +ENTRY(__kvm_restore_host_vfp_state) + push x4, lr + + kern_hyp_va x0 + + // Load Guest HCR, determine if guest is 32 or 64 bit + ldr x2, [x0, #VCPU_HCR_EL2] + msr hcr_el2, x2 + + add x2, x0, #VCPU_CONTEXT + + skip_32bit_state x3, 1f + mrs x4, fpexc32_el2 + str x4, [x2, #CPU_SYSREG_OFFSET(FPEXC32_EL2)] +1: + bl __save_fpsimd + + ldr x2, [x0, #VCPU_HOST_CONTEXT] + kern_hyp_va x2 + bl __restore_fpsimd + + pop x4, lr + ret +ENDPROC(__kvm_restore_host_vfp_state) + __kvm_hyp_panic: // Guess the context by looking at VTTBR: // If zero, then we're already a host.