Skip to contentSkip to conversation

tools: hvmloader: attempt to SHUTDOWN_crash on BUG

PATCH In review Ian Campbell 4 participants 5 messages Apr 18, 2011 – Apr 20, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: hvmloader: attempt to SHUTDOWN_crash on BUG

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1303143704 -3600
# Node ID 05abea47f4dc670974cd513a0e74db54d22eacc9 # Parent 052ffd72382924eee479ca479fd1574750a8adf7
tools: hvmloader: attempt to SHUTDOWN_crash on BUG

If we have got as far as having enabled hypercalls then this signals to the toolstack that something went wrong. Otherwise they tend to assume the guest has either shutdown or rebooted which can lead to simply trying again repeatedly.

tools/firmware/hvmloader/hvmloader.c +3 -0
diff -r 052ffd723829 -r 05abea47f4dc tools/firmware/hvmloader/hvmloader.c
@@ -114,6 +114,8 @@ unsigned long pci_mem_end = PCI_MEM_END;
 
 enum virtual_vga virtual_vga = VGA_none;
 
+int hypercalls_available = 0;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -146,6 +148,7 @@ static void init_hypercalls(void)
     cpuid(base + 1, &eax, &ebx, &ecx, &edx);
     hypercall_xen_version(XENVER_extraversion, extraversion);
     printf("Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion);
+    hypercalls_available = 1;
 }
 
 /*
tools/firmware/hvmloader/hypercall.h +3 -0
diff -r 052ffd723829 -r 05abea47f4dc tools/firmware/hvmloader/hypercall.h
@@ -35,6 +35,9 @@
 #include <xen/xen.h>
 #include "config.h"
 
+/* Have hypercalls been successfully enabled */
+extern int hypercalls_available;
+
 /*
  * NB. Hypercall address needs to be relative to a linkage symbol for
  * some version of ld to relocate the relative calls properly.
tools/firmware/hvmloader/util.c +9 -0
diff -r 052ffd723829 -r 05abea47f4dc tools/firmware/hvmloader/util.c
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <xen/xen.h>
 #include <xen/memory.h>
+#include <xen/sched.h>
 
 void wrmsr(uint32_t idx, uint64_t v)
 {
@@ -547,7 +548,15 @@ void __assert_failed(char *assertion, ch
 
 void __bug(char *file, int line)
 {
+    struct sched_shutdown shutdown = {
+        .reason = SHUTDOWN_crash,
+    };
+
     printf("HVMLoader bug at %s:%d\n", file, line);
+    if (hypercalls_available) {
+        printf("SCHEDOP_shutdown: reason=SHUTDOWN_crash\n");
+        hypercall_sched_op(SCHEDOP_shutdown, &shutdown);
+    }
     for ( ; ; )
         asm volatile ( "ud2" );
 }
#1 lore raw

Ian Campbell writes ("[Xen-devel] [PATCH] tools: hvmloader: attempt to SHUTDOWN_crash on BUG"):

Quoted 6 lines

tools: hvmloader: attempt to SHUTDOWN_crash on BUG

If we have got as far as having enabled hypercalls then this signals to the toolstack that something went wrong. Otherwise they tend to assume the guest has either shutdown or rebooted which can lead to simply trying again repeatedly.

Surely in principle this is wrong. Anything other than a deliberate decision by hvmloader to exit cleanly (how would that ever happen?) should be treated as a crash.

Perhaps the toolstack for an hvm domain should set the shutdown reason to "crashed" before unpausing ? It looks like this is possible with an appropriate domctl ...

Ian.

#2 lore raw

Keir already applied this, but...

Quoted 11 lines · Ian Jackson

Ian Campbell writes ("[Xen-devel] [PATCH] tools: hvmloader: attempt to SHUTDOWN_crash on BUG"):

Quoted 6 lines

tools: hvmloader: attempt to SHUTDOWN_crash on BUG

If we have got as far as having enabled hypercalls then this signals to the toolstack that something went wrong. Otherwise they tend to assume the guest has either shutdown or rebooted which can lead to simply trying again repeatedly.

Surely in principle this is wrong. Anything other than a deliberate decision by hvmloader to exit cleanly (how would that ever happen?) should be treated as a crash.

The toolstack can't tell the difference between hvmloader and the subsequent bootloader then OS doing stuff and they may not be PV'd up.

In this case, the triple fault resulting from an hvmloader crash could also be a legitimate attempt by a guest to reboot itself, since it's one of the ways to reset the processor.

Ian.

#3 lore raw

Ian Campbell writes ("Re: [Xen-devel] [PATCH] tools: hvmloader: attempt to SHUTDOWN_crash on BUG"):

Quoted 2 lines

The toolstack can't tell the difference between hvmloader and the subsequent bootloader then OS doing stuff and they may not be PV'd up.

Indeed. But hvmloader can put the reason code back just before it launches the guest bootloader (or perhaps just before it enters the BIOS).

Ian.

#4 lore raw
Quoted 8 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH] tools: hvmloader: attempt to SHUTDOWN_crash on BUG"):

Quoted 2 lines

The toolstack can't tell the difference between hvmloader and the subsequent bootloader then OS doing stuff and they may not be PV'd up.

Indeed. But hvmloader can put the reason code back just before it launches the guest bootloader (or perhaps just before it enters the BIOS).

Currently the reason code cannot be changed after it has been latched by the hypervisor. Secondly, even if it could be changed, we wouldn't want to change it to a new value after hvmloader has run; we'd want to reset it to no-code. That would be cleanest with a new sched_op. However it is arguable whether this is worthwhile, since I've never heard of hvmloader crashing except on an explicit bug/assert statement (and even those are rare, and during development work). So it's kind of a non problem.

Also I already applied Ian's patch. :-) (I still maintain tools/firmware/, at least until seabios goes in).

-- Keir

Quoted 6 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel