On 10/01/2017 11:25, Huaitong Han wrote: > kvmclock_offset is negative, it should be timespec64_add intead of > timespec64_sub. > > kvm->arch.kvmclock_offset = -ktime_get_boot_ns() No, timespec64_sub is correct (and kvmclock.flat in kvm-unit-tests tests it). The guest computes CLOCK_REALTIME as pvclock_wall_clock + kvmclock (see pvclock_read_wallclock in arch/x86/kvm/pvclock.c). So: host_boot_time = getboottime64() pvclock_wall_clock = guest_boot_time kvmclock_offset = host_boot_time - guest_boot_time The latter is important: kvmclock_offset is negative because guest_boot_time > host_boot_time. Then: pvclock_wall_clock = = guest_boot_time = host_boot_time - (host_boot_time - guest_boot_time) = getboottime64() - kvmclock_offset Thanks, Paolo > Signed-off-by: Huaitong Han <huaitong.han@xxxxxxxxx> > --- > arch/x86/kvm/x86.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 2f22810..7668a0e 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1208,7 +1208,7 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) > > if (kvm->arch.kvmclock_offset) { > struct timespec64 ts = ns_to_timespec64(kvm->arch.kvmclock_offset); > - boot = timespec64_sub(boot, ts); > + boot = timespec64_add(boot, ts); > } > wc.sec = (u32)boot.tv_sec; /* overflow in 2106 guest time */ > wc.nsec = boot.tv_nsec; > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html