From nobody Thu May 16 04:25:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1607705852; cv=none; d=zohomail.com; s=zohoarc; b=Hc/k60sx9vHwZUr9I1pAefUtkcCaNQD1K5MvVLnlkrUwOXMvQlaI73D7aIt4ErxevVuR3+IuHCEVxmai9Wvup9ask8FoLNvZ9TEDTmzEDXB1j+ZXaOJljXisQJ3Y0WpK5pZJ9hi5LfMx+5Bk0mtSMLvJ+tCuTCzODr6VXnhN0Hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607705852; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=8ChdizvACFhuk6mPTEHvVn7Easr+CrNglEF9DDcvX+k=; b=STuOLV2FZSy/zvqYGs59yfsxzL6FE0DaxFrHxdQeolBnySFZwX+QdRmQ7v8oltTNwrEDKgf1CBtu8/gIVu3T4JySVkxqLeu12jjG1xfz3kHqdG02oR5cEKv6GFrpwHPACe5bzL6A5/ww9nGycO7Os8jKQ0KiSFj4djoJE57JCWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607705852115697.8005008245034; Fri, 11 Dec 2020 08:57:32 -0800 (PST) Received: from localhost ([::1]:37900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knljW-00038P-3g for importer@patchew.org; Fri, 11 Dec 2020 11:57:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlh4-0001DN-RN for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:54:59 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:43906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlgy-00053I-Du for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:54:58 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGrS0X005959; Fri, 11 Dec 2020 16:54:51 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 35825mkm65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Dec 2020 16:54:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGiwQv135614; Fri, 11 Dec 2020 16:52:50 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 358kstp4qn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Dec 2020 16:52:50 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BBGqoMK010201; Fri, 11 Dec 2020 16:52:50 GMT Received: from ban25x6uut148.us.oracle.com (/10.153.73.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Dec 2020 08:52:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=8ChdizvACFhuk6mPTEHvVn7Easr+CrNglEF9DDcvX+k=; b=GEk7LYM4IWTUS9lPwKin95goUpbFD3pvne/G0eeRz8tFyoTQsflZKvfIA6ppWzp3uoP0 Ihb3Fn8lXjh66U8he/jgPaK5IKxvMM2SE4IvcknUPT0nIAQHba4zY17w6P0dxNo+CkLf W4VFPNQV7MlDlxpUv5Lr+1yD3flQzbDaH0DpvAymEBHz2p80ojGHoYrP2NVpQRfFjgZB qv07hzr0Nc1jp3jDYg8OLdMXraRnIXBfoEsOOFjzsfZ5fVCX7yz9JoMI5BeJIw8dk4hC qKrhq9JzCzD8yxKa84RtJSKaHMAl0aUas43M/iNy4Y0goXBiMdmEJ+6Yt28IA0eZrTdq kg== From: Alejandro Jimenez To: qemu-devel@nongnu.org Subject: [PATCH v3 1/4] vl: Add an -action option to respond to guest events Date: Fri, 11 Dec 2020 11:52:41 -0500 Message-Id: <1607705564-26264-2-git-send-email-alejandro.j.jimenez@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> References: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=1 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 mlxscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110113 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=alejandro.j.jimenez@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david.edmondson@oracle.com, pbonzini@redhat.com, mihai.carabas@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3Daction Which can be used to specify the existing options above in the following format: -action reboot=3Dnone|shutdown -action shutdown=3Dpoweroff|pause -action watchdog=3Dreset|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. Suggested-by: Paolo Bonzini Signed-off-by: Alejandro Jimenez --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index 68bc160..7dcc4bd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2332,6 +2332,7 @@ M: Paolo Bonzini 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 =20 Read, Copy, Update (RCU) diff --git a/include/sysemu/runstate-action.h b/include/sysemu/runstate-act= ion.h new file mode 100644 index 0000000..dba4b85 --- /dev/null +++ b/include/sysemu/runstate-action.h @@ -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 */ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 817ff4c..dd6897f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -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; diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index a08143b..3589550 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -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) =20 void qmp_quit(Error **errp) { - no_shutdown =3D 0; + shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT); } =20 diff --git a/qapi/run-state.json b/qapi/run-state.json index 964c8ef..7d8ce61 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -329,6 +329,96 @@ 'inject-nmi' ] } =20 ## +# @RunStateEventType: +# +# An enumeration of Run State event types +# +# @reboot: Guest reboot +# +# @shutdown: Guest shutdown +# +# @watchdog: A watchdog device's timer has expired +# +# Since: 6.0 +## +{ 'enum': 'RunStateEventType', + 'data': [ 'reboot', 'shutdown', 'watchdog' ] } + +## +# @RunStateAction: +# +# Describes a guest event and the subsequent action that is taken +# by QEMU when such event takes place. +# +# Since: 6.0 +## +{ 'union': 'RunStateAction', + 'base': { 'event': 'RunStateEventType' }, + 'discriminator': 'event', + 'data': { + 'reboot': 'RunStateRebootAction', + 'shutdown': 'RunStateShutdownAction', + 'watchdog': 'RunStateWatchdogAction' } } + +## +# @RunStateRebootAction: +# +# @action: Action taken by QEMU when guest reboots +# +# Since: 6.0 +## +{ 'struct': 'RunStateRebootAction', + 'data': { 'action': 'RebootAction' } } + +## +# @RebootAction: +# +# Possible QEMU actions upon guest reboot +# +# @none: Reset the VM +# +# @shutdown: Shutdown the VM and exit +# +# Since: 6.0 +## +{ 'enum': 'RebootAction', + 'data': [ 'none', 'shutdown' ] } + +## +# @RunStateShutdownAction: +# +# @action: Action taken by QEMU when guest shuts down +# +# Since: 6.0 +## +{ 'struct': 'RunStateShutdownAction', + 'data': { 'action': 'ShutdownAction' } } + +## +# @ShutdownAction: +# +# Possible QEMU actions upon guest shutdown +# +# @poweroff: Shutdown the VM and exit +# +# @pause: pause the VM# +# +# Since: 6.0 +## +{ 'enum': 'ShutdownAction', + 'data': [ 'poweroff', 'pause' ] } + +## +# @RunStateWatchdogAction: +# +# @action: Action taken by QEMU when watchdog device timer expires +# +# Since: 6.0 +## +{ 'struct': 'RunStateWatchdogAction', + 'data': { 'action': 'WatchdogAction' } } + +## # @watchdog-set-action: # # Set watchdog action diff --git a/qemu-options.hx b/qemu-options.hx index 104632e..a0d50f0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3894,6 +3894,28 @@ SRST changes to the disk image. ERST =20 +DEF("action", HAS_ARG, QEMU_OPTION_action, + "-action reboot=3Dnone|shutdown\n" + " action when guest reboots [default=3Dnone]\n" + "-action shutdown=3Dpoweroff|pause\n" + " action when guest shuts down [default=3Dpoweroff]\= n" + "-action watchdog=3Dreset|shutdown|poweroff|inject-nmi|pause|debug|non= e\n" + " action when watchdog fires [default=3Dreset]\n", + QEMU_ARCH_ALL) +SRST +``-action event=3Daction`` + The action parameter serves to modify QEMU's default behavior when + certain guest events occur. It provides a generic method for specifyin= g the + same behaviors that are modified by the ``-no-reboot`` and ``-no-shutd= own`` + parameters. + + Examples: + + ``-action reboot=3Dshutdown,shutdown=3Dpause`` + ``-watchdog i6300esb -action watchdog=3Dpause`` + +ERST + DEF("loadvm", HAS_ARG, QEMU_OPTION_loadvm, \ "-loadvm [tag|id]\n" \ " start right away with a saved state (loadvm in monito= r)\n", diff --git a/softmmu/meson.build b/softmmu/meson.build index 8f7210b..8ad586e 100644 --- a/softmmu/meson.build +++ b/softmmu/meson.build @@ -10,6 +10,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'qtest.c', 'vl.c', 'cpu-timers.c', + 'runstate-action.c', )]) =20 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files( diff --git a/softmmu/runstate-action.c b/softmmu/runstate-action.c new file mode 100644 index 0000000..5eae320 --- /dev/null +++ b/softmmu/runstate-action.c @@ -0,0 +1,96 @@ +/* + * 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. + * + */ + +#include "qemu/osdep.h" +#include "sysemu/runstate-action.h" +#include "sysemu/watchdog.h" +#include "qemu/config-file.h" +#include "qapi/error.h" +#include "qemu/option_int.h" + +RebootAction reboot_action =3D REBOOT_ACTION_NONE; +ShutdownAction shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; + +static void runstate_action_help(void) +{ + int idx; + + printf("Events for which an action can be specified:\n"); + for (idx =3D 0; idx < RUN_STATE_EVENT_TYPE__MAX; idx++) { + printf("%10s\n", RunStateEventType_str(idx)); + } +} + +/* + * Process an event|action pair and set the appropriate internal + * state if event and action are valid. + */ +static int set_runstate_action(void *opaque, const char *event, + const char *action, Error **errp) +{ + int event_idx; + + event_idx =3D qapi_enum_parse(&RunStateEventType_lookup, event, -1, er= rp); + + switch (event_idx) { + case RUN_STATE_EVENT_TYPE_REBOOT: + reboot_action =3D qapi_enum_parse(&RebootAction_lookup, + action, -1, errp); + break; + case RUN_STATE_EVENT_TYPE_SHUTDOWN: + shutdown_action =3D qapi_enum_parse(&ShutdownAction_lookup, + action, -1, errp); + break; + case RUN_STATE_EVENT_TYPE_WATCHDOG: + if (select_watchdog_action(action) =3D=3D -1) { + error_report("invalid parameter value: %s", action); + exit(1); + } + break; + default: + /* + * The event and action types are checked for validity in the call= s to + * qapi_enum_parse(), which will cause an exit if the requested ev= ent or + * action are invalid, since error_fatal is used as the error para= meter. + * This case is unreachable unless those conditions change. + */ + g_assert_not_reached(); + } + + return 0; +} + +/* + * Parse provided -action arguments from cmdline. + */ +int runstate_action_parse(QemuOptsList *opts_list, const char *optarg) +{ + QemuOpts *opts; + + if (!strcmp(optarg, "help")) { + runstate_action_help(); + return -1; + } + + opts =3D qemu_opts_parse_noisily(opts_list, optarg, false); + if (!opts) { + return -1; + } + return 0; +} + +/* + * Process all the -action parameters parsed from cmdline. + */ +int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp) +{ + if (qemu_opt_foreach(opts, set_runstate_action, NULL, errp)) { + return -1; + } + return 0; +} diff --git a/softmmu/vl.c b/softmmu/vl.c index e6e0ad5..35575a1 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -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,8 +148,6 @@ Chardev *parallel_hds[MAX_PARALLEL_PORTS]; int win2k_install_hack =3D 0; int singlestep =3D 0; int fd_bootchk =3D 1; -static int no_reboot; -int no_shutdown =3D 0; int graphic_rotate =3D 0; const char *watchdog; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; @@ -506,6 +505,21 @@ static QemuOptsList qemu_fw_cfg_opts =3D { }, }; =20 +static QemuOptsList qemu_action_opts =3D { + .name =3D "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 list= s. + */ + .merge_lists =3D false, + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head), + .desc =3D { + /* Validation is done when processing the runstate actions */ + { } + }, +}; + /** * Get machine options * @@ -1436,7 +1450,7 @@ void qemu_system_guest_panicked(GuestPanicInformation= *info) qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, !!info, info); vm_stop(RUN_STATE_GUEST_PANICKED); - if (!no_shutdown) { + if (shutdown_action =3D=3D SHUTDOWN_ACTION_POWEROFF) { qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF, !!info, info); qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC); @@ -1477,7 +1491,8 @@ void qemu_system_guest_crashloaded(GuestPanicInformat= ion *info) =20 void qemu_system_reset_request(ShutdownCause reason) { - if (no_reboot && reason !=3D SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { + if (reboot_action =3D=3D REBOOT_ACTION_SHUTDOWN && + reason !=3D SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { shutdown_requested =3D reason; } else { reset_requested =3D reason; @@ -1554,7 +1569,7 @@ void qemu_system_killed(int signal, pid_t pid) { shutdown_signal =3D signal; shutdown_pid =3D pid; - no_shutdown =3D 0; + shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; =20 /* Cannot call qemu_system_shutdown_request directly because * we are in a signal handler. @@ -1628,7 +1643,7 @@ static bool main_loop_should_exit(void) if (request) { qemu_kill_report(); qemu_system_shutdown(request); - if (no_shutdown) { + if (shutdown_action =3D=3D SHUTDOWN_ACTION_PAUSE) { vm_stop(RUN_STATE_SHUTDOWN); } else { return true; @@ -2948,6 +2963,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); =20 runstate_init(); @@ -3420,6 +3436,12 @@ void qemu_init(int argc, char **argv, char **envp) } watchdog =3D 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) =3D=3D -1) { error_report("unknown -watchdog-action parameter"); @@ -3565,10 +3587,10 @@ void qemu_init(int argc, char **argv, char **envp) qemu_opts_parse_noisily(olist, "hpet=3Doff", false); break; case QEMU_OPTION_no_reboot: - no_reboot =3D 1; + reboot_action =3D REBOOT_ACTION_SHUTDOWN; break; case QEMU_OPTION_no_shutdown: - no_shutdown =3D 1; + shutdown_action =3D SHUTDOWN_ACTION_PAUSE; break; case QEMU_OPTION_show_cursor: warn_report("The -show-cursor option is deprecated. Please= " @@ -3902,6 +3924,11 @@ void qemu_init(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, &error_fatal); =20 + 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); diff --git a/ui/sdl2.c b/ui/sdl2.c index 189d26e..993c311 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -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" =20 @@ -604,7 +605,7 @@ static void handle_windowevent(SDL_Event *ev) allow_close =3D false; } if (allow_close) { - no_shutdown =3D 0; + shutdown_action =3D 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 =3D false; } if (allow_close) { - no_shutdown =3D 0; + shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI); } break; --=20 1.8.3.1 From nobody Thu May 16 04:25:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1607705750; cv=none; d=zohomail.com; s=zohoarc; b=RfAEl1yctpEwdVACF80jWSYaPLCkS6CmPF+RYv1xJlXTQPZNZjgnymY4WZKWMnZ9cANy3TmMwCG25l6AjK5C5l001pKgBct5mPJJMaW5N4WfS2QrVdGUxiKiy1+YgCe3QMRjpJ1D+W/rXw7aUit4xjjfA1IQl/RN+t0UfWArr4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607705750; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=yYE3S0IJePOkYWo2QQBSe/vtKkk7jcLYcway9wa47RY=; b=CBGUaUzmb7xkQQUhUSbx6xs9nt7sT2eOYnzCwefern3ew8azRCaWdAOpen6bJDTg4+YaGLxY0p/tl9xMfzkfC7A9YNn3C+ZYwia5bf2MdshPY5/tgtt/cTNEzsOA6JpvRaYPE92DTvMLLhWr46gSocAOmXBN/EnEj2efcd2hiNw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607705749809720.0430467720904; Fri, 11 Dec 2020 08:55:49 -0800 (PST) Received: from localhost ([::1]:33566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knlhq-0001B1-Hu for importer@patchew.org; Fri, 11 Dec 2020 11:55:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlfA-0007zR-Q7 for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:53:00 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlf6-0004JR-1h for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:52:59 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGo4Gt119947; Fri, 11 Dec 2020 16:52:52 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 3581mrbjfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Dec 2020 16:52:51 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGix50122913; Fri, 11 Dec 2020 16:52:51 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 358kyyad14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Dec 2020 16:52:51 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BBGqotU008411; Fri, 11 Dec 2020 16:52:50 GMT Received: from ban25x6uut148.us.oracle.com (/10.153.73.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Dec 2020 08:52:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=yYE3S0IJePOkYWo2QQBSe/vtKkk7jcLYcway9wa47RY=; b=bZd2kchEgcud8mytH+714oBdB8LT+1kjTi6UR08ng8Mph7LmSYILoImxMefi/id18vW3 fXwRD3tXNZ+PuGv/6AuCExF3E46wnxPJc+jmiJlSNcZQLDH07okRj6d5F7uSC0TbDUph /GAGZGfbuMJzUq9O1fmrHp3x4hM3Fr9DpeO2xDFvWV+A0zyjydl1PNiFjk+YoPAbDpkQ uGL1a7768tHGoXCJt3PQFxJBPAH9jk3v+zxgRq2iwQ7F6ibHMYRRsQKcXbc36QGrU7n4 tYZAMae5kNMyVdrnulMLtHCsecYpuTh+N33MuRW0Yn1mc2Mxm0efzsNyyIFxK6B0lNS4 oQ== From: Alejandro Jimenez To: qemu-devel@nongnu.org Subject: [PATCH v3 2/4] vl: Add option to avoid stopping VM upon guest panic Date: Fri, 11 Dec 2020 11:52:42 -0500 Message-Id: <1607705564-26264-3-git-send-email-alejandro.j.jimenez@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> References: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 mlxscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 clxscore=1015 malwarescore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=alejandro.j.jimenez@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david.edmondson@oracle.com, pbonzini@redhat.com, mihai.carabas@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/52148F88.5000509@redhat.com/ 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=3Dnone in the command line arguments, or during runtime by using an upcoming QMP command. Suggested-by: Paolo Bonzini Signed-off-by: Alejandro Jimenez --- 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(-) diff --git a/include/sysemu/runstate-action.h b/include/sysemu/runstate-act= ion.h index dba4b85..cfc46ec 100644 --- a/include/sysemu/runstate-action.h +++ b/include/sysemu/runstate-action.h @@ -14,6 +14,7 @@ /* in softmmu/runstate-action.c */ extern RebootAction reboot_action; extern ShutdownAction shutdown_action; +extern PanicAction panic_action; =20 int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp); int runstate_action_parse(QemuOptsList *opts_list, const char *optarg); diff --git a/qapi/run-state.json b/qapi/run-state.json index 7d8ce61..03ff78b 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -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' ] } =20 ## # @RunStateAction: @@ -358,6 +360,7 @@ 'data': { 'reboot': 'RunStateRebootAction', 'shutdown': 'RunStateShutdownAction', + 'panic': 'RunStatePanicAction', 'watchdog': 'RunStateWatchdogAction' } } =20 ## @@ -409,6 +412,28 @@ 'data': [ 'poweroff', 'pause' ] } =20 ## +# @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 diff --git a/qemu-options.hx b/qemu-options.hx index a0d50f0..9ac5a26 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3899,6 +3899,8 @@ DEF("action", HAS_ARG, QEMU_OPTION_action, " action when guest reboots [default=3Dnone]\n" "-action shutdown=3Dpoweroff|pause\n" " action when guest shuts down [default=3Dpoweroff]\= n" + "-action panic=3Dpoweroff|pause|none\n" + " action when guest panics [default=3Dpoweroff]\n" "-action watchdog=3Dreset|shutdown|poweroff|inject-nmi|pause|debug|non= e\n" " action when watchdog fires [default=3Dreset]\n", QEMU_ARCH_ALL) @@ -3911,6 +3913,7 @@ SRST =20 Examples: =20 + ``-action panic=3Dnone`` ``-action reboot=3Dshutdown,shutdown=3Dpause`` ``-watchdog i6300esb -action watchdog=3Dpause`` =20 diff --git a/softmmu/runstate-action.c b/softmmu/runstate-action.c index 5eae320..bc30102 100644 --- a/softmmu/runstate-action.c +++ b/softmmu/runstate-action.c @@ -15,6 +15,7 @@ =20 RebootAction reboot_action =3D REBOOT_ACTION_NONE; ShutdownAction shutdown_action =3D SHUTDOWN_ACTION_POWEROFF; +PanicAction panic_action =3D PANIC_ACTION_POWEROFF; =20 static void runstate_action_help(void) { @@ -27,6 +28,18 @@ static void runstate_action_help(void) } =20 /* + * When -no-shutdown is requested either explicitly or by using its equiva= lent + * -action option, the request should be honored even if a panic occurs. + */ +static void fix_panic_action(void) +{ + if (shutdown_action =3D=3D SHUTDOWN_ACTION_PAUSE && + panic_action =3D=3D PANIC_ACTION_POWEROFF) { + panic_action =3D 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 =3D qapi_enum_parse(&ShutdownAction_lookup, action, -1, errp); + fix_panic_action(); + break; + case RUN_STATE_EVENT_TYPE_PANIC: + panic_action =3D qapi_enum_parse(&PanicAction_lookup, action, -1, = errp); break; case RUN_STATE_EVENT_TYPE_WATCHDOG: if (select_watchdog_action(action) =3D=3D -1) { diff --git a/softmmu/vl.c b/softmmu/vl.c index 35575a1..2ff0291 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1447,10 +1447,21 @@ void qemu_system_guest_panicked(GuestPanicInformati= on *info) if (current_cpu) { current_cpu->crash_occurred =3D true; } - qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, - !!info, info); - vm_stop(RUN_STATE_GUEST_PANICKED); - if (shutdown_action =3D=3D SHUTDOWN_ACTION_POWEROFF) { + /* + * TODO: Currently the available panic actions are: none, pause, and + * poweroff, but in principle debug and reset could be supported as we= ll. + * Investigate any potential use cases for the unimplemented actions. + */ + if (panic_action !=3D 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 =3D=3D 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 =3D SHUTDOWN_ACTION_PAUSE; + /* no_shutdown is requested, also honor it if guest panics= */ + if (panic_action =3D=3D PANIC_ACTION_POWEROFF) { + panic_action =3D PANIC_ACTION_PAUSE; + } break; case QEMU_OPTION_show_cursor: warn_report("The -show-cursor option is deprecated. Please= " --=20 1.8.3.1 From nobody Thu May 16 04:25:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1607705999; cv=none; d=zohomail.com; s=zohoarc; b=ko6AB89mJrLJojRN7ofHr7aF6RrG3Mu8pbTzFMWyDodbB2yN10g63bkVZLkPMQO32mj91InJCUOTwyqe49Oi7pSOYDxpjSSuxY6mI1K6f1VR2Ef27QGOkHp/PBahR8ED8LGCoEZjleUwnCIhpmLQN9HTZTq9aWGYhOdgpxCt3CE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607705999; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=466UzwlmAWSNxP1UdP6sV+07ya2npA2iiwNSInGQhO0=; b=Nob4Bv8fwA6MHqXptk2Mxu4BMk4p5ULOsx6lA6rSsngQrd8+oCZCxMdyTOzNLGm3yqLsG2kvZT6DhBaqNDtODPxibtki/mmPQAulxO4w95eoIYHPoJZpcN7QFlXrK0Spa2jjY0B0Jrj6nL6xH6DE0UKDLG7RqCWbJeZwWCcjE/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607705999378424.03288392051104; Fri, 11 Dec 2020 08:59:59 -0800 (PST) Received: from localhost ([::1]:42990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knllu-0005LD-18 for importer@patchew.org; Fri, 11 Dec 2020 11:59:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlfA-00081L-VY for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:53:01 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlf6-0004JS-Fy for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:53:00 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGoClW120041; Fri, 11 Dec 2020 16:52:52 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 3581mrbjfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Dec 2020 16:52:52 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGjsKJ031693; Fri, 11 Dec 2020 16:52:51 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 358m547xrt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Dec 2020 16:52:51 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BBGqp2P008418; Fri, 11 Dec 2020 16:52:51 GMT Received: from ban25x6uut148.us.oracle.com (/10.153.73.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Dec 2020 08:52:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=466UzwlmAWSNxP1UdP6sV+07ya2npA2iiwNSInGQhO0=; b=yMjqU0eAP9bG/4mWZZiAYp9hNhsVeEhAdOuG+ASuf5wSevlbf7NRErNP2vrsC/C7BCUd sgH+ULm/uMZmXLHCAuUqZULx3ryG+YZR28vqjZSqD5wZiMm2ET8/VJcrMSp0Y74mxN5U sZaJV0f6uCWt5dnkclGfA8t54aOIUY963Nh0/SdwuBM1/Osmiz8Vi4IPlNLCf3JZScrG SMLJzZLPH0G8Y2QhQDUA4lxUGOqpQfw3ENwpqKe5Q0rRBc4I2ucbZhOaj/67dWCyaXrJ i+QAi73GtUR8jGwjactLocGFrrRMq3siaBp95e8nBO49iHntLHWfl4hsvB9DSOSIgxec gw== From: Alejandro Jimenez To: qemu-devel@nongnu.org Subject: [PATCH v3 3/4] qmp: Allow setting -action parameters on the fly Date: Fri, 11 Dec 2020 11:52:43 -0500 Message-Id: <1607705564-26264-4-git-send-email-alejandro.j.jimenez@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> References: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 suspectscore=1 bulkscore=0 malwarescore=0 phishscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 mlxlogscore=999 clxscore=1015 malwarescore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=alejandro.j.jimenez@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david.edmondson@oracle.com, pbonzini@redhat.com, mihai.carabas@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a QMP command to allow for the behaviors specified by the -action event=3Daction 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": {} } Suggested-by: Paolo Bonzini Signed-off-by: Alejandro Jimenez --- qapi/run-state.json | 34 ++++++++++++++++++++++++++++++++++ softmmu/runstate-action.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/qapi/run-state.json b/qapi/run-state.json index 03ff78b..4732a89 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -453,6 +453,40 @@ { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} } =20 ## +# @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 diff --git a/softmmu/runstate-action.c b/softmmu/runstate-action.c index bc30102..92feebf 100644 --- a/softmmu/runstate-action.c +++ b/softmmu/runstate-action.c @@ -40,6 +40,35 @@ static void fix_panic_action(void) } =20 /* + * 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 =3D reboot; + } + + if (has_panic) { + panic_action =3D 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 =3D shutdown; + fix_panic_action(); + } +} + +/* * Process an event|action pair and set the appropriate internal * state if event and action are valid. */ --=20 1.8.3.1 From nobody Thu May 16 04:25:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1607705747; cv=none; d=zohomail.com; s=zohoarc; b=nF6GOa8bUPhbfmdYMKnMGonzjdYPNvVN6xauFOFYUJExjgzOAzqAX5YhSoUwzdCBfI4tVM87lDSRg8Kls774iuntucOVfX4m9QQSDOeLxQVwArtvfTKOIQwD0xOe/mzBQKu4DUiT8CQxZQzuv5LH+8NHr6MNtitmm6ZrbQ5/51I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607705747; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0oxtMXUqfsKnZ2mmipX3HD+8EJWKg+SYKhNsIEYyZhE=; b=Qo0IhWo8AJevhOXl0Bc1EOn2iP6VsVCkIpkXvXYBaC1U0tuXqCmkMcLlbIcZnxrcNhA3Hpy5rXWMfNh2qBDj3VgmnP19umOYz9PZP3LTIkyF1JzVj8/JfF7u0Wx0F+q4DnSFeVGFfrNBhKuadtX+zGqkiTbdk0rGXVx7zvGcv98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607705747615337.8519941718961; Fri, 11 Dec 2020 08:55:47 -0800 (PST) Received: from localhost ([::1]:33522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knlhq-00019k-Ga for importer@patchew.org; Fri, 11 Dec 2020 11:55:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlfA-0007zr-QA for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:53:00 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knlf6-0004JV-BR for qemu-devel@nongnu.org; Fri, 11 Dec 2020 11:52:59 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGoNpr120107; Fri, 11 Dec 2020 16:52:52 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 3581mrbjg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Dec 2020 16:52:52 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BBGieUx189020; Fri, 11 Dec 2020 16:52:52 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 358m43vgse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Dec 2020 16:52:52 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BBGqpbj010209; Fri, 11 Dec 2020 16:52:51 GMT Received: from ban25x6uut148.us.oracle.com (/10.153.73.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Dec 2020 08:52:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=0oxtMXUqfsKnZ2mmipX3HD+8EJWKg+SYKhNsIEYyZhE=; b=EWEgxKNkSV1EKai2o27dcZxSM+lo4gtzD4cSGTT9XM6fVXIjbj9+oMTbSRGnqZCE8M4k 3URar3IpiBwNdD4HJ8I4MefiE8+jOjedEhvZWmBn8gFRCOiM2VyUQoYUlWhfzcsJ1+Hc uu6fv09oS2B1zADslw8BxjCLzRu3ptgvXkLqoLGIag7OZNi9uCIEUhBcLilRkIvcVdIT khDkqyk/hdtaw79fkafsYysqxXS6IoCEgCp646entgu462hcGUemL7tNvOPATf5qlrP/ 3mZs7P9Vylddp/MsEhudKiybBnP7Q7cjMmo5avC4PQo6vI3vhIuJrmA97mgLSG3RhGMA 5g== From: Alejandro Jimenez To: qemu-devel@nongnu.org Subject: [PATCH v3 4/4] qtest/pvpanic: Test panic option that allows VM to continue Date: Fri, 11 Dec 2020 11:52:44 -0500 Message-Id: <1607705564-26264-5-git-send-email-alejandro.j.jimenez@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> References: <1607705564-26264-1-git-send-email-alejandro.j.jimenez@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 phishscore=0 suspectscore=1 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9832 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 mlxlogscore=999 clxscore=1015 malwarescore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012110112 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=alejandro.j.jimenez@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david.edmondson@oracle.com, pbonzini@redhat.com, mihai.carabas@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test the scenario where the -action panic=3Dnone parameter is used to signal that the VM must continue executing after a guest panic occurs. Suggested-by: Paolo Bonzini Signed-off-by: Alejandro Jimenez --- tests/qtest/pvpanic-test.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c index 016b32e..6dcad2d 100644 --- a/tests/qtest/pvpanic-test.c +++ b/tests/qtest/pvpanic-test.c @@ -11,13 +11,36 @@ #include "libqos/libqtest.h" #include "qapi/qmp/qdict.h" =20 +static void test_panic_nopause(void) +{ + uint8_t val; + QDict *response, *data; + QTestState *qts; + + qts =3D qtest_init("-device pvpanic -action panic=3Dnone"); + + val =3D qtest_inb(qts, 0x505); + g_assert_cmpuint(val, =3D=3D, 3); + + qtest_outb(qts, 0x505, 0x1); + + response =3D qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); + g_assert(qdict_haskey(response, "data")); + data =3D qdict_get_qdict(response, "data"); + g_assert(qdict_haskey(data, "action")); + g_assert_cmpstr(qdict_get_str(data, "action"), =3D=3D, "run"); + qobject_unref(response); + + qtest_quit(qts); +} + static void test_panic(void) { uint8_t val; QDict *response, *data; QTestState *qts; =20 - qts =3D qtest_init("-device pvpanic"); + qts =3D qtest_init("-device pvpanic -action panic=3Dpause"); =20 val =3D qtest_inb(qts, 0x505); g_assert_cmpuint(val, =3D=3D, 3); @@ -40,6 +63,7 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); qtest_add_func("/pvpanic/panic", test_panic); + qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause); =20 ret =3D g_test_run(); =20 --=20 1.8.3.1