All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards
@ 2025-11-13  3:02 shenjiatong
  2026-07-15  7:13 ` Michael S. Tsirkin
  2026-09-04 22:23 ` Michael S. Tsirkin
  0 siblings, 2 replies; 3+ messages in thread
From: shenjiatong @ 2025-11-13  3:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, pbonzini, shenjiatong

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. This situation is
easy to reproduce for Windows 2012/2016 guests.
---
 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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-07-15  7:13 UTC (permalink / raw)
  To: shenjiatong; +Cc: qemu-devel, pbonzini

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. This situation is
> easy to reproduce for Windows 2012/2016 guests.

Looks like this feel through the cracks.
The patch lacks your Signed off by certifying the DCO.
Could you pls confirm that?

> ---
>  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
> 
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-09-04 22:23 UTC (permalink / raw)
  To: shenjiatong; +Cc: qemu-devel, pbonzini

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
> 
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-04 22:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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.