Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	oliver.upton@linux.dev, james.clark@linaro.org, will@kernel.org,
	joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
	catalin.marinas@arm.com, broonie@kernel.org, qperret@google.com,
	kristina.martsenko@arm.com
Subject: Re: [PATCH v3 14/15] KVM: arm64: Convert the SVE guest vcpu flag to a vm flag
Date: Mon, 02 Dec 2024 14:29:53 +0000	[thread overview]
Message-ID: <86v7w2taxq.wl-maz@kernel.org> (raw)
In-Reply-To: <CA+EHjTysFaaxGBo212e8kSHi_VkpXx6N6ddxwB0UGC6bSoK0gA@mail.gmail.com>

On Mon, 02 Dec 2024 12:57:44 +0000,
Fuad Tabba <tabba@google.com> wrote:
> 
> Hi Marc,
> 
> On Sun, 1 Dec 2024 at 16:01, Fuad Tabba <tabba@google.com> wrote:
> >
> > Hi Marc,
> >
> >
> > On Sun, 1 Dec 2024 at 12:58, Marc Zyngier <maz@kernel.org> wrote:
> > >
> > > On Thu, 28 Nov 2024 12:35:14 +0000,
> > > Fuad Tabba <tabba@google.com> wrote:
> > > >
> > > > The vcpu flag GUEST_HAS_SVE is per-vcpu, but it is based on what
> > > > is now a per-vm feature. Make the flag per-vm.
> > > >
> > > > Signed-off-by: Fuad Tabba <tabba@google.com>
> > > > ---
> > > >  arch/arm64/include/asm/kvm_emulate.h    |  6 +++---
> > > >  arch/arm64/include/asm/kvm_host.h       | 10 ++++++----
> > > >  arch/arm64/kvm/hyp/include/hyp/switch.h |  2 +-
> > > >  arch/arm64/kvm/hyp/nvhe/hyp-main.c      |  2 +-
> > > >  arch/arm64/kvm/hyp/nvhe/pkvm.c          | 11 +++++++----
> > > >  arch/arm64/kvm/hyp/nvhe/switch.c        |  8 ++++----
> > > >  arch/arm64/kvm/hyp/vhe/switch.c         |  2 +-
> > > >  arch/arm64/kvm/reset.c                  |  2 +-
> > > >  8 files changed, 24 insertions(+), 19 deletions(-)
> > > >
> > > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> > > > index 406e99a452bf..ae6d0dc0e4ff 100644
> > > > --- a/arch/arm64/include/asm/kvm_emulate.h
> > > > +++ b/arch/arm64/include/asm/kvm_emulate.h
> > > > @@ -620,7 +620,7 @@ static __always_inline void kvm_write_cptr_el2(u64 val)
> > > >  }
> > > >
> > > >  /* Resets the value of cptr_el2 when returning to the host. */
> > > > -static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu)
> > > > +static __always_inline void kvm_reset_cptr_el2(struct kvm *kvm)
> > >
> > > I'd rather you avoid the resulting churn:
> > >
> > > static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu)
> > > {
> > >         struct kvm *kvm = kern_hyp_va(vcpu->kvm);
> > >         [...]
> > >
> > > which does the trick at zero cost. It is also more logical to keep the
> > > vcpu as a parameter, as the per-VM-ness is only an implementation
> > > detail.
> >
> > The reason for the churn (here and below for vcpu_has_sve()), which in
> > hindsight I should have mentioned in the commit message or as a note,
> > is that this code is called by the host kernel (e.g., in reset.c), and
> > by the hypervisor). For nvhe, we need kern_hyp_va(), but not for the
> > host. Should I gate the va conversion with is_hyp_nvhe()?
> 
> I spoke too soon. Your suggestion results in less churn, and of
> course, solves the issue I had with kern_hyp_va.
> 
> I did have to convert kvm_reset_cptr_el2() into a macro, because it
> now needs kern_hyp_va(), defined in kvm_mmu.h, which in turn includes
> kvm_emulate.h. But since it's __always_inline, it shouldn't make any
> difference in practice.
> 
> If this conversion to a macro is alright by you, I'll respin this.

If you can convert it to something like:

static __always_inline void __kvm_reset_cptr_el2(struct kvm *kvm)
{
	[...]
}

#define kvm_reset_cptr_el2(v)	__kvm_reset_cptr_el2(kern_hyp_va((v)->kvm))

that'd be great, as it keeps the body of the function as C code, which
helps with debugging.

Thanks,

	M.

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

  reply	other threads:[~2024-12-02 14:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28 12:35 [PATCH v3 00/15] KVM: arm64: Rework guest VM fixed feature handling and trapping in pKVM Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 01/15] KVM: arm64: Consolidate allowed and restricted VM feature checks Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 02/15] KVM: arm64: Group setting traps for protected VMs by control register Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 03/15] KVM: arm64: Move checking protected vcpu features to a separate function Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 04/15] KVM: arm64: Use KVM extension checks for allowed protected VM capabilities Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 05/15] KVM: arm64: Initialize feature id registers for protected VMs Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 06/15] KVM: arm64: Set protected VM traps based on its view of feature registers Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 07/15] KVM: arm64: Rework specifying restricted features for protected VMs Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 08/15] KVM: arm64: Remove fixed_config.h header Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 09/15] KVM: arm64: Remove redundant setting of HCR_EL2 trap bit Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 10/15] KVM: arm64: Calculate cptr_el2 traps on activating traps Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 11/15] KVM: arm64: Refactor kvm_reset_cptr_el2() Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 12/15] KVM: arm64: Fix the value of the CPTR_EL2 RES1 bitmask for nVHE Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 13/15] KVM: arm64: Remove PtrAuth guest vcpu flag Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 14/15] KVM: arm64: Convert the SVE guest vcpu flag to a vm flag Fuad Tabba
2024-12-01 12:58   ` Marc Zyngier
2024-12-01 16:01     ` Fuad Tabba
2024-12-02 12:57       ` Fuad Tabba
2024-12-02 14:29         ` Marc Zyngier [this message]
2024-12-02 14:47           ` Fuad Tabba
2024-11-28 12:35 ` [PATCH v3 15/15] KVM: arm64: Renumber remaining vcpu guest configuration flags Fuad Tabba
2024-12-01 12:59   ` Marc Zyngier
2024-12-02  9:16     ` Fuad Tabba
2024-11-28 16:31 ` [PATCH v3 00/15] KVM: arm64: Rework guest VM fixed feature handling and trapping in pKVM James Clark
2024-11-28 17:35 ` 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=86v7w2taxq.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.clark@linaro.org \
    --cc=joey.gouly@arm.com \
    --cc=kristina.martsenko@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.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