Changeset 8876 in vbox for trunk/src/VBox/VMM
- Timestamp:
- May 16, 2008 9:59:07 AM (17 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/HWACCM.cpp
r8873 r8876 156 156 STAM_REG(pVM, &pVM->hwaccm.s.StatFlushTLBWorldSwitch, STAMTYPE_COUNTER, "/HWACCM/Flush/TLB/Switch", STAMUNIT_OCCURENCES, "Nr of occurances"); 157 157 STAM_REG(pVM, &pVM->hwaccm.s.StatNoFlushTLBWorldSwitch, STAMTYPE_COUNTER, "/HWACCM/Flush/TLB/Skipped", STAMUNIT_OCCURENCES, "Nr of occurances"); 158 STAM_REG(pVM, &pVM->hwaccm.s.StatFlushASID, STAMTYPE_COUNTER, "/HWACCM/Flush/TLB/ASID", STAMUNIT_OCCURENCES, "Nr of occurances"); 158 159 159 160 pVM->hwaccm.s.pStatExitReason = 0; -
trunk/src/VBox/VMM/HWACCMInternal.h
r8873 r8876 31 31 #include <VBox/pgm.h> 32 32 #include <iprt/memobj.h> 33 #include <iprt/cpuset.h> 34 #include <iprt/mp.h> 33 35 34 36 __BEGIN_DECLS … … 317 319 STAMCOUNTER StatNoFlushTLBWorldSwitch; 318 320 STAMCOUNTER StatFlushTLBCRxChange; 321 STAMCOUNTER StatFlushASID; 319 322 320 323 STAMCOUNTER StatSwitchGuestIrq; … … 327 330 typedef HWACCM *PHWACCM; 328 331 332 static struct 333 { 334 struct 335 { 336 RTR0MEMOBJ pMemObj; 337 bool fVMXConfigured; 338 bool fSVMConfigured; 339 } aCpuInfo[RTCPUSET_MAX_CPUS]; 340 341 struct 342 { 343 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */ 344 bool fSupported; 345 346 /** Host CR4 value (set by ring-0 VMX init) */ 347 uint64_t hostCR4; 348 349 /** VMX MSR values */ 350 struct 351 { 352 uint64_t feature_ctrl; 353 uint64_t vmx_basic_info; 354 uint64_t vmx_pin_ctls; 355 uint64_t vmx_proc_ctls; 356 uint64_t vmx_exit; 357 uint64_t vmx_entry; 358 uint64_t vmx_misc; 359 uint64_t vmx_cr0_fixed0; 360 uint64_t vmx_cr0_fixed1; 361 uint64_t vmx_cr4_fixed0; 362 uint64_t vmx_cr4_fixed1; 363 uint64_t vmx_vmcs_enum; 364 } msr; 365 /* Last instruction error */ 366 uint32_t ulLastInstrError; 367 } vmx; 368 struct 369 { 370 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */ 371 bool fSupported; 372 373 /** SVM revision. */ 374 uint32_t u32Rev; 375 376 /** Maximum ASID allowed. */ 377 uint32_t u32MaxASID; 378 379 /** SVM feature bits from cpuid 0x8000000a */ 380 uint32_t u32Features; 381 } svm; 382 /** Saved error from detection */ 383 int32_t lLastError; 384 385 struct 386 { 387 uint32_t u32AMDFeatureECX; 388 uint32_t u32AMDFeatureEDX; 389 } cpuid; 390 391 HWACCMSTATE enmHwAccmState; 392 } HWACCMR0GLOBALS; 393 394 typedef struct 395 { 396 RTCPUID idCpu; 397 398 RTR0MEMOBJ pMemObj; 399 /* Current ASID (AMD-V only) */ 400 uint32_t uCurrentASID; 401 402 bool fVMXConfigured; 403 bool fSVMConfigured; 404 } HWACCM_CPUINFO; 405 typedef HWACCM_CPUINFO *PHWACCM_CPUINFO; 329 406 330 407 #ifdef IN_RING0 -
trunk/src/VBox/VMM/VMMR0/HWACCMR0.cpp
r8873 r8876 57 57 * Local Variables * 58 58 *******************************************************************************/ 59 59 60 static struct 60 61 { 61 struct 62 { 63 RTR0MEMOBJ pMemObj; 64 bool fVMXConfigured; 65 bool fSVMConfigured; 66 } aCpuInfo[RTCPUSET_MAX_CPUS]; 62 HWACCM_CPUINFO aCpuInfo[RTCPUSET_MAX_CPUS]; 67 63 68 64 struct … … 536 532 if (pVM->hwaccm.s.vmx.fSupported) 537 533 { 538 paRc[idCpu] = VMXR0EnableCpu( idCpu, pVM, pvPageCpu, pPageCpuPhys);534 paRc[idCpu] = VMXR0EnableCpu(&HWACCMR0Globals.aCpuInfo[idCpu], pVM, pvPageCpu, pPageCpuPhys); 539 535 AssertRC(paRc[idCpu]); 540 536 if (VBOX_SUCCESS(paRc[idCpu])) … … 544 540 if (pVM->hwaccm.s.svm.fSupported) 545 541 { 546 paRc[idCpu] = SVMR0EnableCpu( idCpu, pVM, pvPageCpu, pPageCpuPhys);542 paRc[idCpu] = SVMR0EnableCpu(&HWACCMR0Globals.aCpuInfo[idCpu], pVM, pvPageCpu, pPageCpuPhys); 547 543 AssertRC(paRc[idCpu]); 548 544 if (VBOX_SUCCESS(paRc[idCpu])) … … 577 573 if (HWACCMR0Globals.aCpuInfo[idCpu].fVMXConfigured) 578 574 { 579 paRc[idCpu] = VMXR0DisableCpu( idCpu, pvPageCpu, pPageCpuPhys);575 paRc[idCpu] = VMXR0DisableCpu(&HWACCMR0Globals.aCpuInfo[idCpu], pvPageCpu, pPageCpuPhys); 580 576 AssertRC(paRc[idCpu]); 581 577 HWACCMR0Globals.aCpuInfo[idCpu].fVMXConfigured = false; … … 584 580 if (HWACCMR0Globals.aCpuInfo[idCpu].fSVMConfigured) 585 581 { 586 paRc[idCpu] = SVMR0DisableCpu( idCpu, pvPageCpu, pPageCpuPhys);582 paRc[idCpu] = SVMR0DisableCpu(&HWACCMR0Globals.aCpuInfo[idCpu], pvPageCpu, pPageCpuPhys); 587 583 AssertRC(paRc[idCpu]); 588 584 HWACCMR0Globals.aCpuInfo[idCpu].fSVMConfigured = false; … … 797 793 CPUMCTX *pCtx; 798 794 int rc; 795 RTCPUID idCpu = RTMpCpuId(); 799 796 800 797 rc = CPUMQueryGuestCtxPtr(pVM, &pCtx); … … 804 801 if (pVM->hwaccm.s.vmx.fSupported) 805 802 { 806 return VMXR0RunGuestCode(pVM, pCtx );803 return VMXR0RunGuestCode(pVM, pCtx, &HWACCMR0Globals.aCpuInfo[idCpu]); 807 804 } 808 805 else 809 806 { 810 807 Assert(pVM->hwaccm.s.svm.fSupported); 811 return SVMR0RunGuestCode(pVM, pCtx );808 return SVMR0RunGuestCode(pVM, pCtx, &HWACCMR0Globals.aCpuInfo[idCpu]); 812 809 } 813 810 } -
trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp
r8871 r8876 42 42 #include <iprt/assert.h> 43 43 #include <iprt/asm.h> 44 #include <iprt/cpuset.h> 45 #include <iprt/mp.h> 44 46 #include "HWSVMR0.h" 45 47 … … 50 52 * 51 53 * @returns VBox status code. 52 * @param idCpu The identifier for the CPU the function is called on.54 * @param pCpu CPU info struct 53 55 * @param pVM The VM to operate on. 54 56 * @param pvPageCpu Pointer to the global cpu page 55 57 * @param pPageCpuPhys Physical address of the global cpu page 56 58 */ 57 HWACCMR0DECL(int) SVMR0EnableCpu( RTCPUID idCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys)59 HWACCMR0DECL(int) SVMR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys) 58 60 { 59 61 AssertReturn(pPageCpuPhys, VERR_INVALID_PARAMETER); … … 63 65 /* We must turn on AMD-V and setup the host state physical address, as those MSRs are per-cpu/core. */ 64 66 67 #ifdef LOG_ENABLED 68 SUPR0Printf("SVMR0EnableCpu cpu %d page (%x) %x\n", pCpu->idCpu, pvPageCpu, (uint32_t)pPageCpuPhys); 69 #endif 70 65 71 /* Turn on AMD-V in the EFER MSR. */ 66 72 uint64_t val = ASMRdMsr(MSR_K6_EFER); … … 70 76 /* Write the physical page address where the CPU will store the host state while executing the VM. */ 71 77 ASMWrMsr(MSR_K8_VM_HSAVE_PA, pPageCpuPhys); 78 79 pCpu->uCurrentASID = 0; /* we'll aways increment this the first time (host uses ASID 0) */ 72 80 return VINF_SUCCESS; 73 81 } … … 77 85 * 78 86 * @returns VBox status code. 79 * @param idCpu The identifier for the CPU the function is called on.87 * @param pCpu CPU info struct 80 88 * @param pvPageCpu Pointer to the global cpu page 81 89 * @param pPageCpuPhys Physical address of the global cpu page 82 90 */ 83 HWACCMR0DECL(int) SVMR0DisableCpu( RTCPUID idCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys)91 HWACCMR0DECL(int) SVMR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys) 84 92 { 85 93 AssertReturn(pPageCpuPhys, VERR_INVALID_PARAMETER); 86 94 AssertReturn(pvPageCpu, VERR_INVALID_PARAMETER); 87 95 96 #ifdef LOG_ENABLED 97 SUPR0Printf("SVMR0DisableCpu cpu %d\n", pCpu->idCpu); 98 #endif 99 88 100 /* Turn off AMD-V in the EFER MSR. */ 89 101 uint64_t val = ASMRdMsr(MSR_K6_EFER); … … 92 104 /* Invalidate host state physical address. */ 93 105 ASMWrMsr(MSR_K8_VM_HSAVE_PA, 0); 106 pCpu->uCurrentASID = 0; 107 94 108 return VINF_SUCCESS; 95 109 } … … 301 315 pVMCB->ctrl.u64LBRVirt = 0; 302 316 317 /** The ASID must start at 1; the host uses 0. */ 318 pVMCB->ctrl.TLBCtrl.n.u32ASID = 1; 319 303 320 return rc; 304 321 } … … 638 655 pVMCB->guest.u64EFER = MSR_K6_EFER_SVME; 639 656 640 /** @note We can do more complex things with tagged TLBs. */641 pVMCB->ctrl.TLBCtrl.n.u32ASID = 1;642 643 657 /** TSC offset. */ 644 658 if (TMCpuTickCanUseRealTSC(pVM, &pVMCB->ctrl.u64TSCOffset)) … … 678 692 * @param pVM The VM to operate on. 679 693 * @param pCtx Guest context 694 * @param pCpu CPU info struct 680 695 */ 681 HWACCMR0DECL(int) SVMR0RunGuestCode(PVM pVM, CPUMCTX *pCtx )696 HWACCMR0DECL(int) SVMR0RunGuestCode(PVM pVM, CPUMCTX *pCtx, PHWACCM_CPUINFO pCpu) 682 697 { 683 698 int rc = VINF_SUCCESS; … … 688 703 689 704 STAM_PROFILE_ADV_START(&pVM->hwaccm.s.StatEntry, x); 705 706 AssertReturn(pCpu->fSVMConfigured, VERR_EM_INTERNAL_ERROR); 690 707 691 708 pVMCB = (SVM_VMCB *)pVM->hwaccm.s.svm.pVMCB; … … 771 788 772 789 /* Make sure we flush the TLB when required. */ 773 pVMCB->ctrl.TLBCtrl.n.u1TLBFlush = pVM->hwaccm.s.svm.fForceTLBFlush; 790 if ( pVM->hwaccm.s.svm.fForceTLBFlush 791 && !pVM->hwaccm.s.svm.fAlwaysFlushTLB) 792 { 793 if (++pCpu->uCurrentASID >= pVM->hwaccm.s.svm.u32MaxASID) 794 { 795 pCpu->uCurrentASID = 1; /* start at 1; host uses 0 */ 796 pVMCB->ctrl.TLBCtrl.n.u1TLBFlush = 1; /* wrap around; flush TLB */ 797 } 798 else 799 STAM_COUNTER_INC(&pVM->hwaccm.s.StatFlushASID); 800 } 801 else 802 { 803 Assert(pVM->hwaccm.s.svm.fForceTLBFlush == pVM->hwaccm.s.svm.fAlwaysFlushTLB); 804 pVMCB->ctrl.TLBCtrl.n.u1TLBFlush = pVM->hwaccm.s.svm.fForceTLBFlush; 805 } 806 807 Assert(pCpu->uCurrentASID >= 1 && pCpu->uCurrentASID < pVM->hwaccm.s.svm.u32MaxASID); 808 pVMCB->ctrl.TLBCtrl.n.u32ASID = pCpu->uCurrentASID; 809 774 810 #ifdef VBOX_WITH_STATISTICS 775 811 if (pVMCB->ctrl.TLBCtrl.n.u1TLBFlush) -
trunk/src/VBox/VMM/VMMR0/HWSVMR0.h
r8853 r8876 62 62 * 63 63 * @returns VBox status code. 64 * @param idCpu The identifier for the CPU the function is called on.64 * @param pCpu CPU info struct 65 65 * @param pVM The VM to operate on. 66 66 * @param pvPageCpu Pointer to the global cpu page 67 67 * @param pPageCpuPhys Physical address of the global cpu page 68 68 */ 69 HWACCMR0DECL(int) SVMR0EnableCpu( RTCPUID idCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);69 HWACCMR0DECL(int) SVMR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys); 70 70 71 71 /** … … 73 73 * 74 74 * @returns VBox status code. 75 * @param idCpu The identifier for the CPU the function is called on.75 * @param pCpu CPU info struct 76 76 * @param pvPageCpu Pointer to the global cpu page 77 77 * @param pPageCpuPhys Physical address of the global cpu page 78 78 */ 79 HWACCMR0DECL(int) SVMR0DisableCpu( RTCPUID idCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);79 HWACCMR0DECL(int) SVMR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys); 80 80 81 81 /** … … 112 112 * @param pVM The VM to operate on. 113 113 * @param pCtx Guest context 114 * @param pCpu CPU info struct 114 115 */ 115 HWACCMR0DECL(int) SVMR0RunGuestCode(PVM pVM, CPUMCTX *pCtx );116 HWACCMR0DECL(int) SVMR0RunGuestCode(PVM pVM, CPUMCTX *pCtx, PHWACCM_CPUINFO pCpu); 116 117 117 118 -
trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp
r8659 r8876 63 63 * 64 64 * @returns VBox status code. 65 * @param idCpu The identifier for the CPU the function is called on.65 * @param pCpu CPU info struct 66 66 * @param pVM The VM to operate on. 67 67 * @param pvPageCpu Pointer to the global cpu page 68 68 * @param pPageCpuPhys Physical address of the global cpu page 69 69 */ 70 HWACCMR0DECL(int) VMXR0EnableCpu( RTCPUID idCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys)70 HWACCMR0DECL(int) VMXR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys) 71 71 { 72 72 AssertReturn(pPageCpuPhys, VERR_INVALID_PARAMETER); … … 78 78 79 79 #ifdef LOG_ENABLED 80 SUPR0Printf("VMXR0EnableCpu cpu %d page (%x) %x\n", idCpu, pvPageCpu, (uint32_t)pPageCpuPhys);80 SUPR0Printf("VMXR0EnableCpu cpu %d page (%x) %x\n", pCpu->idCpu, pvPageCpu, (uint32_t)pPageCpuPhys); 81 81 #endif 82 82 /* Set revision dword at the beginning of the VMXON structure. */ … … 105 105 * 106 106 * @returns VBox status code. 107 * @param idCpu The identifier for the CPU the function is called on.107 * @param pCpu CPU info struct 108 108 * @param pvPageCpu Pointer to the global cpu page 109 109 * @param pPageCpuPhys Physical address of the global cpu page 110 110 */ 111 HWACCMR0DECL(int) VMXR0DisableCpu( RTCPUID idCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys)111 HWACCMR0DECL(int) VMXR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys) 112 112 { 113 113 AssertReturn(pPageCpuPhys, VERR_INVALID_PARAMETER); … … 121 121 122 122 #ifdef LOG_ENABLED 123 SUPR0Printf("VMXR0DisableCpu cpu %d\n", idCpu);123 SUPR0Printf("VMXR0DisableCpu cpu %d\n", pCpu->idCpu); 124 124 #endif 125 125 return VINF_SUCCESS; … … 963 963 964 964 /** 965 * Runs guest code in a V MXVM.965 * Runs guest code in a VT-x VM. 966 966 * 967 967 * @note NEVER EVER turn on interrupts here. Due to our illegal entry into the kernel, it might mess things up. (XP kernel traps have been frequently observed) … … 970 970 * @param pVM The VM to operate on. 971 971 * @param pCtx Guest context 972 * @param pCpu CPU info struct 972 973 */ 973 HWACCMR0DECL(int) VMXR0RunGuestCode(PVM pVM, CPUMCTX *pCtx )974 HWACCMR0DECL(int) VMXR0RunGuestCode(PVM pVM, CPUMCTX *pCtx, PHWACCM_CPUINFO pCpu) 974 975 { 975 976 int rc = VINF_SUCCESS; … … 983 984 984 985 Log2(("\nE")); 986 987 AssertReturn(pCpu->fVMXConfigured, VERR_EM_INTERNAL_ERROR); 985 988 986 989 STAM_PROFILE_ADV_START(&pVM->hwaccm.s.StatEntry, x); -
trunk/src/VBox/VMM/VMMR0/HWVMXR0.h
r8155 r8876 63 63 * 64 64 * @returns VBox status code. 65 * @param idCpu The identifier for the CPU the function is called on.65 * @param pCpu CPU info struct 66 66 * @param pVM The VM to operate on. 67 67 * @param pvPageCpu Pointer to the global cpu page 68 68 * @param pPageCpuPhys Physical address of the global cpu page 69 69 */ 70 HWACCMR0DECL(int) VMXR0EnableCpu( RTCPUID idCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);70 HWACCMR0DECL(int) VMXR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys); 71 71 72 72 /** … … 74 74 * 75 75 * @returns VBox status code. 76 * @param idCpu The identifier for the CPU the function is called on.76 * @param pCpu CPU info struct 77 77 * @param pvPageCpu Pointer to the global cpu page 78 78 * @param pPageCpuPhys Physical address of the global cpu page 79 79 */ 80 HWACCMR0DECL(int) VMXR0DisableCpu( RTCPUID idCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);80 HWACCMR0DECL(int) VMXR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys); 81 81 82 82 /** … … 131 131 * @param pVM The VM to operate on. 132 132 * @param pCtx Guest context 133 * @param pCpu CPU info struct 133 134 */ 134 HWACCMR0DECL(int) VMXR0RunGuestCode(PVM pVM, CPUMCTX *pCtx );135 HWACCMR0DECL(int) VMXR0RunGuestCode(PVM pVM, CPUMCTX *pCtx, PHWACCM_CPUINFO pCpu); 135 136 136 137
Note:
See TracChangeset
for help on using the changeset viewer.