1
0
Fork 0
alistair23-linux/virt/kvm/arm
Alexandru Elisei 4a267aa707 KVM: arm64: Treat emulated TVAL TimerValue as a signed 32-bit integer
According to the ARM ARM, registers CNT{P,V}_TVAL_EL0 have bits [63:32]
RES0 [1]. When reading the register, the value is truncated to the least
significant 32 bits [2], and on writes, TimerValue is treated as a signed
32-bit integer [1, 2].

When the guest behaves correctly and writes 32-bit values, treating TVAL
as an unsigned 64 bit register works as expected. However, things start
to break down when the guest writes larger values, because
(u64)0x1_ffff_ffff = 8589934591. but (s32)0x1_ffff_ffff = -1, and the
former will cause the timer interrupt to be asserted in the future, but
the latter will cause it to be asserted now.  Let's treat TVAL as a
signed 32-bit register on writes, to match the behaviour described in
the architecture, and the behaviour experimentally exhibited by the
virtual timer on a non-vhe host.

[1] Arm DDI 0487E.a, section D13.8.18
[2] Arm DDI 0487E.a, section D11.2.4

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
[maz: replaced the read-side mask with lower_32_bits]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Fixes: 8fa7616248 ("KVM: arm/arm64: arch_timer: Fix CNTP_TVAL calculation")
Link: https://lore.kernel.org/r/20200127103652.2326-1-alexandru.elisei@arm.com
2020-01-28 13:09:31 +00:00
..
hyp KVM: arm: vgic-v3: Mark expected switch fall-through 2019-07-26 15:37:11 +01:00
vgic KVM: arm/arm64: vgic: Drop the kvm_vgic_register_mmio_region() 2020-01-19 18:06:24 +00:00
aarch32.c KVM: arm: Make inject_abt32() inject an external abort instead 2020-01-23 10:38:15 +00:00
arch_timer.c KVM: arm64: Treat emulated TVAL TimerValue as a signed 32-bit integer 2020-01-28 13:09:31 +00:00
arm.c KVM: arm: Remove duplicate include 2020-01-19 18:03:33 +00:00
hypercalls.c KVM: arm64: Support stolen time reporting via shared structure 2019-10-21 19:20:28 +01:00
mmio.c KVM: arm/arm64: Cleanup MMIO handling 2020-01-23 10:38:14 +00:00
mmu.c KVM: arm/arm64: Fix young bit from mmu notifier 2020-01-23 10:38:15 +00:00
perf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
pmu.c KVM: arm64: pmu: Only handle supported event counters 2020-01-28 13:05:05 +00:00
psci.c KVM: arm/arm64: Factor out hypercall handling from PSCI code 2019-10-21 19:20:26 +01:00
pvtime.c KVM: arm64: Provide VCPU attributes for stolen time 2019-10-21 19:20:29 +01:00
trace.h KVM: arm/arm64: Fix TRACE_INCLUDE_PATH 2019-02-19 21:05:51 +00:00