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 5EDABC2BD09 for ; Tue, 9 Jul 2024 09:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/OLxk6j1xiwAfh7oXZ9/+OPwHvJeIuMpJ148tbwfLKk=; b=n7FdcwJGvEYvsZj2rU/crWbr7P Sus0ljRthnmfqJMzSxTiBuHNv9DbUexCT9SjTays8SyKCFBrK02vXv0stJCZixZ2dXu2OBsNzhk5z wnGspA8uK0Z4RZ+3BcGtpiXet7rX8RoNvxrdG6A4c32jnFxb60saVgf6gPv22K4kE7ORuyaY3s8pN gg1ZWCCfQOOLpEMxXAuCqNj5KFldbWW28lvh2lbz/XkdoaWS9xfZc+QbtebgqJjxeuPuLP2aqq0dF aMYhP8pBQ5+ZFrLMrwHzGs6YBQveF4EzA7MPiZSE8lMVqy0bqTqdbiZlzE4ETGaDFRvyV9mHsfNOL ikdscAAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sR6nr-00000006XKz-3Whg; Tue, 09 Jul 2024 09:06:27 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sR6nc-00000006XFo-0fO1 for linux-arm-kernel@lists.infradead.org; Tue, 09 Jul 2024 09:06:13 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 757A1CE0AF0; Tue, 9 Jul 2024 09:06:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98C62C3277B; Tue, 9 Jul 2024 09:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720515969; bh=fP0OEw/ZFO/81qUtm8MyMZigpasdzFqbY3cL/G2T5zQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hcXi39/9tMDMiA1U1AT1FSO3EwOqRCDWNMOdl48N+6EIgCNfRmctdfaH0tKprLtW/ OKNKEhgMFJyOYDVTv+FUzCLw5TA4gjyMLqDWo9QIvF0ZL7P2XASyrUBSuYHMGakgfn Qz0nCffNe/qX1qcWS0VMLPhxdBtUWzgWIRS8u0JRWLeXO5cQ+v1RZflY/9PFPx08kE xkaASi1H0dzPpcLxw5YfxBRqfmcqRJl15nYBVKn0b3+bNlnyr8kjVDgp5V2N/BbYZJ zjc3wpeoyzIJYx2juhtLv3D1glzxCk3N08uEt0ZR9MhB8lPZ9q5e9aY4fd1vn0ZJA0 oFXD6mbJTkUxw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.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 1sR6nX-00AqR3-9m; Tue, 09 Jul 2024 10:06:07 +0100 Date: Tue, 09 Jul 2024 10:06:06 +0100 Message-ID: <861q433pfl.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Fuad Tabba , Joey Gouly Subject: Re: [PATCH 3/7] KVM: arm64: Add save/restore support for FPMR In-Reply-To: <8634oj4voc.wl-maz@kernel.org> References: <20240708154438.1218186-1-maz@kernel.org> <20240708154438.1218186-4-maz@kernel.org> <864j8z4vy6.wl-maz@kernel.org> <8634oj4voc.wl-maz@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/29.3 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: broonie@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, tabba@google.com, joey.gouly@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240709_020612_588287_24348612 X-CRM114-Status: GOOD ( 33.22 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 08 Jul 2024 18:53:39 +0100, Marc Zyngier wrote: > > On Mon, 08 Jul 2024 18:47:45 +0100, > Marc Zyngier wrote: > > > > On Mon, 08 Jul 2024 18:34:36 +0100, > > Mark Brown wrote: > > > > > > [1 ] > > > On Mon, Jul 08, 2024 at 04:44:34PM +0100, Marc Zyngier wrote: > > > > Just like the rest of the FP/SIMD state, FPMR needs to be context > > > > switched. > > > > > > > The only interesting thing here is that we need to treat the pKVM > > > > part a bit differently, as the host FP state is never written back > > > > to the vcpu thread, but instead stored locally and eagerly restored. > > > > > > > Signed-off-by: Marc Zyngier > > > > --- > > > > arch/arm64/include/asm/kvm_host.h | 10 ++++++++++ > > > > arch/arm64/kvm/fpsimd.c | 1 + > > > > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++++ > > > > arch/arm64/kvm/hyp/nvhe/switch.c | 10 ++++++++++ > > > > arch/arm64/kvm/hyp/vhe/switch.c | 4 ++++ > > > > 5 files changed, 29 insertions(+) > > > > > > I'm possibly missing something here but I'm not seeing where we load the > > > state for the guest, especially in the VHE case. I would expect to see > > > a change in kvm_hyp_handle_fpsimd() to load FPMR for guests with the > > > feature (it needs to be in there to keep in sync with the ownership > > > tracking for the rest of the FP state, and to avoid loading needlessly > > > in cases where the guest never touches FP). > > > > > > Saving for the guest was handled in the previous patch. > > > > > > > diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c > > > > index 77010b76c150f..a307c1d5ac874 100644 > > > > --- a/arch/arm64/kvm/hyp/vhe/switch.c > > > > +++ b/arch/arm64/kvm/hyp/vhe/switch.c > > > > @@ -312,6 +312,10 @@ static bool kvm_hyp_handle_eret(struct kvm_vcpu *vcpu, u64 *exit_code) > > > > static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu) > > > > { > > > > __fpsimd_save_state(*host_data_ptr(fpsimd_state)); > > > > + > > > > + if (system_supports_fpmr() && > > > > + kvm_has_feat(vcpu->kvm, ID_AA64PFR2_EL1, FPMR, IMP)) > > > > + **host_data_ptr(fpmr_ptr) = read_sysreg_s(SYS_FPMR); > > > > } > > > > > > That's only saving the host state, it doesn't load the guest > > > state. So after cherry-picking my own fixes and realising that I had left pKVM in the lurch, this is what I have added to this patch, which hopefully does the right thing. diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h index f59ccfe11ab9a..52c7dc8446f16 100644 --- a/arch/arm64/kvm/hyp/include/hyp/switch.h +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h @@ -404,6 +404,10 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code) else __fpsimd_restore_state(&vcpu->arch.ctxt.fp_regs); + if (system_supports_fpmr() && + kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64PFR2_EL1, FPMR, IMP)) + write_sysreg_s(__vcpu_sys_reg(vcpu, FPMR), SYS_FPMR); + /* Skip restoring fpexc32 for AArch64 guests */ if (!(read_sysreg(hcr_el2) & HCR_RW)) write_sysreg(__vcpu_sys_reg(vcpu, FPEXC32_EL2), fpexc32_el2); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 6b14a2c13e287..97fc6ae123a03 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -62,6 +62,8 @@ static void fpsimd_sve_flush(void) static void fpsimd_sve_sync(struct kvm_vcpu *vcpu) { + bool has_fpmr; + if (!guest_owns_fp_regs()) return; @@ -73,13 +75,17 @@ static void fpsimd_sve_sync(struct kvm_vcpu *vcpu) else __fpsimd_save_state(&vcpu->arch.ctxt.fp_regs); + has_fpmr = (system_supports_fpmr() && + kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64PFR2_EL1, FPMR, IMP)); + if (has_fpmr) + __vcpu_sys_reg(vcpu, FPMR) = read_sysreg_s(SYS_FPMR); + if (system_supports_sve()) __hyp_sve_restore_host(); else __fpsimd_restore_state(*host_data_ptr(fpsimd_state)); - if (system_supports_fpmr() && - kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64PFR2_EL1, FPMR, IMP)) + if (has_fpmr) write_sysreg_s(*host_data_ptr(fpmr), SYS_FPMR); *host_data_ptr(fp_owner) = FP_STATE_HOST_OWNED; I'll repost the series after -rc1. M. -- Without deviation from the norm, progress is not possible.