Skip to contentSkip to conversation

Add a new -action parameter

PATCH Superseded Alejandro Jimenez 2 participants 8 messages Dec 8, 2020 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add a new -action parameter

This is a follow up to the proposal to add a "-no-panicstop" option to QEMU that would allow us to control whether the VM is paused or allowed to continue running without intervention from a management layer when a guest panic occurs. See the inital thread and replies for details:

https://lore.kernel.org/qemu-devel/[email protected]/

From that discussion came a request for a generic mechanism to group options like -no-shutdown, -no-reboot, etc, that specify an action taken by QEMU in response to a guest event (reboot, shutdown, panic, and watchdog expiration are the current options). The existing options would translate to the new option, like:

* -no-reboot --> "-action reboot=shutdown"
* -no-shutdown --> "-action shutdown=pause"

Please share any questions or comments.

Regards,
Alejandro

Alejandro Jimenez (4):
vl: Add an -action option to respond to guest events
vl: Add option to avoid stopping VM upon guest panic
qmp: Allow setting -action parameters on the fly qtest/pvpanic: Test panic option that allows VM to continue

 MAINTAINERS                      |   2 +
 include/sysemu/runstate-action.h |  16 ++++
 include/sysemu/sysemu.h          |   2 +
 qapi/run-state.json              | 140 +++++++++++++++++++++++++++++++++++
 qemu-options.hx                  |  25 +++++++
 softmmu/meson.build              |   1 +
 softmmu/runstate-action.c        | 153 +++++++++++++++++++++++++++++++++++++++
 softmmu/vl.c                     |  44 ++++++++++-
 tests/qtest/pvpanic-test.c       |  26 ++++++-
 9 files changed, 404 insertions(+), 5 deletions(-)
 create mode 100644 include/sysemu/runstate-action.h
 create mode 100644 softmmu/runstate-action.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 vl: Add an -action option to respond to guest events

Several command line options currently in use are meant to modify the behavior of QEMU in response to certain guest events like:
-no-reboot, -no-shutdown, -watchdog-action.

These can be grouped into a single option of the form:

-action event=action

Which can be used to specify the existing options above in the following format:

-action reboot=none|shutdown
-action shutdown=poweroff|pause
-action watchdog=reset|shutdown|poweroff|pause|debug|none|inject-nmi

This is done in preparation for adding yet another option of this type, which modifies the QEMU behavior when a guest panic occurs.

---
 MAINTAINERS                      |   2 +
 include/sysemu/runstate-action.h |  16 +++++
 include/sysemu/sysemu.h          |   1 +
 qapi/run-state.json              |  88 ++++++++++++++++++++++++++
 qemu-options.hx                  |  22 +++++++
 softmmu/meson.build              |   1 +
 softmmu/runstate-action.c        | 131 +++++++++++++++++++++++++++++++++++++++
 softmmu/vl.c                     |  30 ++++++++-
 8 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 include/sysemu/runstate-action.h
 create mode 100644 softmmu/runstate-action.c
MAINTAINERS +2 -0
index 68bc160..7dcc4bd 100644
@@ -2332,6 +2332,7 @@ M: Paolo Bonzini <[email protected]>
 S: Maintained
 F: include/qemu/main-loop.h
 F: include/sysemu/runstate.h
+F: include/sysemu/runstate-action.h
 F: util/main-loop.c
 F: util/qemu-timer.c
 F: softmmu/vl.c
@@ -2340,6 +2341,7 @@ F: softmmu/cpus.c
 F: softmmu/cpu-throttle.c
 F: softmmu/cpu-timers.c
 F: softmmu/icount.c
+F: softmmu/runstate-action.c
 F: qapi/run-state.json
 
 Read, Copy, Update (RCU)
include/sysemu/runstate-action.h new file +16 -0
new file mode 100644
index 0000000..f545ab3
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef RUNSTATE_ACTION_H
+#define RUNSTATE_ACTION_H
+
+/* in softmmu/runstate-action.c */
+int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp);
+int runstate_action_parse(QemuOptsList *opts_list, const char *optarg);
+
+#endif /* RUNSTATE_ACTION_H */
include/sysemu/sysemu.h +1 -0
index 817ff4c..5480e61 100644
@@ -43,6 +43,7 @@ extern int win2k_install_hack;
 extern int alt_grab;
 extern int ctrl_grab;
 extern int graphic_rotate;
+extern int no_reboot;
 extern int no_shutdown;
 extern int old_param;
 extern int boot_menu;
qapi/run-state.json +88 -0

94 lines not on this page · raw message

