Skip to contentSkip to conversation

hvm: Allow triple fault to imply crash rather than reboot

PATCH In review Andrew Cooper 2 participants 2 messages Feb 14, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hvm: Allow triple fault to imply crash rather than reboot

While the triple fault action on native hardware will result in a system reset, any modern operating system can and will make use of less violent reboot methods. As a result, the most likely cause of a triple fault is a fatal software bug.

This patch allows the toolstack to indicate that a triple fault should mean a crash rather than a reboot. The default of reboot still remains the same.

--
Changes since v2:
* Allow any SHUTDOWN_* values to be set
Changes since v1:
* "reboot" -> "reset"
* v->domain -> d

xen/arch/x86/hvm/hvm.c +11 -2
diff -r 63594ce1708f -r dc98663be34e xen/arch/x86/hvm/hvm.c
@@ -540,6 +540,7 @@ int hvm_domain_initialise(struct domain 
     hvm_init_guest_time(d);
 
     d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
+    d->arch.hvm_domain.params[HVM_PARAM_TRIPLE_FAULT_REASON] = SHUTDOWN_reboot;
 
     hvm_init_cacheattr_region_list(d);
 
@@ -1244,9 +1245,13 @@ void hvm_hlt(unsigned long rflags)
 void hvm_triple_fault(void)
 {
     struct vcpu *v = current;
+    struct domain *d = v->domain;
+    u8 reason = d->arch.hvm_domain.params[HVM_PARAM_TRIPLE_FAULT_REASON];
+
     gdprintk(XENLOG_INFO, "Triple fault on VCPU%d - "
-             "invoking HVM system reset.\n", v->vcpu_id);
-    domain_shutdown(v->domain, SHUTDOWN_reboot);
+             "invoking HVM shutdown action %"PRIu8".\n",
+             v->vcpu_id, reason);
+    domain_shutdown(d, reason);
 }
 
 void hvm_inject_trap(struct hvm_trap *trap)
@@ -3929,6 +3934,10 @@ long do_hvm_op(unsigned long op, XEN_GUE
             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_TRIPLE_FAULT_REASON:
+                if ( a.value > SHUTDOWN_MAX )
+                    rc = -EINVAL;
+                break;
             }
 
             if ( rc == 0 ) 
xen/include/public/hvm/params.h +4 -1
diff -r 63594ce1708f -r dc98663be34e xen/include/public/hvm/params.h
@@ -142,6 +142,9 @@
 #define HVM_PARAM_ACCESS_RING_PFN   28
 #define HVM_PARAM_SHARING_RING_PFN  29
 
-#define HVM_NR_PARAMS          31
+/* SHUTDOWN_* action in case of a triple fault */
+#define HVM_PARAM_TRIPLE_FAULT_REASON 31
+
+#define HVM_NR_PARAMS          32
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
xen/include/public/sched.h +1 -0
diff -r 63594ce1708f -r dc98663be34e xen/include/public/sched.h
@@ -158,6 +158,7 @@ DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t
 #define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.         */
 #define SHUTDOWN_crash      3  /* Tell controller we've crashed.             */
 #define SHUTDOWN_watchdog   4  /* Restart because watchdog time expired.     */
+#define SHUTDOWN_MAX        4  /* Maximum valid shutdown reason.             */
 /* ` } */
 
 #endif /* __XEN_PUBLIC_SCHED_H__ */
Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

While the triple fault action on native hardware will result in a system reset, any modern operating system can and will make use of less violent reboot methods. As a result, the most likely cause of a triple fault is a fatal software bug.

This patch allows the toolstack to indicate that a triple fault should mean a crash rather than a reboot. The default of reboot still remains the same.

Quoted 75 lines

--
Changes since v2:
* Allow any SHUTDOWN_* values to be set
Changes since v1:
* "reboot" -> "reset"
* v->domain -> d

diff -r 63594ce1708f -r dc98663be34e xen/arch/x86/hvm/hvm.c

xen/arch/x86/hvm/hvm.c +11 -2
@@ -540,6 +540,7 @@ int hvm_domain_initialise(struct domain
     hvm_init_guest_time(d);
 
     d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
+    d->arch.hvm_domain.params[HVM_PARAM_TRIPLE_FAULT_REASON] =
 SHUTDOWN_reboot;
 
     hvm_init_cacheattr_region_list(d);
@@ -1244,9 +1245,13 @@ void hvm_hlt(unsigned long rflags)
 void hvm_triple_fault(void)
 {
     struct vcpu *v = current;
+    struct domain *d = v->domain;
+    u8 reason = d->arch.hvm_domain.params[HVM_PARAM_TRIPLE_FAULT_REASON];
+
     gdprintk(XENLOG_INFO, "Triple fault on VCPU%d - "
-             "invoking HVM system reset.\n", v->vcpu_id);
-    domain_shutdown(v->domain, SHUTDOWN_reboot);
+             "invoking HVM shutdown action %"PRIu8".\n",
+             v->vcpu_id, reason);
+    domain_shutdown(d, reason);
 }
 
 void hvm_inject_trap(struct hvm_trap *trap)
@@ -3929,6 +3934,10 @@ long do_hvm_op(unsigned long op, XEN_GUE
             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_TRIPLE_FAULT_REASON:
+                if ( a.value > SHUTDOWN_MAX )
+                    rc = -EINVAL;
+                break;
             }
 
             if ( rc == 0 )

diff -r 63594ce1708f -r dc98663be34e xen/include/public/hvm/params.h

xen/include/public/hvm/params.h +4 -1
@@ -142,6 +142,9 @@
 #define HVM_PARAM_ACCESS_RING_PFN   28
 #define HVM_PARAM_SHARING_RING_PFN  29
 
-#define HVM_NR_PARAMS          31
+/* SHUTDOWN_* action in case of a triple fault */
+#define HVM_PARAM_TRIPLE_FAULT_REASON 31
+
+#define HVM_NR_PARAMS          32
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */

diff -r 63594ce1708f -r dc98663be34e xen/include/public/sched.h

xen/include/public/sched.h +1 -0
@@ -158,6 +158,7 @@ DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t
 #define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.
 */
 #define SHUTDOWN_crash      3  /* Tell controller we've crashed.
 */
 #define SHUTDOWN_watchdog   4  /* Restart because watchdog time expired.
 */
+#define SHUTDOWN_MAX        4  /* Maximum valid shutdown reason.

*/
/* ` } */

#endif /* __XEN_PUBLIC_SCHED_H__ */