On 09/12/2022 09:56, David Woodhouse wrote:
From: Joao Martins <joao.m.mart...@oracle.com>
It allows to shutdown itself via hypercall with any of the 3 reasons:
1) self-reboot
2) shutdown
3) crash
Implementing SCHEDOP_shutdown sub op let us handle crashes gracefully rather
than leading to triple faults if it remains unimplemented.
Signed-off-by: Joao Martins <joao.m.mart...@oracle.com>
Signed-off-by: David Woodhouse <d...@amazon.co.uk>
---
target/i386/xen.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/target/i386/xen.c b/target/i386/xen.c
index f102c40f04..5f3b91450d 100644
--- a/target/i386/xen.c
+++ b/target/i386/xen.c
@@ -17,6 +17,7 @@
#include "trace.h"
#include "hw/i386/kvm/xen_overlay.h"
#include "hw/i386/kvm/xen_evtchn.h"
+#include "sysemu/runstate.h"
#define __XEN_INTERFACE_VERSION__ 0x00040400
@@ -25,6 +26,7 @@
#include "standard-headers/xen/hvm/hvm_op.h"
#include "standard-headers/xen/hvm/params.h"
#include "standard-headers/xen/vcpu.h"
+#include "standard-headers/xen/sched.h"
#include "standard-headers/xen/event_channel.h"
static bool kvm_gva_to_gpa(CPUState *cs, uint64_t gva, uint64_t *gpa,
@@ -491,6 +493,45 @@ static bool kvm_xen_hcall_evtchn_op(struct kvm_xen_exit
*exit,
return true;
}
+static int schedop_shutdown(CPUState *cs, uint64_t arg)
+{
+ struct sched_shutdown shutdown;
+
+ if (kvm_copy_from_gva(cs, arg, &shutdown, sizeof(shutdown))) {
+ return -EFAULT;
+ }
+
+ if (shutdown.reason == SHUTDOWN_crash) {
+ cpu_dump_state(cs, stderr, CPU_DUMP_CODE);
+ qemu_system_guest_panicked(NULL);
+ } else if (shutdown.reason == SHUTDOWN_reboot) {
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+ } else if (shutdown.reason == SHUTDOWN_poweroff) {
+ qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+ }
Why not a switch() statement? I think it would look neater and be more
consistent with other code.
With that change...
Reviewed-by: Paul Durrant <p...@xen.org>