Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: Marc Zyngier <maz@kernel.org>
Cc: oupton@kernel.org, kvmarm@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com,
	seiden@linux.ibm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
	kernel-team@android.com, fuad.tabba@linux.dev,
	stable@vger.kernel.org
Subject: Re: [PATCH v1] KVM: arm64: Use CNTPCT_EL0 for hyp trace clock
Date: Mon, 30 Nov 2026 09:26:12 +0000	[thread overview]
Message-ID: <aw1BNG-g5fAkN4l0@google.com> (raw)
In-Reply-To: <86se0lxpti.wl-maz@kernel.org>

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@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@vger.kernel.org
> > Fixes: b22888917fa4 ("KVM: arm64: Sync boot clock with the nVHE/pKVM hyp")
> > Reported-by: Fuad Tabba <fuad.tabba@linux.dev>
> > Signed-off-by: Vincent Donnefort <vdonnefort@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. 

-- 
Vincent


      parent reply	other threads:[~2026-11-30  9:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 21:27 [PATCH v1] KVM: arm64: Use CNTPCT_EL0 for hyp trace clock Vincent Donnefort
2026-11-28  9:34 ` Marc Zyngier
2026-11-28 10:23   ` Fuad Tabba
2026-11-28 11:27     ` Marc Zyngier
2026-11-30  9:26   ` Vincent Donnefort [this message]

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=aw1BNG-g5fAkN4l0@google.com \
    --to=vdonnefort@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --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