Re: [PATCH v2 0/3] KVM: arm64: timers: Program CVAL from the current count when the hardware won't apply the offset

From: Marc Zyngier

Date: Wed Oct 07 2026 - 08:49:49 EST


On Wed, 07 Oct 2026 08:43:40 +0100, Fuad Tabba wrote:
> Changes since v1 [1]:
> - Patch 3 programs the new case's CVAL as an absolute value near the
> wrap instead of a negative TVAL, so a host stall between the
> counter and timer writes can't make it fire. (Sashiko)
>
> A guest timer can fail to fire, or fire early, once the guest's counter
> is far enough from the host's. Where the hardware won't apply the
> offset itself (the physical timer without CNTPOFF_EL2, a CNTPOFF_EL2
> host while TGE is set, the virtual timer on x1e), KVM adds it to CVAL
> and lets the hardware compare the sum against the raw counter. The
> timer condition is an unsigned compare, and adding the offset to both
> sides of it preserves it only while both sums wrap or neither does: a
> guest whose counter is ahead of the host's by more than CVAL has an
> expired timer that never fires, and one behind it can have a far-future
> timer fire at once.
>
> [...]

Applied to next, thanks!

[1/3] KVM: arm64: timers: Compute an offset-applied CVAL from the current count
commit: 49930b1b557ceb698e0ab7f985ea41c99dc8bf22
[2/3] KVM: arm64: nv: Read a guest hypervisor's CNTV_CVAL_EL0 from memory on x1e
commit: 1dbb5a2b5a21a62a223a2a2a0d775d417dca4242
[3/3] KVM: arm64: selftests: Test a timer set past the counter's wrap
commit: 46e0f2c9d7d6f99a8f16290d4d4e2f3129edfa54

Cheers,

M.
--
Without deviation from the norm, progress is not possible.