Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit fdcdf05

Browse files
committed
Generate #UD exception for unsupported instructions which cause vm-exits,
instead of terminating the guest. Signed-off-by: Alexey Romko <nevilad@yahoo.com>
1 parent 4471ba7 commit fdcdf05

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

core/include/vmx.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ enum {
5858
VMX_EXIT_RDPMC = 15, // Guest executed RDPMC instruction
5959
VMX_EXIT_RDTSC = 16, // Guest executed RDTSC instruction
6060
VMX_EXIT_RSM = 17, // Guest executed RSM instruction in SMM
61-
VMX_EXIT_VMCALL = 18,
62-
VMX_EXIT_VMCLEAR = 19,
63-
VMX_EXIT_VMLAUNCH = 20,
64-
VMX_EXIT_VMPTRLD = 21,
65-
VMX_EXIT_VMPTRST = 22,
66-
VMX_EXIT_VMREAD = 23,
67-
VMX_EXIT_VMRESUME = 24,
68-
VMX_EXIT_VMWRITE = 25,
69-
VMX_EXIT_VMXOFF = 26,
70-
VMX_EXIT_VMXON = 27,
61+
VMX_EXIT_VMCALL = 18, // Guest executed VMCALL instruction
62+
VMX_EXIT_VMCLEAR = 19, // Guest executed VMCLEAR instruction
63+
VMX_EXIT_VMLAUNCH = 20, // Guest executed VMLAUNCH instruction
64+
VMX_EXIT_VMPTRLD = 21, // Guest executed VMPTRLD instruction
65+
VMX_EXIT_VMPTRST = 22, // Guest executed VMPTRST instruction
66+
VMX_EXIT_VMREAD = 23, // Guest executed VMREAD instruction
67+
VMX_EXIT_VMRESUME = 24, // Guest executed VMRESUME instruction
68+
VMX_EXIT_VMWRITE = 25, // Guest executed VMWRITE instruction
69+
VMX_EXIT_VMXOFF = 26, // Guest executed VMXON instruction
70+
VMX_EXIT_VMXON = 27, // Guest executed VMXOFF instruction
7171
VMX_EXIT_CR_ACCESS = 28, // Guest accessed a control register
7272
VMX_EXIT_DR_ACCESS = 29, // Guest attempted access to debug register
7373
VMX_EXIT_IO = 30, // Guest attempted I/O
@@ -91,7 +91,7 @@ enum {
9191
VMX_EXIT_VMX_TIMER_EXIT = 52,
9292
VMX_EXIT_INVVPID = 53,
9393
VMX_EXIT_WBINVD = 54,
94-
VMX_EXIT_XSETBV = 55,
94+
VMX_EXIT_XSETBV = 55, // Guest executed XSETBV instruction
9595
VMX_EXIT_APIC_WRITE = 56,
9696
VMX_EXIT_RDRAND = 57,
9797
VMX_EXIT_INVPCID = 58,

core/vcpu.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static int exit_invalid_guest_state(struct vcpu_t *vcpu,
100100
static int exit_ept_misconfiguration(struct vcpu_t *vcpu,
101101
struct hax_tunnel *htun);
102102
static int exit_ept_violation(struct vcpu_t *vcpu, struct hax_tunnel *htun);
103+
static int exit_unsupported_instruction(struct vcpu_t *vcpu,
104+
struct hax_tunnel *htun);
103105
static int null_handler(struct vcpu_t *vcpu, struct hax_tunnel *hun);
104106

105107
static void advance_rip(struct vcpu_t *vcpu);
@@ -388,6 +390,22 @@ static int (*handler_funcs[])(struct vcpu_t *vcpu, struct hax_tunnel *htun) = {
388390
[VMX_EXIT_FAILED_VMENTER_GS] = exit_invalid_guest_state,
389391
[VMX_EXIT_EPT_VIOLATION] = exit_ept_violation,
390392
[VMX_EXIT_EPT_MISCONFIG] = exit_ept_misconfiguration,
393+
[VMX_EXIT_GETSEC] = exit_unsupported_instruction,
394+
[VMX_EXIT_INVD] = exit_unsupported_instruction,
395+
[VMX_EXIT_VMCALL] = exit_unsupported_instruction,
396+
[VMX_EXIT_VMCLEAR] = exit_unsupported_instruction,
397+
[VMX_EXIT_VMLAUNCH] = exit_unsupported_instruction,
398+
[VMX_EXIT_VMPTRLD] = exit_unsupported_instruction,
399+
[VMX_EXIT_VMPTRST] = exit_unsupported_instruction,
400+
//VMREAD and VMWRITE vm-exits are conditional. When "VMCS shadowing" bit
401+
//in secondary CPU VM-execution control is 0, these exit. This condition
402+
//holds in haxm.
403+
[VMX_EXIT_VMREAD] = exit_unsupported_instruction,
404+
[VMX_EXIT_VMWRITE] = exit_unsupported_instruction,
405+
[VMX_EXIT_VMRESUME] = exit_unsupported_instruction,
406+
[VMX_EXIT_VMXOFF] = exit_unsupported_instruction,
407+
[VMX_EXIT_VMXON] = exit_unsupported_instruction,
408+
[VMX_EXIT_XSETBV] = exit_unsupported_instruction,
391409
};
392410

393411
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)
38823900
return vcpu_emulate_insn(vcpu);
38833901
}
38843902

3903+
static int exit_unsupported_instruction(struct vcpu_t *vcpu,
3904+
struct hax_tunnel *htun)
3905+
{
3906+
hax_inject_exception(vcpu, VECTOR_UD, NO_ERROR_CODE);
3907+
return HAX_RESUME;
3908+
}
3909+
38853910
static void handle_mem_fault(struct vcpu_t *vcpu, struct hax_tunnel *htun)
38863911
{
38873912
hax_log(HAX_LOGW,

0 commit comments

Comments
 (0)