Skip to content

Commit

Permalink
KVM: x86: zero kvmclock_offset when vcpu0 initializes kvmclock system…
Browse files Browse the repository at this point in the history
… MSR

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>
  • Loading branch information
Marcelo Tosatti authored and Paolo Bonzini committed May 29, 2015
1 parent 0ad83ca commit b7e60c5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b7e60c5

Please sign in to comment.