VirtualBox

Changeset 77241 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Feb 10, 2019 10:30:33 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128748
Message:

VMM: Added dev helps for bulk page mapping locking. VMMDev will be using this for a new variation on the HGCM page list parameter type. bugref:9172

File:
1 edited

Legend:

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

    r76553 r77241  
    21262126#endif /* IN_RING3 */
    21272127}
     2128
     2129
     2130#ifdef IN_RING3
     2131/**
     2132 * Release the mapping of multiple guest pages.
     2133 *
     2134 * This is the counter part to PGMR3PhysBulkGCPhys2CCPtrExternal() and
     2135 * PGMR3PhysBulkGCPhys2CCPtrReadOnlyExternal().
     2136 *
     2137 * @param   pVM         The cross context VM structure.
     2138 * @param   cPages      Number of pages to unlock.
     2139 * @param   paLocks     Array of locks lock structure initialized by the mapping
     2140 *                      function.
     2141 */
     2142VMMDECL(void) PGMPhysBulkReleasePageMappingLocks(PVM pVM, uint32_t cPages, PPGMPAGEMAPLOCK paLocks)
     2143{
     2144    Assert(cPages > 0);
     2145    bool const fWriteLock = (paLocks[0].uPageAndType & PGMPAGEMAPLOCK_TYPE_MASK) == PGMPAGEMAPLOCK_TYPE_WRITE;
     2146#ifdef VBOX_STRICT
     2147    for (uint32_t i = 1; i < cPages; i++)
     2148    {
     2149        Assert(fWriteLock == ((paLocks[i].uPageAndType & PGMPAGEMAPLOCK_TYPE_MASK) == PGMPAGEMAPLOCK_TYPE_WRITE));
     2150        AssertPtr(paLocks[i].uPageAndType);
     2151    }
     2152#endif
     2153
     2154    pgmLock(pVM);
     2155    if (fWriteLock)
     2156    {
     2157        /*
     2158         * Write locks:
     2159         */
     2160        for (uint32_t i = 0; i < cPages; i++)
     2161        {
     2162            PPGMPAGE pPage  = (PPGMPAGE)(paLocks[i].uPageAndType & ~PGMPAGEMAPLOCK_TYPE_MASK);
     2163            unsigned cLocks = PGM_PAGE_GET_WRITE_LOCKS(pPage);
     2164            Assert(cLocks > 0);
     2165            if (RT_LIKELY(cLocks > 0 && cLocks < PGM_PAGE_MAX_LOCKS))
     2166            {
     2167                if (cLocks == 1)
     2168                {
     2169                    Assert(pVM->pgm.s.cWriteLockedPages > 0);
     2170                    pVM->pgm.s.cWriteLockedPages--;
     2171                }
     2172                PGM_PAGE_DEC_WRITE_LOCKS(pPage);
     2173            }
     2174
     2175            if (PGM_PAGE_GET_STATE(pPage) != PGM_PAGE_STATE_WRITE_MONITORED)
     2176            { /* probably extremely likely */ }
     2177            else
     2178                pgmPhysPageMakeWriteMonitoredWritable(pVM, pPage, NIL_RTGCPHYS);
     2179
     2180            PPGMPAGEMAP pMap = (PPGMPAGEMAP)paLocks[i].pvMap;
     2181            if (pMap)
     2182            {
     2183                Assert(pMap->cRefs >= 1);
     2184                pMap->cRefs--;
     2185            }
     2186
     2187            /* Yield the lock: */
     2188            if ((i & 1023) == 1023)
     2189            {
     2190                pgmLock(pVM);
     2191                pgmUnlock(pVM);
     2192            }
     2193        }
     2194    }
     2195    else
     2196    {
     2197        /*
     2198         * Read locks:
     2199         */
     2200        for (uint32_t i = 0; i < cPages; i++)
     2201        {
     2202            PPGMPAGE pPage  = (PPGMPAGE)(paLocks[i].uPageAndType & ~PGMPAGEMAPLOCK_TYPE_MASK);
     2203            unsigned cLocks = PGM_PAGE_GET_READ_LOCKS(pPage);
     2204            Assert(cLocks > 0);
     2205            if (RT_LIKELY(cLocks > 0 && cLocks < PGM_PAGE_MAX_LOCKS))
     2206            {
     2207                if (cLocks == 1)
     2208                {
     2209                    Assert(pVM->pgm.s.cReadLockedPages > 0);
     2210                    pVM->pgm.s.cReadLockedPages--;
     2211                }
     2212                PGM_PAGE_DEC_READ_LOCKS(pPage);
     2213            }
     2214
     2215            PPGMPAGEMAP pMap = (PPGMPAGEMAP)paLocks[i].pvMap;
     2216            if (pMap)
     2217            {
     2218                Assert(pMap->cRefs >= 1);
     2219                pMap->cRefs--;
     2220            }
     2221
     2222            /* Yield the lock: */
     2223            if ((i & 1023) == 1023)
     2224            {
     2225                pgmLock(pVM);
     2226                pgmUnlock(pVM);
     2227            }
     2228        }
     2229    }
     2230    pgmUnlock(pVM);
     2231
     2232    RT_BZERO(paLocks, sizeof(paLocks[0]) * cPages);
     2233}
     2234#endif /* IN_RING3 */
    21282235
    21292236
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