implemented VMX Monitor Trap Flag handling

This commit is contained in:
Stanislav Shwartsman 2022-08-16 21:17:05 +03:00
parent 180c1f09d5
commit b946570838
11 changed files with 23 additions and 13 deletions

View File

@ -213,7 +213,7 @@ Bit32u broadwell_ult_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -235,7 +235,7 @@ Bit32u corei3_cnl_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -175,7 +175,7 @@ Bit32u corei5_arrandale_m520_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -154,7 +154,7 @@ Bit32u corei5_lynnfield_750_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_SAVE_DEBUGCTL_DISABLE |

View File

@ -183,7 +183,7 @@ Bit32u corei7_haswell_4770_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -193,7 +193,7 @@ Bit32u corei7_ivy_bridge_3770k_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -189,7 +189,7 @@ Bit32u corei7_sandy_bridge_2600k_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -229,7 +229,7 @@ Bit32u corei7_skylake_x_t::get_vmx_extensions_bitmask(void) const
BX_VMX_VIRTUAL_NMI |
BX_VMX_APIC_VIRTUALIZATION |
BX_VMX_WBINVD_VMEXIT |
/* BX_VMX_MONITOR_TRAP_FLAG | */ // not implemented yet
BX_VMX_MONITOR_TRAP_FLAG |
BX_VMX_VPID |
BX_VMX_EPT |
BX_VMX_UNRESTRICTED_GUEST |

View File

@ -258,8 +258,13 @@ bool BX_CPU_C::handleAsyncEvent(void)
}
#if BX_SUPPORT_VMX
if (is_unmasked_event_pending(BX_EVENT_VMX_MONITOR_TRAP_FLAG)) {
VMexit(VMX_VMEXIT_MONITOR_TRAP_FLAG, 0);
if (is_pending(BX_EVENT_VMX_MONITOR_TRAP_FLAG)) {
if (is_unmasked_event_pending(BX_EVENT_VMX_MONITOR_TRAP_FLAG)) {
VMexit(VMX_VMEXIT_MONITOR_TRAP_FLAG, 0);
}
else {
unmask_event(BX_EVENT_VMX_MONITOR_TRAP_FLAG);
}
}
#endif
@ -369,7 +374,7 @@ bool BX_CPU_C::handleAsyncEvent(void)
// Alignment check
// (handled by rest of the code)
if (!((SVM_GIF && unmasked_events_pending()) || BX_CPU_THIS_PTR debug_trap ||
if (!((SVM_GIF && unmasked_events_pending()) || BX_CPU_THIS_PTR debug_trap || is_unmasked_event_pending(BX_EVENT_VMX_MONITOR_TRAP_FLAG) ||
// BX_CPU_THIS_PTR get_TF() || // implies debug_trap is set
BX_HRQ))
{

View File

@ -2157,6 +2157,11 @@ Bit32u BX_CPU_C::VMenterLoadCheckGuestState(Bit64u *qualification)
mask_event(BX_EVENT_NMI);
}
if (vm->vmexec_ctrls2 & VMX_VM_EXEC_CTRL2_MONITOR_TRAP_FLAG) {
signal_event(BX_EVENT_VMX_MONITOR_TRAP_FLAG);
mask_event(BX_EVENT_VMX_MONITOR_TRAP_FLAG);
}
if (vm->vmexec_ctrls2 & VMX_VM_EXEC_CTRL2_NMI_WINDOW_EXITING)
signal_event(BX_EVENT_VMX_VIRTUAL_NMI);

View File

@ -148,11 +148,11 @@ enum VMX_vmexit_reason {
VMX_VMEXIT_LAST_REASON
};
// note, MONITOR_TRAP_FLAG should not be here because it taken between instructions
#define IS_TRAP_LIKE_VMEXIT(reason) \
(reason == VMX_VMEXIT_TPR_THRESHOLD || \
reason == VMX_VMEXIT_VIRTUALIZED_EOI || \
reason == VMX_VMEXIT_APIC_WRITE || \
reason == VMX_VMEXIT_MONITOR_TRAP_FLAG || \
reason == VMX_VMEXIT_BUS_LOCK)
// VMexit on CR register access
@ -173,7 +173,7 @@ enum VMX_vmentry_error {
// VMABORT error code
enum VMX_vmabort_code {
VMABORT_SAVING_GUEST_MSRS_FAILURE,
VMABORT_SAVING_GUEST_MSRS_FAILURE = 0,
VMABORT_HOST_PDPTR_CORRUPTED,
VMABORT_VMEXIT_VMCS_CORRUPTED,
VMABORT_LOADING_HOST_MSRS,