qemu-options.hx +22 -0
index 104632e..a0d50f0 100644
@@ -3894,6 +3894,28 @@ SRST
     changes to the disk image.
 ERST
 
+DEF("action", HAS_ARG, QEMU_OPTION_action,
+    "-action reboot=none|shutdown\n"
+    "                   action when guest reboots [default=none]\n"
+    "-action shutdown=poweroff|pause\n"
+    "                   action when guest shuts down [default=poweroff]\n"
+    "-action watchdog=reset|shutdown|poweroff|inject-nmi|pause|debug|none\n"
+    "                   action when watchdog fires [default=reset]\n",
+    QEMU_ARCH_ALL)
+SRST
+``-action event=action``
+    The action parameter serves to modify QEMU's default behavior when
+    certain guest events occur. It provides a generic method for specifying the
+    same behaviors that are modified by the ``-no-reboot`` and ``-no-shutdown``
+    parameters.
+
+    Examples:
+
+    ``-action reboot=shutdown,shutdown=pause``
+    ``-watchdog i6300esb -action watchdog=pause``
+
+ERST
+
 DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \
     "-loadvm [tag|id]\n" \
     "                start right away with a saved state (loadvm in monitor)\n",
softmmu/meson.build +1 -0
index 8f7210b..8ad586e 100644
@@ -10,6 +10,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
   'qtest.c',
   'vl.c',
   'cpu-timers.c',
+  'runstate-action.c',
 )])
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files(
softmmu/runstate-action.c new file +131 -0

131 lines not on this page · raw message

softmmu/vl.c +29 -1
index e6e0ad5..2b1583e 100644
@@ -34,6 +34,7 @@
 #include "qemu/uuid.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
+#include "sysemu/runstate-action.h"
 #include "sysemu/seccomp.h"
 #include "sysemu/tcg.h"
 #include "sysemu/xen.h"
@@ -147,7 +148,7 @@ Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 int win2k_install_hack = 0;
 int singlestep = 0;
 int fd_bootchk = 1;
-static int no_reboot;
+int no_reboot;
 int no_shutdown = 0;
 int graphic_rotate = 0;
 const char *watchdog;
@@ -506,6 +507,21 @@ static QemuOptsList qemu_fw_cfg_opts = {
     },
 };
 
