VirtualBox

Changeset 19784 in vbox


Ignore:
Timestamp:
May 18, 2009 1:15:46 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
47420
Message:

Use PDM lock for protecting pdm queue management.

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

Legend:

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

    r19593 r19784  
    613613typedef enum PDMQUEUETYPE
    614614{
     615    /** Uninitialized. */
     616    PDMQUEUETYPE_UNINIT = 0,
    615617    /** Device consumer. */
    616     PDMQUEUETYPE_DEV = 1,
     618    PDMQUEUETYPE_DEV,
    617619    /** Driver consumer. */
    618620    PDMQUEUETYPE_DRV,
     
    10201022int         pdmLockEx(PVM pVM, int rc);
    10211023void        pdmUnlock(PVM pVM);
    1022 
     1024bool        pdmIsLockOwner(PVM pVM);
    10231025/** @} */
    10241026
  • trunk/src/VBox/VMM/PDMQueue.cpp

    r19507 r19784  
    9292     * Initialize the data fields.
    9393     */
    94     pQueue->pVMR3 = pVM;
    95     pQueue->pVMR0 = fRZEnabled ? pVM->pVMR0 : NIL_RTR0PTR;
    96     pQueue->pVMRC = fRZEnabled ? pVM->pVMRC : NIL_RTRCPTR;
     94    pQueue->pVMR3   = pVM;
     95    pQueue->pVMR0   = fRZEnabled ? pVM->pVMR0 : NIL_RTR0PTR;
     96    pQueue->pVMRC   = fRZEnabled ? pVM->pVMRC : NIL_RTRCPTR;
     97    pQueue->enmType = PDMQUEUETYPE_UNINIT;
    9798    pQueue->cMilliesInterval = cMilliesInterval;
    9899    //pQueue->pTimer = NULL;
    99     pQueue->cbItem = cbItem;
    100     pQueue->cItems = cItems;
     100    pQueue->cbItem  = cbItem;
     101    pQueue->cItems  = cItems;
    101102    //pQueue->pPendingR3 = NULL;
    102103    //pQueue->pPendingR0 = NULL;
     
    144145         * Insert into the queue list for timer driven queues.
    145146         */
     147        pdmLock(pVM);
    146148        pQueue->pNext = pVM->pdm.s.pQueuesTimer;
    147149        pVM->pdm.s.pQueuesTimer = pQueue;
     150        pdmUnlock(pVM);
    148151    }
    149152    else
     
    159162         *   problem any longer. The priority might be a nice feature for later though.
    160163         */
     164        pdmLock(pVM);
    161165        if (!pVM->pdm.s.pQueuesForced)
    162166            pVM->pdm.s.pQueuesForced = pQueue;
     
    168172            pPrev->pNext = pQueue;
    169173        }
     174        pdmUnlock(pVM);
    170175    }
    171176
     
    392397     * Unlink it.
    393398     */
     399    pdmLock(pVM);
    394400    if (pQueue->pTimer)
    395401    {
     
    432438    pQueue->pNext = NULL;
    433439    pQueue->pVMR3 = NULL;
     440    pdmUnlock(pVM);
    434441
    435442    /*
     
    476483     * Unlink it.
    477484     */
     485    pdmLock(pVM);
    478486    PPDMQUEUE pQueueNext = pVM->pdm.s.pQueuesTimer;
    479487    PPDMQUEUE pQueue = pVM->pdm.s.pQueuesForced;
     
    499507    } while (pQueue);
    500508
     509    pdmUnlock(pVM);
     510
    501511    return VINF_SUCCESS;
    502512}
     
    525535     * Unlink it.
    526536     */
     537    pdmLock(pVM);
    527538    PPDMQUEUE pQueueNext = pVM->pdm.s.pQueuesTimer;
    528539    PPDMQUEUE pQueue = pVM->pdm.s.pQueuesForced;
     
    547558        pQueueNext = NULL;
    548559    } while (pQueue);
     560    pdmUnlock(pVM);
    549561
    550562    return VINF_SUCCESS;
     
    563575     * Process the queues.
    564576     */
     577    pdmLock(pVM);
    565578    PPDMQUEUE pQueueNext = pVM->pdm.s.pQueuesTimer;
    566579    PPDMQUEUE pQueue = pVM->pdm.s.pQueuesForced;
     
    602615        pQueueNext = NULL;
    603616    } while (pQueue);
     617    pdmUnlock(pVM);
    604618}
    605619
     
    617631    LogFlow(("PDMR3QueuesFlush:\n"));
    618632
     633    Assert(!pdmIsLockOwner(pVM));
    619634    /* Use atomic test and clear to prevent useless checks; pdmR3QueueFlush is SMP safe. */
    620635    if (VM_FF_TESTANDCLEAR(pVM, VM_FF_PDM_QUEUES_BIT))
    621636    {
     637        pdmLock(pVM);
    622638        for (PPDMQUEUE pCur = pVM->pdm.s.pQueuesForced; pCur; pCur = pCur->pNext)
    623639        {
     
    632648            }
    633649        }
     650        pdmUnlock(pVM);
    634651    }
    635652}
     
    653670
    654671    AssertMsg(pItems || pItemsRC || pItemsR0, ("ERROR: can't all be NULL now!\n"));
    655 
     672    Assert(pdmIsLockOwner(pQueue->pVMR3));
    656673
    657674    /*
     
    801818    VM_ASSERT_EMT(pVM);
    802819
     820    pdmLock(pVM);
    803821    /*
    804822     * Flush the queue.
     
    832850            }
    833851    }
     852    pdmUnlock(pVM);
    834853}
    835854
     
    840859 * @param   pQueue  The queue.
    841860 * @param   pItem   The item.
     861 *
     862 * Note: SMP safe
    842863 */
    843864DECLINLINE(void) pdmR3QueueFree(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem)
     
    872893    PPDMQUEUE pQueue = (PPDMQUEUE)pvUser;
    873894    Assert(pTimer == pQueue->pTimer); NOREF(pTimer);
     895    Assert(!pdmIsLockOwner(pVM));
    874896
    875897    if (    pQueue->pPendingR3
    876898        ||  pQueue->pPendingR0
    877899        ||  pQueue->pPendingRC)
     900    {
     901        pdmLock(pVM);
    878902        pdmR3QueueFlush(pQueue);
     903        pdmUnlock(pVM);
     904    }
    879905    int rc = TMTimerSetMillies(pQueue->pTimer, pQueue->cMilliesInterval);
    880906    AssertRC(rc);
  • trunk/src/VBox/VMM/VMMAll/PDMAll.cpp

    r19141 r19784  
    349349}
    350350
     351/**
     352 * Check if this VCPU currently owns the PDM lock.
     353 *
     354 * @returns bool owner/not owner
     355 * @param   pVM         The VM to operate on.
     356 */
     357bool pdmIsLockOwner(PVM pVM)
     358{
     359    return PDMCritSectIsOwner(&pVM->pdm.s.CritSect);
     360}
     361
    351362
    352363/**
  • trunk/src/VBox/VMM/VMMAll/PDMAllQueue.cpp

    r19400 r19784  
    4747 * @param   pQueue      The queue handle.
    4848 * @thread  Any thread.
     49 *
     50 * Note: SMP safe
    4951 */
    5052VMMDECL(PPDMQUEUEITEMCORE) PDMQueueAlloc(PPDMQUEUE pQueue)
     
    7476 * @param   pItem       The item to insert.
    7577 * @thread  Any thread.
     78 *
     79 * Note: SMP safe
    7680 */
    7781VMMDECL(void) PDMQueueInsert(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem)
     
    192196#else /* IN_RING3: */
    193197    PVMREQ pReq;
     198    Assert(!pdmIsLockOwner(pVM));
    194199    VMR3ReqCall(pVM, VMCPUID_ANY, &pReq, RT_INDEFINITE_WAIT, (PFNRT)PDMR3QueueFlushWorker, 2, pVM, pQueue);
    195200    VMR3ReqFree(pReq);
  • trunk/src/VBox/VMM/VMMAll/PGMAllBth.h

    r19782 r19784  
    421421                                && !(uErr & X86_TRAP_PF_P))
    422422                            {
     423                                pgmLock(pVM);
    423424                                rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, PGM_SYNC_NR_PAGES, uErr);
     425                                pgmUnlock(pVM);
    424426                                if (    RT_FAILURE(rc)
    425427                                    || !(uErr & X86_TRAP_PF_RW)
     
    467469                            && !(uErr & X86_TRAP_PF_P))
    468470                        {
     471                            pgmLock(pVM);
    469472                            rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, PGM_SYNC_NR_PAGES, uErr);
     473                            pgmUnlock(pVM);
    470474                            if (    RT_FAILURE(rc)
    471475                                ||  rc == VINF_PGM_SYNCPAGE_MODIFIED_PDE
     
    561565                        &&  !(uErr & X86_TRAP_PF_P))
    562566                    {
     567                        pgmLock(pVM);
    563568                        rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, PGM_SYNC_NR_PAGES, uErr);
     569                        pgmUnlock(pVM);
    564570                        if (    RT_FAILURE(rc)
    565571                            ||  rc == VINF_PGM_SYNCPAGE_MODIFIED_PDE
     
    695701                                 */
    696702                                LogFlow(("CSAM ring 3 job\n"));
     703                                pgmLock(pVM);
    697704                                int rc2 = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, 1, uErr);
     705                                pgmUnlock(pVM);
    698706                                AssertRC(rc2);
    699707
     
    743751                }
    744752#   endif /* PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) && !defined(IN_RING0) */
     753                pgmLock(pVM);
    745754                rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, PGM_SYNC_NR_PAGES, uErr);
     755                pgmUnlock(pVM);
    746756                if (RT_SUCCESS(rc))
    747757                {
     
    788798                     *       page is not present, which is not true in this case.
    789799                     */
     800                    pgmLock(pVM);
    790801                    rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, pvFault, 1, uErr);
     802                    pgmUnlock(pVM);
    791803                    if (RT_SUCCESS(rc))
    792804                    {
     
    12211233                    PGM_BTH_NAME(SyncPageWorkerTrackDeref)(pShwPage, pPT->a[iPTEDst].u & SHW_PTE_PG_MASK);
    12221234#  endif
    1223                     pPT->a[iPTEDst].u = 0;
     1235                    ASMAtomicWriteSize(&pPT->a[iPTEDst], 0);
    12241236                }
    12251237# else /* Syncing it here isn't 100% safe and it's probably not worth spending time syncing it. */
     1238                pgmLock(pVM);
    12261239                rc = PGM_BTH_NAME(SyncPage)(pVCpu, PdeSrc, GCPtrPage, 1, 0);
     1240                pgmUnlock(pVM);
    12271241                if (RT_SUCCESS(rc))
    12281242                    rc = VINF_SUCCESS;
     
    16101624    LogFlow(("SyncPage: GCPtrPage=%RGv cPages=%u uErr=%#x\n", GCPtrPage, cPages, uErr));
    16111625
     1626    Assert(PGMIsLockOwner(pVM));
    16121627#if    (   PGM_GST_TYPE == PGM_TYPE_32BIT  \
    16131628        || PGM_GST_TYPE == PGM_TYPE_PAE    \
Note: See TracChangeset for help on using the changeset viewer.

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