From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A417FC00140 for ; Mon, 15 Aug 2022 22:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Loy1V9FWtrxePHXmtS7dYduNzbhVQPvHl1skae09wrQ=; b=RBgjdhCVFNprKi a8ozw+ck6su4adbtW1O5Xxb5WrsvJyK9py0lGQ8bfXoeqjKTWoKkVPuUmX1rHaJZQyT1E7Z3g6Q4a jwX5GJui3mzPX1D6vvvfiKQP1EXZMbAmZ/OlDT/NMTDIBo0ALHN8vNf5Z74lB21uorgUEs6icP+NC 3brYOzcMogrEDCbDUCj/5mQ19xFlmbiEXtGHFL+6wLGX9Ab/dO8Txl6+xobafvUkadhIuvvW99GNF 1ggnY+1weYWYj3AeRoswo4YXn6wB5hlg+JlMWToe2vlk36o49dR939WkE2JL/2Ea4BMk9HusQuSUN wnoA9cKJgj+93ynl03HQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNj2U-0070nI-0G; Mon, 15 Aug 2022 22:58:30 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNj2A-0070Nd-32 for linux-arm-kernel@lists.infradead.org; Mon, 15 Aug 2022 22:58:12 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AE94C612C8; Mon, 15 Aug 2022 22:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEAEFC43142; Mon, 15 Aug 2022 22:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660604288; bh=823IuBZN/UQBWZKcE77mIapeCPQvkiuDby1PUeAxHQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PryybBb9ZIt6BB13lQMXZxhb+KSTjF3wEtABm8oJGzp2rEkQbGmxdrTrLRbJ1P06r UC6/Y8GxLldPMmGu6r22sPggOhwI/+1y1ahB/FVWrm0KQt03Y8wlbHwb2Sp6RPIRG6 KYRz/QySif+S9eN+o3dt3BaVGzUQ9oeJUjGy9vxcIyfA1C97EENS23xX0eEMDlEJoV iI01VnWc/E//UGIxmhroRmorQ2aaa5OjjbxgpHJBE6at3oJ7r4wrnmLFfBGQRnUb7q 67f54vrrIpL7ItSdaJYieF+/1HuwgtqmCqJ/N5qc0X+xuspstoWwYCkgYfgzaEaAFX VxCN0Ikelckvw== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: Marc Zyngier , Zhang Lei , James Morse , Alexandru Elisei , Andre Przywara , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v3 1/7] KVM: arm64: Discard any SVE state when entering KVM guests Date: Mon, 15 Aug 2022 23:55:23 +0100 Message-Id: <20220815225529.930315-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815225529.930315-1-broonie@kernel.org> References: <20220815225529.930315-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2925; i=broonie@kernel.org; h=from:subject; bh=823IuBZN/UQBWZKcE77mIapeCPQvkiuDby1PUeAxHQk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBi+s7amhSF70GLC1s3r6PC8tLEwnpZe6ROW9vphpBD 6SVOdPCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvrO2gAKCRAk1otyXVSH0A2tB/ 0RG1cYJZdBUPkZgtJwaeQIv0OMi1+b3wNUmlqzveht4ypsLJQKu4mAnrF0ugyPRoYobgEiGJxLRKmL +/WPuigBEgmXV1N4ITZY7l2dXfja0ODO91+MzB0RLncFgiaJpk4OITKFs1h+tHaE3Dz0SNyppmxZxa YlnqsfSVSPc1onzAZB8K+mHTs/JNJozM1zMcJ8W6+LTnBWR7d89MnPqA43Rwq4uG2ESq+HBWmNNeGC Kr38kgvmsftsxLvcchJqOur7oHNbByxm4REzf4MLDMtlPybmkYrZIkecxC4wmeQgx+g1JGiUVgSKde ZwRC6ef/ODe986bK8BqZwWN37PS4cV X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220815_155810_278419_A3258F5D X-CRM114-Status: GOOD ( 18.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since 8383741ab2e773a99 (KVM: arm64: Get rid of host SVE tracking/saving) KVM has not tracked the host SVE state, relying on the fact that we currently disable SVE whenever we perform a syscall. This may not be true in future since performance optimisation may result in us keeping SVE enabled in order to avoid needing to take access traps to reenable it. Handle this by clearing TIF_SVE and converting the stored task state to FPSIMD format when preparing to run the guest. This is done with a new call fpsimd_kvm_prepare() to keep the direct state manipulation functions internal to fpsimd.c. Signed-off-by: Mark Brown --- arch/arm64/include/asm/fpsimd.h | 1 + arch/arm64/kernel/fpsimd.c | 23 +++++++++++++++++++++++ arch/arm64/kvm/fpsimd.c | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 6f86b7ab6c28..c07e4abaca3d 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -56,6 +56,7 @@ extern void fpsimd_signal_preserve_current_state(void); extern void fpsimd_preserve_current_state(void); extern void fpsimd_restore_current_state(void); extern void fpsimd_update_current_state(struct user_fpsimd_state const *state); +extern void fpsimd_kvm_prepare(void); extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state, void *sve_state, unsigned int sve_vl, diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 23834d96d1e7..549e11645e0f 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1627,6 +1627,29 @@ void fpsimd_signal_preserve_current_state(void) sve_to_fpsimd(current); } +/* + * Called by KVM when entering the guest. + */ +void fpsimd_kvm_prepare(void) +{ + if (!system_supports_sve()) + return; + + /* + * KVM does not save host SVE state since we can only enter + * the guest from a syscall so the ABI means that only the + * non-saved SVE state needs to be saved. If we have left + * SVE enabled for performance reasons then update the task + * state to be FPSIMD only. + */ + get_cpu_fpsimd_context(); + + if (test_and_clear_thread_flag(TIF_SVE)) + sve_to_fpsimd(current); + + put_cpu_fpsimd_context(); +} + /* * Associate current's FPSIMD context with this cpu * The caller must have ownership of the cpu FPSIMD context before calling diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c index ec8e4494873d..1c1b309ef420 100644 --- a/arch/arm64/kvm/fpsimd.c +++ b/arch/arm64/kvm/fpsimd.c @@ -75,7 +75,8 @@ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu) void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu) { BUG_ON(!current->mm); - BUG_ON(test_thread_flag(TIF_SVE)); + + fpsimd_kvm_prepare(); if (!system_supports_fpsimd()) return; -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel