VirtualBox

Changeset 6801 in vbox


Ignore:
Timestamp:
Feb 4, 2008 7:36:58 PM (17 years ago)
Author:
vboxsync
Message:

Changed GVM the ownership rules - at long last. EMT is the guy that creates the VM, simple and secure.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/gvmm.h

    r5999 r6801  
    119119
    120120GVMMR0DECL(int)     GVMMR0CreateVM(PSUPDRVSESSION pSession, PVM *ppVM);
    121 GVMMR0DECL(int)     GVMMR0DisassociateEMTFromVM(PVM pVM);
    122121GVMMR0DECL(int)     GVMMR0InitVM(PVM pVM);
    123 GVMMR0DECL(int)     GVMMR0AssociateEMTWithVM(PVM pVM);
    124122GVMMR0DECL(int)     GVMMR0DestroyVM(PVM pVM);
    125123GVMMR0DECL(PGVM)    GVMMR0ByHandle(uint32_t hGVM);
  • trunk/src/VBox/VMM/VMMR0/GVMMR0.cpp

    r6635 r6801  
    486486 * Allocates the VM structure and registers it with GVM.
    487487 *
     488 * The caller will become the VM owner and there by the EMT.
     489 *
    488490 * @returns VBox status code.
    489491 * @param   pSession    The support driver session.
    490492 * @param   ppVM        Where to store the pointer to the VM structure.
    491493 *
    492  * @thread  Any thread.
     494 * @thread  EMT.
    493495 */
    494496GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, PVM *ppVM)
     
    501503    *ppVM = NULL;
    502504
    503     AssertReturn(RTThreadNativeSelf() != NIL_RTNATIVETHREAD, VERR_INTERNAL_ERROR);
     505    RTNATIVETHREAD hEMT = RTThreadNativeSelf();
     506    AssertReturn(hEMT != NIL_RTNATIVETHREAD, VERR_INTERNAL_ERROR);
    504507
    505508    /*
     
    609612                                        pHandle->pVM = pVM;
    610613                                        pHandle->pGVM = pGVM;
     614                                        pHandle->hEMT = hEMT;
    611615                                        pGVM->pVM = pVM;
    612 
     616                                        pGVM->hEMT = hEMT;
    613617
    614618                                        gvmmR0UsedUnlock(pGVMM);
     
    678682
    679683/**
    680  * Associates an EMT thread with a VM.
    681  *
    682  * This is called early during the ring-0 VM initialization so assertions later in
    683  * the process can be handled gracefully.
    684  *
    685  * @returns VBox status code.
    686  *
    687  * @param   pVM         The VM instance data (aka handle), ring-0 mapping of course.
    688  * @thread  EMT.
    689  */
    690 GVMMR0DECL(int) GVMMR0AssociateEMTWithVM(PVM pVM)
    691 {
    692     LogFlow(("GVMMR0AssociateEMTWithVM: pVM=%p\n", pVM));
    693     PGVMM pGVMM;
    694     GVMM_GET_VALID_INSTANCE(pGVMM, VERR_INTERNAL_ERROR);
    695 
    696     /*
    697      * Validate the VM structure, state and handle.
    698      */
    699     AssertPtrReturn(pVM, VERR_INVALID_POINTER);
    700     AssertReturn(!((uintptr_t)pVM & PAGE_OFFSET_MASK), VERR_INVALID_POINTER);
    701     AssertMsgReturn(pVM->enmVMState == VMSTATE_CREATING, ("%d\n", pVM->enmVMState), VERR_WRONG_ORDER);
    702 
    703     RTNATIVETHREAD hEMT = RTThreadNativeSelf();
    704     AssertReturn(hEMT != NIL_RTNATIVETHREAD, VERR_NOT_SUPPORTED);
    705 
    706     const uint16_t hGVM = pVM->hSelf;
    707     AssertReturn(hGVM != NIL_GVM_HANDLE, VERR_INVALID_HANDLE);
    708     AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), VERR_INVALID_HANDLE);
    709 
    710     PGVMHANDLE pHandle = &pGVMM->aHandles[hGVM];
    711     AssertReturn(pHandle->pVM == pVM, VERR_NOT_OWNER);
    712 
    713     /*
    714      * Take the lock, validate the handle and update the structure members.
    715      */
    716     int rc = gvmmR0CreateDestroyLock(pGVMM);
    717     AssertRCReturn(rc, rc);
    718     rc = gvmmR0UsedLock(pGVMM);
    719     AssertRC(rc);
    720 
    721     if (    pHandle->pVM == pVM
    722         &&  VALID_PTR(pHandle->pvObj)
    723         &&  VALID_PTR(pHandle->pSession)
    724         &&  VALID_PTR(pHandle->pGVM)
    725         &&  pHandle->pGVM->u32Magic == GVM_MAGIC)
    726     {
    727         pHandle->hEMT = hEMT;
    728         pHandle->pGVM->hEMT = hEMT;
    729     }
    730     else
    731         rc = VERR_INTERNAL_ERROR;
    732 
    733     gvmmR0UsedUnlock(pGVMM);
    734     gvmmR0CreateDestroyUnlock(pGVMM);
    735     LogFlow(("GVMMR0AssociateEMTWithVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
    736     return rc;
    737 }
    738 
    739 
    740 /**
    741684 * Does the VM initialization.
    742685 *
     
    767710
    768711    LogFlow(("GVMMR0InitVM: returns %Rrc\n", rc));
    769     return rc;
    770 }
    771 
    772 
    773 /**
    774  * Disassociates the EMT thread from a VM.
    775  *
    776  * This is called last in the ring-0 VM termination. After this point anyone is
    777  * allowed to destroy the VM. Ideally, we should associate the VM with the thread
    778  * that's going to call GVMMR0DestroyVM for optimal security, but that's impractical
    779  * at present.
    780  *
    781  * @returns VBox status code.
    782  *
    783  * @param   pVM         The VM instance data (aka handle), ring-0 mapping of course.
    784  * @thread  EMT.
    785  */
    786 GVMMR0DECL(int) GVMMR0DisassociateEMTFromVM(PVM pVM)
    787 {
    788     LogFlow(("GVMMR0DisassociateEMTFromVM: pVM=%p\n", pVM));
    789     PGVMM pGVMM;
    790     GVMM_GET_VALID_INSTANCE(pGVMM, VERR_INTERNAL_ERROR);
    791 
    792     /*
    793      * Validate the VM structure, state and handle.
    794      */
    795     AssertPtrReturn(pVM, VERR_INVALID_POINTER);
    796     AssertReturn(!((uintptr_t)pVM & PAGE_OFFSET_MASK), VERR_INVALID_POINTER);
    797     AssertMsgReturn(pVM->enmVMState >= VMSTATE_CREATING && pVM->enmVMState <= VMSTATE_DESTROYING, ("%d\n", pVM->enmVMState), VERR_WRONG_ORDER);
    798 
    799     RTNATIVETHREAD hEMT = RTThreadNativeSelf();
    800     AssertReturn(hEMT != NIL_RTNATIVETHREAD, VERR_NOT_SUPPORTED);
    801 
    802     const uint16_t hGVM = pVM->hSelf;
    803     AssertReturn(hGVM != NIL_GVM_HANDLE, VERR_INVALID_HANDLE);
    804     AssertReturn(hGVM < RT_ELEMENTS(pGVMM->aHandles), VERR_INVALID_HANDLE);
    805 
    806     PGVMHANDLE pHandle = &pGVMM->aHandles[hGVM];
    807     AssertReturn(pHandle->pVM == pVM, VERR_NOT_OWNER);
    808 
    809     /*
    810      * Take the lock, validate the handle and update the structure members.
    811      */
    812     int rc = gvmmR0CreateDestroyLock(pGVMM);
    813     AssertRCReturn(rc, rc);
    814     rc = gvmmR0UsedLock(pGVMM);
    815     AssertRC(rc);
    816 
    817     if (    VALID_PTR(pHandle->pvObj)
    818         &&  VALID_PTR(pHandle->pSession)
    819         &&  VALID_PTR(pHandle->pGVM)
    820         &&  pHandle->pGVM->u32Magic == GVM_MAGIC)
    821     {
    822         if (    pHandle->pVM == pVM
    823             &&  pHandle->hEMT == hEMT)
    824         {
    825             pHandle->hEMT = NIL_RTNATIVETHREAD;
    826             pHandle->pGVM->hEMT = NIL_RTNATIVETHREAD;
    827         }
    828         else
    829             rc = VERR_NOT_OWNER;
    830     }
    831     else
    832         rc = VERR_INVALID_HANDLE;
    833 
    834     gvmmR0UsedUnlock(pGVMM);
    835     gvmmR0CreateDestroyUnlock(pGVMM);
    836     LogFlow(("GVMMR0DisassociateEMTFromVM: returns %Vrc (hEMT=%RTnthrd)\n", rc, hEMT));
    837712    return rc;
    838713}
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r6796 r6801  
    8383    if (RT_SUCCESS(rc))
    8484    {
    85 //#ifdef VBOX_WITH_NEW_PHYS_CODE /* need to test on windows, solaris and darwin. */
    8685        rc = GMMR0Init();
    87 //#endif
    8886        if (RT_SUCCESS(rc))
    8987        {
     
    134132     * Destroy the GMM and GVMM instances.
    135133     */
    136 //#ifdef VBOX_WITH_NEW_PHYS_CODE
    137134    GMMR0Term();
    138 //#endif
    139135    GVMMR0Term();
    140136
     
    206202
    207203    /*
    208      * Associate the ring-0 EMT thread with the GVM
    209      * and initalize the GVMM and GMM per VM data.
     204     * nitalize the per VM data for GVMM and GMM.
    210205     */
    211     int rc = GVMMR0AssociateEMTWithVM(pVM);
     206    int rc = GVMMR0InitVM(pVM);
     207//    if (RT_SUCCESS(rc))
     208//        rc = GMMR0InitPerVMData(pVM);
    212209    if (RT_SUCCESS(rc))
    213210    {
    214         rc = GVMMR0InitVM(pVM);
    215         //if (RT_SUCCESS(rc))
    216         //    rc = GMMR0InitVM(pVM);
     211        /*
     212         * Init HWACCM.
     213         */
     214        RTCCUINTREG fFlags = ASMIntDisableFlags();
     215        rc = HWACCMR0Init(pVM);
     216        ASMSetFlags(fFlags);
    217217        if (RT_SUCCESS(rc))
    218218        {
    219219            /*
    220              * Init HWACCM.
     220             * Init CPUM.
    221221             */
    222             RTCCUINTREG fFlags = ASMIntDisableFlags();
    223             rc = HWACCMR0Init(pVM);
    224             ASMSetFlags(fFlags);
     222            rc = CPUMR0Init(pVM);
    225223            if (RT_SUCCESS(rc))
    226             {
    227                 /*
    228                  * Init CPUM.
    229                  */
    230                 rc = CPUMR0Init(pVM);
    231                 if (RT_SUCCESS(rc))
    232                     return rc;
    233             }
     224                return rc;
    234225        }
    235226    }
     
    254245     * Deregister the logger.
    255246     */
    256     GVMMR0DisassociateEMTFromVM(pVM);
    257247    RTLogSetDefaultInstanceThread(NULL, 0);
    258248    return VINF_SUCCESS;
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