From patchwork Thu Jun 25 03:30:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 6672011 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 CB893C05AC for ; Thu, 25 Jun 2015 03:34:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C550E205FA for ; Thu, 25 Jun 2015 03:34:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A70CC205DF for ; Thu, 25 Jun 2015 03:34:27 +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 1Z7xsi-0004pk-Bs; Thu, 25 Jun 2015 03:31:16 +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 1Z7xsW-0004km-HO for linux-arm-kernel@lists.infradead.org; Thu, 25 Jun 2015 03:31:05 +0000 Received: from uscpsbgex4.samsung.com (u125.gpu85.samsung.co.kr [203.254.195.125]) by usmailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NQH00HS8DRJXS40@usmailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 24 Jun 2015 23:30:55 -0400 (EDT) X-AuditID: cbfec37d-f79746d0000068cf-1e-558b75ef4fbd Received: from usmmp1.samsung.com ( [203.254.195.77]) by uscpsbgex4.samsung.com (USCPEXMTA) with SMTP id 16.42.26831.FE57B855; Wed, 24 Jun 2015 23:30:55 -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 <0NQH00JA7DRJ8DA0@usmmp1.samsung.com>; Wed, 24 Jun 2015 23:30:55 -0400 (EDT) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.160.11.3) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.3.224.2; Wed, 24 Jun 2015 20:30:54 -0700 From: Mario Smarduch To: kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, christoffer.dall@linaro.org Subject: [PATCH 2/3] arm: KVM: Implement lazy VFP switching outside of Hyp Mode Date: Wed, 24 Jun 2015 20:30:27 -0700 Message-id: <1435203028-23142-3-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1435203028-23142-1-git-send-email-m.smarduch@samsung.com> References: <1435203028-23142-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 X-Originating-IP: [105.160.11.3] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRmVeSWpSXmKPExsVy+t9hX933pd2hBgs/qFi8X9bDaPHi9T9G izlTCy0+njrObrHp8TVWi793/rFZ7N/2j9Xi5ccTLA4cHmvmrWH0uHNtD5vH+U1rmD02L6n3 eL/vKpvH501yAWxRXDYpqTmZZalF+nYJXBlvn89iKTggWXGqK7aBsVGki5GTQ0LAROLQqjWM ELaYxIV769m6GLk4hASWMUpsX/iTFcJpYpK4Ous3VOY8o0T3//1MIC1sAroS++9tZAexRQRC Ja7/bWQCKWIWWMsocWH7SWaQhLCAv8T+P/NYQWwWAVWJ5b//gMV5Bdwk7s2/CdTAAbRbQWLO JBuQMKeAu8SXzTvYQGwhoJIZP6ewQpQLSvyYfI8FpJxZQELi+WcliBJViW03n0N9oCDxc9V6 xgmMQrOQdMxC6FjAyLSKUay0OLmgOCk9tcJErzgxt7g0L10vOT93EyMkGmp3MN7/anOIUYCD UYmHt8K2O1SINbGsuDL3EKMEB7OSCG9jAFCINyWxsiq1KD++qDQntfgQozQHi5I4b4SkXKiQ QHpiSWp2ampBahFMlomDU6qBcVXUcUMmDbOyiQvW64R+izRdsfprcMP+pnzXjKSbrTN+medX s3RNlX2x5JHoloelxSuvreLKy1m3u6buwPI1OYn3c9yn+ufbSTROzU/xE5x1ZQt/bafznET7 KqaG8MDsu/++nJsaH9rm2BWy+1nbvm8MJy4G72L5lXryyWoPBdVXezutqye/V2Ipzkg01GIu Kk4EAMxcLkyCAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150624_203104_674317_FD6E76E0 X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: -8.3 (--------) Cc: kvm@vger.kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, pbonzini@redhat.com, linux-arm-kernel@lists.infradead.org, Mario Smarduch X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 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 implements the VFP context switch code called from vcpu_put in Host KVM. In addition it implements the logic to skip setting a VFP trap if one is not needed. Also resets the flag if Host KVM switched registers to trap new guest vfp accesses. Signed-off-by: Mario Smarduch --- arch/arm/kvm/interrupts.S | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S index 79caf79..0912edd 100644 --- a/arch/arm/kvm/interrupts.S +++ b/arch/arm/kvm/interrupts.S @@ -96,6 +96,21 @@ ENTRY(__kvm_flush_vm_context) bx lr ENDPROC(__kvm_flush_vm_context) +ENTRY(__kvm_restore_host_vfp_state) + push {r3-r7} + + mov r1, #0 + str r1, [r0, #VCPU_VFP_SAVED] + + 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 +146,13 @@ ENTRY(__kvm_vcpu_run) @ Trap coprocessor CRx accesses set_hstr vmentry + + ldr r1, [vcpu, #VCPU_VFP_SAVED] + 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 @@ -173,18 +194,6 @@ __kvm_vcpu_return: set_hcptr vmexit, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11)) #ifdef CONFIG_VFPv3 - @ Save floating point registers we if let guest use them. - tst r2, #(HCPTR_TCP(10) | HCPTR_TCP(11)) - bne after_vfp_restore - - @ 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 @@ -363,10 +372,6 @@ hyp_hvc: @ Check syndrome register mrc p15, 4, r1, c5, c2, 0 @ HSR lsr r0, r1, #HSR_EC_SHIFT -#ifdef CONFIG_VFPv3 - cmp r0, #HSR_EC_CP_0_13 - beq switch_to_guest_vfp -#endif cmp r0, #HSR_EC_HVC bne guest_trap @ Not HVC instr. @@ -380,7 +385,10 @@ hyp_hvc: cmp r2, #0 bne guest_trap @ Guest called HVC -host_switch_to_hyp: + /* + * Getting here means host called HVC, we shift parameters and branch + * to Hyp function. + */ pop {r0, r1, r2} /* Check for __hyp_get_vectors */ @@ -411,6 +419,10 @@ guest_trap: @ Check if we need the fault information lsr r1, r1, #HSR_EC_SHIFT +#ifdef CONFIG_VFPv3 + cmp r1, #HSR_EC_CP_0_13 + beq switch_to_guest_vfp +#endif cmp r1, #HSR_EC_IABT mrceq p15, 4, r2, c6, c0, 2 @ HIFAR beq 2f @@ -479,11 +491,12 @@ guest_trap: */ #ifdef CONFIG_VFPv3 switch_to_guest_vfp: - load_vcpu @ Load VCPU pointer to r0 push {r3-r7} @ NEON/VFP used. Turn on VFP access. set_hcptr vmexit, (HCPTR_TCP(10) | HCPTR_TCP(11)) + mov r1, #1 + str r1, [vcpu, #VCPU_VFP_SAVED] @ Switch VFP/NEON hardware state to the guest's add r7, r0, #VCPU_VFP_HOST