KVM: x86: fire timer when it is migrated and expired, and in oneshot mode
authorLi RongQing <lirongqing@baidu.com>
Fri, 6 Jan 2023 04:06:25 +0000 (12:06 +0800)
committerSean Christopherson <seanjc@google.com>
Tue, 24 Jan 2023 18:04:37 +0000 (10:04 -0800)
when the vCPU was migrated, if its timer is expired, KVM _should_ fire
the timer ASAP, zeroing the deadline here will cause the timer to
immediately fire on the destination

Cc: Sean Christopherson <seanjc@google.com>
Cc: Peter Shier <pshier@google.com>
Cc: Jim Mattson <jmattson@google.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Link: https://lore.kernel.org/r/20230106040625.8404-1-lirongqing@baidu.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/lapic.c

index d2ad5e8b63a4405981780ced94c4bcb96116bd15..c28ba02755807966509727a5b8867ef4d58ce3fd 100644 (file)
@@ -1968,8 +1968,12 @@ static bool set_target_expiration(struct kvm_lapic *apic, u32 count_reg)
                if (unlikely(count_reg != APIC_TMICT)) {
                        deadline = tmict_to_ns(apic,
                                     kvm_lapic_get_reg(apic, count_reg));
-                       if (unlikely(deadline <= 0))
-                               deadline = apic->lapic_timer.period;
+                       if (unlikely(deadline <= 0)) {
+                               if (apic_lvtt_period(apic))
+                                       deadline = apic->lapic_timer.period;
+                               else
+                                       deadline = 0;
+                       }
                        else if (unlikely(deadline > apic->lapic_timer.period)) {
                                pr_info_ratelimited(
                                    "vcpu %i: requested lapic timer restore with "