VirtualBox

Changeset 43379 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Sep 20, 2012 11:29:12 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
80845
Message:

SUPDrv,VMM: Prepared for SUPR0EnableVTx on darwin.

Location:
trunk/src/VBox/VMM/VMMR0
Files:
3 edited

Legend:

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

    r43376 r43379  
    16911691 * @returns VBox status code.
    16921692 * @param   pVM             Pointer to the VM.
     1693 * @param   enmSwitcher     The switcher we're about to use.
    16931694 * @param   pfVTxDisabled   Where to store whether VT-x was disabled or not.
    16941695 */
    1695 VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, bool *pfVTxDisabled)
     1696VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled)
    16961697{
    16971698    Assert(!(ASMGetFlags() & X86_EFL_IF) || !RTThreadPreemptIsEnabled(NIL_RTTHREAD));
     
    16991700    *pfVTxDisabled = false;
    17001701
    1701     if (   !g_HvmR0.fEnabled
    1702         || !g_HvmR0.vmx.fSupported /* no such issues with AMD-V */
    1703         || !g_HvmR0.fGlobalInit    /* Local init implies the CPU is currently not in VMX root mode. */)
    1704         return VINF_SUCCESS;    /* nothing to do */
    1705 
    1706     switch (VMMGetSwitcher(pVM))
     1702    /* No such issues with AMD-V */
     1703    if (!g_HvmR0.vmx.fSupported)
     1704        return VINF_SUCCESS;
     1705
     1706    /* Check if the swithcing we're up to is safe. */
     1707    switch (enmSwitcher)
    17071708    {
    17081709        case VMMSWITCHER_32_TO_32:
     
    17201721    }
    17211722
     1723    /* When using SUPR0EnableVTx we must let the host suspend and resume VT-x,
     1724       regardless of whether we're currently using VT-x or not. */
     1725    if (g_HvmR0.vmx.fUsingSUPR0EnableVTx)
     1726    {
     1727        *pfVTxDisabled = SUPR0SuspendVTxOnCpu();
     1728        return VINF_SUCCESS;
     1729    }
     1730
     1731    /** @todo Check if this code is presumtive wrt other VT-x users on the
     1732     *        system... */
     1733
     1734    /* Nothing to do if we haven't enabled VT-x. */
     1735    if (!g_HvmR0.fEnabled)
     1736        return VINF_SUCCESS;
     1737
     1738    /* Local init implies the CPU is currently not in VMX root mode. */
     1739    if (!g_HvmR0.fGlobalInit)
     1740        return VINF_SUCCESS;
     1741
     1742    /* Ok, disable VT-x. */
    17221743    PHMGLOBLCPUINFO pCpu = HWACCMR0GetCurrentCpu();
    17231744    AssertReturn(pCpu && pCpu->hMemObj != NIL_RTR0MEMOBJ, VERR_HM_IPE_2);
     
    17341755 * switcher turned off paging.
    17351756 *
    1736  * @returns VBox status code.
    17371757 * @param   pVM             Pointer to the VM.
    17381758 * @param   fVTxDisabled    Whether VT-x was disabled or not.
    17391759 */
    1740 VMMR0DECL(int) HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled)
     1760VMMR0DECL(void) HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled)
    17411761{
    17421762    Assert(!(ASMGetFlags() & X86_EFL_IF));
    17431763
    17441764    if (!fVTxDisabled)
    1745         return VINF_SUCCESS;    /* nothing to do */
    1746 
    1747     Assert(g_HvmR0.fEnabled);
     1765        return;         /* nothing to do */
     1766
    17481767    Assert(g_HvmR0.vmx.fSupported);
    1749     Assert(g_HvmR0.fGlobalInit);
    1750 
    1751     PHMGLOBLCPUINFO pCpu = HWACCMR0GetCurrentCpu();
    1752     AssertReturn(pCpu && pCpu->hMemObj != NIL_RTR0MEMOBJ, VERR_HM_IPE_2);
    1753 
    1754     void           *pvCpuPage     = RTR0MemObjAddress(pCpu->hMemObj);
    1755     RTHCPHYS        HCPhysCpuPage = RTR0MemObjGetPagePhysAddr(pCpu->hMemObj, 0);
    1756     return VMXR0EnableCpu(pCpu, pVM, pvCpuPage, HCPhysCpuPage, false);
     1768    if (g_HvmR0.vmx.fUsingSUPR0EnableVTx)
     1769        SUPR0ResumeVTxOnCpu(fVTxDisabled);
     1770    else
     1771    {
     1772        Assert(g_HvmR0.fEnabled);
     1773        Assert(g_HvmR0.fGlobalInit);
     1774
     1775        PHMGLOBLCPUINFO pCpu = HWACCMR0GetCurrentCpu();
     1776        AssertReturnVoid(pCpu && pCpu->hMemObj != NIL_RTR0MEMOBJ);
     1777
     1778        void           *pvCpuPage     = RTR0MemObjAddress(pCpu->hMemObj);
     1779        RTHCPHYS        HCPhysCpuPage = RTR0MemObjGetPagePhysAddr(pCpu->hMemObj, 0);
     1780        VMXR0EnableCpu(pCpu, pVM, pvCpuPage, HCPhysCpuPage, false);
     1781    }
    17571782}
    17581783
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r43361 r43379  
    137137         */
    138138
    139         if (ASMGetCR4() & X86_CR4_VMXE)
    140             return VERR_VMX_IN_VMX_ROOT_MODE;
    141 
    142         ASMSetCR4(ASMGetCR4() | X86_CR4_VMXE);    /* Make sure the VMX instructions don't cause #UD faults. */
     139        /** @todo r=bird: Why is this code different than the probing code earlier
     140         *        on? It just sets VMXE if needed and doesn't check that it isn't
     141         *        set.  Mac OS X host_vmxoff may leave this set and we'll fail here
     142         *        and debug-assert in the calling code.  This is what caused the
     143         *        "regression" after backing out the SUPR0EnableVTx code hours before
     144         *        4.2.0GA (reboot fixed the issue).  I've changed here to do the same
     145         *        as the init code. */
     146        uint64_t uCr4 = ASMGetCR4();
     147        if (!(uCr4 & X86_CR4_VMXE))
     148            ASMSetCR4(ASMGetCR4() | X86_CR4_VMXE);    /* Make sure the VMX instructions don't cause #UD faults. */
    143149
    144150        /*
     
    148154        if (RT_FAILURE(rc))
    149155        {
    150             ASMSetCR4(ASMGetCR4() & ~X86_CR4_VMXE);
     156            ASMSetCR4(uCr4);
    151157            return VERR_VMX_VMXON_FAILED;
    152158        }
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r43303 r43379  
    683683                /* We might need to disable VT-x if the active switcher turns off paging. */
    684684                bool fVTxDisabled;
    685                 int rc = HWACCMR0EnterSwitcher(pVM, &fVTxDisabled);
     685                int rc = HWACCMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
    686686                if (RT_SUCCESS(rc))
    687687                {
     
    999999
    10001000            /* We might need to disable VT-x if the active switcher turns off paging. */
    1001             rc = HWACCMR0EnterSwitcher(pVM, &fVTxDisabled);
     1001            rc = HWACCMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
    10021002            if (RT_FAILURE(rc))
    10031003                return rc;
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