From 7dc58deea79a343ac3adc5cadb97215086054c86 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Tue, 14 Jan 2020 10:31:02 +0800 Subject: [PATCH] pvpanic: implement crashloaded event handling Handle bit 1 write, then post event to monitor. Suggested by Paolo, declear a new event, using GUEST_PANICKED could cause upper layers to react by shutting down or rebooting the guest. In advance for extention, add GuestPanicInformation in event message. Signed-off-by: zhenwei pi Message-Id: <20200114023102.612548-3-pizhenwei@bytedance.com> Signed-off-by: Paolo Bonzini --- docs/specs/pvpanic.txt | 16 ++++++++-------- hw/misc/pvpanic.c | 11 +++++++++-- include/sysemu/runstate.h | 1 + qapi/run-state.json | 24 ++++++++++++++++++++++-- vl.c | 12 ++++++++++++ 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/docs/specs/pvpanic.txt b/docs/specs/pvpanic.txt index bdea68a430..a90fbca72b 100644 --- a/docs/specs/pvpanic.txt +++ b/docs/specs/pvpanic.txt @@ -19,9 +19,10 @@ Software should set only bits both itself and the device recognize. Bit Definition -------------- -bit 0: setting it indicates a guest panic has happened. -bit 1: named crashloaded. setting it indicates a guest panic and run - kexec to handle error by guest itself. +bit 0: a guest panic has happened and should be processed by the host +bit 1: a guest panic has happened and will be handled by the guest; + the host should record it or report it, but should not affect + the execution of the guest. ACPI Interface -------------- @@ -30,13 +31,12 @@ pvpanic device is defined with ACPI ID "QEMU0001". Custom methods: RDPT: To determine whether guest panic notification is supported. Arguments: None -Return: Returns a byte, bit 0 set to indicate guest panic - notification is supported. Other bits are reserved and - should be ignored. +Return: Returns a byte, with the same semantics as the I/O port + interface. WRPT: To send a guest panic event -Arguments: Arg0 is a byte, with bit 0 set to indicate guest panic has - happened. Other bits are reserved and should be cleared. +Arguments: Arg0 is a byte to be written, with the same semantics as + the I/O interface. Return: None The ACPI device will automatically refer to the right port in case it diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c index d65ac86478..4ebda7872a 100644 --- a/hw/misc/pvpanic.c +++ b/hw/misc/pvpanic.c @@ -21,11 +21,13 @@ #include "hw/qdev-properties.h" #include "hw/misc/pvpanic.h" -/* The bit of supported pv event */ +/* The bit of supported pv event, TODO: include uapi header and remove this */ #define PVPANIC_F_PANICKED 0 +#define PVPANIC_F_CRASHLOADED 1 /* The pv event value */ #define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED) +#define PVPANIC_CRASHLOADED (1 << PVPANIC_F_CRASHLOADED) #define ISA_PVPANIC_DEVICE(obj) \ OBJECT_CHECK(PVPanicState, (obj), TYPE_PVPANIC) @@ -34,7 +36,7 @@ static void handle_event(int event) { static bool logged; - if (event & ~PVPANIC_PANICKED && !logged) { + if (event & ~(PVPANIC_PANICKED | PVPANIC_CRASHLOADED) && !logged) { qemu_log_mask(LOG_GUEST_ERROR, "pvpanic: unknown event %#x.\n", event); logged = true; } @@ -43,6 +45,11 @@ static void handle_event(int event) qemu_system_guest_panicked(NULL); return; } + + if (event & PVPANIC_CRASHLOADED) { + qemu_system_guest_crashloaded(NULL); + return; + } } #include "hw/isa/isa.h" diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 0b41555609..f760094858 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -63,6 +63,7 @@ ShutdownCause qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); void qemu_system_reset(ShutdownCause reason); void qemu_system_guest_panicked(GuestPanicInformation *info); +void qemu_system_guest_crashloaded(GuestPanicInformation *info); #endif diff --git a/qapi/run-state.json b/qapi/run-state.json index d7477cd715..b83a436a3e 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -356,6 +356,26 @@ { 'event': 'GUEST_PANICKED', 'data': { 'action': 'GuestPanicAction', '*info': 'GuestPanicInformation' } } +## +# @GUEST_CRASHLOADED: +# +# Emitted when guest OS crash loaded is detected +# +# @action: action that has been taken, currently always "run" +# +# @info: information about a panic +# +# Since: 5.0 +# +# Example: +# +# <- { "event": "GUEST_CRASHLOADED", +# "data": { "action": "run" } } +# +## +{ 'event': 'GUEST_CRASHLOADED', + 'data': { 'action': 'GuestPanicAction', '*info': 'GuestPanicInformation' } } + ## # @GuestPanicAction: # @@ -363,10 +383,10 @@ # # @pause: system pauses # -# Since: 2.1 (poweroff since 2.8) +# Since: 2.1 (poweroff since 2.8, run since 5.0) ## { 'enum': 'GuestPanicAction', - 'data': [ 'pause', 'poweroff' ] } + 'data': [ 'pause', 'poweroff', 'run' ] } ## # @GuestPanicInformationType: diff --git a/vl.c b/vl.c index 71d3e7eefb..9f5f477400 100644 --- a/vl.c +++ b/vl.c @@ -1468,6 +1468,18 @@ void qemu_system_guest_panicked(GuestPanicInformation *info) } } +void qemu_system_guest_crashloaded(GuestPanicInformation *info) +{ + qemu_log_mask(LOG_GUEST_ERROR, "Guest crash loaded"); + + qapi_event_send_guest_crashloaded(GUEST_PANIC_ACTION_RUN, + !!info, info); + + if (info) { + qapi_free_GuestPanicInformation(info); + } +} + void qemu_system_reset_request(ShutdownCause reason) { if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) {