VirtualBox

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


Ignore:
Timestamp:
Mar 20, 2013 11:13:27 AM (12 years ago)
Author:
vboxsync
Message:

PGMPool: Eliminated fictive page (except NIL). #6367

Location:
trunk/src/VBox/VMM/VMMAll
Files:
4 edited

Legend:

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

    r44528 r45103  
    12301230
    12311231        rc = pgmPoolAlloc(pVM, GCPml4, PGMPOOLKIND_EPT_PDPT_FOR_PHYS, PGMPOOLACCESS_DONTCARE, PGM_A20_IS_ENABLED(pVCpu),
    1232                           PGMPOOL_IDX_NESTED_ROOT, iPml4, false /*fLockPage*/,
     1232                          pVCpu->pgm.s.CTX_SUFF(pShwPageCR3)->idx, iPml4, false /*fLockPage*/,
    12331233                          &pShwPage);
    12341234        AssertRCReturn(rc, rc);
  • trunk/src/VBox/VMM/VMMAll/PGMAllBth.h

    r44528 r45103  
    45824582    PPGMPOOL     pPool             = pVM->pgm.s.CTX_SUFF(pPool);
    45834583    PPGMPOOLPAGE pOldShwPageCR3    = pVCpu->pgm.s.CTX_SUFF(pShwPageCR3);
    4584     uint32_t     iOldShwUserTable  = pVCpu->pgm.s.iShwUserTable;
    4585     uint32_t     iOldShwUser       = pVCpu->pgm.s.iShwUser;
    45864584    PPGMPOOLPAGE pNewShwPageCR3;
    45874585
     
    45954593    Assert(!(GCPhysCR3 >> (PAGE_SHIFT + 32)));
    45964594    rc = pgmPoolAlloc(pVM, GCPhysCR3 & GST_CR3_PAGE_MASK, BTH_PGMPOOLKIND_ROOT, PGMPOOLACCESS_DONTCARE, PGM_A20_IS_ENABLED(pVCpu),
    4597                       SHW_POOL_ROOT_IDX, GCPhysCR3 >> PAGE_SHIFT, true /*fLockPage*/,
     4595                      NIL_PGMPOOL_IDX, UINT32_MAX, true /*fLockPage*/,
    45984596                      &pNewShwPageCR3);
    45994597    AssertFatalRC(rc);
     
    46124610#  endif
    46134611
    4614     pVCpu->pgm.s.iShwUser      = SHW_POOL_ROOT_IDX;
    4615     pVCpu->pgm.s.iShwUserTable = GCPhysCR3 >> PAGE_SHIFT;
    46164612    pVCpu->pgm.s.CTX_SUFF(pShwPageCR3) = pNewShwPageCR3;
    46174613#  ifdef IN_RING0
     
    46604656        pgmPoolUnlockPage(pPool, pOldShwPageCR3);
    46614657
    4662         pgmPoolFreeByPage(pPool, pOldShwPageCR3, iOldShwUser, iOldShwUserTable);
     4658        pgmPoolFreeByPage(pPool, pOldShwPageCR3, NIL_PGMPOOL_IDX, UINT32_MAX);
    46634659    }
    46644660    pgmUnlock(pVM);
     
    47434739        PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
    47444740
    4745         Assert(pVCpu->pgm.s.iShwUser != PGMPOOL_IDX_NESTED_ROOT);
    4746 
    47474741# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
    47484742        if (pPool->cDirtyPages)
     
    47534747        pgmPoolUnlockPage(pPool, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
    47544748
    4755         pgmPoolFreeByPage(pPool, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3), pVCpu->pgm.s.iShwUser, pVCpu->pgm.s.iShwUserTable);
     4749        pgmPoolFreeByPage(pPool, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3), NIL_PGMPOOL_IDX, UINT32_MAX);
    47564750        pVCpu->pgm.s.pShwPageCR3R3 = 0;
    47574751        pVCpu->pgm.s.pShwPageCR3R0 = 0;
    47584752        pVCpu->pgm.s.pShwPageCR3RC = 0;
    4759         pVCpu->pgm.s.iShwUser      = 0;
    4760         pVCpu->pgm.s.iShwUserTable = 0;
    47614753    }
    47624754    pgmUnlock(pVM);
  • trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp

    r43387 r45103  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    20142014    {
    20152015        uint16_t iToFree = pPool->iAgeTail;
    2016         if (iToFree == iUser)
     2016        if (iToFree == iUser && iUser != NIL_PGMPOOL_IDX)
    20172017            iToFree = pPool->aPages[iToFree].iAgePrev;
    20182018/* This is the alternative to the SyncCR3 pgmPoolCacheUsed calls.
     
    21732173 * @param   enmAccess   Access type for the mapping (only relevant for big pages)
    21742174 * @param   fA20Enabled Whether the CPU has the A20 gate enabled.
    2175  * @param   iUser       The shadow page pool index of the user table.
    2176  * @param   iUserTable  The index into the user table (shadowed).
     2175 * @param   iUser       The shadow page pool index of the user table.  This is
     2176 *                      NIL_PGMPOOL_IDX for root pages.
     2177 * @param   iUserTable  The index into the user table (shadowed).  Ignored if
     2178 *                      root page
    21772179 * @param   ppPage      Where to store the pointer to the page.
    21782180 */
     
    22022204                    pgmPoolCacheUsed(pPool, pPage);
    22032205
    2204                     int rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
     2206                    int rc = VINF_SUCCESS;
     2207                    if (iUser != NIL_PGMPOOL_IDX)
     2208                        rc = pgmPoolTrackAddUser(pPool, pPage, iUser, iUserTable);
    22052209                    if (RT_SUCCESS(rc))
    22062210                    {
     
    28052809    LogFlow(("pgmPoolTrackInsert GCPhys=%RGp iUser=%d iUserTable=%x\n", GCPhys, iUser, iUserTable));
    28062810
     2811    if (iUser != NIL_PGMPOOL_IDX)
     2812    {
    28072813#ifdef VBOX_STRICT
    2808     /*
    2809      * Check that the entry doesn't already exists.
    2810      */
    2811     if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
    2812     {
    2813         uint16_t i = pPage->iUserHead;
    2814         do
    2815         {
    2816             Assert(i < pPool->cMaxUsers);
    2817             AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
    2818             i = paUsers[i].iNext;
    2819         } while (i != NIL_PGMPOOL_USER_INDEX);
    2820     }
     2814        /*
     2815         * Check that the entry doesn't already exists.
     2816         */
     2817        if (pPage->iUserHead != NIL_PGMPOOL_USER_INDEX)
     2818        {
     2819            uint16_t i = pPage->iUserHead;
     2820            do
     2821            {
     2822                Assert(i < pPool->cMaxUsers);
     2823                AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
     2824                i = paUsers[i].iNext;
     2825            } while (i != NIL_PGMPOOL_USER_INDEX);
     2826        }
    28212827#endif
    28222828
    2823     /*
    2824      * Find free a user node.
    2825      */
    2826     uint16_t i = pPool->iUserFreeHead;
    2827     if (i == NIL_PGMPOOL_USER_INDEX)
    2828     {
    2829         rc = pgmPoolTrackFreeOneUser(pPool, iUser);
    2830         if (RT_FAILURE(rc))
    2831             return rc;
    2832         i = pPool->iUserFreeHead;
    2833     }
    2834 
    2835     /*
    2836      * Unlink the user node from the free list,
    2837      * initialize and insert it into the user list.
    2838      */
    2839     pPool->iUserFreeHead = paUsers[i].iNext;
    2840     paUsers[i].iNext = NIL_PGMPOOL_USER_INDEX;
    2841     paUsers[i].iUser = iUser;
    2842     paUsers[i].iUserTable = iUserTable;
    2843     pPage->iUserHead = i;
     2829        /*
     2830         * Find free a user node.
     2831         */
     2832        uint16_t i = pPool->iUserFreeHead;
     2833        if (i == NIL_PGMPOOL_USER_INDEX)
     2834        {
     2835            rc = pgmPoolTrackFreeOneUser(pPool, iUser);
     2836            if (RT_FAILURE(rc))
     2837                return rc;
     2838            i = pPool->iUserFreeHead;
     2839        }
     2840
     2841        /*
     2842         * Unlink the user node from the free list,
     2843         * initialize and insert it into the user list.
     2844         */
     2845        pPool->iUserFreeHead = paUsers[i].iNext;
     2846        paUsers[i].iNext = NIL_PGMPOOL_USER_INDEX;
     2847        paUsers[i].iUser = iUser;
     2848        paUsers[i].iUserTable = iUserTable;
     2849        pPage->iUserHead = i;
     2850    }
     2851    else
     2852        pPage->iUserHead = NIL_PGMPOOL_USER_INDEX;
     2853
    28442854
    28452855    /*
     
    28812891static int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
    28822892{
     2893    Log3(("pgmPoolTrackAddUser: GCPhys=%RGp iUser=%%x iUserTable=%x\n", pPage->GCPhys, iUser, iUserTable));
    28832894    PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
    2884 
    2885     Log3(("pgmPoolTrackAddUser GCPhys = %RGp iUser %x iUserTable %x\n", pPage->GCPhys, iUser, iUserTable));
     2895    Assert(iUser != NIL_PGMPOOL_IDX);
    28862896
    28872897#  ifdef VBOX_STRICT
     
    28962906        {
    28972907            Assert(i < pPool->cMaxUsers);
    2898             AssertMsg(iUser != PGMPOOL_IDX_PD || iUser != PGMPOOL_IDX_PDPT || iUser != PGMPOOL_IDX_NESTED_ROOT || iUser != PGMPOOL_IDX_AMD64_CR3 ||
    2899                       paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
     2908            /** @todo this assertion looks odd... Shouldn't it be && here? */
     2909            AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
    29002910            i = paUsers[i].iNext;
    29012911        } while (i != NIL_PGMPOOL_USER_INDEX);
     
    29472957 * @param   iUser       The shadow page pool index of the user table.
    29482958 * @param   iUserTable  The index into the user table (shadowed).
     2959 *
     2960 * @remarks Don't call this for root pages.
    29492961 */
    29502962static void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
    29512963{
     2964    Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
     2965    PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
     2966    Assert(iUser != NIL_PGMPOOL_IDX);
     2967
    29522968    /*
    29532969     * Unlink and free the specified user entry.
    29542970     */
    2955     PPGMPOOLUSER paUsers = pPool->CTX_SUFF(paUsers);
    2956 
    2957     Log3(("pgmPoolTrackFreeUser %RGp %x %x\n", pPage->GCPhys, iUser, iUserTable));
     2971
    29582972    /* Special: For PAE and 32-bit paging, there is usually no more than one user. */
    29592973    uint16_t i = pPage->iUserHead;
     
    48994913 * @param   HCPhys      The HC physical address of the shadow page.
    49004914 * @param   iUser       The shadow page pool index of the user table.
    4901  * @param   iUserTable  The index into the user table (shadowed).
     4915 *                      NIL_PGMPOOL_IDX for root pages.
     4916 * @param   iUserTable  The index into the user table (shadowed). Ignored if
     4917 *                      root page.
    49024918 */
    49034919void pgmPoolFreeByPage(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
     
    49114927
    49124928    pgmLock(pVM);
    4913     pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
     4929    if (iUser != NIL_PGMPOOL_IDX)
     4930        pgmPoolTrackFreeUser(pPool, pPage, iUser, iUserTable);
    49144931    if (!pPage->fCached)
    49154932        pgmPoolFlushPage(pPool, pPage);
     
    49334950{
    49344951    PVM pVM = pPool->CTX_SUFF(pVM);
    4935     LogFlow(("pgmPoolMakeMoreFreePages: iUser=%d\n", iUser));
     4952    LogFlow(("pgmPoolMakeMoreFreePages: enmKind=%d iUser=%d\n", enmKind, iUser));
    49364953    NOREF(enmKind);
    49374954
     
    49855002 * @param   enmAccess   Access type for the mapping (only relevant for big pages)
    49865003 * @param   fA20Enabled Whether the A20 gate is enabled or not.
    4987  * @param   iUser       The shadow page pool index of the user table.
    4988  * @param   iUserTable  The index into the user table (shadowed).
     5004 * @param   iUser       The shadow page pool index of the user table.  Root
     5005 *                      pages should pass NIL_PGMPOOL_IDX.
     5006 * @param   iUserTable  The index into the user table (shadowed).  Ignored for
     5007 *                      root pages (iUser == NIL_PGMPOOL_IDX).
    49895008 * @param   fLockPage   Lock the page
    49905009 * @param   ppPage      Where to store the pointer to the page. NULL is stored here on failure.
     
    51195138 * @param   HCPhys      The HC physical address of the shadow page.
    51205139 * @param   iUser       The shadow page pool index of the user table.
    5121  * @param   iUserTable  The index into the user table (shadowed).
     5140 *                      NIL_PGMPOOL_IDX if root page.
     5141 * @param   iUserTable  The index into the user table (shadowed).  Ignored if
     5142 *                      root page.
    51225143 */
    51235144void pgmPoolFree(PVM pVM, RTHCPHYS HCPhys, uint16_t iUser, uint32_t iUserTable)
     
    54075428     * Reinsert active pages into the hash and ensure monitoring chains are correct.
    54085429     */
    5409     for (unsigned i = PGMPOOL_IDX_FIRST_SPECIAL; i < PGMPOOL_IDX_FIRST; i++)
    5410     {
    5411         PPGMPOOLPAGE pPage = &pPool->aPages[i];
    5412 
    5413         /** @todo r=bird: Is this code still needed in any way?  The special root
    5414          *        pages should not be monitored or anything these days AFAIK. */
    5415         Assert(pPage->iNext == NIL_PGMPOOL_IDX);
    5416         Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX);
    5417         Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX);
    5418         Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX);
    5419         Assert(pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
    5420         Assert(!pPage->fMonitored);
    5421 
    5422         pPage->iNext = NIL_PGMPOOL_IDX;
    5423         pPage->iModifiedNext = NIL_PGMPOOL_IDX;
    5424         pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
    5425         pPage->cModifications = 0;
    5426         /* ASSUMES that we're not sharing with any of the other special pages (safe for now). */
    5427         pPage->iMonitoredNext = NIL_PGMPOOL_IDX;
    5428         pPage->iMonitoredPrev = NIL_PGMPOOL_IDX;
    5429         if (pPage->fMonitored)
    5430         {
    5431             int rc = PGMHandlerPhysicalChangeCallbacks(pVM, pPage->GCPhys & ~(RTGCPHYS)PAGE_OFFSET_MASK,
    5432                                                        pPool->pfnAccessHandlerR3, MMHyperCCToR3(pVM, pPage),
    5433                                                        pPool->pfnAccessHandlerR0, MMHyperCCToR0(pVM, pPage),
    5434                                                        pPool->pfnAccessHandlerRC, MMHyperCCToRC(pVM, pPage),
    5435                                                        pPool->pszAccessHandler);
    5436             AssertFatalRCSuccess(rc);
    5437             pgmPoolHashInsert(pPool, pPage);
    5438         }
    5439         Assert(pPage->iUserHead == NIL_PGMPOOL_USER_INDEX); /* for now */
    5440         Assert(pPage->iAgeNext == NIL_PGMPOOL_IDX);
    5441         Assert(pPage->iAgePrev == NIL_PGMPOOL_IDX);
    5442     }
    5443 
    54445430    for (VMCPUID i = 0; i < pVM->cCpus; i++)
    54455431    {
  • trunk/src/VBox/VMM/VMMAll/PGMAllShw.h

    r44528 r45103  
    5252#undef SHW_PDPT_MASK
    5353#undef SHW_PDPE_PG_MASK
    54 #undef SHW_POOL_ROOT_IDX
    5554
    5655#if PGM_SHW_TYPE == PGM_TYPE_32BIT
     
    8584# define SHW_PT_SHIFT                   X86_PT_SHIFT
    8685# define SHW_PT_MASK                    X86_PT_MASK
    87 # define SHW_POOL_ROOT_IDX              PGMPOOL_IDX_PD
    8886
    8987#elif PGM_SHW_TYPE == PGM_TYPE_EPT
     
    121119# define SHW_PDPE_PG_MASK               EPT_PDPE_PG_MASK
    122120# define SHW_TOTAL_PD_ENTRIES           (EPT_PG_AMD64_ENTRIES*EPT_PG_AMD64_PDPE_ENTRIES)
    123 # define SHW_POOL_ROOT_IDX              PGMPOOL_IDX_NESTED_ROOT      /* do not use! exception is real mode & protected mode without paging. */
    124121
    125122#else
     
    159156#  define SHW_PDPE_PG_MASK              X86_PDPE_PG_MASK
    160157#  define SHW_TOTAL_PD_ENTRIES          (X86_PG_AMD64_ENTRIES * X86_PG_AMD64_PDPE_ENTRIES)
    161 #  define SHW_POOL_ROOT_IDX             PGMPOOL_IDX_AMD64_CR3
    162158
    163159# else /* 32 bits PAE mode */
     
    166162#  define SHW_PDPE_PG_MASK              X86_PDPE_PG_MASK
    167163#  define SHW_TOTAL_PD_ENTRIES          (X86_PG_PAE_ENTRIES * X86_PG_PAE_PDPE_ENTRIES)
    168 #  define SHW_POOL_ROOT_IDX             PGMPOOL_IDX_PDPT
    169164
    170165# endif
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