Re: [PATCH 6.19 831/844] arm64: Force the use of CNTVCT_EL0 in __delay()

From: Sasha Levin

Date: Mon Mar 02 2026 - 09:09:08 EST


On Mon, Mar 02, 2026 at 08:07:29AM +0100, Jiri Slaby wrote:
On 28. 02. 26, 18:32, Sasha Levin wrote:
From: Marc Zyngier <maz@xxxxxxxxxx>

[ Upstream commit 29cc0f3aa7c64d3b3cb9d94c0a0984ba6717bf72 ]
...
--- a/arch/arm64/lib/delay.c
+++ b/arch/arm64/lib/delay.c
@@ -23,9 +23,20 @@ static inline unsigned long xloops_to_cycles(unsigned long xloops)
return (xloops * loops_per_jiffy * HZ) >> 32;
}
+/*
+ * Force the use of CNTVCT_EL0 in order to have the same base as WFxT.
+ * This avoids some annoying issues when CNTVOFF_EL2 is not reset 0 on a
+ * KVM host running at EL1 until we do a vcpu_put() on the vcpu. When
+ * running at EL2, the effective offset is always 0.
+ *
+ * Note that userspace cannot change the offset behind our back either,
+ * as the vcpu mutex is held as long as KVM_RUN is in progress.
+ */
+#define __delay_cycles() __arch_counter_get_cntvct_stable()

This needs:
e5cb94ba5f96 arm64: Fix sampling the "stable" virtual counter in preemptible section

Queued up, thanks!

--
Thanks,
Sasha