Re: [PATCH 2/2] KVM: x86: use raw clock values consistently

Paolo Bonzini
2020-01-23T13:54:57Z

On 23/01/20 14:43, Vitaly Kuznetsov wrote:
>> +
>> +static s64 get_kvmclock_base_ns(void)
>> +{
>> + /* Count up from boot time, but with the frequency of the raw clock. */
>> + return ktime_to_ns(ktime_add(ktime_get_raw(), pvclock_gtod_data.offs_boot));
>> +}
>> +#else
>> +static s64 get_kvmclock_base_ns(void)
>> +{
>> + /* Master clock not used, so we can just use CLOCK_BOOTTIME. */
>> + return ktime_get_boottime_ns();
>> +}
>> #endif
> But we could've still used the RAW+offs_boot version, right? And this is
> just to basically preserve the existing behavior on !x86.

Yes, there's no reason to restrict the pvclock_gtod notifier to x86_64.
But this is stable material so I kept it easy.

>>
>> - getboottime64(&boot);
>> + wall_nsec = ktime_get_real_ns() - get_kvmclock_ns(kvm);
>
> There are not that many hosts with more than 50 years uptime and likely
> none running Linux with live kernel patching support so I bet noone will
> ever see this overflowing, however, as wall_nsec is u64 and we're
> dealing with kvmclock here I'd suggest to add a WARN_ON().

You're off by a factor of 10, 2^64 nanoseconds are about 584 years
(584*365*10^9*86400). :)

Paolo