diff --git a/core/include/vmx.h b/core/include/vmx.h index 0d7e4fa9..22ad4e75 100644 --- a/core/include/vmx.h +++ b/core/include/vmx.h @@ -58,16 +58,16 @@ enum { VMX_EXIT_RDPMC = 15, // Guest executed RDPMC instruction VMX_EXIT_RDTSC = 16, // Guest executed RDTSC instruction VMX_EXIT_RSM = 17, // Guest executed RSM instruction in SMM - VMX_EXIT_VMCALL = 18, - VMX_EXIT_VMCLEAR = 19, - VMX_EXIT_VMLAUNCH = 20, - VMX_EXIT_VMPTRLD = 21, - VMX_EXIT_VMPTRST = 22, - VMX_EXIT_VMREAD = 23, - VMX_EXIT_VMRESUME = 24, - VMX_EXIT_VMWRITE = 25, - VMX_EXIT_VMXOFF = 26, - VMX_EXIT_VMXON = 27, + VMX_EXIT_VMCALL = 18, // Guest executed VMCALL instruction + VMX_EXIT_VMCLEAR = 19, // Guest executed VMCLEAR instruction + VMX_EXIT_VMLAUNCH = 20, // Guest executed VMLAUNCH instruction + VMX_EXIT_VMPTRLD = 21, // Guest executed VMPTRLD instruction + VMX_EXIT_VMPTRST = 22, // Guest executed VMPTRST instruction + VMX_EXIT_VMREAD = 23, // Guest executed VMREAD instruction + VMX_EXIT_VMRESUME = 24, // Guest executed VMRESUME instruction + VMX_EXIT_VMWRITE = 25, // Guest executed VMWRITE instruction + VMX_EXIT_VMXOFF = 26, // Guest executed VMXON instruction + VMX_EXIT_VMXON = 27, // Guest executed VMXOFF instruction VMX_EXIT_CR_ACCESS = 28, // Guest accessed a control register VMX_EXIT_DR_ACCESS = 29, // Guest attempted access to debug register VMX_EXIT_IO = 30, // Guest attempted I/O @@ -91,7 +91,7 @@ enum { VMX_EXIT_VMX_TIMER_EXIT = 52, VMX_EXIT_INVVPID = 53, VMX_EXIT_WBINVD = 54, - VMX_EXIT_XSETBV = 55, + VMX_EXIT_XSETBV = 55, // Guest executed XSETBV instruction VMX_EXIT_APIC_WRITE = 56, VMX_EXIT_RDRAND = 57, VMX_EXIT_INVPCID = 58, diff --git a/core/vcpu.c b/core/vcpu.c index 105b8e50..cc38a073 100644 --- a/core/vcpu.c +++ b/core/vcpu.c @@ -100,6 +100,8 @@ static int exit_invalid_guest_state(struct vcpu_t *vcpu, static int exit_ept_misconfiguration(struct vcpu_t *vcpu, struct hax_tunnel *htun); static int exit_ept_violation(struct vcpu_t *vcpu, struct hax_tunnel *htun); +static int exit_unsupported_instruction(struct vcpu_t *vcpu, + struct hax_tunnel *htun); static int null_handler(struct vcpu_t *vcpu, struct hax_tunnel *hun); static void advance_rip(struct vcpu_t *vcpu); @@ -388,6 +390,22 @@ static int (*handler_funcs[])(struct vcpu_t *vcpu, struct hax_tunnel *htun) = { [VMX_EXIT_FAILED_VMENTER_GS] = exit_invalid_guest_state, [VMX_EXIT_EPT_VIOLATION] = exit_ept_violation, [VMX_EXIT_EPT_MISCONFIG] = exit_ept_misconfiguration, + [VMX_EXIT_GETSEC] = exit_unsupported_instruction, + [VMX_EXIT_INVD] = exit_unsupported_instruction, + [VMX_EXIT_VMCALL] = exit_unsupported_instruction, + [VMX_EXIT_VMCLEAR] = exit_unsupported_instruction, + [VMX_EXIT_VMLAUNCH] = exit_unsupported_instruction, + [VMX_EXIT_VMPTRLD] = exit_unsupported_instruction, + [VMX_EXIT_VMPTRST] = exit_unsupported_instruction, + //VMREAD and VMWRITE vm-exits are conditional. When "VMCS shadowing" bit + //in secondary CPU VM-execution control is 0, these exit. This condition + //holds in haxm. + [VMX_EXIT_VMREAD] = exit_unsupported_instruction, + [VMX_EXIT_VMWRITE] = exit_unsupported_instruction, + [VMX_EXIT_VMRESUME] = exit_unsupported_instruction, + [VMX_EXIT_VMXOFF] = exit_unsupported_instruction, + [VMX_EXIT_VMXON] = exit_unsupported_instruction, + [VMX_EXIT_XSETBV] = exit_unsupported_instruction, }; static int nr_handlers = ARRAY_ELEMENTS(handler_funcs); @@ -3882,6 +3900,13 @@ static int exit_ept_violation(struct vcpu_t *vcpu, struct hax_tunnel *htun) return vcpu_emulate_insn(vcpu); } +static int exit_unsupported_instruction(struct vcpu_t *vcpu, + struct hax_tunnel *htun) +{ + hax_inject_exception(vcpu, VECTOR_UD, NO_ERROR_CODE); + return HAX_RESUME; +} + static void handle_mem_fault(struct vcpu_t *vcpu, struct hax_tunnel *htun) { hax_log(HAX_LOGW,