VirtualBox

Changeset 37467 in vbox


Ignore:
Timestamp:
Jun 15, 2011 1:08:45 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72281
Message:

IOM: Clean up locking now that all devices has its own CS.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IOMAll.cpp

    r37466 r37467  
    4040
    4141
    42 
    43 /**
    44  * Try take the EMT/IOM lock, wait in ring-3 return VERR_SEM_BUSY in R0/RC.
    45  *
    46  * @retval  VINF_SUCCESS on success (always in ring-3).
    47  * @retval  VERR_SEM_BUSY in RC and R0 if the semaphore is busy.
    48  *
    49  * @param   pVM         VM handle.
    50  */
    51 int iomLock(PVM pVM)
    52 {
    53     Assert(pVM->cCpus == 1 || !PGMIsLockOwner(pVM));
    54     int rc = PDMCritSectEnter(&pVM->iom.s.EmtLock, VERR_SEM_BUSY);
    55     return rc;
    56 }
    57 
    58 
    59 /**
    60  * Try take the EMT/IOM lock, no waiting.
    61  *
    62  * @retval  VINF_SUCCESS on success.
    63  * @retval  VERR_SEM_BUSY if busy.
    64  *
    65  * @param   pVM         VM handle.
    66  */
    67 int iomTryLock(PVM pVM)
    68 {
    69     int rc = PDMCritSectTryEnter(&pVM->iom.s.EmtLock);
    70     return rc;
    71 }
    72 
    73 
    74 /**
    75  * Release EMT/IOM lock.
    76  *
    77  * @param   pVM         VM handle.
    78  */
    79 void iomUnlock(PVM pVM)
    80 {
    81     PDMCritSectLeave(&pVM->iom.s.EmtLock);
    82 }
    83 
    84 
    8542/**
    8643 * Check if this VCPU currently owns the IOM lock.
     
    9148VMMDECL(bool) IOMIsLockOwner(PVM pVM)
    9249{
    93     return PDMCritSectIsOwner(&pVM->iom.s.EmtLock);
     50    return PDMCritSectIsOwner(&pVM->iom.s.CritSect);
    9451}
    9552
     
    266223 *        handle is buggy and doesn't handle all cases. */
    267224    /* Take the IOM lock before performing any device I/O. */
    268     int rc2 = iomLock(pVM);
     225    int rc2 = IOM_LOCK(pVM);
    269226#ifndef IN_RING3
    270227    if (rc2 == VERR_SEM_BUSY)
     
    311268        {
    312269            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
    313             iomUnlock(pVM);
     270            IOM_UNLOCK(pVM);
    314271            return VINF_IOM_HC_IOPORT_READ;
    315272        }
     
    317274        void           *pvUser    = pRange->pvUser;
    318275        PPDMDEVINS      pDevIns   = pRange->pDevIns;
    319         PPDMCRITSECT    pCritSect = pDevIns->CTX_SUFF(pCritSectRo);
    320 
    321         /*
    322          * Call the device - 4 variations.
    323          */
    324         VBOXSTRICTRC    rcStrict;
    325         if (pCritSect)
    326         {
    327             iomUnlock(pVM);
    328             rcStrict = PDMCritSectEnter(pCritSect, VINF_IOM_HC_IOPORT_READ);
    329             if (rcStrict != VINF_SUCCESS)
    330             {
    331                 STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
    332                 return rcStrict;
    333             }
    334 #ifdef VBOX_WITH_STATISTICS
    335             if (pStats)
    336             {
    337                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
    338                 rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
    339                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    340             }
    341             else
    342 #endif
    343                 rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
    344             PDMCritSectLeave(pCritSect);
     276        IOM_UNLOCK(pVM);
     277
     278        /*
     279         * Call the device.
     280         */
     281        VBOXSTRICTRC rcStrict = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_IOPORT_READ);
     282        if (rcStrict != VINF_SUCCESS)
     283        {
     284            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
     285            return rcStrict;
     286        }
     287#ifdef VBOX_WITH_STATISTICS
     288        if (pStats)
     289        {
     290            STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
     291            rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
     292            STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    345293        }
    346294        else
    347         {
    348 #ifdef VBOX_WITH_STATISTICS
    349             if (pStats)
    350             {
    351                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
    352                 rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
    353                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    354             }
    355             else
    356 #endif
    357                 rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
    358         }
     295#endif
     296            rcStrict = pfnInCallback(pDevIns, pvUser, Port, pu32Value, (unsigned)cbValue);
     297        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
     298
    359299#ifdef VBOX_WITH_STATISTICS
    360300        if (rcStrict == VINF_SUCCESS && pStats)
     
    376316                default:
    377317                    AssertMsgFailed(("Invalid I/O port size %d. Port=%d\n", cbValue, Port));
    378                     if (!pCritSect)
    379                         iomUnlock(pVM);
    380318                    return VERR_IOM_INVALID_IOPORT_SIZE;
    381319            }
    382320        }
    383321        Log3(("IOMIOPortRead: Port=%RTiop *pu32=%08RX32 cb=%d rc=%Rrc\n", Port, *pu32Value, cbValue, VBOXSTRICTRC_VAL(rcStrict)));
    384         if (!pCritSect)
    385             iomUnlock(pVM);
    386322        return rcStrict;
    387323    }
     
    398334            STAM_COUNTER_INC(&pStats->InRZToR3);
    399335# endif
    400         iomUnlock(pVM);
     336        IOM_UNLOCK(pVM);
    401337        return VINF_IOM_HC_IOPORT_READ;
    402338    }
     
    413349# ifndef IN_RING3
    414350        /* Ring-3 will have to create the statistics record. */
    415         iomUnlock(pVM);
     351        IOM_UNLOCK(pVM);
    416352        return VINF_IOM_HC_IOPORT_READ;
    417353# else
     
    431367        default:
    432368            AssertMsgFailed(("Invalid I/O port size %d. Port=%d\n", cbValue, Port));
    433             iomUnlock(pVM);
     369            IOM_UNLOCK(pVM);
    434370            return VERR_IOM_INVALID_IOPORT_SIZE;
    435371    }
    436372    Log3(("IOMIOPortRead: Port=%RTiop *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", Port, *pu32Value, cbValue));
    437     iomUnlock(pVM);
     373    IOM_UNLOCK(pVM);
    438374    return VINF_SUCCESS;
    439375}
     
    459395{
    460396    /* Take the IOM lock before performing any device I/O. */
    461     int rc2 = iomLock(pVM);
     397    int rc2 = IOM_LOCK(pVM);
    462398#ifndef IN_RING3
    463399    if (rc2 == VERR_SEM_BUSY)
     
    507443        {
    508444            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
    509             iomUnlock(pVM);
     445            IOM_UNLOCK(pVM);
    510446            return VINF_IOM_HC_IOPORT_READ;
    511447        }
     
    513449        void           *pvUser    = pRange->pvUser;
    514450        PPDMDEVINS      pDevIns   = pRange->pDevIns;
    515         PPDMCRITSECT    pCritSect = pDevIns->CTX_SUFF(pCritSectRo);
    516 
    517         /*
    518          * Call the device - 4 variations.
    519          */
    520         VBOXSTRICTRC    rcStrict;
    521         if (pCritSect)
    522         {
    523             iomUnlock(pVM);
    524             rcStrict = PDMCritSectEnter(pCritSect, VINF_IOM_HC_IOPORT_READ);
    525             if (rcStrict != VINF_SUCCESS)
    526             {
    527                 STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
    528                 return rcStrict;
    529             }
    530 #ifdef VBOX_WITH_STATISTICS
    531             if (pStats)
    532             {
    533                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
    534                 rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
    535                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    536             }
    537             else
    538 #endif
    539                 rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
    540             PDMCritSectLeave(pCritSect);
     451        IOM_UNLOCK(pVM);
     452
     453        /*
     454         * Call the device.
     455         */
     456        VBOXSTRICTRC rcStrict = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_IOPORT_READ);
     457        if (rcStrict != VINF_SUCCESS)
     458        {
     459            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->InRZToR3); });
     460            return rcStrict;
     461        }
     462#ifdef VBOX_WITH_STATISTICS
     463        if (pStats)
     464        {
     465            STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
     466            rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
     467            STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    541468        }
    542469        else
    543         {
    544 #ifdef VBOX_WITH_STATISTICS
    545             if (pStats)
    546             {
    547                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfIn), a);
    548                 rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
    549                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfIn), a);
    550             }
    551             else
    552 #endif
    553                 rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
    554         }
     470#endif
     471            rcStrict = pfnInStrCallback(pDevIns, pvUser, Port, pGCPtrDst, pcTransfers, cb);
     472        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    555473
    556474#ifdef VBOX_WITH_STATISTICS
     
    564482        Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=%Rrc\n",
    565483              Port, pGCPtrDst, pcTransfers, cTransfers, *pcTransfers, cb, VBOXSTRICTRC_VAL(rcStrict)));
    566         if (!pCritSect)
    567             iomUnlock(pVM);
    568484        return rcStrict;
    569485    }
     
    580496            STAM_COUNTER_INC(&pStats->InRZToR3);
    581497# endif
    582         iomUnlock(pVM);
     498        IOM_UNLOCK(pVM);
    583499        return VINF_IOM_HC_IOPORT_READ;
    584500    }
     
    595511# ifndef IN_RING3
    596512        /* Ring-3 will have to create the statistics record. */
    597         iomUnlock(pVM);
     513        IOM_UNLOCK(pVM);
    598514        return VINF_IOM_HC_IOPORT_READ;
    599515# else
     
    607523    Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n",
    608524          Port, pGCPtrDst, pcTransfers, cTransfers, *pcTransfers, cb));
    609     iomUnlock(pVM);
     525    IOM_UNLOCK(pVM);
    610526    return VINF_SUCCESS;
    611527}
     
    630546{
    631547    /* Take the IOM lock before performing any device I/O. */
    632     int rc2 = iomLock(pVM);
     548    int rc2 = IOM_LOCK(pVM);
    633549#ifndef IN_RING3
    634550    if (rc2 == VERR_SEM_BUSY)
     
    677593        {
    678594            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
    679             iomUnlock(pVM);
     595            IOM_UNLOCK(pVM);
    680596            return VINF_IOM_HC_IOPORT_WRITE;
    681597        }
     
    683599        void           *pvUser    = pRange->pvUser;
    684600        PPDMDEVINS      pDevIns   = pRange->pDevIns;
    685         PPDMCRITSECT    pCritSect = pDevIns->CTX_SUFF(pCritSectRo);
    686 
    687         /*
    688          * Call the device - 4 variations.
    689          */
    690         VBOXSTRICTRC    rcStrict;
    691         if (pCritSect)
    692         {
    693             iomUnlock(pVM);
    694             rcStrict = PDMCritSectEnter(pCritSect, VINF_IOM_HC_IOPORT_WRITE);
    695             if (rcStrict != VINF_SUCCESS)
    696             {
    697                 STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
    698                 return rcStrict;
    699             }
    700 #ifdef VBOX_WITH_STATISTICS
    701             if (pStats)
    702             {
    703                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
    704                 rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
    705                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    706             }
    707             else
    708 #endif
    709                 rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
    710             PDMCritSectLeave(pCritSect);
     601        IOM_UNLOCK(pVM);
     602
     603        /*
     604         * Call the device.
     605         */
     606        VBOXSTRICTRC rcStrict = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_IOPORT_WRITE);
     607        if (rcStrict != VINF_SUCCESS)
     608        {
     609            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
     610            return rcStrict;
     611        }
     612#ifdef VBOX_WITH_STATISTICS
     613        if (pStats)
     614        {
     615            STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
     616            rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
     617            STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    711618        }
    712619        else
    713         {
    714 #ifdef VBOX_WITH_STATISTICS
    715             if (pStats)
    716             {
    717                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
    718                 rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
    719                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    720             }
    721             else
    722 #endif
    723                 rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
    724         }
     620#endif
     621            rcStrict = pfnOutCallback(pDevIns, pvUser, Port, u32Value, (unsigned)cbValue);
     622        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    725623
    726624#ifdef VBOX_WITH_STATISTICS
     
    733631#endif
    734632        Log3(("IOMIOPortWrite: Port=%RTiop u32=%08RX32 cb=%d rc=%Rrc\n", Port, u32Value, cbValue, VBOXSTRICTRC_VAL(rcStrict)));
    735         if (!pCritSect)
    736             iomUnlock(pVM);
    737633        return rcStrict;
    738634    }
     
    749645            STAM_COUNTER_INC(&pStats->OutRZToR3);
    750646# endif
    751         iomUnlock(pVM);
     647        IOM_UNLOCK(pVM);
    752648        return VINF_IOM_HC_IOPORT_WRITE;
    753649    }
     
    765661# ifndef IN_RING3
    766662        /* R3 will have to create the statistics record. */
    767         iomUnlock(pVM);
     663        IOM_UNLOCK(pVM);
    768664        return VINF_IOM_HC_IOPORT_WRITE;
    769665# else
     
    775671#endif
    776672    Log3(("IOMIOPortWrite: Port=%RTiop u32=%08RX32 cb=%d nop\n", Port, u32Value, cbValue));
    777     iomUnlock(pVM);
     673    IOM_UNLOCK(pVM);
    778674    return VINF_SUCCESS;
    779675}
     
    799695{
    800696    /* Take the IOM lock before performing any device I/O. */
    801     int rc2 = iomLock(pVM);
     697    int rc2 = IOM_LOCK(pVM);
    802698#ifndef IN_RING3
    803699    if (rc2 == VERR_SEM_BUSY)
     
    847743        {
    848744            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
    849             iomUnlock(pVM);
     745            IOM_UNLOCK(pVM);
    850746            return VINF_IOM_HC_IOPORT_WRITE;
    851747        }
     
    853749        void           *pvUser    = pRange->pvUser;
    854750        PPDMDEVINS      pDevIns   = pRange->pDevIns;
    855         PPDMCRITSECT    pCritSect = pDevIns->CTX_SUFF(pCritSectRo);
    856 
    857         /*
    858          * Call the device - 4 variations.
    859          */
    860         VBOXSTRICTRC    rcStrict;
    861         if (pCritSect)
    862         {
    863             iomUnlock(pVM);
    864             rcStrict = PDMCritSectEnter(pCritSect, VINF_IOM_HC_IOPORT_WRITE);
    865             if (rcStrict != VINF_SUCCESS)
    866             {
    867                 STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
    868                 return rcStrict;
    869             }
    870 #ifdef VBOX_WITH_STATISTICS
    871             if (pStats)
    872             {
    873                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
    874                 rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
    875                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    876             }
    877             else
    878 #endif
    879                 rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
    880             PDMCritSectLeave(pCritSect);
     751        IOM_UNLOCK(pVM);
     752
     753        /*
     754         * Call the device.
     755         */
     756        VBOXSTRICTRC rcStrict = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_IOPORT_WRITE);
     757        if (rcStrict != VINF_SUCCESS)
     758        {
     759            STAM_STATS({ if (pStats) STAM_COUNTER_INC(&pStats->OutRZToR3); });
     760            return rcStrict;
     761        }
     762#ifdef VBOX_WITH_STATISTICS
     763        if (pStats)
     764        {
     765            STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
     766            rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
     767            STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    881768        }
    882769        else
    883         {
    884 #ifdef VBOX_WITH_STATISTICS
    885             if (pStats)
    886             {
    887                 STAM_PROFILE_START(&pStats->CTX_SUFF_Z(ProfOut), a);
    888                 rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
    889                 STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfOut), a);
    890             }
    891             else
    892 #endif
    893                 rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
    894         }
     770#endif
     771            rcStrict = pfnOutStrCallback(pDevIns, pvUser, Port, pGCPtrSrc, pcTransfers, cb);
     772        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    895773
    896774#ifdef VBOX_WITH_STATISTICS
     
    904782        Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rcStrict=%Rrc\n",
    905783              Port, pGCPtrSrc, pcTransfers, cTransfers, *pcTransfers, cb, VBOXSTRICTRC_VAL(rcStrict)));
    906         if (!pCritSect)
    907             iomUnlock(pVM);
    908784        return rcStrict;
    909785    }
     
    920796            STAM_COUNTER_INC(&pStats->OutRZToR3);
    921797# endif
    922         iomUnlock(pVM);
     798        IOM_UNLOCK(pVM);
    923799        return VINF_IOM_HC_IOPORT_WRITE;
    924800    }
     
    935811# ifndef IN_RING3
    936812        /* Ring-3 will have to create the statistics record. */
    937         iomUnlock(pVM);
     813        IOM_UNLOCK(pVM);
    938814        return VINF_IOM_HC_IOPORT_WRITE;
    939815# else
     
    947823    Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n",
    948824          Port, pGCPtrSrc, pcTransfers, cTransfers, *pcTransfers, cb));
    949     iomUnlock(pVM);
     825    IOM_UNLOCK(pVM);
    950826    return VINF_SUCCESS;
    951827}
  • trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp

    r37466 r37467  
    10701070{
    10711071    /* Take the IOM lock before performing any MMIO. */
    1072     int rc = iomLock(pVM);
     1072    int rc = IOM_LOCK(pVM);
    10731073#ifndef IN_RING3
    10741074    if (rc == VERR_SEM_BUSY)
     
    10931093    {
    10941094# ifdef IN_RING3
    1095         iomUnlock(pVM);
     1095        IOM_UNLOCK(pVM);
    10961096        return VERR_NO_MEMORY;
    10971097# else
    10981098        STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
    10991099        STAM_COUNTER_INC(&pVM->iom.s.StatRZMMIOFailures);
    1100         iomUnlock(pVM);
     1100        IOM_UNLOCK(pVM);
    11011101        return VINF_IOM_HC_MMIO_READ_WRITE;
    11021102# endif
     
    11271127        STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
    11281128        STAM_COUNTER_INC(&pVM->iom.s.StatRZMMIOFailures);
    1129         iomUnlock(pVM);
     1129        IOM_UNLOCK(pVM);
    11301130        return VINF_IOM_HC_MMIO_READ_WRITE;
    11311131    }
     
    11371137    iomMmioRetainRange(pRange);
    11381138    PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns);
    1139     PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo);
    1140     if (!pLock)
    1141         pLock = &pVM->iom.s.EmtLock;
    1142     else
    1143     {
    1144         iomUnlock(pVM);
    1145         rc = PDMCritSectEnter(pLock, VINF_IOM_HC_MMIO_READ_WRITE);
    1146         if (rc != VINF_SUCCESS)
    1147         {
    1148             iomMmioReleaseRange(pVM, pRange);
    1149             return rc;
    1150         }
     1139    IOM_UNLOCK(pVM);
     1140    rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_MMIO_READ_WRITE);
     1141    if (rc != VINF_SUCCESS)
     1142    {
     1143        iomMmioReleaseRange(pVM, pRange);
     1144        return rc;
    11511145    }
    11521146
     
    11621156    {
    11631157        iomMmioReleaseRange(pVM, pRange);
    1164         PDMCritSectLeave(pLock);
     1158        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    11651159        return rc;
    11661160    }
     
    12961290    STAM_PROFILE_STOP(&pVM->iom.s.StatRZMMIOHandler, a);
    12971291    iomMmioReleaseRange(pVM, pRange);
    1298     PDMCritSectLeave(pLock);
     1292    PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    12991293    return rc;
    13001294}
     
    13301324VMMDECL(VBOXSTRICTRC) IOMMMIOPhysHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPHYS GCPhysFault)
    13311325{
    1332     int rc2 = iomLock(pVM);
     1326    int rc2 = IOM_LOCK(pVM);
    13331327#ifndef IN_RING3
    13341328    if (rc2 == VERR_SEM_BUSY)
     
    13361330#endif
    13371331    VBOXSTRICTRC rcStrict = iomMMIOHandler(pVM, (uint32_t)uErrorCode, pCtxCore, GCPhysFault, iomMmioGetRange(pVM, GCPhysFault));
    1338     iomUnlock(pVM);
     1332    IOM_UNLOCK(pVM);
    13391333    return VBOXSTRICTRC_VAL(rcStrict);
    13401334}
     
    13671361     * Validate the range.
    13681362     */
    1369     int rc = iomLock(pVM);
     1363    int rc = IOM_LOCK(pVM);
    13701364    AssertRC(rc);
    13711365    Assert(pRange == iomMmioGetRange(pVM, GCPhysFault));
     
    13761370    iomMmioRetainRange(pRange);
    13771371    PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns);
    1378     PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo);
    1379     if (!pLock)
    1380         pLock = &pVM->iom.s.EmtLock;
    1381     else
    1382     {
    1383         iomUnlock(pVM);
    1384         rc = PDMCritSectEnter(pLock, VINF_IOM_HC_MMIO_READ_WRITE);
    1385         if (rc != VINF_SUCCESS)
    1386         {
    1387             iomMmioReleaseRange(pVM, pRange);
    1388             return rc;
    1389         }
     1372    IOM_UNLOCK(pVM);
     1373    rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_MMIO_READ_WRITE);
     1374    if (rc != VINF_SUCCESS)
     1375    {
     1376        iomMmioReleaseRange(pVM, pRange);
     1377        return rc;
    13901378    }
    13911379
     
    14001388    AssertRC(rc);
    14011389    iomMmioReleaseRange(pVM, pRange);
    1402     PDMCritSectLeave(pLock);
     1390    PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    14031391    return rc;
    14041392}
     
    14191407{
    14201408    /* Take the IOM lock before performing any MMIO. */
    1421     int rc = iomLock(pVM);
     1409    int rc = IOM_LOCK(pVM);
    14221410#ifndef IN_RING3
    14231411    if (rc == VERR_SEM_BUSY)
     
    14361424    if (!pRange)
    14371425    {
    1438         iomUnlock(pVM);
     1426        IOM_UNLOCK(pVM);
    14391427        return VERR_INTERNAL_ERROR;
    14401428    }
     
    14431431    if (!pStats)
    14441432    {
    1445         iomUnlock(pVM);
     1433        IOM_UNLOCK(pVM);
    14461434# ifdef IN_RING3
    14471435        return VERR_NO_MEMORY;
     
    14601448        iomMmioRetainRange(pRange);
    14611449        PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns);
    1462         PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo);
    1463         if (!pLock)
    1464             pLock = &pVM->iom.s.EmtLock;
    1465         else
     1450        IOM_UNLOCK(pVM);
     1451        rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_MMIO_WRITE);
     1452        if (rc != VINF_SUCCESS)
    14661453        {
    1467             iomUnlock(pVM);
    1468             rc = PDMCritSectEnter(pLock, VINF_IOM_HC_MMIO_WRITE);
    1469             if (rc != VINF_SUCCESS)
    1470             {
    1471                 iomMmioReleaseRange(pVM, pRange);
    1472                 return rc;
    1473             }
     1454            iomMmioReleaseRange(pVM, pRange);
     1455            return rc;
    14741456        }
    14751457
     
    14851467                Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
    14861468                iomMmioReleaseRange(pVM, pRange);
    1487                 PDMCritSectLeave(pLock);
     1469                PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    14881470                return rc;
    14891471#ifndef IN_RING3
     
    14951477                Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
    14961478                iomMmioReleaseRange(pVM, pRange);
    1497                 PDMCritSectLeave(pLock);
     1479                PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    14981480                return rc;
    14991481
     
    15011483                switch (cbValue)
    15021484                {
    1503                     case 1: *(uint8_t *)pu32Value = UINT8_C(0x00); break;
     1485                    case 1: *(uint8_t  *)pu32Value = UINT8_C(0x00); break;
    15041486                    case 2: *(uint16_t *)pu32Value = UINT16_C(0x0000); break;
    15051487                    case 4: *(uint32_t *)pu32Value = UINT32_C(0x00000000); break;
     
    15091491                Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
    15101492                iomMmioReleaseRange(pVM, pRange);
    1511                 PDMCritSectLeave(pLock);
     1493                PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    15121494                return VINF_SUCCESS;
    15131495
     
    15151497                switch (cbValue)
    15161498                {
    1517                     case 1: *(uint8_t *)pu32Value = UINT8_C(0xff); break;
     1499                    case 1: *(uint8_t  *)pu32Value = UINT8_C(0xff); break;
    15181500                    case 2: *(uint16_t *)pu32Value = UINT16_C(0xffff); break;
    15191501                    case 4: *(uint32_t *)pu32Value = UINT32_C(0xffffffff); break;
     
    15231505                Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, *pu32Value, cbValue, rc));
    15241506                iomMmioReleaseRange(pVM, pRange);
    1525                 PDMCritSectLeave(pLock);
     1507                PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    15261508                return VINF_SUCCESS;
    15271509        }
     
    15321514    {
    15331515        STAM_COUNTER_INC(&pStats->CTX_MID_Z(Read,ToR3));
    1534         iomUnlock(pVM);
     1516        IOM_UNLOCK(pVM);
    15351517        return VINF_IOM_HC_MMIO_READ;
    15361518    }
     
    15511533    }
    15521534    Log4(("IOMMMIORead: GCPhys=%RGp *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", GCPhys, *pu32Value, cbValue));
    1553     iomUnlock(pVM);
     1535    IOM_UNLOCK(pVM);
    15541536    return VINF_SUCCESS;
    15551537}
     
    15691551{
    15701552    /* Take the IOM lock before performing any MMIO. */
    1571     int rc = iomLock(pVM);
     1553    int rc = IOM_LOCK(pVM);
    15721554#ifndef IN_RING3
    15731555    if (rc == VERR_SEM_BUSY)
     
    15861568    if (!pRange)
    15871569    {
    1588         iomUnlock(pVM);
     1570        IOM_UNLOCK(pVM);
    15891571        return VERR_INTERNAL_ERROR;
    15901572    }
     
    15931575    if (!pStats)
    15941576    {
    1595         iomUnlock(pVM);
     1577        IOM_UNLOCK(pVM);
    15961578# ifdef IN_RING3
    15971579        return VERR_NO_MEMORY;
     
    16101592        iomMmioRetainRange(pRange);
    16111593        PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns);
    1612         PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo);
    1613         if (!pLock)
    1614             pLock = &pVM->iom.s.EmtLock;
    1615         else
     1594        IOM_UNLOCK(pVM);
     1595        rc = PDMCritSectEnter(pDevIns->CTX_SUFF(pCritSectRo), VINF_IOM_HC_MMIO_READ);
     1596        if (rc != VINF_SUCCESS)
    16161597        {
    1617             iomUnlock(pVM);
    1618             rc = PDMCritSectEnter(pLock, VINF_IOM_HC_MMIO_READ);
    1619             if (rc != VINF_SUCCESS)
    1620             {
    1621                 iomMmioReleaseRange(pVM, pRange);
    1622                 return rc;
    1623             }
     1598            iomMmioReleaseRange(pVM, pRange);
     1599            return rc;
    16241600        }
    16251601
     
    16381614        Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, rc));
    16391615        iomMmioReleaseRange(pVM, pRange);
    1640         PDMCritSectLeave(pLock);
     1616        PDMCritSectLeave(pDevIns->CTX_SUFF(pCritSectRo));
    16411617        return rc;
    16421618    }
     
    16451621    {
    16461622        STAM_COUNTER_INC(&pStats->CTX_MID_Z(Write,ToR3));
    1647         iomUnlock(pVM);
     1623        IOM_UNLOCK(pVM);
    16481624        return VINF_IOM_HC_MMIO_WRITE;
    16491625    }
     
    16561632    STAM_PROFILE_STOP(&pStats->CTX_SUFF_Z(ProfWrite), a);
    16571633    Log4(("IOMMMIOWrite: GCPhys=%RGp u32=%08RX32 cb=%d rc=%Rrc\n", GCPhys, u32Value, cbValue, VINF_SUCCESS));
    1658     iomUnlock(pVM);
     1634    IOM_UNLOCK(pVM);
    16591635    return VINF_SUCCESS;
    16601636}
     1637
    16611638
    16621639/**
     
    20151992        return VINF_SUCCESS;    /* ignore */
    20161993
    2017     PDMCritSectEnter(&pVM->iom.s.EmtLock, VINF_SUCCESS);
     1994    IOM_LOCK(pVM);
    20181995
    20191996    /*
     
    20352012    int rc = PGMHandlerPhysicalPageAlias(pVM, pRange->GCPhys, GCPhys, GCPhysRemapped);
    20362013
    2037     PDMCritSectLeave(&pVM->iom.s.EmtLock);
     2014    IOM_UNLOCK(pVM);
    20382015    AssertRCReturn(rc, rc);
    20392016
  • trunk/src/VBox/VMM/VMMR3/IOM.cpp

    r37466 r37467  
    149149    AssertCompileMemberAlignment(VM, iom.s, 32);
    150150    AssertCompile(sizeof(pVM->iom.s) <= sizeof(pVM->iom.padding));
    151     AssertCompileMemberAlignment(IOM, EmtLock, sizeof(uintptr_t));
     151    AssertCompileMemberAlignment(IOM, CritSect, sizeof(uintptr_t));
    152152
    153153    /*
     
    159159     * Initialize the REM critical section.
    160160     */
    161     int rc = PDMR3CritSectInit(pVM, &pVM->iom.s.EmtLock, RT_SRC_POS, "IOM Lock");
     161    int rc = PDMR3CritSectInit(pVM, &pVM->iom.s.CritSect, RT_SRC_POS, "IOM Lock");
    162162    AssertRCReturn(rc, rc);
    163163
     
    227227static void iomR3FlushCache(PVM pVM)
    228228{
    229     iomLock(pVM);
     229    IOM_LOCK(pVM);
     230
    230231    /*
    231232     * Caching of port and statistics (saves some time in rep outs/ins instruction emulation)
     
    252253    pVM->iom.s.pMMIOStatsLastRC  = NIL_RTRCPTR;
    253254
    254     iomUnlock(pVM);
     255    IOM_UNLOCK(pVM);
    255256}
    256257
     
    562563         * Try Insert it.
    563564         */
    564         iomLock(pVM);
     565        IOM_LOCK(pVM);
    565566        if (RTAvlroIOPortInsert(&pVM->iom.s.pTreesR3->IOPortTreeR3, &pRange->Core))
    566567        {
    567             #ifdef VBOX_WITH_STATISTICS
     568#ifdef VBOX_WITH_STATISTICS
    568569            for (unsigned iPort = 0; iPort < cPorts; iPort++)
    569570                iomR3IOPortStatsCreate(pVM, PortStart + iPort, pszDesc);
    570             #endif
    571             iomUnlock(pVM);
     571#endif
     572            IOM_UNLOCK(pVM);
    572573            return VINF_SUCCESS;
    573574        }
    574         iomUnlock(pVM);
     575        IOM_UNLOCK(pVM);
    575576
    576577        /* conflict. */
     
    628629    }
    629630
    630     iomLock(pVM);
     631    IOM_LOCK(pVM);
    631632
    632633    /*
     
    640641        {
    641642            AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
    642             iomUnlock(pVM);
     643            IOM_UNLOCK(pVM);
    643644            return VERR_IOM_NO_HC_IOPORT_RANGE;
    644645        }
     
    651652        {
    652653            AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
    653             iomUnlock(pVM);
     654            IOM_UNLOCK(pVM);
    654655            return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
    655656        }
     
    685686        if (RTAvlroIOPortInsert(&pVM->iom.s.CTX_SUFF(pTrees)->IOPortTreeRC, &pRange->Core))
    686687        {
    687             iomUnlock(pVM);
     688            IOM_UNLOCK(pVM);
    688689            return VINF_SUCCESS;
    689690        }
     
    694695        rc = VERR_IOM_IOPORT_RANGE_CONFLICT;
    695696    }
    696     iomUnlock(pVM);
     697    IOM_UNLOCK(pVM);
    697698    return rc;
    698699}
     
    743744    }
    744745
    745     iomLock(pVM);
     746    IOM_LOCK(pVM);
    746747    /*
    747748     * Validate that there are ring-3 ranges for the ports.
     
    754755        {
    755756            AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
    756             iomUnlock(pVM);
     757            IOM_UNLOCK(pVM);
    757758            return VERR_IOM_NO_HC_IOPORT_RANGE;
    758759        }
     
    765766        {
    766767            AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
    767             iomUnlock(pVM);
     768            IOM_UNLOCK(pVM);
    768769            return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
    769770        }
     
    799800        if (RTAvlroIOPortInsert(&pVM->iom.s.CTX_SUFF(pTrees)->IOPortTreeR0, &pRange->Core))
    800801        {
    801             iomUnlock(pVM);
     802            IOM_UNLOCK(pVM);
    802803            return VINF_SUCCESS;
    803804        }
     
    808809        rc = VERR_IOM_IOPORT_RANGE_CONFLICT;
    809810    }
    810     iomUnlock(pVM);
     811    IOM_UNLOCK(pVM);
    811812    return rc;
    812813}
     
    846847    }
    847848
    848     iomLock(pVM);
     849    IOM_LOCK(pVM);
    849850
    850851    /* Flush the IO port lookup cache */
     
    867868                AssertMsgFailed(("Removal of ports in range %#x-%#x rejected because not owner of %#x-%#x (%s)\n",
    868869                                 PortStart, PortLast, pRange->Core.Key, pRange->Core.KeyLast, pRange->pszDesc));
    869                 iomUnlock(pVM);
     870                IOM_UNLOCK(pVM);
    870871                return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
    871872            }
     
    931932                if (RT_FAILURE(rc2))
    932933                {
    933                     iomUnlock(pVM);
     934                    IOM_UNLOCK(pVM);
    934935                    return rc2;
    935936                }
     
    10141015                if (RT_FAILURE(rc2))
    10151016                {
    1016                     iomUnlock(pVM);
     1017                    IOM_UNLOCK(pVM);
    10171018                    return rc2;
    10181019                }
     
    10961097                if (RT_FAILURE(rc2))
    10971098                {
    1098                     iomUnlock(pVM);
     1099                    IOM_UNLOCK(pVM);
    10991100                    return rc2;
    11001101                }
     
    11251126
    11261127    /* done */
    1127     iomUnlock(pVM);
     1128    IOM_UNLOCK(pVM);
    11281129    return rc;
    11291130}
     
    14711472         * Try register it with PGM and then insert it into the tree.
    14721473         */
    1473         iomLock(pVM);
     1474        IOM_LOCK(pVM);
    14741475        iomR3FlushCache(pVM);
    14751476        rc = PGMR3PhysMMIORegister(pVM, GCPhysStart, cbRange,
     
    14811482            if (RTAvlroGCPhysInsert(&pVM->iom.s.pTreesR3->MMIOTree, &pRange->Core))
    14821483            {
    1483                 iomUnlock(pVM);
     1484                IOM_UNLOCK(pVM);
    14841485                return VINF_SUCCESS;
    14851486            }
    14861487
    14871488            /* bail out */
    1488             iomUnlock(pVM);
     1489            IOM_UNLOCK(pVM);
    14891490            DBGFR3Info(pVM, "mmio", NULL, NULL);
    14901491            AssertMsgFailed(("This cannot happen!\n"));
     
    14921493        }
    14931494        else
    1494             iomUnlock(pVM);
     1495            IOM_UNLOCK(pVM);
    14951496
    14961497        MMHyperFree(pVM, pRange);
     
    15401541     * Find the MMIO range and check that the input matches.
    15411542     */
    1542     iomLock(pVM);
     1543    IOM_LOCK(pVM);
    15431544    PIOMMMIORANGE pRange = iomMmioGetRange(pVM, GCPhysStart);
    1544     AssertReturnStmt(pRange, iomUnlock(pVM), VERR_IOM_MMIO_RANGE_NOT_FOUND);
    1545     AssertReturnStmt(pRange->pDevInsR3 == pDevIns, iomUnlock(pVM), VERR_IOM_NOT_MMIO_RANGE_OWNER);
    1546     AssertReturnStmt(pRange->GCPhys == GCPhysStart, iomUnlock(pVM), VERR_IOM_INVALID_MMIO_RANGE);
    1547     AssertReturnStmt(pRange->cb == cbRange, iomUnlock(pVM), VERR_IOM_INVALID_MMIO_RANGE);
     1545    AssertReturnStmt(pRange, IOM_UNLOCK(pVM), VERR_IOM_MMIO_RANGE_NOT_FOUND);
     1546    AssertReturnStmt(pRange->pDevInsR3 == pDevIns, IOM_UNLOCK(pVM), VERR_IOM_NOT_MMIO_RANGE_OWNER);
     1547    AssertReturnStmt(pRange->GCPhys == GCPhysStart, IOM_UNLOCK(pVM), VERR_IOM_INVALID_MMIO_RANGE);
     1548    AssertReturnStmt(pRange->cb == cbRange, IOM_UNLOCK(pVM), VERR_IOM_INVALID_MMIO_RANGE);
    15481549
    15491550    pRange->pvUserRC          = pvUser;
     
    15521553    pRange->pfnFillCallbackRC = pfnFillCallback;
    15531554    pRange->pDevInsRC         = MMHyperCCToRC(pVM, pDevIns);
    1554     iomUnlock(pVM);
     1555    IOM_UNLOCK(pVM);
    15551556
    15561557    return VINF_SUCCESS;
     
    15971598     * Find the MMIO range and check that the input matches.
    15981599     */
    1599     iomLock(pVM);
     1600    IOM_LOCK(pVM);
    16001601    PIOMMMIORANGE pRange = iomMmioGetRange(pVM, GCPhysStart);
    1601     AssertReturnStmt(pRange, iomUnlock(pVM), VERR_IOM_MMIO_RANGE_NOT_FOUND);
    1602     AssertReturnStmt(pRange->pDevInsR3 == pDevIns, iomUnlock(pVM), VERR_IOM_NOT_MMIO_RANGE_OWNER);
    1603     AssertReturnStmt(pRange->GCPhys == GCPhysStart, iomUnlock(pVM), VERR_IOM_INVALID_MMIO_RANGE);
    1604     AssertReturnStmt(pRange->cb == cbRange, iomUnlock(pVM), VERR_IOM_INVALID_MMIO_RANGE);
     1602    AssertReturnStmt(pRange, IOM_UNLOCK(pVM), VERR_IOM_MMIO_RANGE_NOT_FOUND);
     1603    AssertReturnStmt(pRange->pDevInsR3 == pDevIns, IOM_UNLOCK(pVM), VERR_IOM_NOT_MMIO_RANGE_OWNER);
     1604    AssertReturnStmt(pRange->GCPhys == GCPhysStart, IOM_UNLOCK(pVM), VERR_IOM_INVALID_MMIO_RANGE);
     1605    AssertReturnStmt(pRange->cb == cbRange, IOM_UNLOCK(pVM), VERR_IOM_INVALID_MMIO_RANGE);
    16051606
    16061607    pRange->pvUserR0          = pvUser;
     
    16091610    pRange->pfnFillCallbackR0 = pfnFillCallback;
    16101611    pRange->pDevInsR0         = MMHyperCCToR0(pVM, pDevIns);
    1611     iomUnlock(pVM);
     1612    IOM_UNLOCK(pVM);
    16121613
    16131614    return VINF_SUCCESS;
     
    16441645    }
    16451646
    1646     iomLock(pVM);
     1647    IOM_LOCK(pVM);
    16471648
    16481649    /*
     
    16551656        if (!pRange)
    16561657        {
    1657             iomUnlock(pVM);
     1658            IOM_UNLOCK(pVM);
    16581659            return VERR_IOM_MMIO_RANGE_NOT_FOUND;
    16591660        }
    16601661        AssertMsgReturnStmt(pRange->pDevInsR3 == pDevIns,
    16611662                            ("Not owner! GCPhys=%RGp %RGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pRange->pszDesc),
    1662                             iomUnlock(pVM),
     1663                            IOM_UNLOCK(pVM),
    16631664                            VERR_IOM_NOT_MMIO_RANGE_OWNER);
    16641665        AssertMsgReturnStmt(pRange->Core.KeyLast <= GCPhysLast,
    16651666                            ("Incomplete R3 range! GCPhys=%RGp %RGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pRange->pszDesc),
    1666                             iomUnlock(pVM),
     1667                            IOM_UNLOCK(pVM),
    16671668                            VERR_IOM_INCOMPLETE_MMIO_RANGE);
    16681669
     
    16831684        Assert(pRange);
    16841685        Assert(pRange->Core.Key == GCPhys && pRange->Core.KeyLast <= GCPhysLast);
    1685         iomUnlock(pVM); /** @todo r=bird: Why are we leving the lock here? We don't leave it when registering the range above... */
     1686        IOM_UNLOCK(pVM); /** @todo r=bird: Why are we leaving the lock here? We don't leave it when registering the range above... */
    16861687
    16871688        /* remove it from PGM */
     
    16891690        AssertRC(rc);
    16901691
    1691         iomLock(pVM);
     1692        IOM_LOCK(pVM);
    16921693
    16931694        /* advance and free. */
     
    17011702    }
    17021703
    1703     iomUnlock(pVM);
     1704    IOM_UNLOCK(pVM);
    17041705    return VINF_SUCCESS;
    17051706}
  • trunk/src/VBox/VMM/include/IOMInline.h

    r37452 r37467  
    3535DECLINLINE(CTX_SUFF(PIOMIOPORTRANGE)) iomIOPortGetRange(PVM pVM, RTIOPORT Port)
    3636{
    37     Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock) || !PDMCritSectIsInitialized(&pVM->iom.s.EmtLock));
     37    Assert(PDMCritSectIsOwner(&pVM->iom.s.CritSect));
    3838    return (CTX_SUFF(PIOMIOPORTRANGE))RTAvlroIOPortRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->CTX_SUFF(IOPortTree), Port);
    3939}
     
    5151DECLINLINE(PIOMIOPORTRANGER3) iomIOPortGetRangeR3(PVM pVM, RTIOPORT Port)
    5252{
    53     Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock) || !PDMCritSectIsInitialized(&pVM->iom.s.EmtLock));
     53    Assert(PDMCritSectIsOwner(&pVM->iom.s.CritSect));
    5454    return (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->IOPortTreeR3, Port);
    5555}
     
    6767DECLINLINE(PIOMMMIORANGE) iomMmioGetRange(PVM pVM, RTGCPHYS GCPhys)
    6868{
    69     Assert(PDMCritSectIsOwner(&pVM->iom.s.EmtLock));
     69    Assert(PDMCritSectIsOwner(&pVM->iom.s.CritSect));
    7070    PIOMMMIORANGE pRange = pVM->iom.s.CTX_SUFF(pMMIORangeLast);
    7171    if (    !pRange
     
    101101DECLINLINE(PIOMMMIORANGE) iomMmioGetRangeWithRef(PVM pVM, RTGCPHYS GCPhys)
    102102{
    103     int rc = PDMCritSectEnter(&pVM->iom.s.EmtLock, VINF_SUCCESS);
     103    int rc = PDMCritSectEnter(&pVM->iom.s.CritSect, VINF_SUCCESS);
    104104    AssertRCReturn(rc, NULL);
    105105
     
    112112        iomMmioRetainRange(pRange);
    113113
    114     PDMCritSectLeave(&pVM->iom.s.EmtLock);
     114    PDMCritSectLeave(&pVM->iom.s.CritSect);
    115115    return pRange;
    116116}
     
    169169DECLINLINE(PIOMMMIOSTATS) iomMmioGetStats(PVM pVM, RTGCPHYS GCPhys, PIOMMMIORANGE pRange)
    170170{
    171     PDMCritSectEnter(&pVM->iom.s.EmtLock, VINF_SUCCESS);
     171    PDMCritSectEnter(&pVM->iom.s.CritSect, VINF_SUCCESS);
    172172
    173173    /* For large ranges, we'll put everything on the first byte. */
     
    186186    }
    187187
    188     PDMCritSectLeave(&pVM->iom.s.EmtLock);
     188    PDMCritSectLeave(&pVM->iom.s.CritSect);
    189189    return pStats;
    190190}
  • trunk/src/VBox/VMM/include/IOMInternal.h

    r37452 r37467  
    323323
    324324    /** Lock serializing EMT access to IOM. */
    325     PDMCRITSECT                     EmtLock;
     325    PDMCRITSECT                     CritSect;
    326326
    327327    /** @name Caching of I/O Port and MMIO ranges and statistics.
     
    433433
    434434/* IOM locking helpers. */
    435 int     iomLock(PVM pVM);
    436 int     iomTryLock(PVM pVM);
    437 void    iomUnlock(PVM pVM);
     435#define IOM_LOCK(a_pVM)     PDMCritSectEnter(&(a_pVM)->iom.s.CritSect, VERR_SEM_BUSY)
     436#define IOM_UNLOCK(a_pVM)   do { PDMCritSectLeave(&(a_pVM)->iom.s.CritSect); } while (0)
     437
    438438
    439439/* Disassembly helpers used in IOMAll.cpp & IOMAllMMIO.cpp */
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r37354 r37467  
    378378#endif
    379379
    380     CHECK_MEMBER_ALIGNMENT(IOM, EmtLock, sizeof(uintptr_t));
     380    CHECK_MEMBER_ALIGNMENT(IOM, CritSect, sizeof(uintptr_t));
    381381    CHECK_MEMBER_ALIGNMENT(EM, CritSectREM, sizeof(uintptr_t));
    382382    CHECK_MEMBER_ALIGNMENT(PGM, CritSect, sizeof(uintptr_t));
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