VirtualBox

Changeset 43045 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Aug 28, 2012 2:21:43 PM (12 years ago)
Author:
vboxsync
Message:

PGM: Employ the 4 unused PGMPHYSPAGE bits for checksumming shared pages in strict builds.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r42976 r43045  
    32883288    Assert(pGMM->cAllocatedPages > 0);
    32893289    Assert(!pPage->Shared.cRefs);
    3290 #if defined(VBOX_WITH_PAGE_SHARING) && defined(VBOX_STRICT) && HC_ARCH_BITS == 64
    3291     if (pPage->Shared.u14Checksum)
    3292     {
    3293         uint32_t uChecksum = gmmR0StrictPageChecksum(pGMM, pGVM, idPage);
    3294         uChecksum &= UINT32_C(0x00003fff);
    3295         AssertMsg(!uChecksum || uChecksum == pPage->Shared.u14Checksum,
    3296                   ("%#x vs %#x - idPage=%#x\n", uChecksum, pPage->Shared.u14Checksum, idPage));
    3297     }
    3298 #endif
    32993290
    33003291    pChunk->cShared--;
     
    34043395            {
    34053396                Assert(pGVM->gmm.s.Stats.cSharedPages);
     3397                Assert(pPage->Shared.cRefs);
     3398#if defined(VBOX_WITH_PAGE_SHARING) && defined(VBOX_STRICT) && HC_ARCH_BITS == 64
     3399                if (pPage->Shared.u14Checksum)
     3400                {
     3401                    uint32_t uChecksum = gmmR0StrictPageChecksum(pGMM, pGVM, idPage);
     3402                    uChecksum &= UINT32_C(0x00003fff);
     3403                    AssertMsg(!uChecksum || uChecksum == pPage->Shared.u14Checksum,
     3404                              ("%#x vs %#x - idPage=%#x\n", uChecksum, pPage->Shared.u14Checksum, idPage));
     3405                }
     3406#endif
    34063407                pGVM->gmm.s.Stats.cSharedPages--;
    3407                 Assert(pPage->Shared.cRefs);
    34083408                if (!--pPage->Shared.cRefs)
    34093409                    gmmR0FreeSharedPage(pGMM, pGVM, idPage, pPage);
     
    47064706 * @param   pPage       The page structure.
    47074707 */
    4708 DECLINLINE(void) gmmR0ConvertToSharedPage(PGMM pGMM, PGVM pGVM, RTHCPHYS HCPhys, uint32_t idPage, PGMMPAGE pPage)
     4708DECLINLINE(void) gmmR0ConvertToSharedPage(PGMM pGMM, PGVM pGVM, RTHCPHYS HCPhys, uint32_t idPage, PGMMPAGE pPage,
     4709                                          PGMMSHAREDPAGEDESC pPageDesc)
    47094710{
    47104711    PGMMCHUNK pChunk = gmmR0GetChunk(pGMM, idPage >> GMM_CHUNKID_SHIFT);
     
    47254726    pPage->Shared.cRefs       = 1;
    47264727#ifdef VBOX_STRICT
    4727     pPage->Shared.u14Checksum = gmmR0StrictPageChecksum(pGMM, pGVM, idPage);
     4728    pPageDesc->u32StrictChecksum = gmmR0StrictPageChecksum(pGMM, pGVM, idPage);
     4729    pPage->Shared.u14Checksum = pPageDesc->u32StrictChecksum;
    47284730#else
    47294731    pPage->Shared.u14Checksum = 0;
     
    47454747    AssertMsg(pPageDesc->GCPhys == (pPage->Private.pfn << 12), ("desc %RGp gmm %RGp\n", pPageDesc->HCPhys, (pPage->Private.pfn << 12)));
    47464748
    4747     gmmR0ConvertToSharedPage(pGMM, pGVM, pPageDesc->HCPhys, pPageDesc->idPage, pPage);
     4749    gmmR0ConvertToSharedPage(pGMM, pGVM, pPageDesc->HCPhys, pPageDesc->idPage, pPage, pPageDesc);
    47484750
    47494751    /* Keep track of these references. */
     
    47794781    PGMM    pGMM;
    47804782    GMM_GET_VALID_INSTANCE(pGMM, VERR_GMM_INSTANCE);
     4783    pPageDesc->u32StrictChecksum = 0;
    47814784
    47824785    AssertMsgReturn(idxRegion < pModule->cRegions,
     
    48734876    }
    48744877    uint8_t *pbSharedPage = pbChunk + ((pGlobalRegion->paidPages[idxPage] & GMM_PAGEID_IDX_MASK) << PAGE_SHIFT);
     4878
    48754879#ifdef VBOX_STRICT
    4876     if (pPage->Shared.u14Checksum)
    4877     {
    4878         uint32_t uChecksum = RTCrc32(pbSharedPage, PAGE_SIZE) & UINT32_C(0x00003fff);
    4879         AssertMsg(!uChecksum || uChecksum == pPage->Shared.u14Checksum,
    4880                   ("%#x vs %#x - idPage=%# - %s %s\n", uChecksum, pPage->Shared.u14Checksum,
    4881                    pGlobalRegion->paidPages[idxPage], pModule->szName, pModule->szVersion));
    4882     }
     4880    pPageDesc->u32StrictChecksum = RTCrc32(pbSharedPage, PAGE_SIZE);
     4881    uint32_t uChecksum = pPageDesc->u32StrictChecksum & UINT32_C(0x00003fff);
     4882    AssertMsg(!uChecksum || uChecksum == pPage->Shared.u14Checksum || !pPage->Shared.u14Checksum,
     4883              ("%#x vs %#x - idPage=%# - %s %s\n", uChecksum, pPage->Shared.u14Checksum,
     4884               pGlobalRegion->paidPages[idxPage], pModule->szName, pModule->szVersion));
    48834885#endif
    48844886
     
    49484950    RTAvlGCPtrDestroy(&pGVM->gmm.s.pSharedModuleTree, gmmR0CleanupSharedModule, &Args);
    49494951
    4950     Assert(pGVM->gmm.s.Stats.cShareableModules == 0);
     4952    AssertMsg(pGVM->gmm.s.Stats.cShareableModules == 0, ("%d\n", pGVM->gmm.s.Stats.cShareableModules));
    49514953    pGVM->gmm.s.Stats.cShareableModules = 0;
    49524954
  • trunk/src/VBox/VMM/VMMR0/PGMR0SharedPage.cpp

    r43042 r43045  
    130130                        pVM->pgm.s.cPrivatePages--;
    131131                        PGM_PAGE_SET_STATE(pVM, pPage, PGM_PAGE_STATE_SHARED);
     132
     133# ifdef VBOX_STRICT /* check sum hack */
     134                        pPage->s.u2Unused0 = PageDesc.u32StrictChecksum        & 3;
     135                        pPage->s.u2Unused1 = (PageDesc.u32StrictChecksum >> 8) & 3;
     136# endif
    132137                    }
    133138                }
  • trunk/src/VBox/VMM/VMMR3/GMM.cpp

    r41965 r43045  
    55
    66/*
    7  * Copyright (C) 2008 Oracle Corporation
     7 * Copyright (C) 2008-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    287287}
    288288
     289
    289290/**
    290291 * @see GMMR0QueryVMMMemoryStatsReq
     
    317318}
    318319
     320
    319321/**
    320322 * @see GMMR0QueryMemoryStatsReq
     
    343345}
    344346
     347
    345348/**
    346349 * @see GMMR0MapUnmapChunk
     
    360363}
    361364
     365
    362366/**
    363367 * @see GMMR0FreeLargePage
     
    371375    return VMMR3CallR0(pVM, VMMR0_DO_GMM_FREE_LARGE_PAGE, 0, &Req.Hdr);
    372376}
     377
    373378
    374379/**
     
    394399}
    395400
     401
    396402/**
    397403 * @see GMMR0RegisterSharedModule
     
    404410}
    405411
     412
    406413/**
    407414 * @see GMMR0ResetSharedModules
     
    412419}
    413420
     421
    414422/**
    415423 * @see GMMR0CheckSharedModules
     
    419427    return VMMR3CallR0(pVM, VMMR0_DO_GMM_CHECK_SHARED_MODULES, 0, NULL);
    420428}
     429
    421430
    422431#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
     
    436445    if (rc == VINF_SUCCESS)
    437446        return Req.fDuplicate;
    438     else
    439         return false;
     447    return false;
    440448}
    441449#endif /* VBOX_STRICT && HC_ARCH_BITS == 64 */
  • trunk/src/VBox/VMM/VMMR3/PGMPhys.cpp

    r41965 r43045  
    3939#include <iprt/alloc.h>
    4040#include <iprt/asm.h>
     41#ifdef VBOX_STRICT
     42# include <iprt/crc.h>
     43#endif
    4144#include <iprt/thread.h>
    4245#include <iprt/string.h>
     
    18171820
    18181821/**
     1822 * Checks shared page checksums.
     1823 *
     1824 * @param   pVM     Pointer to the shared VM structure.
     1825 */
     1826void pgmR3PhysAssertSharedPageChecksums(PVM pVM)
     1827{
     1828#ifdef VBOX_STRICT
     1829    pgmLock(pVM);
     1830
     1831    if (pVM->pgm.s.cSharedPages > 0)
     1832    {
     1833        /*
     1834         * Walk the ram ranges.
     1835         */
     1836        for (PPGMRAMRANGE pRam = pVM->pgm.s.pRamRangesXR3; pRam; pRam = pRam->pNextR3)
     1837        {
     1838            uint32_t iPage = pRam->cb >> PAGE_SHIFT;
     1839            AssertMsg(((RTGCPHYS)iPage << PAGE_SHIFT) == pRam->cb, ("%RGp %RGp\n", (RTGCPHYS)iPage << PAGE_SHIFT, pRam->cb));
     1840
     1841            while (iPage-- > 0)
     1842            {
     1843                PPGMPAGE pPage = &pRam->aPages[iPage];
     1844                if (PGM_PAGE_IS_SHARED(pPage))
     1845                {
     1846                    uint32_t u32Checksum = pPage->s.u2Unused0 | ((uint32_t)pPage->s.u2Unused1 << 8);
     1847                    if (!u32Checksum)
     1848                    {
     1849                        RTGCPHYS    GCPhysPage  = pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT);
     1850                        void const *pvPage;
     1851                        int rc = pgmPhysPageMapReadOnly(pVM, pPage, GCPhysPage, &pvPage);
     1852                        if (RT_SUCCESS(rc))
     1853                        {
     1854                            uint32_t u32Checksum2 = RTCrc32(pvPage, PAGE_SIZE);
     1855# if 0
     1856                            AssertMsg((u32Checksum2 & UINT32_C(0x00000303)) == u32Checksum, ("GCPhysPage=%RGp\n", GCPhysPage));
     1857# else
     1858                            if ((u32Checksum2 & UINT32_C(0x00000303)) == u32Checksum)
     1859                                LogFlow(("shpg %#x @ %RGp %#x [OK]\n", PGM_PAGE_GET_PAGEID(pPage), GCPhysPage, u32Checksum2));
     1860                            else
     1861                                AssertMsgFailed(("shpg %#x @ %RGp %#x\n", PGM_PAGE_GET_PAGEID(pPage), GCPhysPage, u32Checksum2));
     1862# endif
     1863                        }
     1864                        else
     1865                            AssertRC(rc);
     1866                    }
     1867                }
     1868
     1869            } /* for each page */
     1870
     1871        } /* for each ram range */
     1872    }
     1873
     1874    pgmUnlock(pVM);
     1875#endif /* VBOX_STRICT */
     1876    NOREF(pVM);
     1877}
     1878
     1879
     1880/**
    18191881 * Resets (zeros) the RAM.
    18201882 *
     
    18341896#ifdef VBOX_WITH_PAGE_SHARING
    18351897    /* Clear all registered shared modules. */
     1898    pgmR3PhysAssertSharedPageChecksums(pVM);
    18361899    rc = GMMR3ResetSharedModules(pVM);
    18371900    AssertRC(rc);
     
    19782041}
    19792042
     2043
    19802044/**
    19812045 * Frees all RAM during VM termination
     
    19962060#ifdef VBOX_WITH_PAGE_SHARING
    19972061    /* Clear all registered shared modules. */
     2062    pgmR3PhysAssertSharedPageChecksums(pVM);
    19982063    rc = GMMR3ResetSharedModules(pVM);
    19992064    AssertRC(rc);
     
    20172082        AssertMsg(((RTGCPHYS)iPage << PAGE_SHIFT) == pRam->cb, ("%RGp %RGp\n", (RTGCPHYS)iPage << PAGE_SHIFT, pRam->cb));
    20182083
    2019         /* Replace all RAM pages by ZERO pages. */
    20202084        while (iPage-- > 0)
    20212085        {
     
    20252089                case PGMPAGETYPE_RAM:
    20262090                    /* Free all shared pages. Private pages are automatically freed during GMM VM cleanup. */
     2091                    /** @todo change this to explicitly free private pages here. */
    20272092                    if (PGM_PAGE_IS_SHARED(pPage))
    20282093                    {
  • trunk/src/VBox/VMM/VMMR3/PGMSharedPage.cpp

    r41803 r43045  
    9999             * Issue the request.  In strict builds, do some local tracking.
    100100             */
     101            pgmR3PhysAssertSharedPageChecksums(pVM);
    101102            rc = GMMR3RegisterSharedModule(pVM, pReq);
    102103            if (RT_SUCCESS(rc))
     
    165166        if (RT_SUCCESS(rc))
    166167        {
     168            pgmR3PhysAssertSharedPageChecksums(pVM);
    167169            rc = GMMR3UnregisterSharedModule(pVM, pReq);
     170            pgmR3PhysAssertSharedPageChecksums(pVM);
    168171
    169172# ifdef VBOX_STRICT
     
    211214    }
    212215
     216
    213217    /* Flush all pending handy page operations before changing any shared page assignments. */
    214218    int rc = PGMR3PhysAllocateHandyPages(pVM);
    215219    AssertRC(rc);
    216220
    217     /* Lock it here as we can't deal with busy locks in this ring-0 path. */
     221    /*
     222     * Lock it here as we can't deal with busy locks in this ring-0 path.
     223     */
     224    LogFlow(("pgmR3SharedModuleRegRendezvous: start (%d)\n", pVM->pgm.s.cSharedPages));
     225
    218226    pgmLock(pVM);
     227    pgmR3PhysAssertSharedPageChecksums(pVM);
    219228    rc = GMMR3CheckSharedModules(pVM);
     229    pgmR3PhysAssertSharedPageChecksums(pVM);
    220230    pgmUnlock(pVM);
    221231    AssertLogRelRC(rc);
    222232
     233    LogFlow(("pgmR3SharedModuleRegRendezvous: done (%d)\n", pVM->pgm.s.cSharedPages));
    223234    return rc;
    224235}
  • trunk/src/VBox/VMM/include/PGMInternal.h

    r43025 r43045  
    39603960int             pgmR3PhysRamTerm(PVM pVM);
    39613961void            pgmR3PhysRomTerm(PVM pVM);
     3962void            pgmR3PhysAssertSharedPageChecksums(PVM pVM);
    39623963
    39633964int             pgmR3PoolInit(PVM pVM);
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