]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: Add support for pvpanic devices for x86
authorCezar Craciunoiu <cezar.craciunoiu@gmail.com>
Mon, 7 Aug 2023 09:03:40 +0000 (12:03 +0300)
committerUnikraft <monkey@unikraft.io>
Mon, 7 Aug 2023 16:07:21 +0000 (16:07 +0000)
Unikraft already offers exit codes through the ISA device, but these
are only a convention and are not understood by QEMU itself.

When using `-device pvpanic`, a GUEST_PANICKED event[1] is sent to QEMU
when the unikernel crashes.
This event can be seen when using QMP[1] for example.
The bits corresponding to each even are set as per the documentation[2].

The main usage of this is in kraftkit where unikernels are detached
and exit codes are lost.
Using this can signal when the unikernel crashes.

[1] https://qemu-project.gitlab.io/qemu/interop/qemu-qmp-ref.html#qapidoc-152
[2] https://github.com/qemu/qemu/blob/master/docs/specs/pvpanic.txt

Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1022

plat/common/x86/cpu_native.c

index 7c216a477cde63d2f95dc884d4cd9f235adb14f9..166d4ae2fa6cb9b0f8c3a626b4e02caa68b24fb8 100644 (file)
@@ -55,6 +55,13 @@ unsigned long read_cr2(void)
 /* This corresponds to an 85 (42 << 1 | 1) return value from QEMU */
 #define QEMU_ISA_DEBUG_EXIT_CRASH      42
 
+/* The port used by QEMU by default for the pvpanic device */
+#define QEMU_PVPANIC_EXIT_PORT         0x505
+/* This corresponds to a GUEST_PANICKED event for QEMU */
+#define QEMU_PVPANIC_GUEST_PANICKED    (1 << 0)
+/* This corresponds to a GUEST_CRASHLOADED event for QEMU */
+#define QEMU_PVPANIC_GUEST_CRASHLOADED (1 << 1)
+
 /**
  * Trigger an exit() in QEMU with the code `value << 1 | 1`.
  * @param value the value used in the calculation of the exit code
@@ -79,9 +86,13 @@ void system_off(enum ukplat_gstate request __maybe_unused)
         * device.
         * Should be harmless if it is not present. This is used to enable
         * automated tests on virtio.
+        * Also send a panic request to the pvpanic device.
+        * Should be also harmless and helps with automated tests.
         */
-       if (request == UKPLAT_CRASH)
+       if (request == UKPLAT_CRASH) {
                qemu_debug_exit(QEMU_ISA_DEBUG_EXIT_CRASH);
+               outb(QEMU_PVPANIC_EXIT_PORT, QEMU_PVPANIC_GUEST_PANICKED);
+       }
 #endif /* CONFIG_KVM_VMM_QEMU */
 
        /*