KVM: arm/arm64: arch_timer: Fix CNTP_TVAL calculation
authorWei Huang <wei@redhat.com>
Fri, 29 Mar 2019 20:12:53 +0000 (15:12 -0500)
committerMarc Zyngier <marc.zyngier@arm.com>
Sat, 30 Mar 2019 10:06:00 +0000 (10:06 +0000)
commit8fa76162487143d202db20ce84e12061b671a058
tree09aa11fc53786a4e0079683f16752899f4fd875b
parent8324c3d518cfd69f2a17866b52c13bf56d3042d8
KVM: arm/arm64: arch_timer: Fix CNTP_TVAL calculation

Recently the generic timer test of kvm-unit-tests failed to complete
(stalled) when a physical timer is being used. This issue is caused
by incorrect update of CNTP_CVAL when CNTP_TVAL is being accessed,
introduced by 'Commit 84135d3d18da ("KVM: arm/arm64: consolidate arch
timer trap handlers")'. According to Arm ARM, the read/write behavior
of accesses to the TVAL registers is expected to be:

  * READ: TimerValue = (CompareValue – (Counter - Offset)
  * WRITE: CompareValue = ((Counter - Offset) + Sign(TimerValue)

This patch fixes the TVAL read/write code path according to the
specification.

Fixes: 84135d3d18da ("KVM: arm/arm64: consolidate arch timer trap handlers")
Signed-off-by: Wei Huang <wei@redhat.com>
[maz: commit message tidy-up]
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
virt/kvm/arm/arch_timer.c