Skip to contentSkip to conversation

rdtsc emulation (PV and HVM) must be monotonically increasing

PATCH New Dan Magenheimer 1 participant 1 message Sep 1, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rdtsc emulation (PV and HVM) must be monotonically increasing

The Intel SDM (section 18.10) clearly states that rdtsc returns a "monotonically increasing unique value". Current emulation code for rdtsc (both PV and HVM) returns only a monotonically-non-decreasing (non-unique) value, so ensure stale value is always incremented.

xen/arch/x86/hvm/vpt.c +2 -2
diff -r 8fc927798476 xen/arch/x86/hvm/vpt.c
@@ -47,10 +47,10 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
     spin_lock(&pl->pl_time_lock);
     now = get_s_time() + pl->stime_offset;
-    if ( (int64_t)(now - pl->last_guest_time) >= 0 )
+    if ( (int64_t)(now - pl->last_guest_time) > 0 )
         pl->last_guest_time = now;
     else
-        now = pl->last_guest_time;
+        now = ++pl->last_guest_time;
     spin_unlock(&pl->pl_time_lock);
 
     return now + v->arch.hvm_vcpu.stime_offset;
xen/arch/x86/time.c +2 -2
diff -r 8fc927798476 xen/arch/x86/time.c
@@ -1454,10 +1454,10 @@ void pv_soft_rdtsc(struct vcpu *v, struc
         rdtsc_usercount++;
         spin_lock(&v->domain->arch.vtsc_lock);
         now = get_s_time() + v->domain->arch.vtsc_stime_offset;
-        if ( (int64_t)(now - v->domain->arch.vtsc_last) >= 0 )
+        if ( (int64_t)(now - v->domain->arch.vtsc_last) > 0 )
             v->domain->arch.vtsc_last = now;
         else
-            now = v->domain->arch.vtsc_last;
+            now = ++v->domain->arch.vtsc_last;
         spin_unlock(&v->domain->arch.vtsc_lock);
         regs->eax = (uint32_t)now;
         regs->edx = (uint32_t)(now >> 32);
xen/arch/x86/hvm/vpt.c +2 -2
diff -r 8fc927798476 xen/arch/x86/hvm/vpt.c
@@ -47,10 +47,10 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
     spin_lock(&pl->pl_time_lock);
     now = get_s_time() + pl->stime_offset;
-    if ( (int64_t)(now - pl->last_guest_time) >= 0 )
+    if ( (int64_t)(now - pl->last_guest_time) > 0 )
         pl->last_guest_time = now;
     else
-        now = pl->last_guest_time;
+        now = ++pl->last_guest_time;
     spin_unlock(&pl->pl_time_lock);
 
     return now + v->arch.hvm_vcpu.stime_offset;
xen/arch/x86/time.c +2 -2
diff -r 8fc927798476 xen/arch/x86/time.c
@@ -1454,10 +1454,10 @@ void pv_soft_rdtsc(struct vcpu *v, struc
         rdtsc_usercount++;
         spin_lock(&v->domain->arch.vtsc_lock);
         now = get_s_time() + v->domain->arch.vtsc_stime_offset;
-        if ( (int64_t)(now - v->domain->arch.vtsc_last) >= 0 )
+        if ( (int64_t)(now - v->domain->arch.vtsc_last) > 0 )
             v->domain->arch.vtsc_last = now;
         else
-            now = v->domain->arch.vtsc_last;
+            now = ++v->domain->arch.vtsc_last;
         spin_unlock(&v->domain->arch.vtsc_lock);
         regs->eax = (uint32_t)now;
         regs->edx = (uint32_t)(now >> 32);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel