VirtualBox

Changeset 13533 in vbox


Ignore:
Timestamp:
Oct 23, 2008 1:00:28 PM (16 years ago)
Author:
vboxsync
Message:

Extra assertions to check for unexpected use conditions.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/HWACCMInternal.h

    r13347 r13533  
    143143typedef struct
    144144{
    145     RTCPUID     idCpu;
    146 
    147     RTR0MEMOBJ  pMemObj;
     145    RTCPUID             idCpu;
     146
     147    RTR0MEMOBJ          pMemObj;
    148148    /* Current ASID (AMD-V)/VPID (Intel) */
    149     uint32_t    uCurrentASID;
     149    uint32_t            uCurrentASID;
    150150    /* TLB flush count */
    151     uint32_t    cTLBFlushes;
     151    uint32_t            cTLBFlushes;
    152152
    153153    /* Set the first time a cpu is used to make sure we start with a clean TLB. */
    154     bool        fFlushTLB;
    155 
    156     bool        fConfigured;
     154    bool                fFlushTLB;
     155
     156    /** Configured for VT-x or AMD-V. */
     157    bool                fConfigured;
     158
     159    /** In use by our code. (for power suspend) */
     160    volatile bool       fInUse;
    157161} HWACCM_CPUINFO;
    158162typedef HWACCM_CPUINFO *PHWACCM_CPUINFO;
  • trunk/src/VBox/VMM/VMMR0/HWACCMR0.cpp

    r13532 r13533  
    603603    Assert(idCpu < RT_ELEMENTS(HWACCMR0Globals.aCpuInfo));
    604604    Assert(!pCpu->fConfigured);
     605    Assert(ASMAtomicReadBool(&pCpu->fInUse) == false);
    605606
    606607    pCpu->idCpu     = idCpu;
     
    648649    Assert(idCpu == (RTCPUID)RTMpCpuIdToSetIndex(idCpu)); /// @todo fix idCpu == index assumption (rainy day)
    649650    Assert(idCpu < RT_ELEMENTS(HWACCMR0Globals.aCpuInfo));
     651    Assert(ASMAtomicReadBool(&pCpu->fInUse) == false);
    650652
    651653    if (!pCpu->pMemObj)
     
    735737VMMR0DECL(int) HWACCMR0InitVM(PVM pVM)
    736738{
     739    int             rc;
     740    RTCPUID         idCpu = RTMpCpuId();
     741    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
     742
    737743    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    738744
     
    780786    pVM->hwaccm.s.uCurrentASID              = 0;
    781787
     788    ASMAtomicWriteBool(&pCpu->fInUse, true);
     789
    782790    /* Init a VT-x or AMD-V VM. */
    783     return HWACCMR0Globals.pfnInitVM(pVM);
     791    rc = HWACCMR0Globals.pfnInitVM(pVM);
     792
     793    ASMAtomicWriteBool(&pCpu->fInUse, false);
     794
     795    return rc;
    784796}
    785797
     
    793805VMMR0DECL(int) HWACCMR0TermVM(PVM pVM)
    794806{
     807    int             rc;
     808    RTCPUID         idCpu = RTMpCpuId();
     809    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
     810
    795811    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    796812
     
    802818    AssertReturn(!ASMAtomicReadBool(&HWACCMR0Globals.fSuspended), VERR_HWACCM_SUSPEND_PENDING);
    803819
     820    ASMAtomicWriteBool(&pCpu->fInUse, true);
     821
    804822    /* Terminate a VT-x or AMD-V VM. */
    805     return HWACCMR0Globals.pfnTermVM(pVM);
     823    rc = HWACCMR0Globals.pfnTermVM(pVM);
     824
     825    ASMAtomicWriteBool(&pCpu->fInUse, false);
     826    return rc;
    806827}
    807828
     
    815836VMMR0DECL(int) HWACCMR0SetupVM(PVM pVM)
    816837{
     838    int             rc;
     839    RTCPUID         idCpu = RTMpCpuId();
     840    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
     841
    817842    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    818843
     
    824849#endif
    825850
     851    ASMAtomicWriteBool(&pCpu->fInUse, true);
     852
    826853    /* Setup VT-x or AMD-V. */
    827     return HWACCMR0Globals.pfnSetupVM(pVM);
     854    rc = HWACCMR0Globals.pfnSetupVM(pVM);
     855
     856    ASMAtomicWriteBool(&pCpu->fInUse, false);
     857
     858    return rc;
    828859}
    829860
     
    837868VMMR0DECL(int) HWACCMR0Enter(PVM pVM)
    838869{
    839     CPUMCTX *pCtx;
    840     int      rc;
    841     RTCPUID  idCpu = RTMpCpuId();
     870    PCPUMCTX        pCtx;
     871    int             rc;
     872    RTCPUID         idCpu = RTMpCpuId();
     873    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
    842874
    843875    /* Make sure we can't enter a session after we've disabled hwaccm in preparation of a suspend. */
    844876    AssertReturn(!ASMAtomicReadBool(&HWACCMR0Globals.fSuspended), VERR_HWACCM_SUSPEND_PENDING);
     877    ASMAtomicWriteBool(&pCpu->fInUse, true);
    845878
    846879    pCtx = CPUMQueryGuestCtxPtr(pVM);
     
    861894        pVM->hwaccm.s.u64RegisterMask = UINT64_C(0xFFFFFFFF);
    862895
    863     rc  = HWACCMR0Globals.pfnEnterSession(pVM, &HWACCMR0Globals.aCpuInfo[idCpu]);
     896    rc  = HWACCMR0Globals.pfnEnterSession(pVM, pCpu);
    864897    AssertRC(rc);
    865898    /* We must save the host context here (VT-x) as we might be rescheduled on a different cpu after a long jump back to ring 3. */
     
    889922VMMR0DECL(int) HWACCMR0Leave(PVM pVM)
    890923{
    891     CPUMCTX *pCtx;
    892     int      rc;
     924    PCPUMCTX        pCtx;
     925    int             rc;
     926    RTCPUID         idCpu = RTMpCpuId();
     927    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
    893928
    894929    AssertReturn(!ASMAtomicReadBool(&HWACCMR0Globals.fSuspended), VERR_HWACCM_SUSPEND_PENDING);
     
    913948#ifdef VBOX_STRICT
    914949    /* keep track of the CPU owning the VMCS for debugging scheduling weirdness and ring-3 calls. */
    915     RTCPUID idCpu = RTMpCpuId();
    916950    AssertMsg(pVM->hwaccm.s.idEnteredCpu == idCpu, ("owner is %d, I'm %d", (int)pVM->hwaccm.s.idEnteredCpu, (int)idCpu));
    917951    pVM->hwaccm.s.idEnteredCpu = NIL_RTCPUID;
    918952#endif
    919953
     954    ASMAtomicWriteBool(&pCpu->fInUse, false);
    920955    return rc;
    921956}
     
    932967    int      rc;
    933968    RTCPUID  idCpu = RTMpCpuId(); NOREF(idCpu);
     969#ifdef VBOX_STRICT
     970    PHWACCM_CPUINFO pCpu = &HWACCMR0Globals.aCpuInfo[idCpu];
     971#endif
    934972
    935973    Assert(!VM_FF_ISPENDING(pVM, VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL));
    936974    Assert(HWACCMR0Globals.aCpuInfo[idCpu].fConfigured);
    937975    AssertReturn(!ASMAtomicReadBool(&HWACCMR0Globals.fSuspended), VERR_HWACCM_SUSPEND_PENDING);
     976    Assert(ASMAtomicReadBool(&pCpu->fInUse) == true);
    938977
    939978    pCtx = CPUMQueryGuestCtxPtr(pVM);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette