VirtualBox

Changeset 14811 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 29, 2008 11:48:26 PM (16 years ago)
Author:
vboxsync
Message:

VMM: Always call VMMR0TermVM{HWACCMR0TermVM,PGMR0DynMapTerm}, don't rely on ring-3 always making that call.

Location:
trunk/src/VBox/VMM/VMMR0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r13796 r14811  
    4343#include <VBox/gvm.h>
    4444#include <VBox/vm.h>
     45#include <VBox/vmm.h>
    4546#include <VBox/err.h>
    4647#include <iprt/alloc.h>
     
    698699    pGVM->gvmm.s.VMPagesMapObj = NIL_RTR0MEMOBJ;
    699700    pGVM->gvmm.s.HaltEventMulti = NIL_RTSEMEVENTMULTI;
     701    pGVM->gvmm.s.fDoneVMMR0Init = false;
     702    pGVM->gvmm.s.fDoneVMMR0Term = false;
    700703}
    701704
     
    719722    if (RT_SUCCESS(rc))
    720723    {
    721         if (pGVM->gvmm.s.HaltEventMulti == NIL_RTSEMEVENTMULTI)
     724        if (   !pGVM->gvmm.s.fDoneVMMR0Init
     725            && pGVM->gvmm.s.HaltEventMulti == NIL_RTSEMEVENTMULTI)
    722726        {
    723727            rc = RTSemEventMultiCreate(&pGVM->gvmm.s.HaltEventMulti);
     
    731735    LogFlow(("GVMMR0InitVM: returns %Rrc\n", rc));
    732736    return rc;
     737}
     738
     739
     740/**
     741 * Indicates that we're done with the ring-0 initialization
     742 * of the VM.
     743 *
     744 * @param   pVM         Pointer to the shared VM structure.
     745 */
     746GVMMR0DECL(void) GVMMR0DoneInitVM(PVM pVM)
     747{
     748    /* Validate the VM structure, state and handle. */
     749    PGVM pGVM;
     750    PGVMM pGVMM;
     751    int rc = gvmmR0ByVMAndEMT(pVM, &pGVM, &pGVMM);
     752    AssertRCReturnVoid(rc);
     753
     754    /* Set the indicator. */
     755    pGVM->gvmm.s.fDoneVMMR0Init = true;
     756}
     757
     758
     759/**
     760 * Indicates that we're doing the ring-0 termination of the VM.
     761 *
     762 * @returns true if termination hasn't been done already, false if it has.
     763 * @param   pVM         Pointer to the shared VM structure.
     764 * @param   pGVM        Pointer to the global VM structure. Optional.
     765 */
     766GVMMR0DECL(bool) GVMMR0DoingTermVM(PVM pVM, PGVM pGVM)
     767{
     768    /* Validate the VM structure, state and handle. */
     769    AssertPtrNullReturn(pGVM, false);
     770    AssertPtrNullReturn(!pGVM || pGVM->u32Magic == GVM_MAGIC, false);
     771    if (!pGVM)
     772    {
     773        PGVMM pGVMM;
     774        int rc = gvmmR0ByVMAndEMT(pVM, &pGVM, &pGVMM);
     775        AssertRCReturn(rc, false);
     776    }
     777
     778    /* Set the indicator. */
     779    if (pGVM->gvmm.s.fDoneVMMR0Term)
     780        return false;
     781    pGVM->gvmm.s.fDoneVMMR0Term = true;
     782    return true;
    733783}
    734784
     
    807857
    808858/**
     859 * Performs VM cleanup task as part of object destruction.
     860 *
     861 * @param   pGVM        The GVM pointer.
     862 */
     863static void gmmR0CleanupVM(PGVM pGVM)
     864{
     865    if (    pGVM->gvmm.s.fDoneVMMR0Init
     866        &&  !pGVM->gvmm.s.fDoneVMMR0Term)
     867    {
     868        if (    pGVM->gvmm.s.VMMemObj != NIL_RTR0MEMOBJ
     869            &&  RTR0MemObjAddress(pGVM->gvmm.s.VMMemObj) == pGVM->pVM)
     870        {
     871            LogFlow(("gmmR0CleanupVM: Calling VMMR0TermVM\n"));
     872            VMMR0TermVM(pGVM->pVM, pGVM);
     873        }
     874        else
     875            AssertMsgFailed(("gmmR0CleanupVM: VMMemObj=%p pVM=%p\n", pGVM->gvmm.s.VMMemObj, pGVM->pVM));
     876    }
     877}
     878
     879
     880/**
    809881 * Handle destructor.
    810882 *
    811  * @param   pvGVMM       The GVM instance pointer.
     883 * @param   pvGVMM      The GVM instance pointer.
    812884 * @param   pvHandle    The handle pointer.
    813885 */
     
    896968        &&  pGVM->u32Magic == GVM_MAGIC)
    897969    {
    898         /// @todo GMMR0CleanupVM(pGVM);
     970        gmmR0CleanupVM(pGVM);
    899971
    900972        /*
  • trunk/src/VBox/VMM/VMMR0/GVMMR0Internal.h

    r8155 r14811  
    2525#include <iprt/mem.h>
    2626
     27
    2728/**
    2829 * The GVMM per VM data.
     
    4950    /** The scheduler statistics. */
    5051    GVMMSTATSSCHED      StatsSched;
     52
     53    /** Whether the per-VM ring-0 initialization has been performed. */
     54    bool                fDoneVMMR0Init;
     55    /** Whether the per-VM ring-0 termination is being or has been performed. */
     56    bool                fDoneVMMR0Term;
    5157} GVMMPERVM;
    5258/** Pointer to the GVMM per VM data. */
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r14719 r14811  
    239239#endif
    240240                if (RT_SUCCESS(rc))
     241                {
     242                    GVMMR0DoneInitVM(pVM);
    241243                    return rc;
     244                }
    242245
    243246                /* bail out */
     
    254257 * Terminates the R0 driver for a particular VM instance.
    255258 *
     259 * This is normally called by ring-3 as part of the VM termination process, but
     260 * may alternatively be called during the support driver session cleanup when
     261 * the VM object is destroyed (see GVMM).
     262 *
    256263 * @returns VBox status code.
    257264 *
    258265 * @param   pVM         The VM instance in question.
    259  * @thread  EMT.
    260  */
    261 static int vmmR0TermVM(PVM pVM)
    262 {
    263 /** @todo @bugref{1865,3202}: Make these tail onto the VM object destruction
    264  *        to make sure they are *always* executed and don't leave mess behind
    265  *        when the process is killed. */
     266 * @param   pGVM        Pointer to the global VM structure. Optional.
     267 * @thread  EMT or session clean up thread.
     268 */
     269VMMR0DECL(int) VMMR0TermVM(PVM pVM, PGVM pGVM)
     270{
     271    /*
     272     * Tell GVMM what we're up to and check that we only do this once.
     273     */
     274    if (GVMMR0DoingTermVM(pVM, pGVM))
     275    {
    266276#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    267     PGMR0DynMapTermVM(pVM);
    268 #endif
    269     HWACCMR0TermVM(pVM);
     277        PGMR0DynMapTermVM(pVM);
     278#endif
     279        HWACCMR0TermVM(pVM);
     280    }
    270281
    271282    /*
     
    727738         */
    728739        case VMMR0_DO_VMMR0_TERM:
    729             return vmmR0TermVM(pVM);
     740            return VMMR0TermVM(pVM, NULL);
    730741
    731742        /*
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