From patchwork Sat Jul 11 01:19:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 6769631 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 3AD8B9F380 for ; Sat, 11 Jul 2015 01:22:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3DDDA207F2 for ; Sat, 11 Jul 2015 01:22:18 +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 26C97207F5 for ; Sat, 11 Jul 2015 01:22:16 +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 1ZDjSG-0000UI-C7; Sat, 11 Jul 2015 01:19:48 +0000 Received: from mailout3.w2.samsung.com ([211.189.100.13] helo=usmailout3.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZDjSD-0000QR-Mz for linux-arm-kernel@lists.infradead.org; Sat, 11 Jul 2015 01:19:46 +0000 Received: from uscpsbgex1.samsung.com (u122.gpu85.samsung.co.kr [203.254.195.122]) by usmailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NRA002V7UCCV830@usmailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 10 Jul 2015 21:19:24 -0400 (EDT) X-AuditID: cbfec37a-f79c96d000005f02-26-55a06f1b0a9e Received: from usmmp1.samsung.com ( [203.254.195.77]) by uscpsbgex1.samsung.com (USCPEXMTA) with SMTP id 15.79.24322.B1F60A55; Fri, 10 Jul 2015 21:19:23 -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 <0NRA00LALUCBDRF0@usmmp1.samsung.com>; Fri, 10 Jul 2015 21:19:23 -0400 (EDT) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.145.24.65) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.3.224.2; Fri, 10 Jul 2015 18:19:23 -0700 From: Mario Smarduch To: kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, christoffer.dall@linaro.org Subject: [PATCH v4 1/2] arm64: KVM: Optimize arm64 non-VHE fpsimd skip 30-50% save/restore on exits Date: Fri, 10 Jul 2015 18:19:06 -0700 Message-id: <1436577547-5646-2-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1436577547-5646-1-git-send-email-m.smarduch@samsung.com> References: <1436577547-5646-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 X-Originating-IP: [105.145.24.65] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJLMWRmVeSWpSXmKPExsVy+t9hX13p/AWhBg1LbSxevP7HaDFnaqHF x1PH2S02Pb7GavH3zj82B1aPNfPWMHrcubaHzeP8pjXMHpuX1Ht83iQXwBrFZZOSmpNZllqk b5fAlfHy7gXmgiOqFecX32VvYLwt08XIySEhYCLxccVHNghbTOLCvfVANheHkMAyRok5M5uZ IZwmJol9f94yQTgXGCVetnxlBGlhE9CV2H9vIzuILSIQKnH9byMTiM0skCEx++k/oDgHh7BA qsT3OywgYRYBVYkTE76BlfMKuEr8+zKTBaREQkBBYs4kG5Awp4CbxMGHi1lBbCGgkocfjzBC lAtK/Jh8D6ycWUBC4vlnJYgSVYltN58zQkxRlJj3gWkCo9AsJA2zEBoWMDKtYhQrLU4uKE5K T60w1CtOzC0uzUvXS87P3cQICfCqHYx3vtocYhTgYFTi4Q1gmx8qxJpYVlyZe4hRgoNZSYR3 jvyCUCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8CyTkQoUE0hNLUrNTUwtSi2CyTBycUg2MxZOq PEQrVmqJHGiZcSJLv//vtrt3/z0qi+5duviW/So77jn63i3N25suf9fSmuv37NqFnfuO6t7V XPfjf/21S3OmrzxhFuZh9F64eM/GJbvvbm+Z8ah+/fGwMpmzt/2C5rx/6bDiw+wPMassPtlc SfndKmdyfnqC/Z/lluvXhR29dFqxwf7CXEYlluKMREMt5qLiRACSwrl8bAIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150710_181945_832182_012D9F68 X-CRM114-Status: GOOD ( 12.59 ) X-Spam-Score: -7.5 (-------) 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.8 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 only saves and restores FP/SIMD registers on Guest access. To do this cptr_el2 FP/SIMD trap is set on Guest entry and later checked on exit. The non-VHE path has been tested, future work would add VHE support. Signed-off-by: Mario Smarduch --- arch/arm64/include/asm/kvm_arm.h | 5 +++- arch/arm64/kvm/hyp.S | 58 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index c8998c0..0a1d152 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -172,10 +172,13 @@ #define HSTR_EL2_TTEE (1 << 16) #define HSTR_EL2_T(x) (1 << x) +/* Hyp Coproccessor Trap Register Shifts */ +#define CPTR_EL2_TFP_SHIFT 10 + /* Hyp Coprocessor Trap Register */ #define CPTR_EL2_TCPAC (1 << 31) #define CPTR_EL2_TTA (1 << 20) -#define CPTR_EL2_TFP (1 << 10) +#define CPTR_EL2_TFP (1 << CPTR_EL2_TFP_SHIFT) /* Hyp Debug Configuration Register bits */ #define MDCR_EL2_TDRA (1 << 11) diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index 64a5280..9d154ed 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -731,6 +731,15 @@ ifnvhe "mrs \tmp, hcr_el2", _S_(ldr \tmp, [x0, #VCPU_HCR_EL2]) tbz \tmp, #KVM_ARM64_DEBUG_DIRTY_SHIFT, \target .endm +/* + * For non-VHE - branch to target if CPTR_EL2.TFP bit is set (VFP/SIMD trapping + * enabled). For VHE do nothing. + */ +.macro skip_fpsimd_state tmp, target +ifnvhe "mrs \tmp, cptr_el2", nop +ifnvhe _S_(tbnz \tmp, #CPTR_EL2_TFP_SHIFT, \target), nop +.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. @@ -823,7 +832,7 @@ ifnvhe "mrs \tmp, hcr_el2", _S_(ldr \tmp, [x0, #VCPU_HCR_EL2]) adr x3, __kvm_hyp_vector ifnvhe nop, "msr vbar_el1, x3" ifnvhe nop, "mrs x2, cpacr_el1" -ifnvhe _S_(ldr x2, =(CPTR_EL2_TTA)), "orr x2, x2, #(1 << 28)" +ifnvhe _S_(ldr x2, =(CPTR_EL2_TTA|CPTR_EL2_TFP)), "orr x2, x2, #(1 << 28)" ifnvhe "msr cptr_el2, x2", "msr cpacr_el1, x2" mov x2, #(1 << 15) // Trap CP15 Cr=15 @@ -851,7 +860,7 @@ ifnvhe nop, _S_(orr x2, x2, #HCR_E2H) ifnvhe nop, "mrs x2, cpacr_el1" ifnvhe nop, "movn x3, #(1 << 12), lsl #16" ifnvhe nop, "and x2, x2, x3" -ifnvhe "msr cptr_el2, xzr", "msr cpacr_el1, x2" +ifnvhe nop, "msr cpacr_el1, x2" msr hstr_el2, xzr mrs x2, mdcr_el2 @@ -988,6 +997,33 @@ __restore_fpsimd: ret /* + * For non-VHE - on first FP/SIMD access, restore guest, save host registers + * and disable future trapping. For VHE this should never get called. + */ +switch_to_guest_fpsimd: + push x4, lr + + mrs x2, cptr_el2 + bic x2, x2, #CPTR_EL2_TFP + msr cptr_el2, x2 + + mrs x0, tpidr_el2 + + ldr x2, [x0, #VCPU_HOST_CONTEXT] + kern_hyp_va x2 + bl __save_fpsimd + + add x2, x0, #VCPU_CONTEXT + bl __restore_fpsimd + + pop x4, lr + pop x2, x3 + pop x0, x1 + + eret + + +/* * u64 __kvm_vcpu_run(struct kvm_vcpu *vcpu); * * This is the world switch. The first half of the function @@ -1007,7 +1043,7 @@ ENTRY(__kvm_vcpu_run) kern_hyp_va x2 save_host_regs - bl __save_fpsimd +ifnvhe nop, "bl __save_fpsimd" ifnvhe "bl __save_sysregs", "nop" bl __save_shared_sysregs @@ -1025,7 +1061,7 @@ ifnvhe "bl __save_sysregs", "nop" bl __restore_sysregs bl __restore_shared_sysregs - bl __restore_fpsimd +ifnvhe "nop", "bl __restore_fpsimd" skip_debug_state x3, 1f bl __restore_debug @@ -1044,7 +1080,9 @@ __kvm_vcpu_return: add x2, x0, #VCPU_CONTEXT save_guest_regs + skip_fpsimd_state x3, 1f bl __save_fpsimd +1: bl __save_sysregs bl __save_shared_sysregs @@ -1072,7 +1110,11 @@ __kvm_vcpu_return_irq: ifnvhe "bl __restore_sysregs", "nop" bl __restore_shared_sysregs + skip_fpsimd_state x3, 1f bl __restore_fpsimd +1: + /* For non-VHE - Clear FPSIMD and Trace trapping, do nothig for VHE */ +ifnvhe "msr cptr_el2, xzr", "nop" skip_debug_state x3, 1f // Clear the dirty flag for the next run, as all the state has @@ -1298,6 +1340,14 @@ el1_trap: * x1: ESR * x2: ESR_EC */ + + /* + * For non-VHE Guest accessed FP/SIMD registers, save host, restore + * guest. For VHE condition should never be true. + */ + cmp x2, #ESR_ELx_EC_FP_ASIMD + b.eq switch_to_guest_fpsimd + cmp x2, #ESR_ELx_EC_DABT_LOW mov x0, #ESR_ELx_EC_IABT_LOW ccmp x2, x0, #4, ne