x86/hvm: fix saved pmtimer and hpet values
authorKouya Shimura <kouya@jp.fujitsu.com>
Fri, 11 Sep 2015 14:24:56 +0000 (16:24 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 11 Sep 2015 14:24:56 +0000 (16:24 +0200)
The ACPI PM timer is sometimes broken on live migration.
Since vcpu->arch.hvm_vcpu.guest_time is always zero in other than
"delay for missed ticks mode". Even in "delay for missed ticks mode",
vcpu's guest_time field is not valid (i.e. zero) when
the state of vcpu is "blocked". (see pt_save_timer function)

The original author (Tim Deegan) of pmtimer_save() must have intended
that it saves the last scheduled time of the vcpu. Unfortunately it was
already implied this bug. FYI, there is no other timer mode than
"delay for missed ticks mode" then.

For consistency with HPET, pmtimer_save() should refer hvm_get_guest_time()
to update the counter as well as hpet_save() does.

Without this patch, the clock of windows server 2012R2 without HPET
might leap forward several minutes on live migration.

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
Retain use of ->arch.hvm_vcpu.guest_time when non-zero. Do the inverse
adjustment for vHPET.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Tim Deegan <tim@xen.org>
Reviewed-by: Kouya Shimura <kouya@jp.fujitsu.com>
Release-acked-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/hvm/hpet.c
xen/arch/x86/hvm/pmtimer.c

index edf9a1746d4168d7c43b89676cfefae5538e3159..facab83dc517feb77b5de037cca42c3c54188811 100644 (file)
@@ -513,11 +513,13 @@ static const struct hvm_mmio_ops hpet_mmio_ops = {
 static int hpet_save(struct domain *d, hvm_domain_context_t *h)
 {
     HPETState *hp = domain_vhpet(d);
+    struct vcpu *v = pt_global_vcpu_target(d);
     int rc;
     uint64_t guest_time;
 
     write_lock(&hp->lock);
-    guest_time = guest_time_hpet(hp);
+    guest_time = (v->arch.hvm_vcpu.guest_time ?: hvm_get_guest_time(v)) /
+                 STIME_PER_HPET_TICK;
 
     /* Write the proper value into the main counter */
     if ( hpet_enabled(hp) )
index 07594e174b7aa73a2915727cd82aa043e982e8e4..c8229e0eab68ae136827ef3efff7b85e35289b19 100644 (file)
@@ -249,10 +249,12 @@ static int pmtimer_save(struct domain *d, hvm_domain_context_t *h)
 
     spin_lock(&s->lock);
 
-    /* Update the counter to the guest's current time.  We always save
-     * with the domain paused, so the saved time should be after the
-     * last_gtime, but just in case, make sure we only go forwards */
-    x = ((s->vcpu->arch.hvm_vcpu.guest_time - s->last_gtime) * s->scale) >> 32;
+    /*
+     * Update the counter to the guest's current time.  Make sure it only
+     * goes forwards.
+     */
+    x = (((s->vcpu->arch.hvm_vcpu.guest_time ?: hvm_get_guest_time(s->vcpu)) -
+          s->last_gtime) * s->scale) >> 32;
     if ( x < 1UL<<31 )
         s->pm.tmr_val += x;
     if ( (s->pm.tmr_val & TMR_VAL_MSB) != msb )