VirtualBox

Changeset 80911 in vbox


Ignore:
Timestamp:
Sep 20, 2019 5:20:00 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133487
Message:

VMM/HM: Clear CR4.VMXE only when we set it ourselves and not if it's already set (for whatever reason).

Location:
trunk/src/VBox/VMM
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HMR0.cpp

    r80871 r80911  
    9494    DECLR0CALLBACKMEMBER(int,          pfnEnableCpu, (PHMPHYSCPU pHostCpu, PVMCC pVM, void *pvCpuPage, RTHCPHYS HCPhysCpuPage,
    9595                                                      bool fEnabledByHost, PCSUPHWVIRTMSRS pHwvirtMsrs));
    96     DECLR0CALLBACKMEMBER(int,          pfnDisableCpu, (void *pvCpuPage, RTHCPHYS HCPhysCpuPage));
     96    DECLR0CALLBACKMEMBER(int,          pfnDisableCpu, (PHMPHYSCPU pHostCpu, void *pvCpuPage, RTHCPHYS HCPhysCpuPage));
    9797    DECLR0CALLBACKMEMBER(int,          pfnInitVM, (PVMCC pVM));
    9898    DECLR0CALLBACKMEMBER(int,          pfnTermVM, (PVMCC pVM));
     
    246246}
    247247
    248 static DECLCALLBACK(int) hmR0DummyDisableCpu(void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
    249 {
    250     RT_NOREF2(pvCpuPage, HCPhysCpuPage);
     248static DECLCALLBACK(int) hmR0DummyDisableCpu(PHMPHYSCPU pHostCpu, void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
     249{
     250    RT_NOREF3(pHostCpu, pvCpuPage, HCPhysCpuPage);
    251251    return VINF_SUCCESS;
    252252}
     
    997997    if (pHostCpu->fConfigured)
    998998    {
    999         rc = g_HmR0.pfnDisableCpu(pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj);
     999        rc = g_HmR0.pfnDisableCpu(pHostCpu, pHostCpu->pvMemObj, pHostCpu->HCPhysMemObj);
    10001000        AssertRCReturn(rc, rc);
    10011001
  • trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp

    r80587 r80911  
    588588 *
    589589 * @returns VBox status code.
     590 * @param   pHostCpu        The HM physical-CPU structure.
    590591 * @param   pvCpuPage       Pointer to the global CPU page.
    591592 * @param   HCPhysCpuPage   Physical address of the global CPU page.
    592593 */
    593 VMMR0DECL(int) SVMR0DisableCpu(void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
    594 {
     594VMMR0DECL(int) SVMR0DisableCpu(PHMPHYSCPU pHostCpu, void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
     595{
     596    RT_NOREF1(pHostCpu);
    595597    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
    596598    AssertReturn(   HCPhysCpuPage
  • trunk/src/VBox/VMM/VMMR0/HMSVMR0.h

    r80587 r80911  
    4444VMMR0DECL(int)          SVMR0EnableCpu(PHMPHYSCPU pHostCpu, PVMCC pVM, void *pvPageCpu, RTHCPHYS HCPhysCpuPage,
    4545                                       bool fEnabledBySystem, PCSUPHWVIRTMSRS pHwvirtMsrs);
    46 VMMR0DECL(int)          SVMR0DisableCpu(void *pvPageCpu, RTHCPHYS pPageCpuPhys);
     46VMMR0DECL(int)          SVMR0DisableCpu(PHMPHYSCPU pHostCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
    4747VMMR0DECL(int)          SVMR0InitVM(PVMCC pVM);
    4848VMMR0DECL(int)          SVMR0TermVM(PVMCC pVM);
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r80871 r80911  
    15911591 *
    15921592 * @returns VBox status code.
     1593 * @param   pHostCpu        The HM physical-CPU structure.
    15931594 * @param   pVM             The cross context VM structure. Can be
    15941595 *                          NULL, after a resume.
     
    15961597 * @param   pvCpuPage       Pointer to the VMXON region.
    15971598 */
    1598 static int hmR0VmxEnterRootMode(PVMCC pVM, RTHCPHYS HCPhysCpuPage, void *pvCpuPage)
    1599 {
     1599static int hmR0VmxEnterRootMode(PHMPHYSCPU pHostCpu, PVMCC pVM, RTHCPHYS HCPhysCpuPage, void *pvCpuPage)
     1600{
     1601    Assert(pHostCpu);
    16001602    Assert(HCPhysCpuPage && HCPhysCpuPage != NIL_RTHCPHYS);
    16011603    Assert(RT_ALIGN_T(HCPhysCpuPage, _4K, RTHCPHYS) == HCPhysCpuPage);
     
    16151617    RTCCUINTREG const uOldCr4 = SUPR0ChangeCR4(X86_CR4_VMXE, RTCCUINTREG_MAX);
    16161618
     1619    /* Record whether VMXE was already prior to us enabling it above. */
     1620    pHostCpu->fVmxeAlreadyEnabled = RT_BOOL(uOldCr4 & X86_CR4_VMXE);
     1621
    16171622    /* Enter VMX root mode. */
    16181623    int rc = VMXEnable(HCPhysCpuPage);
     
    16201625    {
    16211626        /* Restore CR4.VMXE if it was not set prior to our attempt to set it above. */
    1622         if (!(uOldCr4 & X86_CR4_VMXE))
     1627        if (!pHostCpu->fVmxeAlreadyEnabled)
    16231628            SUPR0ChangeCR4(0 /* fOrMask */, ~(uint64_t)X86_CR4_VMXE);
    16241629
     
    16371642 *
    16381643 * @returns VBox status code.
    1639  */
    1640 static int hmR0VmxLeaveRootMode(void)
     1644 * @param   pHostCpu        The HM physical-CPU structure.
     1645 */
     1646static int hmR0VmxLeaveRootMode(PHMPHYSCPU pHostCpu)
    16411647{
    16421648    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
     
    16531659        /* Exit VMX root mode and clear the VMX bit in CR4. */
    16541660        VMXDisable();
    1655         SUPR0ChangeCR4(0 /* fOrMask */, ~(uint64_t)X86_CR4_VMXE);
     1661
     1662        /* Clear CR4.VMXE only if it was clear prior to use setting it. */
     1663        if (!pHostCpu->fVmxeAlreadyEnabled)
     1664            SUPR0ChangeCR4(0 /* fOrMask */, ~(uint64_t)X86_CR4_VMXE);
     1665
    16561666        rc = VINF_SUCCESS;
    16571667    }
     
    41194129    if (!fEnabledByHost)
    41204130    {
    4121         int rc = hmR0VmxEnterRootMode(pVM, HCPhysCpuPage, pvCpuPage);
     4131        int rc = hmR0VmxEnterRootMode(pHostCpu, pVM, HCPhysCpuPage, pvCpuPage);
    41224132        if (RT_FAILURE(rc))
    41234133            return rc;
     
    41484158 *
    41494159 * @returns VBox status code.
     4160 * @param   pHostCpu        The HM physical-CPU structure.
    41504161 * @param   pvCpuPage       Pointer to the VMXON region.
    41514162 * @param   HCPhysCpuPage   Physical address of the VMXON region.
     
    41544165 *          similar was used to enable VT-x on the host.
    41554166 */
    4156 VMMR0DECL(int) VMXR0DisableCpu(void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
     4167VMMR0DECL(int) VMXR0DisableCpu(PHMPHYSCPU pHostCpu, void *pvCpuPage, RTHCPHYS HCPhysCpuPage)
    41574168{
    41584169    RT_NOREF2(pvCpuPage, HCPhysCpuPage);
    41594170
    41604171    Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
    4161     return hmR0VmxLeaveRootMode();
     4172    return hmR0VmxLeaveRootMode(pHostCpu);
    41624173}
    41634174
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.h

    r80587 r80911  
    3636VMMR0DECL(int)          VMXR0EnableCpu(PHMPHYSCPU pHostCpu, PVMCC pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys,
    3737                                       bool fEnabledBySystem, PCSUPHWVIRTMSRS pHwvirtMsrs);
    38 VMMR0DECL(int)          VMXR0DisableCpu(void *pvPageCpu, RTHCPHYS pPageCpuPhys);
     38VMMR0DECL(int)          VMXR0DisableCpu(PHMPHYSCPU pHostCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
    3939VMMR0DECL(int)          VMXR0GlobalInit(void);
    4040VMMR0DECL(void)         VMXR0GlobalTerm(void);
  • trunk/src/VBox/VMM/include/HMInternal.h

    r80740 r80911  
    275275    /** Set if the VBOX_HWVIRTEX_IGNORE_SVM_IN_USE hack is active. */
    276276    bool                fIgnoreAMDVInUseError;
     277    /** Whether CR4.VMXE was already enabled prior to us enabling it. */
     278    bool                fVmxeAlreadyEnabled;
    277279    /** In use by our code. (for power suspend) */
    278280    bool volatile       fInUse;
Note: See TracChangeset for help on using the changeset viewer.

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