All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	kvm@vger.kernel.org, James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	Zenghui Yu <yuzenghui@huawei.com>, Fuad Tabba <tabba@google.com>,
	Joey Gouly <joey.gouly@arm.com>
Subject: Re: [PATCH 3/7] KVM: arm64: Add save/restore support for FPMR
Date: Mon, 08 Jul 2024 18:47:45 +0100	[thread overview]
Message-ID: <864j8z4vy6.wl-maz@kernel.org> (raw)
In-Reply-To: <b44b29f0-b4c5-43a2-a5f6-b4fd84f77192@sirena.org.uk>

On Mon, 08 Jul 2024 18:34:36 +0100,
Mark Brown <broonie@kernel.org> wrote:
> 
> [1  <text/plain; us-ascii (7bit)>]
> 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 <maz@kernel.org>
> > ---
> >  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.

Ah, I forgot to cherry-pick the fixes. Fsck knows what else I forgot.
Thanks for reminding me.

	M.

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);

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2024-07-08 17:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-08 15:44 [PATCH 0/7] KVM: arm64: Add support for FP8 Marc Zyngier
2024-07-08 15:44 ` [PATCH 1/7] KVM: arm64: Move SVCR into the sysreg array Marc Zyngier
2024-07-08 15:53   ` Mark Brown
2024-07-08 15:44 ` [PATCH 2/7] KVM: arm64: Move FPMR " Marc Zyngier
2024-07-08 15:44 ` [PATCH 3/7] KVM: arm64: Add save/restore support for FPMR Marc Zyngier
2024-07-08 17:34   ` Mark Brown
2024-07-08 17:47     ` Marc Zyngier [this message]
2024-07-08 17:53       ` Marc Zyngier
2024-07-09  9:06         ` Marc Zyngier
2024-07-09 15:43           ` Mark Brown
2024-07-12 15:28           ` Mark Brown
2024-07-08 15:44 ` [PATCH 4/7] KVM: arm64: Honor trap routing " Marc Zyngier
2024-07-08 15:44 ` [PATCH 5/7] KVM: arm64: Expose ID_AA64FPFR0_EL1 as a writable ID reg Marc Zyngier
2024-07-08 15:44 ` [PATCH 6/7] KVM: arm64: Enable FP8 support when available and configured Marc Zyngier
2024-07-08 15:44 ` [PATCH 7/7] KVM: arm64: Expose ID_AA64PFR2_EL1 to userspace and guests Marc Zyngier
2024-07-08 17:53 ` [PATCH 0/7] KVM: arm64: Add support for FP8 Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=864j8z4vy6.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=broonie@kernel.org \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.