]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
x86/tsc: update vcpu time info on guest TSC adjustments
authorRoger Pau Monné <roger.pau@citrix.com>
Wed, 23 Oct 2019 08:57:39 +0000 (10:57 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 23 Oct 2019 16:01:56 +0000 (17:01 +0100)
If a HVM/PVH guest writes to MSR_IA32_TSC{_ADJUST} and thus changes
the value of the time stamp counter the vcpu time info must also be
updated, or the time calculated by the guest using the Xen PV clock
interface will be skewed.

Update the vcpu time info when the guest writes to either MSR_IA32_TSC
or MSR_IA32_TSC_ADJUST. This fixes lockups seen when running the
pv-shim on AMD hardware, since the shim will aggressively try to keep
TSCs in sync by periodically writing to MSR_IA32_TSC if the TSC is not
reliable.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Liu <wl@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
xen/arch/x86/hvm/hvm.c

index 9acd359c99eaa2aca12d42224e7f5d378b7da9a4..e4c042533078afdf4d7b82c15e9865f1cf8bf7d4 100644 (file)
@@ -442,6 +442,8 @@ static void hvm_set_guest_tsc_msr(struct vcpu *v, u64 guest_tsc)
 
     hvm_set_guest_tsc(v, guest_tsc);
     v->arch.hvm.msr_tsc_adjust += v->arch.hvm.cache_tsc_offset - tsc_offset;
+    if ( v == current )
+        update_vcpu_system_time(v);
 }
 
 static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
@@ -449,6 +451,8 @@ static void hvm_set_guest_tsc_adjust(struct vcpu *v, u64 tsc_adjust)
     v->arch.hvm.cache_tsc_offset += tsc_adjust - v->arch.hvm.msr_tsc_adjust;
     hvm_set_tsc_offset(v, v->arch.hvm.cache_tsc_offset, 0);
     v->arch.hvm.msr_tsc_adjust = tsc_adjust;
+    if ( v == current )
+        update_vcpu_system_time(v);
 }
 
 u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc)