From patchwork Fri Sep 18 01:05:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 7212081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7DA30BEEC1 for ; Fri, 18 Sep 2015 01:07:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B1EC20412 for ; Fri, 18 Sep 2015 01:07:52 +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 F19D120761 for ; Fri, 18 Sep 2015 01:07:49 +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 1Zck7s-0000SQ-Kc; Fri, 18 Sep 2015 01:06:08 +0000 Received: from mailout2.w2.samsung.com ([211.189.100.12] helo=usmailout2.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zck7j-0000K5-JR for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2015 01:06:00 +0000 Received: from uscpsbgex4.samsung.com (u125.gpu85.samsung.co.kr [203.254.195.125]) by mailout2.w2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NUU00BFPLPIC630@mailout2.w2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2015 21:05:43 -0400 (EDT) X-AuditID: cbfec37d-f79746d0000068cf-b6-55fb63666307 Received: from usmmp1.samsung.com ( [203.254.195.77]) by uscpsbgex4.samsung.com (USCPEXMTA) with SMTP id 65.60.26831.6636BF55; Thu, 17 Sep 2015 21:05:42 -0400 (EDT) Received: from sisasmtp.sisa.samsung.com ([105.144.21.116]) by usmmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NUU00HTDLPI7P20@usmmp1.samsung.com>; Thu, 17 Sep 2015 21:05:42 -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; Thu, 17 Sep 2015 18:05:42 -0700 From: Mario Smarduch To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Subject: [PATCH 2/2] KVM/arm: enable armv7 fp/simd lazy switch Date: Thu, 17 Sep 2015 18:05:17 -0700 Message-id: <1442538317-13618-3-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1442538317-13618-1-git-send-email-m.smarduch@samsung.com> References: <1442538317-13618-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 X-Originating-IP: [105.145.28.253] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRmVeSWpSXmKPExsVy+t9hX9205N+hBtNeWFm8eP2P0WLO1EKL j6eOs1tsenyN1eLvnX9sDqwea+atYfS4c20Pm8f5TWuYPTYvqff4vEkugDWKyyYlNSezLLVI 3y6BK2PDmk7WglmyFQ+mL2duYFwm3sXIySEhYCLx7NgqNghbTOLCvfVANheHkMAyRol7D94w QjhNTBKTr9xkhXAuMkps/9LBCtLCJqArsf/eRnYQW0QgVGLK8tdMIDazQIbE7Kf/gOIcHMIC dhKTTiWChFkEVCWatk4HK+EVcJPYNHESC8RmOYmTxyaDjeQUcJdYcXclmC0EVPNn0kVWiHpB iR+T77GAjGQWkJB4/lkJokRVYtvN54wgYQkBJYkd27UnMArNQtIwC6FhASPTKkax0uLkguKk 9NQKE73ixNzi0rx0veT83E2MkBCv3cF4/6vNIUYBDkYlHl4Pj9+hQqyJZcWVuYcYJTiYlUR4 z0UDhXhTEiurUovy44tKc1KLDzFKc7AoifNGSMqFCgmkJ5akZqemFqQWwWSZODilGhgvKxed +SHlrtOZqmXW7jN/rZRYzAOfh5fX/ly3sEy/OcuQ/dDTiJ1Nn7estJk2XfBGs/713lN1C72t P5xiVq2ONBFOO+upMrFjr2DradZeuyMmv7ebnj3ufWftwu7MzqcSPjdVgnYkyW98LcJv9G7h ivqUGeatq5Y+82j9JyBusq9FsFa/xFKJpTgj0VCLuag4EQD5cZ9AbQIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150917_180559_746668_03A7F6B2 X-CRM114-Status: GOOD ( 14.61 ) 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, T_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 Adds code to enable fp/simd lazy switch. On each entry check if fp/simd registers have been switched to guest, if no set the trap flag. On trap switch fp/simd registers and set vfp_lazy to true and disable trapping. When the vcpu is about to be put, then context switch fp/simd registers save guest and restore host and reset the vfp_lazy state to enable trapping again. Signed-off-by: Mario Smarduch --- arch/arm/kvm/arm.c | 17 +++++++++++++++++ arch/arm/kvm/interrupts.S | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index ce404a5..0acbb69 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -105,6 +105,20 @@ void kvm_arch_check_processor_compat(void *rtn) *(int *)rtn = 0; } +/** + * kvm_switch_fp_regs() - switch guest/host VFP/SIMD registers + * @vcpu: pointer to vcpu structure. + * + */ +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 +} /** * kvm_arch_init_vm - initializes a VM data structure @@ -295,6 +309,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { + /* Check if Guest accessed VFP registers */ + kvm_switch_fp_regs(vcpu); + /* * The arch-generic KVM code expects the cpu field of a vcpu to be -1 * if the vcpu is no longer assigned to a cpu. This is used for the diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S index 900ef6d..a47acc1 100644 --- a/arch/arm/kvm/interrupts.S +++ b/arch/arm/kvm/interrupts.S @@ -96,6 +96,24 @@ ENTRY(__kvm_flush_vm_context) bx lr ENDPROC(__kvm_flush_vm_context) +/** + * void __kvm_restore_host_vfp_state(struct vcpu *vcpu) - Executes a lazy + * fp/simd switch, saves the guest, restores host. + * + */ +ENTRY(__kvm_restore_host_vfp_state) + push {r3-r7} + + add r7, r0, #VCPU_VFP_GUEST + store_vfp_state r7 + + add r7, r0, #VCPU_VFP_HOST + ldr r7, [r7] + restore_vfp_state r7 + + pop {r3-r7} + bx lr +ENDPROC(__kvm_restore_host_vfp_state) /******************************************************************** * Hypervisor world-switch code @@ -131,7 +149,14 @@ ENTRY(__kvm_vcpu_run) @ Trap coprocessor CRx accesses set_hstr vmentry + + ldr r1, [vcpu, #VCPU_VFP_LAZY] + cmp r1, #1 + beq skip_guest_vfp_trap + set_hcptr vmentry, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11)) +skip_guest_vfp_trap: + set_hdcr vmentry @ Write configured ID register into MIDR alias @@ -170,22 +195,12 @@ __kvm_vcpu_return: @ Don't trap coprocessor accesses for host kernel set_hstr vmexit set_hdcr vmexit - set_hcptr vmexit, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11)), after_vfp_restore + set_hcptr vmexit, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11)) #ifdef CONFIG_VFPv3 - @ Switch VFP/NEON hardware state to the host's - add r7, vcpu, #VCPU_VFP_GUEST - store_vfp_state r7 - add r7, vcpu, #VCPU_VFP_HOST - ldr r7, [r7] - restore_vfp_state r7 - -after_vfp_restore: @ Restore FPEXC_EN which we clobbered on entry pop {r2} VFPFMXR FPEXC, r2 -#else -after_vfp_restore: #endif @ Reset Hyp-role @@ -485,6 +500,9 @@ switch_to_guest_vfp: @ NEON/VFP used. Turn on VFP access. set_hcptr vmtrap, (HCPTR_TCP(10) | HCPTR_TCP(11)) + mov r1, #1 + str r1, [vcpu, #VCPU_VFP_LAZY] + @ Switch VFP/NEON hardware state to the guest's add r7, r0, #VCPU_VFP_HOST ldr r7, [r7]