Skip to contentSkip to conversation

mc146818rtc: add rtc-reset-reinjection QMP command

PATCH In review Marcelo Tosatti 3 participants 3 messages Jun 24, 2014 – Jun 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mc146818rtc: add rtc-reset-reinjection QMP command

It is necessary to reset RTC interrupt reinjection backlog if guest time is synchronized via a different mechanism, such as QGA's guest-set-time command.

Failing to do so causes both corrections to be applied (summed), resulting in an incorrect guest time.

hw/timer/mc146818rtc.c +18 -0
index 1201f90..5bd8710 100644
@@ -26,6 +26,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
+#include "qmp-commands.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -84,6 +85,7 @@ typedef struct RTCState {
     Notifier clock_reset_notifier;
     LostTickPolicy lost_tick_policy;
     Notifier suspend_notifier;
+    QLIST_ENTRY(RTCState) link;
 } RTCState;
 
 static void rtc_set_time(RTCState *s);
@@ -522,6 +524,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
         rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
 }
 
+static QLIST_HEAD(, RTCState) rtc_devices =
+    QLIST_HEAD_INITIALIZER(rtc_devices);
+
+#ifdef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    RTCState *s;
+
+    QLIST_FOREACH(s, &rtc_devices, link) {
+        s->irq_coalesced = 0;
+    }
+}
+#endif
+
 static void rtc_set_time(RTCState *s)
 {
     struct tm tm;
@@ -910,6 +926,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
     } else {
         isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
     }
+    QLIST_INSERT_HEAD(&rtc_devices, s, link);
+
     return isadev;
 }
 
monitor.c +9 -0
index 2901187..51c9a1d 100644
@@ -5475,3 +5475,12 @@ QemuOptsList qemu_mon_opts = {
         { /* end of list */ }
     },
 };
+
+#ifndef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    error_set(errp, QERR_COMMAND_NOT_FOUND, "rtc-reset-reinjection");
+    return;
+}
+#endif
+
qapi-schema.json +12 -0
index dc2abe4..7e04d28 100644
@@ -3080,3 +3080,15 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @rtc-reset-reinjection
+#
+# This command will reset the RTC interrupt reinjection backlog.
+# Can be used if another mechanism to synchronize guest time
+# is in effect, for example QEMU guest agent's guest-set-time
+# command.
+#
+# Since: 2.1
+##
+{ 'command': 'rtc-reset-reinjection' }
qmp-commands.hx +23 -0
index d6bb0f4..87ce94a 100644
@@ -3574,3 +3574,26 @@ Example:
                    } } ] }
 
 EQMP
+
+#if defined TARGET_I386
+    {
+        .name       = "rtc-reset-reinjection",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
+    },
+#endif
+
+SQMP
+rtc-reset-reinjection
+---------------------
+
+Reset the RTC interrupt reinjection backlog.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "rtc-reset-reinjection" }
+<- { "return": {} }
+
+EQMP
Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · Marcelo Tosatti

It is necessary to reset RTC interrupt reinjection backlog if guest time is synchronized via a different mechanism, such as QGA's guest-set-time command.

Failing to do so causes both corrections to be applied (summed), resulting in an incorrect guest time.

No --- separator? No mention what changed in v3 relative to v2?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Marcelo Tosatti
Quoted 9 lines · Marcelo Tosatti

It is necessary to reset RTC interrupt reinjection backlog if guest time is synchronized via a different mechanism, such as QGA's guest-set-time command.

Failing to do so causes both corrections to be applied (summed), resulting in an incorrect guest time.

Doesn't seem to apply :(

error: patch failed: hw/timer/mc146818rtc.c:26
error: hw/timer/mc146818rtc.c: patch does not apply
error: patch failed: monitor.c:5475
error: monitor.c: patch does not apply
error: patch failed: qapi-schema.json:3080
error: qapi-schema.json: patch does not apply
error: patch failed: qmp-commands.hx:3574
error: qmp-commands.hx: patch does not apply

Quoted 55 lines
hw/timer/mc146818rtc.c +18 -0
index 1201f90..5bd8710 100644
@@ -26,6 +26,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
+#include "qmp-commands.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -84,6 +85,7 @@ typedef struct RTCState {
     Notifier clock_reset_notifier;
     LostTickPolicy lost_tick_policy;
     Notifier suspend_notifier;
+    QLIST_ENTRY(RTCState) link;
 } RTCState;
 
 static void rtc_set_time(RTCState *s);
@@ -522,6 +524,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
         rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
 }
 
+static QLIST_HEAD(, RTCState) rtc_devices =
+    QLIST_HEAD_INITIALIZER(rtc_devices);
+
+#ifdef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    RTCState *s;
+
+    QLIST_FOREACH(s, &rtc_devices, link) {
+        s->irq_coalesced = 0;
+    }
+}
+#endif
+
 static void rtc_set_time(RTCState *s)
 {
     struct tm tm;
@@ -910,6 +926,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
     } else {
         isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
     }
+    QLIST_INSERT_HEAD(&rtc_devices, s, link);
+
     return isadev;
 }
 
monitor.c +0 -0
index 2901187..51c9a1d 100644

monitor.c QemuOptsList qemu_mon_opts = { · line 5482

Quoted 8 lines
monitor.c +5 -0
@@ -5475,3 +5475,12 @@ QemuOptsList qemu_mon_opts = {
         { /* end of list */ }
     },
 };
+
+#ifndef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    error_set(errp, QERR_COMMAND_NOT_FOUND, "rtc-reset-reinjection");

Is there a way to get here on non 386?
If no let's do assert.
If yes, looks more like QERR_FEATURE_DISABLED to me.

monitor.c QemuOptsList qemu_mon_opts = { · line 5483

Quoted 1 line
monitor.c +1 -0
+    return;

return not necessary.

monitor.c QemuOptsList qemu_mon_opts = { · line 5486

Quoted 3 lines
monitor.c +3 -0
+}
+#endif
+

Adds whitespace at EOF.

Quoted 51 lines
qapi-schema.json +12 -0
index dc2abe4..7e04d28 100644
@@ -3080,3 +3080,15 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @rtc-reset-reinjection
+#
+# This command will reset the RTC interrupt reinjection backlog.
+# Can be used if another mechanism to synchronize guest time
+# is in effect, for example QEMU guest agent's guest-set-time
+# command.
+#
+# Since: 2.1
+##
+{ 'command': 'rtc-reset-reinjection' }
qmp-commands.hx +23 -0
index d6bb0f4..87ce94a 100644
@@ -3574,3 +3574,26 @@ Example:
                    } } ] }
 
 EQMP
+
+#if defined TARGET_I386
+    {
+        .name       = "rtc-reset-reinjection",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
+    },
+#endif
+
+SQMP
+rtc-reset-reinjection
+---------------------
+
+Reset the RTC interrupt reinjection backlog.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "rtc-reset-reinjection" }
+<- { "return": {} }
+
+EQMP