]> xenbits.xensource.com Git - xtf.git/commitdiff
32bit: Save and restore %ds and %es when handling exceptions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 14 Feb 2018 15:42:25 +0000 (15:42 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 15 Feb 2018 13:50:48 +0000 (13:50 +0000)
For tests which play with segments (especially those which reduce %ds.limit),
failing to restore usable segments can result in cascade failures (most
obviously when trying to poke characters into the console ring).

Remove the vm86 special case in handle_exception() and load __KERN_DS into %ds
and %es unconditionally.  Forgo the unconditional loading of %fs and %gs as
they are unreferenced in exception context.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/entry_32.S
arch/x86/include/arch/regs.h
tests/nmi-taskswitch-priv/main.c

index d1bdbab2548efa8b73c8ba4cc675dff7e0561a2c..9869b78c70cc20a3cfca8b798b165029004ec8f2 100644 (file)
@@ -75,25 +75,24 @@ exception_entry VE  X86_EXC_VE
         .align 16
 handle_exception:
 
-        SAVE_ALL
+        push %es
+        push %ds
 
-#if defined(CONFIG_HVM)
-        testl $X86_EFLAGS_VM, 11*4(%esp)
-        jz 1f
+        SAVE_ALL
 
-        mov $__KERN_DS, %eax    /* Restore data segments if leaving vm86 mode. */
+        mov $__KERN_DS, %eax    /* Restore data segments. */
         mov %eax, %ds
         mov %eax, %es
-        mov %eax, %fs
-        mov %eax, %gs
-1:
-#endif
 
         push %esp               /* struct cpu_regs * */
         call do_exception
         add $4, %esp
 
         RESTORE_ALL
+
+        pop %ds
+        pop %es
+
         add $8, %esp            /* Pop error_code/entry_vector. */
 
         env_IRET
index 618b5624afce9f4fc6b5bdec49ae6a6ee0555786..963d2a0c0cc1eaa3381e6b71519e0579db39de1f 100644 (file)
@@ -19,6 +19,9 @@ struct cpu_regs {
     DECL_REG(si);
     DECL_REG(di);
 
+    uint16_t ds, :16;
+    uint16_t es, :16;
+
     uint32_t entry_vector;
     uint32_t error_code;
 
index cbb6f0911a2d2b9475418bdb25adf741556bfce8..61565cbf1da0b553b40377e8635ec7d64e1e6ef7 100644 (file)
@@ -64,6 +64,9 @@ asm("exit_NMI_task:"
     "push $0;"
     "push $" STR(X86_EXC_NMI) ";"
 
+    "push %es;"
+    "push %ds;"
+
     "push %edi;"
     "push %esi;"
     "push %edx;"
@@ -84,6 +87,9 @@ asm("exit_NMI_task:"
     "pop %esi;"
     "pop %edi;"
 
+    "pop %ds;"
+    "pop %es;"
+
     "add $2*4, %esp;" /* entry_vector/error_code. */
 
     "jmp exit_NMI_task;");