Skip to contentSkip to conversation

Resend: x86: Reboot CPU on triple fault

PATCH In review [email protected] 3 participants 5 messages Jan 4, 2009 – Jan 12, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Resend: x86: Reboot CPU on triple fault

This is a (slightly adjusted for 2009-01-04 SVN) resend of Jan Kiszka's Reboot CPU on triple fault patch (see patch file for the exact reference)

It seems like a consensus was reached on how to deal with tripple faults, but noone commited the last version (8) of the patch anyways.

Just for the record -- 386BSD relies on this behavior to reset the CPU -- it unmaps the whole address space in order to trigger a tripple fault.

This is a slightly adjusted (for 2009-01-04 SVN) "reset on tripple fault patch"

Originally from:

Subject: [Qemu-devel] Re: [PATCH] x86: Reboot CPU on triple fault - Version 8
Message-ID: <[email protected]>
Date: Tue, 27 May 2008 18:17:18 +0200
From: Jan Kiszka <[email protected]>

exec.c +2 -0
Index: exec.c
===================================================================
@@ -1571,6 +1571,8 @@
 #ifdef TARGET_I386
     { CPU_LOG_PCALL, "pcall",
       "show protected mode far calls/returns/exceptions" },
+    { CPU_LOG_RESET, "cpu_reset",
+      "show CPU state before CPU resets" },
 #endif
 #ifdef DEBUG_IOPORT
     { CPU_LOG_IOPORT, "ioport",
helper.c +5 -0
Index: target-i386/helper.c
===================================================================
@@ -418,6 +418,11 @@
 {
     int i;
 
+   if (loglevel & CPU_LOG_RESET) {
+       fprintf(logfile, "CPU Reset (CPU %d)\n", env->cpu_index);
+       cpu_dump_state(env, logfile, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
+   }
+
     memset(env, 0, offsetof(CPUX86State, breakpoints));
 
     tlb_flush(env, 1);
op_helper.c +15 -2
Index: target-i386/op_helper.c
===================================================================
@@ -1244,6 +1244,9 @@
     }
 }
 
+/* This should come from sysemu.h - if we could include it here... */
+void qemu_system_reset_request(void);
+
 /*
  * Check nested exceptions and change to double or triple fault if
  * needed. It should only be called, if this is not an interrupt.
@@ -1261,9 +1264,19 @@
         fprintf(logfile, "check_exception old: 0x%x new 0x%x\n",
                 env->old_exception, intno);
 
-    if (env->old_exception == EXCP08_DBLE)
-        cpu_abort(env, "triple fault");
+#if !defined(CONFIG_USER_ONLY)
+    if (env->old_exception == EXCP08_DBLE) {
+        if (env->intercept)
+            helper_vmexit(SVM_EXIT_SHUTDOWN, 0);
 
+        if (loglevel & CPU_LOG_RESET)
+            fprintf(logfile, "Triple fault\n");
+
+        qemu_system_reset_request();
+        return EXCP_HLT;
+    }
+#endif
+
     if ((first_contributory && second_contributory)
         || (env->old_exception == EXCP0E_PAGE &&
             (second_contributory || (intno == EXCP0E_PAGE)))) {
cpu-all.h +1 -0
Index: cpu-all.h
===================================================================
@@ -815,6 +815,7 @@
 #define CPU_LOG_PCALL      (1 << 6)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
+#define CPU_LOG_RESET      (1 << 9)
 
 /* define log items */
 typedef struct CPULogItem {
#1 lore raw
Quoted 9 lines · [email protected] wrote:

This is a (slightly adjusted for 2009-01-04 SVN) resend of Jan Kiszka's Reboot CPU on triple fault patch (see patch file for the exact reference)

It seems like a consensus was reached on how to deal with tripple faults, but noone commited the last version (8) of the patch anyways.

Just for the record -- 386BSD relies on this behavior to reset the CPU -- it unmaps the whole address space in order to trigger a tripple fault.

Good that you picked this up! It is still on my to-do list to get this in, but with medium prio. However, let's try to push it a bit.

Quoted 8 lines

This is a slightly adjusted (for 2009-01-04 SVN) "reset on tripple fault patch"

Originally from:

Subject: [Qemu-devel] Re: [PATCH] x86: Reboot CPU on triple fault - Version 8
Message-ID: <[email protected]>
Date: Tue, 27 May 2008 18:17:18 +0200
From: Jan Kiszka <[email protected]>

Note that I posted an enhanced version on 2008-09-02, also covering reset logging for non-x86 archs. Please use that one.

...

Quoted 26 lines

Index: target-i386/op_helper.c
===================================================================

op_helper.c +8 -2
@@ -1244,6 +1244,9 @@
     }
 }
 
+/* This should come from sysemu.h - if we could include it here... */
+void qemu_system_reset_request(void);
+
 /*
  * Check nested exceptions and change to double or triple fault if
  * needed. It should only be called, if this is not an interrupt.
@@ -1261,9 +1264,19 @@
         fprintf(logfile, "check_exception old: 0x%x new 0x%x\n",
                 env->old_exception, intno);
 
-    if (env->old_exception == EXCP08_DBLE)
-        cpu_abort(env, "triple fault");
+#if !defined(CONFIG_USER_ONLY)
+    if (env->old_exception == EXCP08_DBLE) {
+        if (env->intercept)
+            helper_vmexit(SVM_EXIT_SHUTDOWN, 0);
 
+        if (loglevel & CPU_LOG_RESET)

op_helper.c line 1282

Quoted 10 lines
op_helper.c +7 -0
+            fprintf(logfile, "Triple fault\n");
+
+        qemu_system_reset_request();
+        return EXCP_HLT;
+    }
+#endif
+
     if ((first_contributory && second_contributory)
         || (env->old_exception == EXCP0E_PAGE &&
             (second_contributory || (intno == EXCP0E_PAGE)))) {

I meanwhile think that SVM hook should rather look like this

helper_svm_check_intercept_param(SVM_EXIT_SHUTDOWN, 0);

in order to properly check if shutdown events are actually intercepted. Alexander, am I right?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 67 lines · Jan Kiszka
Quoted 9 lines · [email protected] wrote:

This is a (slightly adjusted for 2009-01-04 SVN) resend of Jan Kiszka's Reboot CPU on triple fault patch (see patch file for the exact reference)

It seems like a consensus was reached on how to deal with tripple faults, but noone commited the last version (8) of the patch anyways.

Just for the record -- 386BSD relies on this behavior to reset the CPU -- it unmaps the whole address space in order to trigger a tripple fault.

Good that you picked this up! It is still on my to-do list to get this in, but with medium prio. However, let's try to push it a bit.

Quoted 8 lines

This is a slightly adjusted (for 2009-01-04 SVN) "reset on tripple fault patch"

Originally from:

Subject: [Qemu-devel] Re: [PATCH] x86: Reboot CPU on triple fault - Version 8
Message-ID: <[email protected]>
Date: Tue, 27 May 2008 18:17:18 +0200
From: Jan Kiszka <[email protected]>

Note that I posted an enhanced version on 2008-09-02, also covering reset logging for non-x86 archs. Please use that one.

...

Quoted 27 lines

Index: target-i386/op_helper.c
===================================================================

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +3 -0
@@ -1244,6 +1244,9 @@
    }
 }
 
+/* This should come from sysemu.h - if we could include it here...  
 */
+void qemu_system_reset_request(void);
+
 /*
 * Check nested exceptions and change to double or triple fault if

* needed. It should only be called, if this is not an interrupt.

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +5 -2
@@ -1261,9 +1264,19 @@
        fprintf(logfile, "check_exception old: 0x%x new 0x%x\n",
                env->old_exception, intno);
 
-    if (env->old_exception == EXCP08_DBLE)
-        cpu_abort(env, "triple fault");
+#if !defined(CONFIG_USER_ONLY)
+    if (env->old_exception == EXCP08_DBLE) {
+        if (env->intercept)
+            helper_vmexit(SVM_EXIT_SHUTDOWN, 0);
 
+        if (loglevel & CPU_LOG_RESET)

op_helper.c (working copy) line 1282

Quoted 10 lines
op_helper.c (working copy) renamed from op_helper.c (revision 6159) +7 -0
+            fprintf(logfile, "Triple fault\n");
+
+        qemu_system_reset_request();
+        return EXCP_HLT;
+    }
+#endif
+
    if ((first_contributory && second_contributory)
        || (env->old_exception == EXCP0E_PAGE &&
            (second_contributory || (intno == EXCP0E_PAGE)))) {

I meanwhile think that SVM hook should rather look like this

Quoted 5 lines

helper_svm_check_intercept_param(SVM_EXIT_SHUTDOWN, 0);

in order to properly check if shutdown events are actually intercepted. Alexander, am I right?

Yes, sounds right. Any reason not to put the intercept in reset_request? (asking blindly, I don't have access to the qemu source right now)

Alex

Quoted 7 lines

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 77 lines · Alexander Graf
Quoted 71 lines · Jan Kiszka
Quoted 4 lines · [email protected] wrote:

This is a (slightly adjusted for 2009-01-04 SVN) resend of Jan Kiszka's Reboot CPU on triple fault patch (see patch file for the exact reference)

Quoted 8 lines

It seems like a consensus was reached on how to deal with tripple faults,
but noone commited the last version (8) of the patch anyways.

Just for the record -- 386BSD relies on this behavior to reset the CPU --
it unmaps the whole address space in order to trigger a tripple fault.

Good that you picked this up! It is still on my to-do list to get this in, but with medium prio. However, let's try to push it a bit.

Quoted 10 lines

This is a slightly adjusted (for 2009-01-04 SVN) "reset on tripple fault patch"

Originally from:

Subject: [Qemu-devel] Re: [PATCH] x86: Reboot CPU on triple fault - Version 8
Message-ID: <[email protected]>
Date: Tue, 27 May 2008 18:17:18 +0200
From: Jan Kiszka <[email protected]>

Note that I posted an enhanced version on 2008-09-02, also covering reset logging for non-x86 archs. Please use that one.

...

Quoted 26 lines

Index: target-i386/op_helper.c
===================================================================

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +8 -2
@@ -1244,6 +1244,9 @@
    }
 }
 
+/* This should come from sysemu.h - if we could include it here... */
+void qemu_system_reset_request(void);
+
 /*
 * Check nested exceptions and change to double or triple fault if
 * needed. It should only be called, if this is not an interrupt.
@@ -1261,9 +1264,19 @@
        fprintf(logfile, "check_exception old: 0x%x new 0x%x\n",
                env->old_exception, intno);
 
-    if (env->old_exception == EXCP08_DBLE)
-        cpu_abort(env, "triple fault");
+#if !defined(CONFIG_USER_ONLY)
+    if (env->old_exception == EXCP08_DBLE) {
+        if (env->intercept)
+            helper_vmexit(SVM_EXIT_SHUTDOWN, 0);
 
+        if (loglevel & CPU_LOG_RESET)

op_helper.c (working copy) line 1282

Quoted 10 lines
op_helper.c (working copy) renamed from op_helper.c (revision 6159) +7 -0
+            fprintf(logfile, "Triple fault\n");
+
+        qemu_system_reset_request();
+        return EXCP_HLT;
+    }
+#endif
+
    if ((first_contributory && second_contributory)
        || (env->old_exception == EXCP0E_PAGE &&
            (second_contributory || (intno == EXCP0E_PAGE)))) {

I meanwhile think that SVM hook should rather look like this

Quoted 8 lines
Quoted 5 lines

helper_svm_check_intercept_param(SVM_EXIT_SHUTDOWN, 0);

in order to properly check if shutdown events are actually intercepted. Alexander, am I right?

Yes, sounds right. Any reason not to put the intercept in reset_request? (asking blindly, I don't have access to the qemu source right now)

You mean qemu_system_reset_request? That's generic code while the hook is x86-specific.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux
#4 lore raw
Quoted 82 lines · Jan Kiszka
Quoted 81 lines · Alexander Graf
Quoted 75 lines · Jan Kiszka
Quoted 4 lines · [email protected] wrote:

This is a (slightly adjusted for 2009-01-04 SVN) resend of Jan Kiszka's Reboot CPU on triple fault patch (see patch file for the exact reference)

Quoted 8 lines

It seems like a consensus was reached on how to deal with tripple faults,
but noone commited the last version (8) of the patch anyways.

Just for the record -- 386BSD relies on this behavior to reset the CPU --
it unmaps the whole address space in order to trigger a tripple fault.

Good that you picked this up! It is still on my to-do list to get this in, but with medium prio. However, let's try to push it a bit.

Quoted 10 lines

This is a slightly adjusted (for 2009-01-04 SVN) "reset on tripple fault patch"

Originally from:

Subject: [Qemu-devel] Re: [PATCH] x86: Reboot CPU on triple fault - Version 8
Message-ID: <[email protected]>
Date: Tue, 27 May 2008 18:17:18 +0200
From: Jan Kiszka <[email protected]>

Note that I posted an enhanced version on 2008-09-02, also covering reset logging for non-x86 archs. Please use that one.

...

Quoted 27 lines

Index: target-i386/op_helper.c
===================================================================

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +1 -0
@@ -1244,6 +1244,9 @@
   }
 }
 
+/* This should come from sysemu.h - if we could include it  

here... */

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +2 -0
+void qemu_system_reset_request(void);
+

/*
* Check nested exceptions and change to double or triple fault if
* needed. It should only be called, if this is not an interrupt.

op_helper.c (working copy) renamed from op_helper.c (revision 6159) +5 -2
@@ -1261,9 +1264,19 @@
       fprintf(logfile, "check_exception old: 0x%x new 0x%x\n",
               env->old_exception, intno);
 
-    if (env->old_exception == EXCP08_DBLE)
-        cpu_abort(env, "triple fault");
+#if !defined(CONFIG_USER_ONLY)
+    if (env->old_exception == EXCP08_DBLE) {
+        if (env->intercept)
+            helper_vmexit(SVM_EXIT_SHUTDOWN, 0);
 
+        if (loglevel & CPU_LOG_RESET)

op_helper.c (working copy) line 1282

Quoted 10 lines
op_helper.c (working copy) renamed from op_helper.c (revision 6159) +7 -0
+            fprintf(logfile, "Triple fault\n");
+
+        qemu_system_reset_request();
+        return EXCP_HLT;
+    }
+#endif
+
   if ((first_contributory && second_contributory)
       || (env->old_exception == EXCP0E_PAGE &&
           (second_contributory || (intno == EXCP0E_PAGE)))) {

I meanwhile think that SVM hook should rather look like this

helper_svm_check_intercept_param(SVM_EXIT_SHUTDOWN, 0);

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

in order to properly check if shutdown events are actually intercepted. Alexander, am I right?

Yes, sounds right. Any reason not to put the intercept in reset_request? (asking blindly, I don't have access to the qemu source right now)

You mean qemu_system_reset_request? That's generic code while the hook is x86-specific.

Sounds like the right place then. :-)

Alex

Quoted 7 lines

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26
Corporate Competence Center Embedded Linux