KVM: arm/arm64: Properly handle arch-timer IRQs after vtimer_save_state
authorChristoffer Dall <christoffer.dall@linaro.org>
Thu, 14 Dec 2017 18:54:50 +0000 (19:54 +0100)
committerChristoffer Dall <christoffer.dall@linaro.org>
Mon, 18 Dec 2017 09:53:24 +0000 (10:53 +0100)
commit36e5cfd410ad6060b527e51d1b4bc174a8068cfd
tree3e0aaea6f2b06375ef0aa0f2ca6cc6a6f9a02719
parentf384dcfe4d918c1d80477d290c22ce0093823771
KVM: arm/arm64: Properly handle arch-timer IRQs after vtimer_save_state

The recent timer rework was assuming that once the timer was disabled,
we should no longer see any interrupts from the timer.  This assumption
turns out to not be true, and instead we have to handle the case when
the timer ISR runs even after the timer has been disabled.

This requires a couple of changes:

First, we should never overwrite the cached guest state of the timer
control register when the ISR runs, because KVM may have disabled its
timers when doing vcpu_put(), even though the guest still had the timer
enabled.

Second, we shouldn't assume that the timer is actually firing just
because we see an interrupt, but we should check the actual state of the
timer in the timer control register to understand if the hardware timer
is really firing or not.

We also add an ISB to vtimer_save_state() to ensure the timer is
actually disabled once we enable interrupts, which should clarify the
intention of the implementation, and reduce the risk of unwanted
interrupts.

Fixes: b103cc3f10c0 ("KVM: arm/arm64: Avoid timer save/restore in vcpu entry/exit")
Reported-by: Marc Zyngier <marc.zyngier@arm.com>
Reported-by: Jia He <hejianet@gmail.com>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
virt/kvm/arm/arch_timer.c