Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] KVM: arm64: Use CNTPCT_EL0 for hyp trace clock
@ 2026-11-27 21:27 Vincent Donnefort
  2026-11-28  9:34 ` Marc Zyngier
  0 siblings, 1 reply; 4+ messages in thread
From: Vincent Donnefort @ 2026-11-27 21:27 UTC (permalink / raw)
  To: maz, oupton, kvmarm, linux-arm-kernel
  Cc: joey.gouly, seiden, suzuki.poulose, yuzenghui, catalin.marinas,
	will, kernel-team, fuad.tabba, Vincent Donnefort, stable

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.

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;
 		}
 	}

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.56.1.839.g22a8290db9-goog



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-28 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox