x86/idt: Factor out enabling and disabling of ISTs
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 19 Oct 2017 15:11:28 +0000 (15:11 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 19 Jan 2018 18:16:14 +0000 (18:16 +0000)
All alteration of IST settings (other than the crash path) happen in an
identical triple.  Introduce helpers to keep the triple in sync, and reduce
the risk of opencoded mistakes.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/common.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/smpboot.c
xen/arch/x86/traps.c
xen/include/asm-x86/processor.h

index 1ff121887c210cf7bf249d7dbe54a5d58c375abe..4306e5965085fbbfbf2f26ff6e410e97de1cd91c 100644 (file)
@@ -771,9 +771,7 @@ void load_system_tables(void)
        ltr(TSS_ENTRY << 3);
        lldt(0);
 
-       set_ist(&idt_tables[cpu][TRAP_double_fault],  IST_DF);
-       set_ist(&idt_tables[cpu][TRAP_nmi],           IST_NMI);
-       set_ist(&idt_tables[cpu][TRAP_machine_check], IST_MCE);
+       enable_each_ist(idt_tables[cpu]);
 
        /*
         * Bottom-of-stack must be 16-byte aligned!
index 9d9ad777d1e45dc2e349b0e606f1ce3e80746159..6509b90c99596b467caec548d364d8b4fbc8594d 100644 (file)
@@ -1038,9 +1038,7 @@ static void svm_ctxt_switch_from(struct vcpu *v)
     svm_vmload_pa(per_cpu(host_vmcb, cpu));
 
     /* Resume use of ISTs now that the host TR is reinstated. */
-    set_ist(&idt_tables[cpu][TRAP_double_fault],  IST_DF);
-    set_ist(&idt_tables[cpu][TRAP_nmi],           IST_NMI);
-    set_ist(&idt_tables[cpu][TRAP_machine_check], IST_MCE);
+    enable_each_ist(idt_tables[cpu]);
 }
 
 static void svm_ctxt_switch_to(struct vcpu *v)
@@ -1059,9 +1057,7 @@ static void svm_ctxt_switch_to(struct vcpu *v)
      * Cannot use ISTs for NMI/#MC/#DF while we are running with the guest TR.
      * But this doesn't matter: the IST is only req'd to handle SYSCALL/SYSRET.
      */
-    set_ist(&idt_tables[cpu][TRAP_double_fault],  IST_NONE);
-    set_ist(&idt_tables[cpu][TRAP_nmi],           IST_NONE);
-    set_ist(&idt_tables[cpu][TRAP_machine_check], IST_NONE);
+    disable_each_ist(idt_tables[cpu]);
 
     svm_restore_dr(v);
 
index 2cdd431b5f70e958073643f7549af25070145997..fe637dae405470d48a227573dc14fd53539731f5 100644 (file)
@@ -919,9 +919,7 @@ static int cpu_smpboot_alloc(unsigned int cpu)
     if ( idt_tables[cpu] == NULL )
         goto out;
     memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES * sizeof(idt_entry_t));
-    set_ist(&idt_tables[cpu][TRAP_double_fault],  IST_NONE);
-    set_ist(&idt_tables[cpu][TRAP_nmi],           IST_NONE);
-    set_ist(&idt_tables[cpu][TRAP_machine_check], IST_NONE);
+    disable_each_ist(idt_tables[cpu]);
 
     rc = setup_cpu_root_pgt(cpu);
     if ( rc )
index 513961cc87414edb358c07aaf17dde67c99de602..181badde01c218e1ac77565db68f669981119c8f 100644 (file)
@@ -1889,9 +1889,7 @@ void __init init_idt_traps(void)
     set_intr_gate(TRAP_simd_error,&simd_coprocessor_error);
 
     /* Specify dedicated interrupt stacks for NMI, #DF, and #MC. */
-    set_ist(&idt_table[TRAP_double_fault],  IST_DF);
-    set_ist(&idt_table[TRAP_nmi],           IST_NMI);
-    set_ist(&idt_table[TRAP_machine_check], IST_MCE);
+    enable_each_ist(idt_table);
 
     /* CPU0 uses the master IDT. */
     idt_tables[0] = idt_table;
index 80f841135565e024b12c837908fa0bfada94011b..9dd29bb04cf38b897c3a40f6f97b1e42a9c816f1 100644 (file)
@@ -459,6 +459,20 @@ static always_inline void set_ist(idt_entry_t *idt, unsigned long ist)
     _write_gate_lower(idt, &new);
 }
 
+static inline void enable_each_ist(idt_entry_t *idt)
+{
+    set_ist(&idt[TRAP_double_fault],  IST_DF);
+    set_ist(&idt[TRAP_nmi],           IST_NMI);
+    set_ist(&idt[TRAP_machine_check], IST_MCE);
+}
+
+static inline void disable_each_ist(idt_entry_t *idt)
+{
+    set_ist(&idt[TRAP_double_fault],  IST_NONE);
+    set_ist(&idt[TRAP_nmi],           IST_NONE);
+    set_ist(&idt[TRAP_machine_check], IST_NONE);
+}
+
 #define IDT_ENTRIES 256
 extern idt_entry_t idt_table[];
 extern idt_entry_t *idt_tables[];