+static QemuOptsList qemu_action_opts = {
+    .name = "action",
+    /*
+     * When lists are merged, the location is set to the first use of the
+     * option. If a subsequent option has an invalid parameter, the error msg
+     * will display the wrong location. Avoid this by not merging the lists.
+     */
+    .merge_lists = false,
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head),
+    .desc = {
+        /* Validation is done when processing the runstate actions */
+        { }
+    },
+};
+
 /**
  * Get machine options
  *
@@ -2948,6 +2964,7 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_icount_opts);
     qemu_add_opts(&qemu_semihosting_config_opts);
     qemu_add_opts(&qemu_fw_cfg_opts);
+    qemu_add_opts(&qemu_action_opts);
     module_call_init(MODULE_INIT_OPTS);
 
     runstate_init();
@@ -3420,6 +3437,12 @@ void qemu_init(int argc, char **argv, char **envp)
                 }
                 watchdog = optarg;
                 break;
+            case QEMU_OPTION_action:
+                if (runstate_action_parse(qemu_find_opts("action"),
+                                            optarg) < 0) {
+                    exit(1);
+                }
+                break;
             case QEMU_OPTION_watchdog_action:
                 if (select_watchdog_action(optarg) == -1) {
                     error_report("unknown -watchdog-action parameter");
@@ -3902,6 +3925,11 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_opts_foreach(qemu_find_opts("name"),
                       parse_name, NULL, &error_fatal);
 
+    if (qemu_opts_foreach(qemu_find_opts("action"),
+                        process_runstate_actions, NULL, &error_fatal)) {
+        exit(1);
+    }
+
 #ifndef _WIN32
     qemu_opts_foreach(qemu_find_opts("add-fd"),
                       parse_add_fd, NULL, &error_fatal);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/4 vl: Add option to avoid stopping VM upon guest panic

In reply to Alejandro Jimenez

The current default action of pausing a guest after a panic event is received leaves the responsibility to resume guest execution to the management layer. The reasons for this behavior are discussed here:
https://lore.kernel.org/qemu-devel/[email protected]/

However, in instances like the case of older guests (Linux and Windows) using a pvpanic device but missing support for the PVPANIC_CRASHLOADED event, and Windows guests using the hv-crash enlightenment, it is desirable to allow the guests to continue running after sending a PVPANIC_PANICKED event. This allows such guests to proceed to capture a crash dump and automatically reboot without intervention of a management layer.

Add an option to avoid stopping a VM after a panic event is received, by passing:

-action panic=none

in the command line arguments, or during runtime by using an upcoming QMP command.

---
 include/sysemu/sysemu.h   |  1 +
 qapi/run-state.json       | 27 ++++++++++++++++++++++++++-
 qemu-options.hx           |  3 +++
 softmmu/runstate-action.c | 22 ++++++++++++++++++++++
 softmmu/vl.c              | 14 +++++++++++---
 5 files changed, 63 insertions(+), 4 deletions(-)
include/sysemu/sysemu.h +1 -0
index 5480e61..863142e 100644
@@ -45,6 +45,7 @@ extern int ctrl_grab;
 extern int graphic_rotate;
 extern int no_reboot;
 extern int no_shutdown;
+extern int pause_on_panic;
 extern int old_param;
 extern int boot_menu;
 extern bool boot_strict;
qapi/run-state.json +26 -1
index 6b033c1..27b62ce 100644
@@ -337,12 +337,14 @@
 #
 # @shutdown: Guest shutdown
 #
+# @panic: Guest has panicked
+#
 # @watchdog: A watchdog device's timer has expired
 #
 # Since: 6.0
 ##
 { 'enum': 'RunStateEventType',
-  'data': [ 'reboot', 'shutdown', 'watchdog' ] }
+  'data': [ 'reboot', 'shutdown', 'panic', 'watchdog' ] }
 
 ##
 # @RunStateAction:
@@ -358,6 +360,7 @@
   'data': {
     'reboot': 'RunStateRebootAction',
     'shutdown': 'RunStateShutdownAction',
+    'panic': 'RunStatePanicAction',
     'watchdog': 'RunStateWatchdogAction' } }
 
 ##
@@ -407,6 +410,28 @@
   'data': [ 'pause', 'poweroff' ] }
 
 ##
+# @RunStatePanicAction:
+#
+# @action: Action taken by QEMU when guest panicks
+#
+# Since: 6.0
+##
+{ 'struct': 'RunStatePanicAction',
+  'data': { 'action': 'PanicAction' } }
+
+##
+# @PanicAction:
+#
+# @none: Continue VM execution
+#
+# @pause: Pause the VM
+#
+# Since: 6.0
+##
+{ 'enum': 'PanicAction',
+  'data': [ 'none', 'pause' ] }
+
+##
 # @RunStateWatchdogAction:
 #
 # @action: Action taken by QEMU when watchdog device timer expires
qemu-options.hx +3 -0
index a0d50f0..8b7d8bb 100644
@@ -3899,6 +3899,8 @@ DEF("action", HAS_ARG, QEMU_OPTION_action,
     "                   action when guest reboots [default=none]\n"
     "-action shutdown=poweroff|pause\n"
     "                   action when guest shuts down [default=poweroff]\n"
+    "-action panic=pause|none\n"
+    "                   action when guest panics [default=pause]\n"
     "-action watchdog=reset|shutdown|poweroff|inject-nmi|pause|debug|none\n"
     "                   action when watchdog fires [default=reset]\n",
     QEMU_ARCH_ALL)
@@ -3911,6 +3913,7 @@ SRST
 
     Examples:
 
+    ``-action panic=none``
     ``-action reboot=shutdown,shutdown=pause``
     ``-watchdog i6300esb -action watchdog=pause``
 
softmmu/runstate-action.c +22 -0
index bbbbc07..9c92595 100644
@@ -62,6 +62,24 @@ static void qmp_shutdown_set_action(ShutdownAction act, Error **errp)
 }
 
 /*
+ * Set the internal state to react to a guest panic event
+ * as specified by the action parameter.
+ */
+static void qmp_panic_set_action(PanicAction action, Error **errp)
+{
+    switch (action) {
+    case PANIC_ACTION_NONE:
+        pause_on_panic = 0;
+        break;
+    case PANIC_ACTION_PAUSE:
+        pause_on_panic = 1;
+        break;
+    default:
+        g_assert_not_reached();
+    }
+}
+
+/*
  * Process an event|action pair and set the appropriate internal
  * state if event and action are valid.
  */
