]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: arm/arm64: Fix potential loss of ptimer interrupts
authorChristoffer Dall <christoffer.dall@arm.com>
Wed, 25 Jul 2018 09:21:27 +0000 (10:21 +0100)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:45:22 +0000 (19:45 -0600)
BugLink: https://bugs.launchpad.net/bugs/1835972
commit 7afc4ddbf299a13aaf28406783d141a34c6b4f5a upstream.

kvm_timer_update_state() is called when changing the phys timer
configuration registers, either via vcpu reset, as a result of a trap
from the guest, or when userspace programs the registers.

phys_timer_emulate() is in turn called by kvm_timer_update_state() to
either cancel an existing software timer, or program a new software
timer, to emulate the behavior of a real phys timer, based on the change
in configuration registers.

Unfortunately, the interaction between these two functions left a small
race; if the conceptual emulated phys timer should actually fire, but
the soft timer hasn't executed its callback yet, we cancel the timer in
phys_timer_emulate without injecting an irq.  This only happens if the
check in kvm_timer_update_state is called before the timer should fire,
which is relatively unlikely, but possible.

The solution is to update the state of the phys timer after calling
phys_timer_emulate, which will pick up the pending timer state and
update the interrupt value.

Note that this leaves the opportunity of raising the interrupt twice,
once in the just-programmed soft timer, and once in
kvm_timer_update_state.  Since this always happens synchronously with
the VCPU execution, there is no harm in this, and the guest ever only
sees a single timer interrupt.

Cc: Stable <stable@vger.kernel.org> # 4.15+
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
virt/kvm/arm/arch_timer.c

index 811631a1296cc5b1a40069836b794dfdc8ba8270..b06135e17c2e073dd86bf56702919a1bb64e672e 100644 (file)
@@ -309,9 +309,9 @@ static void phys_timer_emulate(struct kvm_vcpu *vcpu)
        struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
 
        /*
-        * If the timer can fire now we have just raised the IRQ line and we
-        * don't need to have a soft timer scheduled for the future.  If the
-        * timer cannot fire at all, then we also don't need a soft timer.
+        * If the timer can fire now, we don't need to have a soft timer
+        * scheduled for the future.  If the timer cannot fire at all,
+        * then we also don't need a soft timer.
         */
        if (kvm_timer_should_fire(ptimer) || !kvm_timer_irq_can_fire(ptimer)) {
                soft_timer_cancel(&timer->phys_timer, NULL);
@@ -338,10 +338,10 @@ static void kvm_timer_update_state(struct kvm_vcpu *vcpu)
        if (kvm_timer_should_fire(vtimer) != vtimer->irq.level)
                kvm_timer_update_irq(vcpu, !vtimer->irq.level, vtimer);
 
+       phys_timer_emulate(vcpu);
+
        if (kvm_timer_should_fire(ptimer) != ptimer->irq.level)
                kvm_timer_update_irq(vcpu, !ptimer->irq.level, ptimer);
-
-       phys_timer_emulate(vcpu);
 }
 
 static void vtimer_save_state(struct kvm_vcpu *vcpu)