@@ -353,3 +353,27 @@ void print_current_tss_info(void)
tr, tss[0].prev, tss[i].prev);
}
#endif
+
+static bool exception;
+static void *exception_return;
+
+static void exception_handler(struct ex_regs *regs)
+{
+ exception = true;
+ regs->rip = (unsigned long)exception_return;
+}
+
+bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data),
+ void *data)
+{
+ handle_exception(ex, exception_handler);
+ exception = false;
+ trigger_func(data);
+ handle_exception(ex, NULL);
+ return exception;
+}
+
+void set_exception_return(void *addr)
+{
+ exception_return = addr;
+}
@@ -84,4 +84,8 @@ void set_intr_task_gate(int e, void *fn);
void print_current_tss_info(void);
void handle_exception(u8 v, void (*func)(struct ex_regs *regs));
+bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data),
+ void *data);
+void set_exception_return(void *addr);
+
#endif
@@ -538,38 +538,18 @@ static void init_vmx(void)
memset(guest_syscall_stack, 0, PAGE_SIZE);
}
-static bool exception;
-static void *exception_return;
-
-static void exception_handler(struct ex_regs *regs)
+static void do_vmxon_off(void *data)
{
- exception = true;
- regs->rip = (u64)exception_return;
-}
-
-static int test_for_exception(unsigned int ex, void (*func)(void))
-{
- handle_exception(ex, exception_handler);
- exception = false;
- func();
- handle_exception(ex, NULL);
- return exception;
-}
-
-static void do_vmxon_off(void)
-{
- exception_return = &&resume;
- barrier();
+ set_exception_return(&&resume);
vmx_on();
vmx_off();
resume:
barrier();
}
-static void do_write_feature_control(void)
+static void do_write_feature_control(void *data)
{
- exception_return = &&resume;
- barrier();
+ set_exception_return(&&resume);
wrmsr(MSR_IA32_FEATURE_CONTROL, 0);
resume:
barrier();
@@ -592,18 +572,18 @@ static int test_vmx_feature_control(void)
wrmsr(MSR_IA32_FEATURE_CONTROL, 0);
report("test vmxon with FEATURE_CONTROL cleared",
- test_for_exception(GP_VECTOR, &do_vmxon_off));
+ test_for_exception(GP_VECTOR, &do_vmxon_off, NULL));
wrmsr(MSR_IA32_FEATURE_CONTROL, 0x4);
report("test vmxon without FEATURE_CONTROL lock",
- test_for_exception(GP_VECTOR, &do_vmxon_off));
+ test_for_exception(GP_VECTOR, &do_vmxon_off, NULL));
wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5);
vmx_enabled = ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) == 0x5);
report("test enable VMX in FEATURE_CONTROL", vmx_enabled);
report("test FEATURE_CONTROL lock bit",
- test_for_exception(GP_VECTOR, &do_write_feature_control));
+ test_for_exception(GP_VECTOR, &do_write_feature_control, NULL));
return !vmx_enabled;
}