From: Thomas Gleixner <tglx@linutronix.de>
To: Paolo Bonzini <pbonzini@redhat.com>, Miklos Szeredi <miklos@szeredi.hu>
Cc: kvm@vger.kernel.org,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Juergen Gross <jgross@suse.com>,
linux-kernel@vger.kernel.org
Subject: Re: system time goes weird in kvm guest after host suspend/resume
Date: Fri, 05 Jun 2020 12:11:59 +0200 [thread overview]
Message-ID: <87k10l7rf4.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <1a1c32fe-d124-0e47-c9e4-695be7ea7567@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 04/06/20 21:28, Miklos Szeredi wrote:
>> time(2) returns good time, while clock_gettime(2) returns bad time.
>> Here's an example:
>>
>> time=1591298725 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
>> time=1591298726 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
>> time=1591298727 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
>> time=1591298728 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
>> time=1591298729 RT=1591300383 MONO=39582 MONO_RAW=39582 BOOT=39582
>>
>> As you can see, only time(2) is updated, the others remain the same.
>> date(1) uses clock_gettime(CLOCK_REALTIME) so that shows the bad date.
>>
>> When the correct time reaches the value returned by CLOCK_REALTIME,
>> the value jumps exactly 2199 seconds.
Which value jumps?
> clockid_to_kclock(CLOCK_REALTIME) is &clock_realtime, so clock_gettime
> calls ktime_get_real_ts64, which is:
>
>
> do {
> seq = read_seqcount_begin(&tk_core.seq);
>
> ts->tv_sec = tk->xtime_sec;
> nsecs = timekeeping_get_ns(&tk->tkr_mono);
>
> } while (read_seqcount_retry(&tk_core.seq, seq));
>
> ts->tv_nsec = 0;
> timespec64_add_ns(ts, nsecs);
>
> time(2) instead should actually be gettimeofday(2), which just returns
> tk->xtime_sec.
time(2) is either handled in the VDSO or it is handled via syscall and
yes, it's only looking at the xtime_sec value.
gettimeofday(2) returns seconds and microseconds. It's using the same
mechanism as clock_gettime(2) and divides the nanoseconds part by 1000.
> So the problem is the nanosecond part which is off by
> 2199*10^9 nanoseconds, and that is suspiciously close to 2^31...
Not really. It's 2^41.
I can actually now reproduce, but I won't be able to investigate that
before monday.
Thanks,
tglx
next prev parent reply other threads:[~2020-06-05 10:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 19:45 system time goes weird in kvm guest after host suspend/resume Miklos Szeredi
2020-05-28 20:43 ` Thomas Gleixner
2020-05-29 9:51 ` Miklos Szeredi
2020-05-29 9:57 ` Miklos Szeredi
2020-05-29 12:21 ` Thomas Gleixner
2020-05-29 12:31 ` Miklos Szeredi
2020-05-29 12:33 ` Miklos Szeredi
2020-06-03 15:41 ` Thomas Gleixner
2020-06-03 15:45 ` Thomas Gleixner
2020-06-04 17:30 ` Thomas Gleixner
2020-06-04 19:28 ` Miklos Szeredi
2020-06-04 20:14 ` Paolo Bonzini
2020-06-05 7:35 ` Miklos Szeredi
2020-06-05 8:09 ` Paolo Bonzini
2020-06-05 10:11 ` Thomas Gleixner [this message]
2020-06-05 10:21 ` Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k10l7rf4.fsf@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=jgross@suse.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=pbonzini@redhat.com \
--cc=vincenzo.frascino@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).