{
        struct kvm_vcpu *vcpu = container_of(timer, struct kvm_vcpu,
                                             arch.xen.timer);
+       struct kvm_xen_evtchn e;
+       int rc;
+
        if (atomic_read(&vcpu->arch.xen.timer_pending))
                return HRTIMER_NORESTART;
 
+       e.vcpu_id = vcpu->vcpu_id;
+       e.vcpu_idx = vcpu->vcpu_idx;
+       e.port = vcpu->arch.xen.timer_virq;
+       e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
+
+       rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
+       if (rc != -EWOULDBLOCK) {
+               vcpu->arch.xen.timer_expires = 0;
+               return HRTIMER_NORESTART;
+       }
+
        atomic_inc(&vcpu->arch.xen.timer_pending);
        kvm_make_request(KVM_REQ_UNBLOCK, vcpu);
        kvm_vcpu_kick(vcpu);
 
 static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs, s64 delta_ns)
 {
+       /*
+        * Avoid races with the old timer firing. Checking timer_expires
+        * to avoid calling hrtimer_cancel() will only have false positives
+        * so is fine.
+        */
+       if (vcpu->arch.xen.timer_expires)
+               hrtimer_cancel(&vcpu->arch.xen.timer);
+
        atomic_set(&vcpu->arch.xen.timer_pending, 0);
        vcpu->arch.xen.timer_expires = guest_abs;
 
                break;
 
        case KVM_XEN_VCPU_ATTR_TYPE_TIMER:
+               /*
+                * Ensure a consistent snapshot of state is captured, with a
+                * timer either being pending, or the event channel delivered
+                * to the corresponding bit in the shared_info. Not still
+                * lurking in the timer_pending flag for deferred delivery.
+                * Purely as an optimisation, if the timer_expires field is
+                * zero, that means the timer isn't active (or even in the
+                * timer_pending flag) and there is no need to cancel it.
+                */
+               if (vcpu->arch.xen.timer_expires) {
+                       hrtimer_cancel(&vcpu->arch.xen.timer);
+                       kvm_xen_inject_timer_irqs(vcpu);
+               }
+
                data->u.timer.port = vcpu->arch.xen.timer_virq;
                data->u.timer.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
                data->u.timer.expires_ns = vcpu->arch.xen.timer_expires;
+
+               /*
+                * The hrtimer may trigger and raise the IRQ immediately,
+                * while the returned state causes it to be set up and
+                * raised again on the destination system after migration.
+                * That's fine, as the guest won't even have had a chance
+                * to run and handle the interrupt. Asserting an already
+                * pending event channel is idempotent.
+                */
+               if (vcpu->arch.xen.timer_expires)
+                       hrtimer_start_expires(&vcpu->arch.xen.timer,
+                                             HRTIMER_MODE_ABS_HARD);
+
                r = 0;
                break;