@@ -81,6 +99,10 @@ static int set_runstate_action(void *opaque, const char *event,
         act_idx = qapi_enum_parse(&ShutdownAction_lookup, action, -1, errp);
         qmp_shutdown_set_action(act_idx, NULL);
         break;
+    case RUN_STATE_EVENT_TYPE_PANIC:
+        act_idx = qapi_enum_parse(&PanicAction_lookup, action, -1, errp);
+        qmp_panic_set_action(act_idx, NULL);
+        break;
     case RUN_STATE_EVENT_TYPE_WATCHDOG:
         if (select_watchdog_action(action) == -1) {
             error_report("unknown watchdog action parameter");
softmmu/vl.c +11 -3
index 2b1583e..20f89cb 100644
@@ -150,6 +150,7 @@ int singlestep = 0;
 int fd_bootchk = 1;
 int no_reboot;
 int no_shutdown = 0;
+int pause_on_panic = 1;
 int graphic_rotate = 0;
 const char *watchdog;
 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
@@ -1449,9 +1450,16 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
     if (current_cpu) {
         current_cpu->crash_occurred = true;
     }
-    qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
-                                   !!info, info);
-    vm_stop(RUN_STATE_GUEST_PANICKED);
+
+    if (pause_on_panic) {
+        qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE,
+                                        !!info, info);
+        vm_stop(RUN_STATE_GUEST_PANICKED);
+    } else {
+        qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_RUN,
+                                        !!info, info);
+    }
+
     if (!no_shutdown) {
         qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
                                        !!info, info);
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/4 qmp: Allow setting -action parameters on the fly

In reply to Alejandro Jimenez

Add QMP commands to allow for the behaviors specified by the -action event=action command line option to be set at runtime, mimicking the watchdog-set-action QMP command.

---
 qapi/run-state.json       | 27 +++++++++++++++++++++++++++
 softmmu/runstate-action.c |  6 +++---
 2 files changed, 30 insertions(+), 3 deletions(-)
