From: "Michael S. Tsirkin" <mst@redhat.com>
To: shenjiatong <yshxxsjt715@163.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com
Subject: Re: [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards
Date: Fri, 4 Sep 2026 18:23:20 -0400 [thread overview]
Message-ID: <20260904182057-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20251113030211.6283-1-yshxxsjt715@163.com>
On Thu, Nov 13, 2025 at 11:02:11AM +0800, shenjiatong wrote:
> Loosen restriction on computed lost_tick. When QEMU's rtc_clock is set
> to host, the walltime is used for mc146818rtc which requires computed
> lost_tick to be strictly non-negative. But host walltime could possibly
> run backwards, for example, configured by NTP service. Under such
> circumstances QEMU process could crash unexpectly.
could crash -> crashes on an assert
remove "unexpectly."
> This situation is
> easy to reproduce for Windows 2012/2016 guests.
hmm what does it matter what is the guest?
Pls describe a fix shortly here.
And please follow standard practice to submit changes,
such as read and sign off on the DCO.
> ---
> hw/rtc/mc146818rtc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
> index 8631386b9f..04185eb6e9 100644
> --- a/hw/rtc/mc146818rtc.c
> +++ b/hw/rtc/mc146818rtc.c
> @@ -173,8 +173,7 @@ static void periodic_timer_update(MC146818RtcState *s, int64_t current_time,
> 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;
> - assert(lost_clock >= 0);
> + lost_clock = MAX(cur_clock - last_periodic_clock, 0);
> }
>
> /*
> --
> 2.34.1
>
>
>
prev parent reply other threads:[~2026-09-04 22:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 3:02 [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards shenjiatong
2026-07-15 7:13 ` Michael S. Tsirkin
2026-09-04 22:23 ` 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=20260904182057-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yshxxsjt715@163.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 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.