qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: peng.hao2@zte.com.cn
Cc: liu.yi24@zte.com.cn, qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH V3] rtc: fix a infinite loop in windows vm startup
Date: Tue, 25 Jul 2017 09:17:44 +0200	[thread overview]
Message-ID: <713ce91f-d163-8607-ea39-673317b70eed@redhat.com> (raw)
In-Reply-To: <201707251214058120036@zte.com.cn>

On 25/07/2017 06:14, peng.hao2@zte.com.cn wrote:
>> On 24/07/2017 20:35, Peng Hao wrote:
> 
> 
> 
> 
> 
>>> When a windows vm starts, periodic timer of rtc will stop several times.
>>> windows kernel will check whether REG_A_UIP is changed. REG_C's interrupt
>>> flags will not be cleared when periodic timer stops and the update timer
>>> will switch to alarm timer. So the expiration time of alarm timer is very
>>> long and REG_A_UIP will not vary.At last windows kernel will repeat to 
>>> check REG_A_UIP all the time.
> 
>> This should not happen.  REG_A_UIP is set and cleared in register A
>> every second, like this:
>>        case RTC_REG_A:
> 
>>            if (update_in_progress(s)) {
>>                s->cmos_data[s->cmos_index] |= REG_A_UIP
>>            } else {
>>                s->cmos_data[s->cmos_index] &= ~REG_A_UIP
>>            }
>>            ret = s->cmos_data[s->cmos_index]
>>            break
> 
> 
> 
> when periodic timer stop, update timer is set to a long expire time (as alarm timer).

I think I see the bug now:

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 1b8d3d7d4c..6184b4378e 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -321,9 +321,11 @@ static void check_update_timer(RTCState *s)
     s->next_alarm_time = next_update_time +
                          (next_alarm_sec - 1) * NANOSECONDS_PER_SECOND;
 
-    if (s->cmos_data[RTC_REG_C] & REG_C_UF) {
-        /* UF is set, but AF is clear.  Program the timer to target
-         * the alarm time.  */
+    if ((s->cmos_data[RTC_REG_C] & REG_C_UF) &&
+        !(s->cmos_data[RTC_REG_A] & REG_A_UIP)) {
+        /* If UIP was latched, we need to clear it at the next update.
+         * Otherwise, if UF is set we only need to program the timer to
+         * target the alarm time.  */
         next_update_time = s->next_alarm_time;
     }
     if (next_update_time != timer_expire_time_ns(s->update_timer)) {


but I would like to have a testcase for it in tests/rtc-test.c.

Can you check if the above works and try writing a testcase (that fails 
without the patch and succeeds with it)?

Thanks,

Paolo

  reply	other threads:[~2017-07-25  7:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25  4:14 [Qemu-devel] [PATCH V3] rtc: fix a infinite loop in windows vm startup peng.hao2
2017-07-25  7:17 ` Paolo Bonzini [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-07-24 18:35 Peng Hao
2017-07-24 11:53 ` Paolo Bonzini
2017-07-24 11:54 ` Eric Blake

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=713ce91f-d163-8607-ea39-673317b70eed@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=liu.yi24@zte.com.cn \
    --cc=mst@redhat.com \
    --cc=peng.hao2@zte.com.cn \
    --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 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).