qapi/run-state.json +27 -0
index 27b62ce..de27516 100644
@@ -451,6 +451,33 @@
 { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
 
 ##
+# @reboot-set-action:
+#
+# Set reboot action
+#
+# Since: 6.0
+##
+{ 'command': 'reboot-set-action', 'data' : {'action': 'RebootAction'} }
+
+##
+# @shutdown-set-action:
+#
+# Set shutdown action
+#
+# Since: 6.0
+##
+{ 'command': 'shutdown-set-action', 'data' : {'action': 'ShutdownAction'} }
+
+##
+# @panic-set-action:
+#
+# Set panic action
+#
+# Since: 6.0
+##
+{ 'command': 'panic-set-action', 'data' : {'action': 'PanicAction'} }
+
+##
 # @GUEST_PANICKED:
 #
 # Emitted when guest OS panic is detected
softmmu/runstate-action.c +3 -3
index 9c92595..aef23b8 100644
@@ -29,7 +29,7 @@ static void runstate_action_help(void)
  * Set the internal state to react to a guest reboot event
  * as specified by the action parameter.
  */
-static void qmp_reboot_set_action(RebootAction act, Error **errp)
+void qmp_reboot_set_action(RebootAction act, Error **errp)
 {
     switch (act) {
     case REBOOT_ACTION_NONE:
@@ -47,7 +47,7 @@ static void qmp_reboot_set_action(RebootAction act, Error **errp)
  * Set the internal state to react to a guest shutdown event
  * as specified by the action parameter.
  */
-static void qmp_shutdown_set_action(ShutdownAction act, Error **errp)
+void qmp_shutdown_set_action(ShutdownAction act, Error **errp)
 {
     switch (act) {
     case SHUTDOWN_ACTION_PAUSE:
@@ -65,7 +65,7 @@ static void qmp_shutdown_set_action(ShutdownAction act, Error **errp)
  * Set the internal state to react to a guest panic event
  * as specified by the action parameter.
  */
-static void qmp_panic_set_action(PanicAction action, Error **errp)
+void qmp_panic_set_action(PanicAction action, Error **errp)
 {
     switch (action) {
     case PANIC_ACTION_NONE:
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH 3/4] qmp: Allow setting -action parameters on the fly

Quoted 18 lines · Alejandro Jimenez

##

qapi/run-state.json +17 -0
+# @reboot-set-action:
+#
+# Set reboot action
+#
+# Since: 6.0
+##
+{ 'command': 'reboot-set-action', 'data' : {'action': 'RebootAction'} }
+
+##
+# @shutdown-set-action:
+#
+# Set shutdown action
+#
+# Since: 6.0
+##
+{ 'command': 'shutdown-set-action', 'data' : {'action': 'ShutdownAction'} }
+

qapi/run-state.json line 480

Quoted 10 lines
qapi/run-state.json +10 -0
+##
+# @panic-set-action:
+#
+# Set panic action
+#
+# Since: 6.0
+##
+{ 'command': 'panic-set-action', 'data' : {'action': 'PanicAction'} }
+
+##

What about a single action-set command with arguments reboot, shutdown and panic?

Paolo

#5 lore raw

Re: [PATCH 3/4] qmp: Allow setting -action parameters on the fly

Quoted 24 lines · Paolo Bonzini
Quoted 23 lines · Alejandro Jimenez

  ##

qapi/run-state.json +16 -0
+# @reboot-set-action:
+#
+# Set reboot action
+#
+# Since: 6.0
+##
+{ 'command': 'reboot-set-action', 'data' : {'action': 'RebootAction'} }
+
+##
+# @shutdown-set-action:
+#
+# Set shutdown action
+#
+# Since: 6.0
+##
+{ 'command': 'shutdown-set-action', 'data' : {'action': 

'ShutdownAction'} }

qapi/run-state.json +5 -0
+
+##
+# @panic-set-action:
+#
+# Set panic action
Quoted 8 lines

qapi/run-state.json line 480

Quoted 6 lines
qapi/run-state.json +6 -0
+#
+# Since: 6.0
+##
+{ 'command': 'panic-set-action', 'data' : {'action': 'PanicAction'} }
+
+##

What about a single action-set command with arguments reboot, shutdown and panic?

(and watchdog, of course)?

Paolo

#6 lore raw

Re: [PATCH 3/4] qmp: Allow setting -action parameters on the fly

Quoted 35 lines · Paolo Bonzini
Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Alejandro Jimenez

  ##

qapi/run-state.json +7 -0
+# @reboot-set-action:
+#
+# Set reboot action
+#
+# Since: 6.0
+##
+{ 'command': 'reboot-set-action', 'data' : {'action': 

'RebootAction'} }

qapi/run-state.json +9 -0
+
+##
+# @shutdown-set-action:
+#
+# Set shutdown action
+#
+# Since: 6.0
+##
+{ 'command': 'shutdown-set-action', 'data' : {'action': 

'ShutdownAction'} }

qapi/run-state.json +5 -0
+
+##
+# @panic-set-action:
+#
+# Set panic action
Quoted 8 lines

qapi/run-state.json line 480

Quoted 6 lines
qapi/run-state.json +6 -0
+#
+# Since: 6.0
+##
+{ 'command': 'panic-set-action', 'data' : {'action': 'PanicAction'} }
+
+##

What about a single action-set command with arguments reboot, shutdown and panic?

Quoted 1 line

(and watchdog, of course)?

Just to make sure I understand the request: an action-set QMP command would need to take two arguments: an event (reboot|shutdown|panic|watchdog), and a valid action for that event type, akin to what set_runstate_action() does. I'll work on it.

Alejandro

Quoted 2 lines

Paolo

#7 lore raw

PATCH 4/4 qtest/pvpanic: Test panic option that allows VM to continue

In reply to Alejandro Jimenez

Test the scenario where the -action panic=none parameter is used to signal that the VM must continue executing after a guest panic occurs.

---
 tests/qtest/pvpanic-test.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
tests/qtest/pvpanic-test.c +25 -1
index 016b32e..6dcad2d 100644
@@ -11,13 +11,36 @@
 #include "libqos/libqtest.h"
 #include "qapi/qmp/qdict.h"
 
+static void test_panic_nopause(void)
+{
+    uint8_t val;
+    QDict *response, *data;
+    QTestState *qts;
+
+    qts = qtest_init("-device pvpanic -action panic=none");
+
+    val = qtest_inb(qts, 0x505);
+    g_assert_cmpuint(val, ==, 3);
+
+    qtest_outb(qts, 0x505, 0x1);
+
+    response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED");
+    g_assert(qdict_haskey(response, "data"));
+    data = qdict_get_qdict(response, "data");
+    g_assert(qdict_haskey(data, "action"));
+    g_assert_cmpstr(qdict_get_str(data, "action"), ==, "run");
+    qobject_unref(response);
+
+    qtest_quit(qts);
+}
+
 static void test_panic(void)
 {
     uint8_t val;
     QDict *response, *data;
     QTestState *qts;
 
-    qts = qtest_init("-device pvpanic");
+    qts = qtest_init("-device pvpanic -action panic=pause");
 
     val = qtest_inb(qts, 0x505);
     g_assert_cmpuint(val, ==, 3);
@@ -40,6 +63,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/pvpanic/panic", test_panic);
+    qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause);
 
     ret = g_test_run();
 
Signature · 1 line
1.8.3.1