linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Zenghui Yu <yuzenghui@huawei.com>
Cc: <kvmarm@lists.cs.columbia.edu>, <kvm@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Alexandru Elisei	<alexandru.elisei@arm.com>,
	Quentin Perret <qperret@google.com>,
	Will Deacon	<will@kernel.org>, <broonie@kernel.org>,
	<kernel-team@android.com>
Subject: Re: [PATCH v2 2/5] KVM: arm64: Get rid of host SVE tracking/saving
Date: Mon, 22 Nov 2021 15:57:32 +0000	[thread overview]
Message-ID: <871r38dvyr.wl-maz@kernel.org> (raw)
In-Reply-To: <5ab3836f-2b39-2ff5-3286-8258addd01e4@huawei.com>

Hi Zenghui,

On Wed, 10 Nov 2021 13:19:23 +0000,
Zenghui Yu <yuzenghui@huawei.com> wrote:
> 
> Hi Marc,
> 
> On 2021/10/28 19:16, Marc Zyngier wrote:
> > The SVE host tracking in KVM is pretty involved. It relies on a
> > set of flags tracking the ownership of the SVE register, as well
> > as that of the EL0 access.
> > 
> > It is also pretty scary: __hyp_sve_save_host() computes
> > a thread_struct pointer and obtains a sve_state which gets directly
> > accessed without further ado, even on nVHE. How can this even work?
> > 
> > The answer to that is that it doesn't, and that this is mostly dead
> > code. Closer examination shows that on executing a syscall, userspace
> > loses its SVE state entirely. This is part of the ABI. Another
> > thing to notice is that although the kernel provides helpers such as
> > kernel_neon_begin()/end(), they only deal with the FP/NEON state,
> > and not SVE.
> > 
> > Given that you can only execute a guest as the result of a syscall,
> > and that the kernel cannot use SVE by itself, it becomes pretty
> > obvious that there is never any host SVE state to save, and that
> > this code is only there to increase confusion.
> > 
> > Get rid of the TIF_SVE tracking and host save infrastructure altogether.
> > 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
> > index 5621020b28de..38ca332c10fe 100644
> > --- a/arch/arm64/kvm/fpsimd.c
> > +++ b/arch/arm64/kvm/fpsimd.c
> > @@ -73,15 +73,11 @@ 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));
> >  -	vcpu->arch.flags &= ~(KVM_ARM64_FP_ENABLED |
> > -			      KVM_ARM64_HOST_SVE_IN_USE |
> > -			      KVM_ARM64_HOST_SVE_ENABLED);
> > +	vcpu->arch.flags &= ~KVM_ARM64_FP_ENABLED;
> >  	vcpu->arch.flags |= KVM_ARM64_FP_HOST;
> >  -	if (test_thread_flag(TIF_SVE))
> > -		vcpu->arch.flags |= KVM_ARM64_HOST_SVE_IN_USE;
> 
> The comment about TIF_SVE on top of kvm_arch_vcpu_load_fp() becomes
> obsolete now. Maybe worth removing it?
> 
> | *
> | * TIF_SVE is backed up here, since it may get clobbered with guest state.
> | * This flag is restored by kvm_arch_vcpu_put_fp(vcpu).

Indeed. Now gone.

> 
> > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
> > index a0e78a6027be..722dfde7f1aa 100644
> > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h
> > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
> > @@ -207,16 +207,6 @@ static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)
> >  	return __get_fault_info(esr, &vcpu->arch.fault);
> >  }
> >  -static inline void __hyp_sve_save_host(struct kvm_vcpu *vcpu)
> > -{
> > -	struct thread_struct *thread;
> > -
> > -	thread = container_of(vcpu->arch.host_fpsimd_state, struct thread_struct,
> > -			      uw.fpsimd_state);
> > -
> > -	__sve_save_state(sve_pffr(thread), &vcpu->arch.host_fpsimd_state->fpsr);
> > -}
> 
> Nit: This removes the only user of __sve_save_state() helper. Should we
> still keep it in fpsimd.S?

I was in two minds about that, as I'd like to eventually be able to
use SVE for protected guests, where the hypervisor itself has to be in
charge of the FP/SVE save-restore.

But that's probably several months away, and I can always revert a
deletion patch if I need to, so let's get rid of it now.

Thanks for the suggestions.

	M.

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-11-22 15:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 11:16 [PATCH v2 0/5] KVM: arm64: Rework FPSIMD/SVE tracking Marc Zyngier
2021-10-28 11:16 ` [PATCH v2 1/5] KVM: arm64: Reorder vcpu flag definitions Marc Zyngier
2021-10-28 11:16 ` [PATCH v2 2/5] KVM: arm64: Get rid of host SVE tracking/saving Marc Zyngier
2021-10-28 13:02   ` Mark Brown
2021-11-10 13:19   ` Zenghui Yu
2021-11-22 15:57     ` Marc Zyngier [this message]
2021-11-22 17:58       ` Mark Brown
2021-11-22 18:10         ` Marc Zyngier
2021-11-22 18:30           ` Mark Brown
2021-11-23 10:11             ` Marc Zyngier
2021-11-23 12:33               ` Mark Brown
2021-10-28 11:16 ` [PATCH v2 3/5] KVM: arm64: Introduce flag shadowing TIF_FOREIGN_FPSTATE Marc Zyngier
2021-10-28 11:16 ` [PATCH v2 4/5] KVM: arm64: Stop mapping current thread_info at EL2 Marc Zyngier
2021-10-28 11:16 ` [PATCH v2 5/5] arm64/fpsimd: Document the use of TIF_FOREIGN_FPSTATE by KVM Marc Zyngier
2021-10-28 13:14   ` 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=871r38dvyr.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=alexandru.elisei@arm.com \
    --cc=broonie@kernel.org \
    --cc=james.morse@arm.com \
    --cc=kernel-team@android.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=qperret@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --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).