Changeset 41893 in vbox for trunk/src/VBox
- Timestamp:
- Jun 23, 2012 8:01:09 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/HWACCM.cpp
r41801 r41893 374 374 375 375 #if HC_ARCH_BITS == 32 376 /* 64-bit mode is configurable and it depends on both the kernel mode and VT-x. 377 * (To use the default, don't set 64bitEnabled in CFGM.) */ 376 /* 377 * 64-bit mode is configurable and it depends on both the kernel mode and VT-x. 378 * (To use the default, don't set 64bitEnabled in CFGM.) 379 */ 378 380 rc = CFGMR3QueryBoolDef(pHWVirtExt, "64bitEnabled", &pVM->hwaccm.s.fAllow64BitGuests, false); 379 381 AssertLogRelRCReturn(rc, rc); … … 388 390 } 389 391 #else 390 /* On 64-bit hosts 64-bit guest support is enabled by default, but allow this to be overridden 391 * via VBoxInternal/HWVirtExt/64bitEnabled=0. (ConsoleImpl2.cpp doesn't set this to false for 64-bit.) */ 392 /* 393 * On 64-bit hosts 64-bit guest support is enabled by default, but allow this to be overridden 394 * via VBoxInternal/HWVirtExt/64bitEnabled=0. (ConsoleImpl2.cpp doesn't set this to false for 64-bit.)* 395 */ 392 396 rc = CFGMR3QueryBoolDef(pHWVirtExt, "64bitEnabled", &pVM->hwaccm.s.fAllow64BitGuests, true); 393 397 AssertLogRelRCReturn(rc, rc); … … 395 399 396 400 397 /** Determine the init method for AMD-V and VT-x; either one global init for each host CPU 401 /* 402 * Determine the init method for AMD-V and VT-x; either one global init for each host CPU 398 403 * or local init each time we wish to execute guest code. 399 404 * … … 414 419 return rc; 415 420 } 421 416 422 417 423 /** … … 570 576 #endif 571 577 572 for (unsigned j =0;j<RT_ELEMENTS(pVCpu->hwaccm.s.StatExitCRxWrite);j++)578 for (unsigned j = 0; j < RT_ELEMENTS(pVCpu->hwaccm.s.StatExitCRxWrite); j++) 573 579 { 574 580 rc = STAMR3RegisterF(pVM, &pVCpu->hwaccm.s.StatExitCRxWrite[j], STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_OCCURENCES, "Profiling of CRx writes", … … 589 595 { 590 596 const char * const *papszDesc = ASMIsIntelCpu() ? &g_apszVTxExitReasons[0] : &g_apszAmdVExitReasons[0]; 591 for (int j =0;j<MAX_EXITREASON_STAT;j++)597 for (int j = 0; j < MAX_EXITREASON_STAT; j++) 592 598 { 593 599 if (papszDesc[j]) … … 637 643 } 638 644 645 639 646 /** 640 647 * Called when a init phase has completed. … … 657 664 } 658 665 659 /** 660 * Turns off normal raw mode features 666 667 /** 668 * Turns off normal raw mode features. 661 669 * 662 670 * @param pVM Pointer to the VM. … … 690 698 } 691 699 700 692 701 /** 693 702 * Initialize VT-x or AMD-V. … … 700 709 int rc; 701 710 702 /* Hack to allow users to work around broken BIOSes that incorrectly set EFER.SVME, which makes us believe somebody else 711 /* 712 * Hack to allow users to work around broken BIOSes that incorrectly set EFER.SVME, which makes us believe somebody else 703 713 * is already using AMD-V. 704 714 */ … … 1134 1144 *((unsigned char *)pVM->hwaccm.s.vmx.pRealModeTSS + HWACCM_VTX_TSS_SIZE - 2) = 0xff; 1135 1145 1136 /* Construct a 1024 element page directory with 4 MB pages for the identity mapped page table used in 1146 /* 1147 * Construct a 1024 element page directory with 4 MB pages for the identity mapped page table used in 1137 1148 * real and protected mode without paging with EPT. 1138 1149 */ 1139 1150 pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable = (PX86PD)((char *)pVM->hwaccm.s.vmx.pRealModeTSS + PAGE_SIZE * 3); 1140 for (unsigned i =0;i<X86_PG_ENTRIES;i++)1151 for (unsigned i = 0; i < X86_PG_ENTRIES; i++) 1141 1152 { 1142 1153 pVM->hwaccm.s.vmx.pNonPagingModeEPTPageTable->a[i].u = _4M * i; … … 1399 1410 } 1400 1411 1412 1401 1413 /** 1402 1414 * Applies relocations to data and code managed by this … … 1426 1438 { 1427 1439 int rc; 1428 1429 switch(PGMGetHostMode(pVM)) 1440 switch (PGMGetHostMode(pVM)) 1430 1441 { 1431 case PGMMODE_32_BIT:1432 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_32_TO_AMD64);1433 break;1434 1435 case PGMMODE_PAE:1436 case PGMMODE_PAE_NX:1437 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_PAE_TO_AMD64);1438 break;1439 1440 default:1441 AssertFailed();1442 break;1442 case PGMMODE_32_BIT: 1443 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_32_TO_AMD64); 1444 break; 1445 1446 case PGMMODE_PAE: 1447 case PGMMODE_PAE_NX: 1448 pVM->hwaccm.s.pfnHost32ToGuest64R0 = VMMR3GetHostToGuestSwitcher(pVM, VMMSWITCHER_PAE_TO_AMD64); 1449 break; 1450 1451 default: 1452 AssertFailed(); 1453 break; 1443 1454 } 1444 1455 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "VMXGCStartVM64", &pVM->hwaccm.s.pfnVMXGCStartVM64); … … 1463 1474 } 1464 1475 1465 /** 1466 * Checks hardware accelerated raw mode is allowed. 1467 * 1468 * @returns boolean 1476 1477 /** 1478 * Checks if hardware accelerated raw mode is allowed. 1479 * 1480 * @returns true if hardware acceleration is allowed, otherwise false. 1469 1481 * @param pVM Pointer to the VM. 1470 1482 */ … … 1473 1485 return pVM->hwaccm.s.fAllowed; 1474 1486 } 1487 1475 1488 1476 1489 /** … … 1526 1539 /* Reset the contents of the read cache. */ 1527 1540 PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache; 1528 for (unsigned j =0;j<pCache->Read.cValidEntries;j++)1541 for (unsigned j = 0; j < pCache->Read.cValidEntries; j++) 1529 1542 pCache->Read.aFieldVal[j] = 0; 1530 1543 } 1531 1544 1545 1532 1546 /** 1533 1547 * Terminates the HWACCM. 1534 1548 * 1535 1549 * Termination means cleaning up and freeing all resources, 1536 * the VM it self is at this pointpowered off or suspended.1550 * the VM itself is, at this point, powered off or suspended. 1537 1551 * 1538 1552 * @returns VBox status code. … … 1549 1563 return 0; 1550 1564 } 1565 1551 1566 1552 1567 /** … … 1586 1601 } 1587 1602 1603 1588 1604 /** 1589 1605 * Resets a virtual CPU. … … 1611 1627 /* Reset the contents of the read cache. */ 1612 1628 PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache; 1613 for (unsigned j =0;j<pCache->Read.cValidEntries;j++)1629 for (unsigned j = 0; j < pCache->Read.cValidEntries; j++) 1614 1630 pCache->Read.aFieldVal[j] = 0; 1615 1631 … … 1620 1636 #endif 1621 1637 } 1638 1622 1639 1623 1640 /** … … 1653 1670 } 1654 1671 1655 /** 1656 * Callback to patch a TPR instruction (vmmcall or mov cr8) 1672 1673 /** 1674 * Callback to patch a TPR instruction (vmmcall or mov cr8). 1657 1675 * 1658 1676 * @returns VBox strict status code. 1659 1677 * @param pVM Pointer to the VM. 1660 1678 * @param pVCpu The VMCPU for the EMT we're being called on. 1661 * @param pvUser Unused 1662 * 1679 * @param pvUser Unused. 1663 1680 */ 1664 1681 DECLCALLBACK(VBOXSTRICTRC) hwaccmR3RemovePatches(PVM pVM, PVMCPU pVCpu, void *pvUser) … … 1718 1735 } 1719 1736 1720 /** 1721 * Enable patching in a VT-x/AMD-V guest 1737 1738 /** 1739 * Worker for enabling patching in a VT-x/AMD-V guest. 1722 1740 * 1723 1741 * @returns VBox status code. 1724 1742 * @param pVM Pointer to the VM. 1725 * @param idCpu VCPU to execute hwaccmR3RemovePatches on 1726 * @param pPatchMem Patch memory range 1727 * @param cbPatchMem Size of the memory range 1728 */ 1729 int hwaccmR3EnablePatching(PVM pVM, VMCPUID idCpu, RTRCPTR pPatchMem, unsigned cbPatchMem)1743 * @param idCpu VCPU to execute hwaccmR3RemovePatches on. 1744 * @param pPatchMem Patch memory range. 1745 * @param cbPatchMem Size of the memory range. 1746 */ 1747 static int hwaccmR3EnablePatching(PVM pVM, VMCPUID idCpu, RTRCPTR pPatchMem, unsigned cbPatchMem) 1730 1748 { 1731 1749 int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONE_BY_ONE, hwaccmR3RemovePatches, (void *)(uintptr_t)idCpu); … … 1738 1756 } 1739 1757 1758 1740 1759 /** 1741 1760 * Enable patching in a VT-x/AMD-V guest … … 1743 1762 * @returns VBox status code. 1744 1763 * @param pVM Pointer to the VM. 1745 * @param pPatchMem Patch memory range 1746 * @param cbPatchMem Size of the memory range 1764 * @param pPatchMem Patch memory range. 1765 * @param cbPatchMem Size of the memory range. 1747 1766 */ 1748 1767 VMMR3DECL(int) HWACMMR3EnablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem) … … 1761 1780 } 1762 1781 1763 /** 1764 * Disable patching in a VT-x/AMD-V guest 1782 1783 /** 1784 * Disable patching in a VT-x/AMD-V guest. 1765 1785 * 1766 1786 * @returns VBox status code. 1767 1787 * @param pVM Pointer to the VM. 1768 * @param pPatchMem Patch memory range 1769 * @param cbPatchMem Size of the memory range 1788 * @param pPatchMem Patch memory range. 1789 * @param cbPatchMem Size of the memory range. 1770 1790 */ 1771 1791 VMMR3DECL(int) HWACMMR3DisablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem) … … 1789 1809 1790 1810 /** 1791 * Callback to patch a TPR instruction (vmmcall or mov cr8) 1811 * Callback to patch a TPR instruction (vmmcall or mov cr8). 1792 1812 * 1793 1813 * @returns VBox strict status code. 1794 1814 * @param pVM Pointer to the VM. 1795 1815 * @param pVCpu The VMCPU for the EMT we're being called on. 1796 * @param pvUser User specified CPU context 1816 * @param pvUser User specified CPU context. 1797 1817 * 1798 1818 */ … … 1960 1980 } 1961 1981 1962 /** 1963 * Callback to patch a TPR instruction (jump to generated code) 1982 1983 /** 1984 * Callback to patch a TPR instruction (jump to generated code). 1964 1985 * 1965 1986 * @returns VBox strict status code. 1966 1987 * @param pVM Pointer to the VM. 1967 1988 * @param pVCpu The VMCPU for the EMT we're being called on. 1968 * @param pvUser User specified CPU context 1989 * @param pvUser User specified CPU context. 1969 1990 * 1970 1991 */ … … 2192 2213 } 2193 2214 2194 /** 2195 * Attempt to patch TPR mmio instructions 2215 2216 /** 2217 * Attempt to patch TPR mmio instructions. 2196 2218 * 2197 2219 * @returns VBox status code. … … 2210 2232 } 2211 2233 2212 /** 2213 * Force execution of the current IO code in the recompiler 2234 2235 /** 2236 * Force execution of the current IO code in the recompiler. 2214 2237 * 2215 2238 * @returns VBox status code. … … 2236 2259 } 2237 2260 2261 2238 2262 /** 2239 2263 * Checks if we can currently use hardware accelerated raw mode. 2240 2264 * 2241 * @returns boolean2265 * @returns true if we can currently use hardware acceleration, otherwise false. 2242 2266 * @param pVM Pointer to the VM. 2243 2267 * @param pCtx Partial VM execution context. … … 2273 2297 if (!pVM->hwaccm.s.vmx.fUnrestrictedGuest) 2274 2298 { 2275 /** The VMM device heap is a requirement for emulating real mode or protected mode without paging when the unrestricted guest execution feature is missing. */ 2299 /* 2300 * The VMM device heap is a requirement for emulating real mode or protected mode without paging with the unrestricted 2301 * guest execution feature i missing (VT-x only). 2302 */ 2276 2303 if (fSupportsRealMode) 2277 2304 { … … 2360 2387 if (pCtx->rsp >= pCtx->ssHid.u32Limit) 2361 2388 return false; 2362 2389 #if 0 2363 2390 if ( pCtx->cs >= pCtx->gdtr.cbGdt 2364 2391 || pCtx->ss >= pCtx->gdtr.cbGdt … … 2368 2395 || pCtx->gs >= pCtx->gdtr.cbGdt) 2369 2396 return false; 2370 2397 #endif 2371 2398 } 2372 2399 } … … 2418 2445 } 2419 2446 2420 /** 2421 * Checks if we need to reschedule due to VMM device heap changes 2422 * 2423 * @returns boolean 2447 2448 /** 2449 * Checks if we need to reschedule due to VMM device heap changes. 2450 * 2451 * @returns true if a reschedule is required, otherwise false. 2424 2452 * @param pVM Pointer to the VM. 2425 2453 * @param pCtx VM execution context. … … 2427 2455 VMMR3DECL(bool) HWACCMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx) 2428 2456 { 2429 /** The VMM device heap is a requirement for emulating real mode or protected mode without paging when the unrestricted guest execution feature is missing. (VT-x only) */ 2457 /* 2458 * The VMM device heap is a requirement for emulating real mode or protected mode without paging 2459 * when the unrestricted guest execution feature is missing (VT-x only). 2460 */ 2430 2461 if ( pVM->hwaccm.s.vmx.fEnabled 2431 2462 && !pVM->hwaccm.s.vmx.fUnrestrictedGuest … … 2450 2481 } 2451 2482 2483 2452 2484 /** 2453 2485 * Notification from EM about returning from instruction emulation (REM / EM). … … 2460 2492 } 2461 2493 2494 2462 2495 /** 2463 2496 * Checks if we are currently using hardware accelerated raw mode. 2464 2497 * 2465 * @returns boolean2498 * @returns true if hardware acceleration is being used, otherwise false. 2466 2499 * @param pVCpu Pointer to the VMCPU. 2467 2500 */ … … 2471 2504 } 2472 2505 2506 2473 2507 /** 2474 2508 * Checks if we are currently using nested paging. 2475 2509 * 2476 * @returns boolean2510 * @returns true if nested paging is being used, otherwise false. 2477 2511 * @param pVM Pointer to the VM. 2478 2512 */ … … 2482 2516 } 2483 2517 2518 2484 2519 /** 2485 2520 * Checks if we are currently using VPID in VT-x mode. 2486 2521 * 2487 * @returns boolean2522 * @returns true if VPID is being used, otherwise false. 2488 2523 * @param pVM Pointer to the VM. 2489 2524 */ … … 2497 2532 * Checks if internal events are pending. In that case we are not allowed to dispatch interrupts. 2498 2533 * 2499 * @returns boolean2534 * @returns true if an internal event is pending, otherwise false. 2500 2535 * @param pVM Pointer to the VM. 2501 2536 */ … … 2505 2540 } 2506 2541 2542 2507 2543 /** 2508 2544 * Checks if the VMX-preemption timer is being used. 2509 2545 * 2510 * @returns true if it is, false if it isn't.2546 * @returns true if the VMX-preemption timer is being used, otherwise false. 2511 2547 * @param pVM Pointer to the VM. 2512 2548 */ … … 2517 2553 && pVM->hwaccm.s.vmx.fUsePreemptTimer; 2518 2554 } 2555 2519 2556 2520 2557 /** … … 2545 2582 switch (enmType) 2546 2583 { 2547 case HWACCMPENDINGIO_PORT_READ: 2548 { 2549 uint32_t uAndVal = pVCpu->hwaccm.s.PendingIO.s.Port.uAndVal; 2550 uint32_t u32Val = 0; 2551 2552 rcStrict = IOMIOPortRead(pVM, pVCpu->hwaccm.s.PendingIO.s.Port.uPort, 2553 &u32Val, 2554 pVCpu->hwaccm.s.PendingIO.s.Port.cbSize); 2555 if (IOM_SUCCESS(rcStrict)) 2584 case HWACCMPENDINGIO_PORT_READ: 2556 2585 { 2557 /* Write back to the EAX register. */ 2558 pCtx->eax = (pCtx->eax & ~uAndVal) | (u32Val & uAndVal); 2559 pCtx->rip = pVCpu->hwaccm.s.PendingIO.GCPtrRipNext; 2586 uint32_t uAndVal = pVCpu->hwaccm.s.PendingIO.s.Port.uAndVal; 2587 uint32_t u32Val = 0; 2588 2589 rcStrict = IOMIOPortRead(pVM, pVCpu->hwaccm.s.PendingIO.s.Port.uPort, 2590 &u32Val, 2591 pVCpu->hwaccm.s.PendingIO.s.Port.cbSize); 2592 if (IOM_SUCCESS(rcStrict)) 2593 { 2594 /* Write back to the EAX register. */ 2595 pCtx->eax = (pCtx->eax & ~uAndVal) | (u32Val & uAndVal); 2596 pCtx->rip = pVCpu->hwaccm.s.PendingIO.GCPtrRipNext; 2597 } 2598 break; 2560 2599 } 2561 break; 2562 } 2563 2564 case HWACCMPENDINGIO_PORT_WRITE: 2565 rcStrict = IOMIOPortWrite(pVM, pVCpu->hwaccm.s.PendingIO.s.Port.uPort, 2566 pCtx->eax & pVCpu->hwaccm.s.PendingIO.s.Port.uAndVal, 2567 pVCpu->hwaccm.s.PendingIO.s.Port.cbSize); 2568 if (IOM_SUCCESS(rcStrict)) 2569 pCtx->rip = pVCpu->hwaccm.s.PendingIO.GCPtrRipNext; 2570 break; 2571 2572 default: 2573 AssertLogRelFailedReturn(VERR_HM_UNKNOWN_IO_INSTRUCTION); 2600 2601 case HWACCMPENDINGIO_PORT_WRITE: 2602 rcStrict = IOMIOPortWrite(pVM, pVCpu->hwaccm.s.PendingIO.s.Port.uPort, 2603 pCtx->eax & pVCpu->hwaccm.s.PendingIO.s.Port.uAndVal, 2604 pVCpu->hwaccm.s.PendingIO.s.Port.cbSize); 2605 if (IOM_SUCCESS(rcStrict)) 2606 pCtx->rip = pVCpu->hwaccm.s.PendingIO.GCPtrRipNext; 2607 break; 2608 2609 default: 2610 AssertLogRelFailedReturn(VERR_HM_UNKNOWN_IO_INSTRUCTION); 2574 2611 } 2575 2612 2576 2613 return rcStrict; 2577 2614 } 2615 2578 2616 2579 2617 /** … … 2588 2626 return VINF_SUCCESS; 2589 2627 } 2628 2590 2629 2591 2630 /** … … 2633 2672 } 2634 2673 } 2674 2635 2675 2636 2676 /** … … 2716 2756 return VINF_SUCCESS; 2717 2757 } 2758 2718 2759 2719 2760 /**
Note:
See TracChangeset
for help on using the changeset viewer.