Add a new -action parameter
v3 cover Add a new -action parameter
v3:
- Replaced the no_reboot and no_shutdown internal flags with enumerations that hold the current action selected in case of reboot or shutdown events. The same approach is used for panic and watchdog events.
- Ensured that -no-shutdown option overrides any previously issued action panic=poweroff setting.
- Added TODO comment to add more panic actions if viable (debug, reset).
- Modified QMP command to take multiple optional args specifying actions for each event type, and added 'allow-preconfig': true
v2:
- Replaced the individual qmp commands in patch 3/4 for a generic set-action command that takes a RunStateAction parameter, specifying an event|action pair.
- Removed qmp_ prefix from X_set_action() functions in runstate-action.c
***
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 | 22 ++++++ include/sysemu/sysemu.h | 1 - monitor/qmp-cmds.c | 3 +- qapi/run-state.json | 149 +++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 25 +++++++ softmmu/meson.build | 1 + softmmu/runstate-action.c | 142 +++++++++++++++++++++++++++++++++++++ softmmu/vl.c | 64 ++++++++++++++--- tests/qtest/pvpanic-test.c | 26 ++++++- ui/sdl2.c | 5 +- 11 files changed, 424 insertions(+), 16 deletions(-) create mode 100644 include/sysemu/runstate-action.h create mode 100644 softmmu/runstate-action.c
Signature · 1 line
1.8.3.1
PATCH v3 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 | 21 +++++++++ include/sysemu/sysemu.h | 1 - monitor/qmp-cmds.c | 3 +- qapi/run-state.json | 90 +++++++++++++++++++++++++++++++++++++ qemu-options.hx | 22 +++++++++ softmmu/meson.build | 1 + softmmu/runstate-action.c | 96 ++++++++++++++++++++++++++++++++++++++++ softmmu/vl.c | 43 ++++++++++++++---- ui/sdl2.c | 5 ++- 10 files changed, 272 insertions(+), 12 deletions(-) create mode 100644 include/sysemu/runstate-action.h create mode 100644 softmmu/runstate-action.c
MAINTAINERS +2 -0
@@ -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 +21 -0
@@ -0,0 +1,21 @@ +/* +* 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 + +#include "qapi/qapi-commands-run-state.h" + +/* in softmmu/runstate-action.c */ +extern RebootAction reboot_action; +extern ShutdownAction shutdown_action; + +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 +0 -1
@@ -43,7 +43,6 @@ extern int win2k_install_hack;extern int alt_grab;extern int ctrl_grab;extern int graphic_rotate; -extern int no_shutdown;extern int old_param;extern int boot_menu;extern bool boot_strict;
monitor/qmp-cmds.c +2 -1
@@ -26,6 +26,7 @@#include "ui/vnc.h" #include "sysemu/kvm.h" #include "sysemu/runstate.h" +#include "sysemu/runstate-action.h" #include "sysemu/arch_init.h" #include "sysemu/blockdev.h" #include "sysemu/block-backend.h"
@@ -72,7 +73,7 @@ UuidInfo *qmp_query_uuid(Error **errp)void qmp_quit (Error **errp) { - no_shutdown =0 ; + shutdown_action =SHUTDOWN_ACTION_POWEROFF ;qemu_system_shutdown_request (SHUTDOWN_CAUSE_HOST_QMP_QUIT ); }
qapi/run-state.json +90 -0
96 lines not on this page · raw message
qemu-options.hx +22 -0
@@ -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
@@ -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 +96 -0
96 lines not on this page · raw message
softmmu/vl.c +35 -8
111 lines not on this page · raw message
ui/sdl2.c +3 -2
@@ -30,6 +30,7 @@#include "ui/input.h" #include "ui/sdl2.h" #include "sysemu/runstate.h" +#include "sysemu/runstate-action.h" #include "sysemu/sysemu.h" #include "ui/win32-kbd-hook.h"
@@ -604,7 +605,7 @@ static void handle_windowevent(SDL_Event *ev) allow_close = false; }if (allow_close) { - no_shutdown =0 ; + shutdown_action =SHUTDOWN_ACTION_POWEROFF ;qemu_system_shutdown_request (SHUTDOWN_CAUSE_HOST_UI ); } }else {
@@ -651,7 +652,7 @@ void sdl2_poll_events(struct sdl2_console *scon) allow_close = false; }if (allow_close) { - no_shutdown =0 ; + shutdown_action =SHUTDOWN_ACTION_POWEROFF ;qemu_system_shutdown_request (SHUTDOWN_CAUSE_HOST_UI ); }break ;
Signature · 1 line
1.8.3.1
PATCH v3 2/4 vl: Add option to avoid stopping VM upon guest panic
In reply to Alejandro JimenezThe 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/runstate-action.h | 1 + qapi/run-state.json | 27 ++++++++++++++++++++++++++- qemu-options.hx | 3 +++ softmmu/runstate-action.c | 17 +++++++++++++++++ softmmu/vl.c | 23 +++++++++++++++++++---- 5 files changed, 66 insertions(+), 5 deletions(-)
include/sysemu/runstate-action.h +1 -0
@@ -14,6 +14,7 @@/* in softmmu/runstate-action.c */ extern RebootAction reboot_action;extern ShutdownAction shutdown_action; +extern PanicAction panic_action;int process_runstate_actions (void *opaque,QemuOpts *opts,Error **errp);int runstate_action_parse (QemuOptsList *opts_list,const char *optarg);
qapi/run-state.json +26 -1
@@ -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' } } ##
@@ -409,6 +412,28 @@ 'data': [ 'poweroff', 'pause' ] } ## +# @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': [ 'poweroff', 'pause', 'none' ] } + +## # @RunStateWatchdogAction: # # @action: Action taken by QEMU when watchdog device timer expires
qemu-options.hx +3 -0
@@ -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=poweroff|pause|none\n" + " action when guest panics [default=poweroff]\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 +17 -0
@@ -15,6 +15,7 @@RebootAction reboot_action =REBOOT_ACTION_NONE ;ShutdownAction shutdown_action =SHUTDOWN_ACTION_POWEROFF ; +PanicAction panic_action =PANIC_ACTION_POWEROFF ;static void runstate_action_help (void ) {
@@ -27,6 +28,18 @@ static void runstate_action_help(void) }/* +* When -no-shutdown is requested either explicitly or by using its equivalent +* -action option, the request should be honored even if a panic occurs. +*/ +static void fix_panic_action (void ) +{ +if (shutdown_action ==SHUTDOWN_ACTION_PAUSE && + panic_action ==PANIC_ACTION_POWEROFF ) { + panic_action =PANIC_ACTION_PAUSE ; + } +} + +/* * Process an event|action pair and set the appropriate internal * state if event and action are valid. */
@@ -45,6 +58,10 @@ static int set_runstate_action(void *opaque, const char *event,case RUN_STATE_EVENT_TYPE_SHUTDOWN : shutdown_action =qapi_enum_parse (&ShutdownAction_lookup, action,-1 , errp); +fix_panic_action (); +break ; +case RUN_STATE_EVENT_TYPE_PANIC : + panic_action =qapi_enum_parse (&PanicAction_lookup, action,-1 , errp);break ;case RUN_STATE_EVENT_TYPE_WATCHDOG :if (select_watchdog_action (action) ==-1 ) {
softmmu/vl.c +19 -4
@@ -1447,10 +1447,21 @@ 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 (shutdown_action ==SHUTDOWN_ACTION_POWEROFF ) { +/* +* TODO: Currently the available panic actions are: none, pause, and +* poweroff, but in principle debug and reset could be supported as well. +* Investigate any potential use cases for the unimplemented actions. +*/ +if (panic_action !=PANIC_ACTION_NONE ) { +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 (panic_action ==PANIC_ACTION_POWEROFF ) {qapi_event_send_guest_panicked (GUEST_PANIC_ACTION_POWEROFF , !!info, info);qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_PANIC );
@@ -3591,6 +3602,10 @@ void qemu_init(int argc, char **argv, char **envp)break ;case QEMU_OPTION_no_shutdown: shutdown_action =SHUTDOWN_ACTION_PAUSE ; +/* no_shutdown is requested, also honor it if guest panics */ +if (panic_action ==PANIC_ACTION_POWEROFF ) { + panic_action =PANIC_ACTION_PAUSE ; + }break ;case QEMU_OPTION_show_cursor: warn_report("The -show-cursor option is deprecated. Please "
Signature · 1 line
1.8.3.1
PATCH v3 3/4 qmp: Allow setting -action parameters on the fly
In reply to Alejandro JimenezAdd a QMP command to allow for the behaviors specified by the -action event=action command line option to be set at runtime. The new command is named set-action and takes optional arguments with an event and a corresponding action to take.
Example:
-> { "execute": "set-action",
"arguments": {
"reboot": "none",
"shutdown": "poweroff",
"panic": "none",
"watchdog": "debug" } }<- { "return": {} }
--- qapi/run-state.json | 34 ++++++++++++++++++++++++++++++++++ softmmu/runstate-action.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
qapi/run-state.json +34 -0
@@ -453,6 +453,40 @@ { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} } ## +# @set-action: +# +# Set the actions that will be taken by the emulator in response to guest +# events. +# +# @reboot: @RebootAction action taken on guest reboot. +# +# @shutdown: @ShutdownAction action taken on guest shutdown. +# +# @panic: @PanicAction action taken on guest panic. +# +# @watchdog: @WatchdogAction action taken when watchdog timer expires . +# +# Returns: Nothing on success. +# +# Since: 6.0 +# +# Example: +# +# -> { "execute": "set-action", +# "arguments": { "reboot": "shutdown", +# "shutdown" : "pause", +# "panic": "pause", +# "watchdog": "inject-nmi" } } +# <- { "return": {} } +## +{ 'command': 'set-action', + 'data': { '*reboot': 'RebootAction', + '*shutdown': 'ShutdownAction', + '*panic': 'PanicAction', + '*watchdog': 'WatchdogAction' }, + 'allow-preconfig': true } + +## # @GUEST_PANICKED: # # Emitted when guest OS panic is detected
softmmu/runstate-action.c +29 -0
@@ -40,6 +40,35 @@ static void fix_panic_action(void) }/* +* Receives actions to be applied for specific guest events +* and sets the internal state as requested. +*/ +void qmp_set_action (bool has_reboot,RebootAction reboot, +bool has_shutdown,ShutdownAction shutdown, +bool has_panic,PanicAction panic, +bool has_watchdog,WatchdogAction watchdog, +Error **errp) +{ +if (has_reboot) { + reboot_action = reboot; + } + +if (has_panic) { + panic_action = panic; + } + +if (has_watchdog) { +qmp_watchdog_set_action (watchdog, errp); + } + +/* Process shutdown last, in case the panic action needs to be altered */ +if (has_shutdown) { + shutdown_action = shutdown; +fix_panic_action (); + } +} + +/* * Process an event|action pair and set the appropriate internal * state if event and action are valid. */
Signature · 1 line
1.8.3.1
PATCH v3 4/4 qtest/pvpanic: Test panic option that allows VM to continue
In reply to Alejandro JimenezTest 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
@@ -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
Quoted 6 lines · Alejandro Jimenez
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:
Quoted 8 lines
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.
Thanks, this looks good.
(Actually there are a bunch of changes needed for other patches that I have queued, but I can take care of that. Basically, I am moving command line parsing from softmmu/runstate-action.c to softmmu/vl.c because we're trying to move all command line stuff there + in turn make vl.c use QMP commands as much as possible).
Paolo