From: Sascha Bischoff <Sascha.Bischoff@arm.com>
To: "oliver.upton@linux.dev" <oliver.upton@linux.dev>
Cc: "yuzenghui@huawei.com" <yuzenghui@huawei.com>,
Timothy Hayes <Timothy.Hayes@arm.com>,
Suzuki Poulose <Suzuki.Poulose@arm.com>, nd <nd@arm.com>,
"lpieralisi@kernel.org" <lpieralisi@kernel.org>,
"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Joey Gouly <Joey.Gouly@arm.com>,
"maz@kernel.org" <maz@kernel.org>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"will@kernel.org" <will@kernel.org>
Subject: Re: [PATCH 4/5] KVM: arm64: gic-v5: Support GICv3 compat
Date: Mon, 23 Jun 2025 13:11:48 +0000 [thread overview]
Message-ID: <e34738676fef5ec6f06564ecf22a4de1705df66f.camel@arm.com> (raw)
In-Reply-To: <aFXomXKBk1V9iYSa@linux.dev>
On Fri, 2025-06-20 at 16:02 -0700, Oliver Upton wrote:
> On Fri, Jun 20, 2025 at 01:20:36PM -0700, Oliver Upton wrote:
> > > +void __vgic_v3_compat_mode_enable(void)
> > > +{
> > > + sysreg_clear_set_s(SYS_ICH_VCTLR_EL2, 0,
> > > ICH_VCTLR_EL2_V3);
> > > + isb();
> > > +}
> > > +
> > > +void __vgic_v3_compat_mode_disable(void)
> > > +{
> > > + sysreg_clear_set_s(SYS_ICH_VCTLR_EL2, ICH_VCTLR_EL2_V3,
> > > 0);
> > > + isb();
> > > +}
> > > +
> >
> > It isn't clear to me what these ISBs are synchonizing against.
> > AFAICT,
> > the whole compat thing is always visible and we can restore the
> > rest of
> > the VGICv3 context before guaranteeing the enable bit has been
> > observed.
> >
> > Can we consolidate this into a single hyp call along with
> > __vgic_v3_*_vmcr_aprs()?
> >
> > Last bit as an FYI, kvm_call_hyp() has an implied context
> > synchronization upon
> > return, either because of ERET in nVHE or an explicit ISB on VHE.
>
> Ah, reading the spec was a useful exercise. ICH_VMCR_EL2 is a modal
> register... I hear implementation folks *love* those :)
>
> Please do the aforementioned consolidation, at which point the
> purpose
> of the ISB should be apparent.
If we are happy to move to only touching the ICH_VCTLR_EL2.V3 compat
mode control in the v3/v5 load path, I think this change can happen
now. However, we otherwise need to clean up the WFI load/put path first
to avoid the double calls.
> > > + if
> > > (!static_branch_unlikely(&kvm_vgic_global_state.gicv5_cpuif)) {
> >
> > Can we use the GCIE cpucap instead, possibly via a shared helper
> > with
> > the driver?
I'll look into it.
> > > - if (kvm_vgic_global_state.type == VGIC_V3) {
> > > + if (kvm_vgic_global_state.type == VGIC_V3 ||
> > > kvm_vgic_in_v3_compat_mode()) {
> >
> > Can we do a helper for this too?
Will do.
> >
> > > val &= ~ID_AA64PFR0_EL1_GIC_MASK;
> > > val |= SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, GIC,
> > > IMP);
> > > }
> > >
> > > + if
> > > (static_branch_unlikely(&kvm_vgic_global_state.gicv5_cpuif))
> > > + kvm_call_hyp(__vgic_v3_compat_mode_disable);
>
> Do we need to eagerly disable compat mode or can we just configure
> the
> VGIC correctly for the intended vCPU at load()?
I've responded to this in the other thread (I think we could do it
purely on load, and drop eager disable).
>
> > > }
> > > diff --git a/arch/arm64/kvm/vgic/vgic-v5.c
> > > b/arch/arm64/kvm/vgic/vgic-v5.c
> > > new file mode 100644
> > > index 000000000000..57199449ca0f
> > > --- /dev/null
> > > +++ b/arch/arm64/kvm/vgic/vgic-v5.c
> > > @@ -0,0 +1,14 @@
> > > +// SPDX-License-Identifier: GPL-2.0-only
> > > +
> > > +#include <kvm/arm_vgic.h>
> > > +
> > > +#include "vgic.h"
> > > +
> > > +inline bool kvm_vgic_in_v3_compat_mode(void)a
> >
> > nit: we're generally trusting of the compiler to 'do the right
> > thing'
> > and avoid explicit inline specifiers unless necessary.
Dropped the explicit inline.
> >
> > > +{
> > > + if
> > > (static_branch_unlikely(&kvm_vgic_global_state.gicv5_cpuif) &&
> > > + kvm_vgic_global_state.has_gcie_v3_compat)
> > > + return true;
> > > +
> > > + return false;
> > > +}
> >
> > This should be a per-VM thing once KVM support for GICv5 lands. Can
> > you
> > get ahead of that and take a KVM pointer that goes unused. Maybe
> > rename
> > it:
> >
> > bool vgic_is_v3_compat(struct kvm *kvm)
> >
> > Or something similar.
OK, will do. There's one case were we use this without access to a
struct kvm* in kvm_vgic_init_cpu_hardware, so that will need to be done
without this helper, but we could fall back to using cpucaps directly
there.
Thanks,
Sascha
>
next prev parent reply other threads:[~2025-06-23 13:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 16:07 [PATCH 0/5] KVM: arm64: Enable GICv3 guests on GICv5 hosts using FEAT_GCIE_LEGACY Sascha Bischoff
2025-06-20 16:07 ` [PATCH 1/5] irqchip/gic-v5: Skip deactivate for forwarded PPI interrupts Sascha Bischoff
2025-06-23 15:21 ` Lorenzo Pieralisi
2025-06-27 9:49 ` Sascha Bischoff
2025-06-20 16:07 ` [PATCH 3/5] arm64/sysreg: Add ICH_VCTLR_EL2 Sascha Bischoff
2025-06-20 16:07 ` [PATCH 4/5] KVM: arm64: gic-v5: Support GICv3 compat Sascha Bischoff
2025-06-20 20:20 ` Oliver Upton
2025-06-20 23:02 ` Oliver Upton
2025-06-23 13:11 ` Sascha Bischoff [this message]
2025-06-22 12:19 ` Marc Zyngier
2025-06-22 12:37 ` Oliver Upton
2025-06-23 13:02 ` Sascha Bischoff
2025-06-20 16:07 ` [PATCH 2/5] irqchip/gic-v5: Populate struct gic_kvm_info Sascha Bischoff
2025-06-23 15:14 ` Lorenzo Pieralisi
2025-06-27 9:49 ` Sascha Bischoff
2025-06-20 16:07 ` [PATCH 5/5] KVM: arm64: gic-v5: Probe for GICv5 Sascha Bischoff
2025-06-20 20:25 ` Oliver Upton
2025-06-23 13:12 ` Sascha Bischoff
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=e34738676fef5ec6f06564ecf22a4de1705df66f.camel@arm.com \
--to=sascha.bischoff@arm.com \
--cc=Joey.Gouly@arm.com \
--cc=Suzuki.Poulose@arm.com \
--cc=Timothy.Hayes@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=maz@kernel.org \
--cc=nd@arm.com \
--cc=oliver.upton@linux.dev \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®