• Christoffer Dall's avatar
    KVM: arm/arm64: Fix incorrect timer_is_pending logic · 13e59ece
    Christoffer Dall authored
    After the recently introduced support for level-triggered mapped
    interrupt, I accidentally left the VCPU thread busily going back and
    forward between the guest and the hypervisor whenever the guest was
    blocking, because I would always incorrectly report that a timer
    interrupt was pending.
    
    This is because the timer->irq.level field is not valid for mapped
    interrupts, where we offload the level state to the hardware, and as a
    result this field is always true.
    
    Luckily the problem can be relatively easily solved by not checking the
    cached signal state of either timer in kvm_timer_should_fire() but
    instead compute the timer state on the fly, which we do already if the
    cached signal state wasn't high.  In fact, the only reason for checking
    the cached signal state was a tiny optimization which would only be
    potentially faster when the polling loop detects a pending timer
    interrupt, which is quite unlikely.
    
    Instead of duplicating the logic from kvm_arch_timer_handler(), we
    enlighten kvm_timer_should_fire() to report something valid when the
    timer state is loaded onto the hardware.  We can then call this from
    kvm_arch_timer_handler() as well and avoid the call to
    __timer_snapshot_state() in kvm_arch_timer_get_input_level().
    Reported-by: default avatarTomasz Nowicki <tn@semihalf.com>
    Tested-by: default avatarTomasz Nowicki <tn@semihalf.com>
    Reviewed-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
    Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
    13e59ece
arch_timer.c 24.5 KB