Changeset 43379 in vbox
- Timestamp:
- Sep 20, 2012 11:29:12 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
-
include/VBox/sup.h (modified) (1 diff)
-
include/VBox/vmm/hwaccm.h (modified) (2 diffs)
-
src/VBox/HostDrivers/Support/Makefile.kmk (modified) (1 diff)
-
src/VBox/HostDrivers/Support/SUPDrv.c (modified) (2 diffs)
-
src/VBox/HostDrivers/Support/SUPDrvIOC.h (modified) (1 diff)
-
src/VBox/HostDrivers/Support/SUPDrvInternal.h (modified) (1 diff)
-
src/VBox/HostDrivers/Support/SUPLib.cpp (modified) (1 diff)
-
src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp (modified) (11 diffs)
-
src/VBox/VMM/VMMR0/HWACCMR0.cpp (modified) (4 diffs)
-
src/VBox/VMM/VMMR0/HWVMXR0.cpp (modified) (2 diffs)
-
src/VBox/VMM/VMMR0/VMMR0.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/sup.h
r41147 r43379 1363 1363 SUPR0DECL(SUPPAGINGMODE) SUPR0GetPagingMode(void); 1364 1364 SUPR0DECL(int) SUPR0EnableVTx(bool fEnable); 1365 SUPR0DECL(bool) SUPR0SuspendVTxOnCpu(void); 1366 SUPR0DECL(void) SUPR0ResumeVTxOnCpu(bool fSuspended); 1365 1367 1366 1368 /** @name Absolute symbols -
trunk/include/VBox/vmm/hwaccm.h
r37320 r43379 29 29 #include <VBox/vmm/pgm.h> 30 30 #include <VBox/vmm/cpum.h> 31 #include <VBox/vmm/vmm.h> 31 32 #include <iprt/mp.h> 32 33 … … 82 83 VMMR0DECL(int) HWACCMR0TermVM(PVM pVM); 83 84 VMMR0DECL(int) HWACCMR0EnableAllCpus(PVM pVM); 84 VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, bool *pfVTxDisabled);85 VMMR0DECL( int)HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled);85 VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled); 86 VMMR0DECL(void) HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled); 86 87 87 88 VMMR0DECL(void) HWACCMR0SavePendingIOPortWrite(PVMCPU pVCpu, RTGCPTR GCPtrRip, RTGCPTR GCPtrRipNext, unsigned uPort, unsigned uAndVal, unsigned cbSize); -
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r43315 r43379 267 267 endif 268 268 #VBoxDrv_DEFS.debug += DEBUG_DARWIN_GIP 269 #VBoxDrv_DEFS.darwin := VBOX_WITH_HOST_VMX - break raw-mode, hack+enable after 4.2.0!269 #VBoxDrv_DEFS.darwin := VBOX_WITH_HOST_VMX 270 270 VBoxDrv_DEFS.linux := \ 271 271 KBUILD_MODNAME=KBUILD_STR\(vboxdrv\) KBUILD_BASENAME=KBUILD_STR\(vboxdrv\) MODULE CONFIG_VBOXDRV_AS_MISC -
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r42024 r43379 173 173 { "SUPR0ContFree", (void *)SUPR0ContFree }, 174 174 { "SUPR0EnableVTx", (void *)SUPR0EnableVTx }, 175 { "SUPR0SuspendVTxOnCpu", (void *)SUPR0SuspendVTxOnCpu }, 176 { "SUPR0ResumeVTxOnCpu", (void *)SUPR0ResumeVTxOnCpu }, 175 177 { "SUPR0GetPagingMode", (void *)SUPR0GetPagingMode }, 176 178 { "SUPR0LockMem", (void *)SUPR0LockMem }, … … 3188 3190 3189 3191 3192 /** 3193 * Suspends hardware virtualization extensions using the native OS API. 3194 * 3195 * This is called prior to entering raw-mode context. 3196 * 3197 * @returns @c true if suspended, @c false if not. 3198 */ 3199 SUPR0DECL(bool) SUPR0SuspendVTxOnCpu(void) 3200 { 3201 #ifdef RT_OS_DARWIN 3202 return supdrvOSSuspendVTxOnCpu(); 3203 #else 3204 return false; 3205 #endif 3206 } 3207 3208 3209 /** 3210 * Resumes hardware virtualization extensions using the native OS API. 3211 * 3212 * This is called after to entering raw-mode context. 3213 * 3214 * @param fSuspended The return value of SUPR0SuspendVTxOnCpu. 3215 */ 3216 SUPR0DECL(void) SUPR0ResumeVTxOnCpu(bool fSuspended) 3217 { 3218 #ifdef RT_OS_DARWIN 3219 supdrvOSResumeVTxOnCpu(fSuspended); 3220 #else 3221 Assert(!fSuspended); 3222 #endif 3223 } 3224 3225 3190 3226 /** @todo document me */ 3191 3227 SUPR0DECL(int) SUPR0QueryVTCaps(PSUPDRVSESSION pSession, uint32_t *pfCaps) -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r41783 r43379 194 194 * - Remove RTSpinlockReleaseNoInts. 195 195 */ 196 #define SUPDRV_IOC_VERSION 0x001a000 4196 #define SUPDRV_IOC_VERSION 0x001a0005 197 197 198 198 /** SUP_IOCTL_COOKIE. */ -
trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
r42784 r43379 601 601 bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt); 602 602 int VBOXCALL supdrvOSEnableVTx(bool fEnabled); 603 bool VBOXCALL supdrvOSSuspendVTxOnCpu(void); 604 void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended); 603 605 604 606 /** -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r43358 r43379 269 269 CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION; 270 270 const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x00190000 271 ? 0x001 90003271 ? 0x001a0005 272 272 : SUPDRV_IOC_VERSION & 0xffff0000; 273 273 CookieReq.u.In.u32MinVersion = uMinVersion; -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r43308 r43379 43 43 #include <VBox/version.h> 44 44 #include <iprt/asm.h> 45 #include <iprt/asm-amd64-x86.h> 45 46 #include <iprt/initterm.h> 46 47 #include <iprt/assert.h> … … 50 51 #include <iprt/alloc.h> 51 52 #include <iprt/power.h> 53 #include <iprt/dbg.h> 52 54 #include <VBox/err.h> 53 55 #include <VBox/log.h> … … 99 101 static IOReturn VBoxDrvDarwinSleepHandler(void *pvTarget, void *pvRefCon, UInt32 uMessageType, IOService *pProvider, void *pvMessageArgument, vm_size_t argSize); 100 102 RT_C_DECLS_END 103 104 static void vboxdrvDarwinResolveSymbols(void); 101 105 102 106 … … 211 215 static int32_t volatile g_cSessions = 0; 212 216 /** The notifier handle for the sleep callback handler. */ 213 static IONotifier *g_pSleepNotifier = NULL; 214 217 static IONotifier *g_pSleepNotifier = NULL; 218 219 /** Pointer to vmx_suspend(). */ 220 static PFNRT g_pfnVmxSuspend = NULL; 221 /** Pointer to vmx_resume(). */ 222 static PFNRT g_pfnVmxResume = NULL; 223 /** Pointer to vmx_use_count. */ 224 static int volatile *g_pVmxUseCount = NULL; 215 225 216 226 … … 267 277 LogRel(("VBoxDrv: register for sleep/wakeup events failed\n")); 268 278 279 /* Find kernel symbols that are kind of optional. */ 280 vboxdrvDarwinResolveSymbols(); 269 281 return KMOD_RETURN_SUCCESS; 270 282 } … … 296 308 297 309 /** 310 * Resolves kernel symbols we want (but may do without). 311 */ 312 static void vboxdrvDarwinResolveSymbols(void) 313 { 314 RTDBGKRNLINFO hKrnlInfo; 315 int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0); 316 if (RT_SUCCESS(rc)) 317 { 318 /* The VMX stuff. */ 319 int rc1 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_resume", (void **)&g_pfnVmxResume); 320 int rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_suspend", (void **)&g_pfnVmxSuspend); 321 int rc3 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vmx_use_count", (void **)&g_pVmxUseCount); 322 if (RT_SUCCESS(rc1) && RT_SUCCESS(rc2) && RT_SUCCESS(rc3)) 323 { 324 LogRel(("VBoxDrv: vmx_resume=%p vmx_suspend=%p vmx_use_count=%p (%d) cr4=%#x\n", 325 g_pfnVmxResume, g_pfnVmxSuspend, g_pVmxUseCount, *g_pVmxUseCount, ASMGetCR4() )); 326 } 327 else 328 { 329 LogRel(("VBoxDrv: failed to resolve vmx stuff: vmx_resume=%Rrc vmx_suspend=%Rrc vmx_use_count=%Rrc", rc1, rc2, rc3)); 330 g_pfnVmxResume = NULL; 331 g_pfnVmxSuspend = NULL; 332 g_pVmxUseCount = NULL; 333 } 334 335 RTR0DbgKrnlInfoRelease(hKrnlInfo); 336 } 337 else 338 LogRel(("VBoxDrv: Failed to open kernel symbols, rc=%Rrc\n", rc)); 339 } 340 341 342 /** 298 343 * Stop the kernel module. 299 344 */ … … 711 756 712 757 /** 713 * Enables or disables VT-x using kernel functions. 714 * 715 * @returns VBox status code. VERR_NOT_SUPPORTED has a special meaning. 716 * @param fEnable Whether to enable or disable. 758 * @copydoc SUPR0EnableVTx 717 759 */ 718 760 int VBOXCALL supdrvOSEnableVTx(bool fEnable) … … 720 762 #ifdef VBOX_WITH_HOST_VMX 721 763 int rc; 722 if (version_major >= 10 /* 10 = 10.6.x = Snow Leopard */) 764 if ( version_major >= 10 /* 10 = 10.6.x = Snow Leopard */ 765 && g_pfnVmxSuspend 766 && g_pfnVmxResume 767 && g_pVmxUseCount) 723 768 { 724 769 if (fEnable) … … 736 781 rc = VERR_UNRESOLVED_ERROR; 737 782 } 783 LogRel(("VBoxDrv: host_vmxon -> vmx_use_count=%d rc=%Rrc\n", *g_pVmxUseCount, rc)); 738 784 } 739 785 else … … 741 787 host_vmxoff(); 742 788 rc = VINF_SUCCESS; 789 LogRel(("VBoxDrv: host_vmxoff -> vmx_use_count=%d\n", *g_pVmxUseCount)); 743 790 } 744 791 } … … 752 799 #else 753 800 return VERR_NOT_SUPPORTED; 801 #endif 802 } 803 804 805 /** 806 * @copydoc SUPR0SuspendVTxOnCpu 807 */ 808 bool VBOXCALL supdrvOSSuspendVTxOnCpu(void) 809 { 810 #ifdef VBOX_WITH_HOST_VMX 811 /* 812 * Consult the VMX usage counter, don't try suspend if not enabled. 813 * 814 * Note! The host_vmxon/off code is still race prone since, but this is 815 * currently the best we can do without always enable VMX when 816 * loading the driver. 817 */ 818 if ( g_pVmxUseCount 819 && *g_pVmxUseCount > 0) 820 { 821 g_pfnVmxSuspend(); 822 return true; 823 } 824 return false; 825 #else 826 return false; 827 #endif 828 } 829 830 831 /** 832 * @copydoc SUPR0ResumeVTxOnCpu 833 */ 834 void VBOXCALL supdrvOSResumeVTxOnCpu(bool fSuspended) 835 { 836 #ifdef VBOX_WITH_HOST_VMX 837 /* 838 * Don't consult the counter here, the state knows better. 839 * We're executing with interrupts disabled and anyone racing us with 840 * disabling VT-x will be waiting in the rendezvous code. 841 */ 842 if ( fSuspended 843 && g_pfnVmxResume) 844 g_pfnVmxResume(); 845 else 846 Assert(!fSuspended); 847 #else 848 Assert(!fSuspended); 754 849 #endif 755 850 } -
trunk/src/VBox/VMM/VMMR0/HWACCMR0.cpp
r43376 r43379 1691 1691 * @returns VBox status code. 1692 1692 * @param pVM Pointer to the VM. 1693 * @param enmSwitcher The switcher we're about to use. 1693 1694 * @param pfVTxDisabled Where to store whether VT-x was disabled or not. 1694 1695 */ 1695 VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, bool *pfVTxDisabled)1696 VMMR0DECL(int) HWACCMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled) 1696 1697 { 1697 1698 Assert(!(ASMGetFlags() & X86_EFL_IF) || !RTThreadPreemptIsEnabled(NIL_RTTHREAD)); … … 1699 1700 *pfVTxDisabled = false; 1700 1701 1701 if ( !g_HvmR0.fEnabled1702 || !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) 1707 1708 { 1708 1709 case VMMSWITCHER_32_TO_32: … … 1720 1721 } 1721 1722 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. */ 1722 1743 PHMGLOBLCPUINFO pCpu = HWACCMR0GetCurrentCpu(); 1723 1744 AssertReturn(pCpu && pCpu->hMemObj != NIL_RTR0MEMOBJ, VERR_HM_IPE_2); … … 1734 1755 * switcher turned off paging. 1735 1756 * 1736 * @returns VBox status code.1737 1757 * @param pVM Pointer to the VM. 1738 1758 * @param fVTxDisabled Whether VT-x was disabled or not. 1739 1759 */ 1740 VMMR0DECL( int) HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled)1760 VMMR0DECL(void) HWACCMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled) 1741 1761 { 1742 1762 Assert(!(ASMGetFlags() & X86_EFL_IF)); 1743 1763 1744 1764 if (!fVTxDisabled) 1745 return VINF_SUCCESS; /* nothing to do */ 1746 1747 Assert(g_HvmR0.fEnabled); 1765 return; /* nothing to do */ 1766 1748 1767 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 } 1757 1782 } 1758 1783 -
trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp
r43361 r43379 137 137 */ 138 138 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. */ 143 149 144 150 /* … … 148 154 if (RT_FAILURE(rc)) 149 155 { 150 ASMSetCR4( ASMGetCR4() & ~X86_CR4_VMXE);156 ASMSetCR4(uCr4); 151 157 return VERR_VMX_VMXON_FAILED; 152 158 } -
trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
r43303 r43379 683 683 /* We might need to disable VT-x if the active switcher turns off paging. */ 684 684 bool fVTxDisabled; 685 int rc = HWACCMR0EnterSwitcher(pVM, &fVTxDisabled);685 int rc = HWACCMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled); 686 686 if (RT_SUCCESS(rc)) 687 687 { … … 999 999 1000 1000 /* 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); 1002 1002 if (RT_FAILURE(rc)) 1003 1003 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.

