Skip to content

Commit d9130a2

Browse files
Zelin Dengbonzini
authored andcommitted
KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted
When MSR_IA32_TSC_ADJUST is written by guest due to TSC ADJUST feature especially there's a big tsc warp (like a new vCPU is hot-added into VM which has been up for a long time), tsc_offset is added by a large value then go back to guest. This causes system time jump as tsc_timestamp is not adjusted in the meantime and pvclock monotonic character. To fix this, just notify kvm to update vCPU's guest time before back to guest. Cc: [email protected] Signed-off-by: Zelin Deng <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4ac2145 commit d9130a2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,6 +3321,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
33213321
if (!msr_info->host_initiated) {
33223322
s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr;
33233323
adjust_tsc_offset_guest(vcpu, adj);
3324+
/* Before back to guest, tsc_timestamp must be adjusted
3325+
* as well, otherwise guest's percpu pvclock time could jump.
3326+
*/
3327+
kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
33243328
}
33253329
vcpu->arch.ia32_tsc_adjust_msr = data;
33263330
}

0 commit comments

Comments
 (0)