VirtualBox

Changeset 76040 in vbox


Ignore:
Timestamp:
Dec 7, 2018 7:01:21 AM (6 years ago)
Author:
vboxsync
Message:

VMM/IEM: Nested VMX: bugref:9180 IEM-only EM execution policy fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImplVmxInstr.cpp.h

    r76002 r76040  
    9999
    100100/** Gets the guest-physical address of the shadows VMCS for the given VCPU. */
    101 #define IEM_VMX_GET_SHADOW_VMCS(a_pVCpu)            ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysShadowVmcs)
     101# define IEM_VMX_GET_SHADOW_VMCS(a_pVCpu)           ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysShadowVmcs)
    102102
    103103/** Whether a shadow VMCS is present for the given VCPU. */
    104 #define IEM_VMX_HAS_SHADOW_VMCS(a_pVCpu)            RT_BOOL(IEM_VMX_GET_SHADOW_VMCS(a_pVCpu) != NIL_RTGCPHYS)
     104# define IEM_VMX_HAS_SHADOW_VMCS(a_pVCpu)           RT_BOOL(IEM_VMX_GET_SHADOW_VMCS(a_pVCpu) != NIL_RTGCPHYS)
    105105
    106106/** Gets the VMXON region pointer. */
    107 #define IEM_VMX_GET_VMXON_PTR(a_pVCpu)              ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysVmxon)
     107# define IEM_VMX_GET_VMXON_PTR(a_pVCpu)             ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysVmxon)
    108108
    109109/** Gets the guest-physical address of the current VMCS for the given VCPU. */
    110 #define IEM_VMX_GET_CURRENT_VMCS(a_pVCpu)           ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs)
     110# define IEM_VMX_GET_CURRENT_VMCS(a_pVCpu)          ((a_pVCpu)->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs)
    111111
    112112/** Whether a current VMCS is present for the given VCPU. */
    113 #define IEM_VMX_HAS_CURRENT_VMCS(a_pVCpu)           RT_BOOL(IEM_VMX_GET_CURRENT_VMCS(a_pVCpu) != NIL_RTGCPHYS)
     113# define IEM_VMX_HAS_CURRENT_VMCS(a_pVCpu)          RT_BOOL(IEM_VMX_GET_CURRENT_VMCS(a_pVCpu) != NIL_RTGCPHYS)
    114114
    115115/** Assigns the guest-physical address of the current VMCS for the given VCPU. */
    116 #define IEM_VMX_SET_CURRENT_VMCS(a_pVCpu, a_GCPhysVmcs) \
     116# define IEM_VMX_SET_CURRENT_VMCS(a_pVCpu, a_GCPhysVmcs) \
    117117    do \
    118118    { \
     
    122122
    123123/** Clears any current VMCS for the given VCPU. */
    124 #define IEM_VMX_CLEAR_CURRENT_VMCS(a_pVCpu) \
     124# define IEM_VMX_CLEAR_CURRENT_VMCS(a_pVCpu) \
    125125    do \
    126126    { \
     
    130130/** Check for VMX instructions requiring to be in VMX operation.
    131131 * @note Any changes here, check if IEMOP_HLP_IN_VMX_OPERATION needs updating. */
    132 #define IEM_VMX_IN_VMX_OPERATION(a_pVCpu, a_szInstr, a_InsDiagPrefix) \
     132# define IEM_VMX_IN_VMX_OPERATION(a_pVCpu, a_szInstr, a_InsDiagPrefix) \
    133133    do \
    134134    { \
     
    144144
    145145/** Marks a VM-entry failure with a diagnostic reason, logs and returns. */
    146 #define IEM_VMX_VMENTRY_FAILED_RET(a_pVCpu, a_pszInstr, a_pszFailure, a_VmxDiag) \
     146# define IEM_VMX_VMENTRY_FAILED_RET(a_pVCpu, a_pszInstr, a_pszFailure, a_VmxDiag) \
    147147    do \
    148148    { \
     
    154154
    155155/** Marks a VM-exit failure with a diagnostic reason, logs and returns. */
    156 #define IEM_VMX_VMEXIT_FAILED_RET(a_pVCpu, a_uExitReason, a_pszFailure, a_VmxDiag) \
     156# define IEM_VMX_VMEXIT_FAILED_RET(a_pVCpu, a_uExitReason, a_pszFailure, a_VmxDiag) \
    157157    do \
    158158    { \
     
    162162        return VERR_VMX_VMEXIT_FAILED; \
    163163    } while (0)
     164
     165/** Enables/disables IEM-only EM execution policy in and from ring-3.   */
     166# if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
     167#  define IEM_VMX_R3_EXECPOLICY_IEM_ALL_ENABLE_RET(a_pVCpu, a_pszLogPrefix) \
     168    do { \
     169        Log(("%s: Enabling IEM-only EM execution policy!\n", (a_pszLogPrefix))); \
     170        return EMR3SetExecutionPolicy((a_pVCpu)->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, true); \
     171    } while (0)
     172
     173#  define IEM_VMX_R3_EXECPOLICY_IEM_ALL_DISABLE(a_pVCpu, a_pszLogPrefix) \
     174    do { \
     175        Log(("%s: Disabling IEM-only EM execution policy!\n", (a_pszLogPrefix))); \
     176        EMR3SetExecutionPolicy((a_pVCpu)->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, false); \
     177    } while (0)
     178# else
     179#  define IEM_VMX_R3_EXECPOLICY_IEM_ALL_ENABLE_RET(a_pVCpu, a_pszLogPrefix)     do { return VINF_SUCCESS; } while (0)
     180#  define IEM_VMX_R3_EXECPOLICY_IEM_ALL_DISABLE(a_pVCpu, a_pszLogPrefix)        do { } while (0)
     181# endif
    164182
    165183
     
    28092827IEM_STATIC VBOXSTRICTRC iemVmxVmexit(PVMCPU pVCpu, uint32_t uExitReason)
    28102828{
     2829# if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     2830    RT_NOREF2(pVCpu, uExitReason);
     2831    return VINF_EM_RAW_EMULATE_INSTR;
     2832# else
    28112833    PVMXVVMCS pVmcs = pVCpu->cpum.GstCtx.hwvirt.vmx.CTX_SUFF(pVmcs);
    28122834    Assert(pVmcs);
     
    28302852        { /* likely */ }
    28312853        else
     2854        {
     2855            IEM_VMX_R3_EXECPOLICY_IEM_ALL_DISABLE(pVCpu, "VMX-Abort");
    28322856            return iemVmxAbort(pVCpu, VMXABORT_SAVE_GUEST_MSRS);
     2857        }
    28332858    }
    28342859    else
     
    28532878
    28542879    Assert(rcStrict == VINF_SUCCESS);
     2880    IEM_VMX_R3_EXECPOLICY_IEM_ALL_DISABLE(pVCpu, "VM-exit");
    28552881    return VINF_VMX_VMEXIT;
     2882# endif
    28562883}
    28572884
     
    71337160IEM_STATIC VBOXSTRICTRC iemVmxVmlaunchVmresume(PVMCPU pVCpu, uint8_t cbInstr, VMXINSTRID uInstrId, PCVMXVEXITINFO pExitInfo)
    71347161{
     7162# if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     7163    RT_NOREF4(pVCpu, cbInstr, uInstrId, pExitInfo);
     7164    return VINF_EM_RAW_EMULATE_INSTR;
     7165# else
    71357166    Assert(   uInstrId == VMXINSTRID_VMLAUNCH
    71367167           || uInstrId == VMXINSTRID_VMRESUME);
     
    73327363    iemVmxVmFail(pVCpu, VMXINSTRERR_VMENTRY_INVALID_CTLS);
    73337364    iemRegAddToRipAndClearRF(pVCpu, cbInstr);
    7334     return VINF_SUCCESS;
     7365    IEM_VMX_R3_EXECPOLICY_IEM_ALL_ENABLE_RET(pVCpu, pszInstr);
     7366# endif
    73357367}
    73367368
     
    78957927        rcStrict = PGMPhysSimpleWriteGCPhys(pVCpu->CTX_SUFF(pVM), GCPtrVmcs + RT_UOFFSETOF(VMXVVMCS, fVmcsState),
    78967928                                            (const void *)&fVmcsStateClear, sizeof(fVmcsStateClear));
     7929        if (RT_FAILURE(rcStrict))
     7930            return rcStrict;
    78977931    }
    78987932
    78997933    iemVmxVmSucceed(pVCpu);
    79007934    iemRegAddToRipAndClearRF(pVCpu, cbInstr);
    7901     return rcStrict;
     7935    return VINF_SUCCESS;
    79027936}
    79037937
     
    81088142                                    PCVMXVEXITINFO pExitInfo)
    81098143{
    8110 #if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
    8111     RT_NOREF5(pVCpu, cbInstr, iEffSeg, GCPtrVmxon, pExitInfo);
    8112     return VINF_EM_RAW_EMULATE_INSTR;
    8113 #else
    81148144    if (!IEM_VMX_IS_ROOT_MODE(pVCpu))
    81158145    {
     
    82678297        iemVmxVmSucceed(pVCpu);
    82688298        iemRegAddToRipAndClearRF(pVCpu, cbInstr);
    8269 # if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
    8270         return EMR3SetExecutionPolicy(pVCpu->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, true);
    8271 # else
    82728299        return VINF_SUCCESS;
    8273 # endif
    82748300    }
    82758301    else if (IEM_VMX_IS_NON_ROOT_MODE(pVCpu))
     
    82968322    iemRegAddToRipAndClearRF(pVCpu, cbInstr);
    82978323    return VINF_SUCCESS;
    8298 #endif
    82998324}
    83008325
     
    83088333IEM_CIMPL_DEF_0(iemCImpl_vmxoff)
    83098334{
    8310 # if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
    8311     RT_NOREF2(pVCpu, cbInstr);
    8312     return VINF_EM_RAW_EMULATE_INSTR;
    8313 # else
    83148335    /* Nested-guest intercept. */
    83158336    if (IEM_VMX_IS_NON_ROOT_MODE(pVCpu))
     
    83458366    iemVmxVmSucceed(pVCpu);
    83468367    iemRegAddToRipAndClearRF(pVCpu, cbInstr);
    8347 #  if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
    8348     return EMR3SetExecutionPolicy(pVCpu->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, false);
    8349 #  else
    83508368    return VINF_SUCCESS;
    8351 #  endif
    8352 # endif
    83538369}
    83548370
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette