From: "Michael S. Tsirkin" <mst@redhat.com>
To: Yaowei Bai <baiyw2@chinatelecom.cn>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/rtc: fix crash caused by lost_clock >= 0 assertion
Date: Tue, 11 Apr 2023 06:45:12 -0400 [thread overview]
Message-ID: <20230411064451-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1670228615-2684-1-git-send-email-baiyw2@chinatelecom.cn>
On Mon, Dec 05, 2022 at 04:23:35PM +0800, Yaowei Bai wrote:
> In our production environment a guest crashed with this log:
>
> qemu-kvm: /home/abuild/rpmbuild/BUILD/qemu-5.0.0/hw/rtc/mc146818rtc.c:201: periodic_timer_update: Assertion `lost_clock >= 0' failed.
> 2022-09-26 10:00:28.747+0000: shutting down, reason=crashed
>
> This happened after the host synced time with the NTP server which
> we had adjusted backward the time because it mistakenly went faster
> than the real time. Other people also have this problem:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=2054781
>
> After the host adjusted backward the time, the guset reconfigured the
> period, this makes cur_clock smaller than last_periodic_clock in
> periodic_timer_update function. However, the code assumes that cur_clock
> is bigger than last_periodic_clock, which is not true in the situation
> above. So we need to make it clear by introducing a if statement. With
> this patch we can handle this crash situation to just reset the
> next_periodic_time.
>
> Signed-off-by: Yaowei Bai <baiyw2@chinatelecom.cn>
Hmm not sure this is a good fix. Paolo what's your take?
> ---
> hw/rtc/mc146818rtc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
> index 1ebb412..a397949 100644
> --- a/hw/rtc/mc146818rtc.c
> +++ b/hw/rtc/mc146818rtc.c
> @@ -199,7 +199,9 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period, bo
> next_periodic_clock = muldiv64(s->next_periodic_time,
> RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
> last_periodic_clock = next_periodic_clock - old_period;
> - lost_clock = cur_clock - last_periodic_clock;
> + if (cur_clock > last_periodic_clock) {
> + lost_clock = cur_clock - last_periodic_clock;
> + }
> assert(lost_clock >= 0);
> }
>
> --
> 2.7.4
prev parent reply other threads:[~2023-04-11 10:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 8:23 [PATCH] hw/rtc: fix crash caused by lost_clock >= 0 assertion Yaowei Bai
2023-04-11 10:45 ` Michael S. Tsirkin [this message]
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=20230411064451-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=baiyw2@chinatelecom.cn \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.