Changeset 47989 in vbox for trunk/src/VBox/VMM/VMMR0/HMR0.cpp
- Timestamp:
- Aug 22, 2013 1:56:52 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR0/HMR0.cpp
r47959 r47989 475 475 } 476 476 477 /* Enter VMX Root Mode */ 477 /* 478 * The only way of checking if we're in VMX root mode or not is to try and enter it. 479 * There is no instruction or control bit that tells us if we're in VMX root mode. 480 * Therefore, try and enter VMX root mode here. 481 */ 478 482 rc = VMXEnable(HCPhysScratchPage); 479 483 if (RT_SUCCESS(rc)) … … 989 993 { 990 994 Assert(g_HvmR0.aCpuInfo[i].hMemObj == NIL_RTR0MEMOBJ); 991 g_HvmR0.aCpuInfo[i].fConfigured = false; 992 g_HvmR0.aCpuInfo[i].cTlbFlushes = 0; 995 g_HvmR0.aCpuInfo[i].fConfigured = false; 996 g_HvmR0.aCpuInfo[i].cTlbFlushes = 0; 997 g_HvmR0.aCpuInfo[i].uCurrentAsid = 0; 993 998 } 994 999 … … 1012 1017 * We're doing the job ourselves. 1013 1018 */ 1014 /* Allocate one page per cpu for the global vt-x and amd-vpages */1019 /* Allocate one page per cpu for the global VT-x and AMD-V pages */ 1015 1020 for (unsigned i = 0; i < RT_ELEMENTS(g_HvmR0.aCpuInfo); i++) 1016 1021 { … … 1030 1035 } 1031 1036 1032 if (RT_SUCCESS(rc) && g_HvmR0.fGlobalInit) 1037 if ( RT_SUCCESS(rc) 1038 && g_HvmR0.fGlobalInit) 1033 1039 { 1034 1040 /* First time, so initialize each cpu/core. */ … … 1411 1417 1412 1418 /* Enable VT-x or AMD-V if local init is required, or enable if it's a freshly onlined CPU. */ 1413 if ( !pCpu->fConfigured 1414 || !g_HvmR0.fGlobalInit) 1415 { 1419 if (!pCpu->fConfigured) 1416 1420 hmR0EnableCpu(pVCpu->CTX_SUFF(pVM), idCpu); 1417 }1418 1421 1419 1422 /* Reload host-context (back from ring-3/migrated CPUs), reload guest CR0 (for FPU bits). */ … … 1455 1458 1456 1459 int rc = g_HvmR0.pfnEnterSession(pVM, pVCpu, pCpu); 1457 Assert RC(rc);1460 AssertMsgRC(rc, ("pfnEnterSession failed. rc=%Rrc pVCpu=%p HostCpuId=%u\n", rc, pVCpu, idCpu)); 1458 1461 1459 1462 /* Load the host as we may be resuming code after a longjmp and quite 1460 1463 possibly be scheduled on a different CPU. */ 1461 1464 rc |= g_HvmR0.pfnSaveHostState(pVM, pVCpu); 1462 Assert RC(rc);1465 AssertMsgRC(rc, ("pfnSaveHostState failed. rc=%Rrc pVCpu=%p HostCpuId=%u\n", rc, pVCpu, idCpu)); 1463 1466 1464 1467 /** @todo This is not needed to be done here anymore, can fix/optimize later. */ 1465 1468 rc |= g_HvmR0.pfnLoadGuestState(pVM, pVCpu, pCtx); 1466 Assert RC(rc);1469 AssertMsgRC(rc, ("pfnLoadGuestState failed. rc=%Rrc pVCpu=%p HostCpuId=%u\n", rc, pVCpu, idCpu)); 1467 1470 1468 1471 #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE … … 1489 1492 Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD)); 1490 1493 1491 if (!g_HvmR0.fGlobalInit) 1492 { 1493 RTCPUID idCpu = RTMpCpuId(); 1494 RTCPUID idCpu = RTMpCpuId(); 1495 PHMGLOBALCPUINFO pCpu = &g_HvmR0.aCpuInfo[idCpu]; 1496 1497 if ( !g_HvmR0.fGlobalInit 1498 && pCpu->fConfigured) 1499 { 1494 1500 int rc = hmR0DisableCpu(idCpu); 1495 1501 AssertRCReturn(rc, rc); 1502 Assert(!pCpu->fConfigured); 1496 1503 } 1497 1504 1498 1505 /* Reset these to force a TLB flush for the next entry. */ 1499 1506 pVCpu->hm.s.idLastCpu = NIL_RTCPUID; 1507 pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID; 1500 1508 pVCpu->hm.s.uCurrentAsid = 0; 1501 1509 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH); … … 1520 1528 AssertReturn(!ASMAtomicReadBool(&g_HvmR0.fSuspended), VERR_HM_SUSPEND_PENDING); 1521 1529 1522 PCPUMCTX pCtx 1530 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu); 1523 1531 AssertPtr(pCtx); 1524 1532 1533 bool fDisabledPreempt = false; 1534 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER; 1535 if (RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 1536 { 1537 Assert(VMMR0ThreadCtxHooksAreRegistered(pVCpu)); 1538 RTThreadPreemptDisable(&PreemptState); 1539 fDisabledPreempt = true; 1540 } 1541 1525 1542 int rc = g_HvmR0.pfnLeaveSession(pVM, pVCpu, pCtx); 1526 1543 1527 /*1528 * When thread-context hooks are not used, leave HM context and if necessary disable HM on the CPU.1529 * When thread-context hooks -are- used, this work would be done in the VT-x and AMD-V thread-context callback.1530 */1531 1544 if (!VMMR0ThreadCtxHooksAreRegistered(pVCpu)) 1532 1545 { 1533 Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));1534 RTCPUID idCpu = RTMpCpuId();1535 1536 1546 /* Keep track of the CPU owning the VMCS for debugging scheduling weirdness 1537 1547 and ring-3 calls when thread-context hooks are not supported. */ 1548 RTCPUID idCpu = RTMpCpuId(); 1538 1549 AssertMsgStmt( pVCpu->hm.s.idEnteredCpu == idCpu 1539 1550 || RT_FAILURE_NP(rc), ("Owner is %u, I'm %u", pVCpu->hm.s.idEnteredCpu, idCpu), 1540 1551 rc = VERR_HM_WRONG_CPU_1); 1541 1552 } 1553 1554 /* Leave HM context, takes care of local init (term). */ 1555 if (RT_SUCCESS(rc)) 1556 { 1542 1557 rc = HMR0LeaveEx(pVCpu); 1543 1558 AssertRCReturn(rc, rc); 1544 1559 } 1560 1561 /* Deregister hook now that we've left HM context before re-enabling preemption. */ 1562 /** @todo This is bad. Deregistering here means we need to VMCLEAR always 1563 * (longjmp/exit-to-r3) in VT-x which is not efficient. */ 1564 if (VMMR0ThreadCtxHooksAreRegistered(pVCpu)) 1565 VMMR0ThreadCtxHooksDeregister(pVCpu); 1566 1567 if (fDisabledPreempt) 1568 RTThreadPreemptRestore(&PreemptState); 1545 1569 1546 1570 /* Guest FPU and debug state shouldn't be active now, it's likely that we're going back to ring-3. */ … … 1548 1572 Assert(!CPUMIsGuestDebugStateActive(pVCpu)); 1549 1573 1550 pVCpu->hm.s.idEnteredCpu = NIL_RTCPUID;1551 1574 return rc; 1552 1575 }
Note:
See TracChangeset
for help on using the changeset viewer.