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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 595FBC54EE9 for ; Tue, 20 Sep 2022 16:44:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E959B4B640; Tue, 20 Sep 2022 12:44:08 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IlBh4yNf4gIQ; Tue, 20 Sep 2022 12:44:07 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C83094B62E; Tue, 20 Sep 2022 12:44:07 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 6B7B44B621 for ; Tue, 20 Sep 2022 12:44:06 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZdUahpzP3HwS for ; Tue, 20 Sep 2022 12:44:05 -0400 (EDT) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 39FC341016 for ; Tue, 20 Sep 2022 12:44:05 -0400 (EDT) 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 751F7624D3; Tue, 20 Sep 2022 16:44:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9671C433D6; Tue, 20 Sep 2022 16:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663692243; bh=+u9+5k11L8vx9DIAUug8D6CJGRhNjlmpf+3ZODQKs7M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Jtm4Li72inh2MJf+izhaviRFvbPxTAhKABWY0r07dfaT4iTowGqVT1SMGUcIU4fcK 3K6xEDl4wVBQjb5yxKc4BqJakaIQTmkNN4zrTASFkI7N+VvMG2BEFa6mhSED7leIN5 BZOwQQsGlHsqH+RzT92sJG6YSnb6RlqRMlgp/KzLpoIZDk24Tnnjzxofix7jTEHOkX fXj32Cx45xmsiAvkDczcYQNeQvDyYoGbJE4ROffSRBiNt8+aelqEYTlh2QiygwoMGM xaakWXLF8r1DuHnXd5xHqx2qC0AHavNXYMjEdNbi8ivN/WAFawoWjSwlvsLjcXrckr QoUE92Vclg66A== Received: from 185-176-101-241.host.sccbroadband.ie ([185.176.101.241] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oagLp-00BSBE-Q4; Tue, 20 Sep 2022 17:44:01 +0100 Date: Tue, 20 Sep 2022 17:44:01 +0100 Message-ID: <87zgeuj8ry.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Subject: Re: [PATCH v3 1/7] KVM: arm64: Discard any SVE state when entering KVM guests In-Reply-To: <20220815225529.930315-2-broonie@kernel.org> References: <20220815225529.930315-1-broonie@kernel.org> <20220815225529.930315-2-broonie@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.176.101.241 X-SA-Exim-Rcpt-To: broonie@kernel.org, catalin.marinas@arm.com, will@kernel.org, zhang.lei@jp.fujitsu.com, james.morse@arm.com, alexandru.elisei@arm.com, andre.przywara@arm.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: Catalin Marinas , Zhang Lei , Andre Przywara , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Mon, 15 Aug 2022 23:55:23 +0100, Mark Brown wrote: > > 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(); Why is this *before* the check against system_supports_fpsimd()? I don't think the architecture allows SVE without FP, for obvious reasons... > > if (!system_supports_fpsimd()) > return; Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm