linux-arm-kernel.lists.infradead.org archive mirror
 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 v2 4/8] KVM: arm64: Add save/restore support for FPMR
Date: Thu, 01 Aug 2024 21:09:40 +0100	[thread overview]
Message-ID: <87ttg43szf.wl-maz@kernel.org> (raw)
In-Reply-To: <1a00165f-7ae5-4c58-9283-836716205db7@sirena.org.uk>

On Thu, 01 Aug 2024 20:07:16 +0100,
Mark Brown <broonie@kernel.org> wrote:
> 
> [1  <text/plain; us-ascii (7bit)>]
> On Thu, Aug 01, 2024 at 10:19:51AM +0100, Marc Zyngier wrote:
> 
> > index 6af179c6356d..2466dd231362 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> > @@ -198,6 +198,15 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu)
> >  	} else {
> >  		__fpsimd_save_state(*host_data_ptr(fpsimd_state));
> >  	}
> > +
> > +	if (kvm_has_fpmr(vcpu->kvm)) {
> 
> nVHE is faulting for me, apparently on the kvm_has_fpmr() check though I
> ran out of time to actually figure out where exactly it is going wrong.
> I'll have a further poke tomorrow.  Backtrace below.

Well, that's actually pretty obvious when you see the crash
(FAR:ffffff880115cd1c spills the beans).

>
> > +		u64 fpmr = read_sysreg_s(SYS_FPMR);
> > +
> > +		if (unlikely(is_protected_kvm_enabled()))
> > +			*host_data_ptr(fpmr) = fpmr;
> 
> That looks wrong until you remember what host_data_ptr() does but but
> it's actually fine.  host_data_ptr() is looking inside the struct
> kvm_host_data for the CPU rather than referencing the locally defined
> variable fpmr here.  I do think it's worth avoiding the name collision
> though, perhaps just avoid the temporary variable?

I'll rename the variable if that avoids people getting their brains in
a twist. Full potential fix below.

Thanks,

	M.

diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 2466dd231362..c0832ca0285b 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -199,13 +199,13 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu)
 		__fpsimd_save_state(*host_data_ptr(fpsimd_state));
 	}
 
-	if (kvm_has_fpmr(vcpu->kvm)) {
-		u64 fpmr = read_sysreg_s(SYS_FPMR);
+	if (kvm_has_fpmr(kern_hyp_va(vcpu->kvm))) {
+		u64 val = read_sysreg_s(SYS_FPMR);
 
 		if (unlikely(is_protected_kvm_enabled()))
-			*host_data_ptr(fpmr) = fpmr;
+			*host_data_ptr(fpmr) = val;
 		else
-			**host_data_ptr(fpmr_ptr) = fpmr;
+			**host_data_ptr(fpmr_ptr) = val;
 	}
 }
 

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


  reply	other threads:[~2024-08-01 20:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-01  9:19 [PATCH v2 0/8] KVM: arm64: Add support for FP8 Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 1/8] KVM: arm64: Move SVCR into the sysreg array Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 2/8] KVM: arm64: Add predicate for FPMR support in a VM Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 3/8] KVM: arm64: Move FPMR into the sysreg array Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 4/8] KVM: arm64: Add save/restore support for FPMR Marc Zyngier
2024-08-01 19:07   ` Mark Brown
2024-08-01 20:09     ` Marc Zyngier [this message]
2024-08-02 13:03       ` Mark Brown
2024-08-01  9:19 ` [PATCH v2 5/8] KVM: arm64: Honor trap routing " Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 6/8] KVM: arm64: Expose ID_AA64FPFR0_EL1 as a writable ID reg Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 7/8] KVM: arm64: Enable FP8 support when available and configured Marc Zyngier
2024-08-01  9:19 ` [PATCH v2 8/8] KVM: arm64: Expose ID_AA64PFR2_EL1 to userspace and guests Marc Zyngier

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=87ttg43szf.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).