On 02/05/2017 23:36, Marcelo Tosatti wrote: > In the masterclock enabled case, kvmclock_offset must be adjusted so > that user_ns.clock = master_kernel_ns + kvmclock_offset (that is, the > value set from KVM_SET_CLOCK is the one visible at system_timestamp). > > This way the guest clock: > > 1. Starts counting when KVM_SET_CLOCK executes. > 2. With the value provided by userspace. So this fixes rounding errors? > - now_ns = get_kvmclock_ns(kvm); > - kvm->arch.kvmclock_offset += user_ns.clock - now_ns; > + > kvm_gen_update_masterclock(kvm); > + if (ka->use_master_clock) { > + /* > + * In the masterclock enabled case, > + * kvmclock_offset must be adjusted so that > + * user_ns.clock = master_kernel_ns + kvmclock_offset > + * (that is, the value set from KVM_SET_CLOCK is the > + * one visible at system_timestamp). > + */ > + kvm->arch.kvmclock_offset = user_ns.clock - > + ka->master_kernel_ns; > + This needs to hold ka->pvclock_gtod_sync_lock, I think. > + kvm_for_each_vcpu(i, vcpu, kvm) > + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); kvm_gen_update_masterclock already does that, why did you move that to before the assignment? Paolo