KVM: x86: zero kvmclock_offset when vcpu0 initializes kvmclock system MSR
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 28 May 2015 23:20:41 +0000 (20:20 -0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 29 May 2015 12:02:40 +0000 (14:02 +0200)
Initialize kvmclock base, on kvmclock system MSR write time,
so that the guest sees kvmclock counting from zero.

This matches baremetal behaviour when kvmclock in guest
sets sched clock stable.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
[Remove unnecessary comment. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 2211213a84e7a4184d297842ecc354b0760a6573..79dde1656db6553e77b423e7b58aa4e7024e8897 100644 (file)
@@ -1700,6 +1700,8 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
                vcpu->pvclock_set_guest_stopped_request = false;
        }
 
+       pvclock_flags |= PVCLOCK_COUNTS_FROM_ZERO;
+
        /* If the host uses TSC clocksource, then it is stable */
        if (use_master_clock)
                pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
@@ -2282,6 +2284,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                                        &vcpu->requests);
 
                        ka->boot_vcpu_runs_old_kvmclock = tmp;
+
+                       ka->kvmclock_offset = -get_kernel_ns();
                }
 
                vcpu->arch.time = data;