x86/vtsc: update vcpu_time in hvm_set_guest_time
authorRoger Pau Monné <roger.pau@citrix.com>
Wed, 5 Jun 2013 08:03:08 +0000 (10:03 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 5 Jun 2013 08:03:08 +0000 (10:03 +0200)
When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset,
which is used in the vcpu time structure to calculate the
tsc_timestamp, so after updating stime_offset we need to propagate the
change to vcpu_time in order for the guest to get the right time if
using the PV clock.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@eu.citrix.com>
xen/arch/x86/hvm/vpt.c

index 8dee662130a1eac197272ef88b49a1ab2979af07..1961bda6a3b8351290b58a5c95d6f406721ae946 100644 (file)
@@ -57,7 +57,19 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
 void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
 {
-    v->arch.hvm_vcpu.stime_offset += guest_time - hvm_get_guest_time(v);
+    u64 offset = guest_time - hvm_get_guest_time(v);
+
+    if ( offset )
+    {
+        v->arch.hvm_vcpu.stime_offset += offset;
+        /*
+         * If hvm_vcpu.stime_offset is updated make sure to
+         * also update vcpu time, since this value is used to
+         * calculate the TSC.
+         */
+        if ( v == current )
+            update_vcpu_system_time(v);
+    }
 }
 
 static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)