[PATCH v1] KVM: arm64: Use CNTPCT_EL0 for hyp trace clock
Marc Zyngier
maz at kernel.org
Mon Nov 30 03:15:17 PST 2026
On Mon, 30 Nov 2026 09:26:12 +0000,
Vincent Donnefort <vdonnefort at google.com> wrote:
>
> On Sat, Nov 28, 2026 at 09:34:01AM +0000, Marc Zyngier wrote:
> > On Fri, 27 Nov 2026 21:27:43 +0000,
> > Vincent Donnefort <vdonnefort at google.com> wrote:
> > >
> > > trace_hyp_clock() reads the virtual counter (CNTVCT_EL0). Under nVHE
> > > (and pKVM without hVHE), loading a guest with a non-zero offset applies
> > > that offset to CNTVCT_EL0, corrupting the trace timestamps. Use
> > > CNTPCT_EL0 instead.
> >
> > pKVM mandates CNTVOFF_EL2 being 0. Has that changed?
> >
> > >
> > > Cc: stable at vger.kernel.org
> > > Fixes: b22888917fa4 ("KVM: arm64: Sync boot clock with the nVHE/pKVM hyp")
> > > Reported-by: Fuad Tabba <fuad.tabba at linux.dev>
> > > Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
> > > ---
> > > arch/arm64/kvm/hyp/nvhe/clock.c | 2 +-
> > > arch/arm64/kvm/hyp_trace.c | 4 ++--
> > > 2 files changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/arch/arm64/kvm/hyp/nvhe/clock.c b/arch/arm64/kvm/hyp/nvhe/clock.c
> > > index f3e2619db4e4..ea4412e6737c 100644
> > > --- a/arch/arm64/kvm/hyp/nvhe/clock.c
> > > +++ b/arch/arm64/kvm/hyp/nvhe/clock.c
> > > @@ -54,7 +54,7 @@ u64 trace_hyp_clock(void)
> > > u64 bank = smp_load_acquire(&clock->cur);
> > > u64 cyc, ns;
> > >
> > > - cyc = __arch_counter_get_cntvct() - clock->data[bank].epoch_cyc;
> > > + cyc = __arch_counter_get_cntpct() - clock->data[bank].epoch_cyc;
> > >
> > > if (likely(cyc < clock->data[bank].cyc_overflow64)) {
> > > ns = cyc * clock->data[bank].mult;
> > > diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
> > > index b9404496f977..06d6bd7aeac7 100644
> > > --- a/arch/arm64/kvm/hyp_trace.c
> > > +++ b/arch/arm64/kvm/hyp_trace.c
> > > @@ -510,8 +510,8 @@ int __init kvm_hyp_trace_init(void)
> > > per_cpu(timer_unstable_counter_workaround, cpu);
> > >
> > > if (IS_ENABLED(CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND) &&
> > > - wa && wa->read_cntvct_el0) {
> > > - pr_warn("hyp trace can't handle CNTVCT workaround '%s'\n", wa->desc);
> > > + wa && wa->read_cntpct_el0) {
> > > + pr_warn("hyp trace can't handle CNTPCT workaround '%s'\n", wa->desc);
> > > return -EOPNOTSUPP;
> > > }
> > > }
> > >
> >
> > This is a bad idea. Virtualising the physical counter is extremely
> > expensive, while the virtual counter is basically free. On top of
> > that, nVHE is a dried up turd we shouldn't invest any effort into.
> >
> > I can see two options: disabling trace on nVHE altogether (my
> > favourite one, because let's face it, *nobody* is using pKVM on that),
> > or reset CNTVOFF_EL2 to 0 across the read of the counter when on nVHE.
> >
> > M.
> >
> > --
> > Without deviation from the norm, progress is not possible.
>
> I am more than happy with nuking the nVHE support, getting rid of it should
> simplify a lot hyp_trace.c.
Can we nuke nVHE support from pKVM entirely? ARMv8.1 was released in
2014, and it is high time we start moving forward. ARMv8.0 HW can
still use KVM as initially intended (without paying the cost of S2 on
the host).
M.
--
Without deviation from the norm, progress is not possible.
More information about the linux-arm-kernel
mailing list