VirtualBox

Changeset 40226 in vbox for trunk/src


Ignore:
Timestamp:
Feb 23, 2012 11:05:45 AM (13 years ago)
Author:
vboxsync
Message:

GMM: Checksum shared pages in strict builds.

File:
1 edited

Legend:

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

    r40054 r40226  
    55
    66/*
    7  * Copyright (C) 2007-2011 Oracle Corporation
     7 * Copyright (C) 2007-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    162162#include <iprt/asm.h>
    163163#include <iprt/avl.h>
     164#ifdef VBOX_STRICT
     165# include <iprt/crc.h>
     166#endif
    164167#include <iprt/list.h>
    165168#include <iprt/mem.h>
     
    222225        /** The reference count (64K VMs). */
    223226        uint32_t    cRefs : 16;
    224         /** Reserved. Checksum or something? Two hGVMs for forking? */
    225         uint32_t    u14Reserved : 14;
     227        /** Used for debug checksumming. */
     228        uint32_t    u14Checksum : 14;
    226229        /** The page state. */
    227230        uint32_t    u2State : 2;
     
    723726#ifdef VBOX_WITH_PAGE_SHARING
    724727static void                 gmmR0SharedModuleCleanup(PGMM pGMM, PGVM pGVM);
     728# ifdef VBOX_STRICT
     729static uint32_t             gmmR0StrictPageChecksum(PGMM pGMM, PGVM pGVM, uint32_t idPage);
     730# endif
    725731#endif
    726732
     
    32823288    Assert(pGMM->cAllocatedPages > 0);
    32833289    Assert(!pPage->Shared.cRefs);
     3290#ifdef VBOX_STRICT
     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=%#\n", uChecksum, pPage->Shared.u14Checksum, idPage));
     3297    }
     3298#endif
    32843299
    32853300    pChunk->cShared--;
     
    39783993 * @param   ppvR3       Where to store the ring-3 address of the mapping.
    39793994 */
    3980 static int gmmR0IsChunkMapped(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, PRTR3PTR ppvR3)
     3995static bool gmmR0IsChunkMapped(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, PRTR3PTR ppvR3)
    39813996{
    39823997    GMMR0CHUNKMTXSTATE MtxState;
     
    41684183
    41694184#ifdef VBOX_WITH_PAGE_SHARING
     4185
     4186# ifdef VBOX_STRICT
     4187/**
     4188 * For checksumming shared pages in strict builds.
     4189 *
     4190 * The purpose is making sure that a page doesn't change.
     4191 *
     4192 * @returns Checksum, 0 on failure.
     4193 * @param   GMM                 The GMM instance data.
     4194 * @param   idPage              The page ID.
     4195 */
     4196static uint32_t gmmR0StrictPageChecksum(PGMM pGMM, PGVM pGVM, uint32_t idPage)
     4197{
     4198    PGMMCHUNK pChunk = gmmR0GetChunk(pGMM, idPage >> GMM_CHUNKID_SHIFT);
     4199    AssertMsgReturn(pChunk, ("idPage=%#x\n", idPage), 0);
     4200
     4201    uint8_t *pbChunk;
     4202    if (!gmmR0IsChunkMapped(pGMM, pGVM, pChunk, (PRTR3PTR)&pbChunk))
     4203        return 0;
     4204    uint8_t const *pbPage = pbChunk + ((idPage & GMM_PAGEID_IDX_MASK) << PAGE_SHIFT);
     4205
     4206    return RTCrc32(pbPage, PAGE_SIZE);
     4207}
     4208# endif /* VBOX_STRICT */
     4209
    41704210
    41714211/**
     
    46824722
    46834723    /* Modify the page structure. */
    4684     pPage->Shared.pfn     = (uint32_t)(uint64_t)(HCPhys >> PAGE_SHIFT);
    4685     pPage->Shared.cRefs   = 1;
    4686     pPage->Common.u2State = GMM_PAGE_STATE_SHARED;
     4724    pPage->Shared.pfn         = (uint32_t)(uint64_t)(HCPhys >> PAGE_SHIFT);
     4725    pPage->Shared.cRefs       = 1;
     4726#ifdef VBOX_STRICT
     4727    pPage->Shared.u14Checksum = gmmR0StrictPageChecksum(pGMM, pGVM, idPage);
     4728#else
     4729    pPage->Shared.u14Checksum = 0;
     4730#endif
     4731    pPage->Shared.u2State     = GMM_PAGE_STATE_SHARED;
    46874732}
    46884733
     
    48284873    }
    48294874    uint8_t *pbSharedPage = pbChunk + ((pGlobalRegion->paidPages[idxPage] & GMM_PAGEID_IDX_MASK) << PAGE_SHIFT);
     4875#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    }
     4883#endif
    48304884
    48314885    /** @todo write ASMMemComparePage. */
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