PGMR0SharedPage.cpp revision 46ae097c942b4a2d5038d9593e312856238da75f
00fa3bc989ffe84474e828c8b90b24284dcfdf0cvboxsync * PGM - Page Manager and Monitor, Page Sharing, Ring-0.
5f4259f329a2073f6644399b6922077adca01529vboxsync * Copyright (C) 2010-2012 Oracle Corporation
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * available from http://www.virtualbox.org. This file is free software;
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * you can redistribute it and/or modify it under the terms of the GNU
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * General Public License (GPL) as published by the Free Software
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync/*******************************************************************************
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync* Header Files *
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync*******************************************************************************/
5f4259f329a2073f6644399b6922077adca01529vboxsync * Check a registered module for shared page changes.
5f4259f329a2073f6644399b6922077adca01529vboxsync * The PGM lock shall be taken prior to calling this method.
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync * @returns The following VBox status codes.
4bfa7b58e362a1bca0628643c352c137900bf01avboxsync * @param pVM Pointer to the VM.
5f4259f329a2073f6644399b6922077adca01529vboxsync * @param pGVM Pointer to the GVM instance data.
5f4259f329a2073f6644399b6922077adca01529vboxsync * @param idCpu The ID of the calling virtual CPU.
67b4b089c50d0ab8ad847dddd8c0e0812fdadc9evboxsync * @param pModule Global module description.
5f4259f329a2073f6644399b6922077adca01529vboxsync * @param paRegionsGCPtrs Array parallel to pModules->aRegions with the
5f4259f329a2073f6644399b6922077adca01529vboxsync * addresses of the regions in the calling
5f4259f329a2073f6644399b6922077adca01529vboxsyncVMMR0DECL(int) PGMR0SharedModuleCheck(PVM pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, PCRTGCPTR64 paRegionsGCPtrs)
5f4259f329a2073f6644399b6922077adca01529vboxsync bool fFlushTLBs = false;
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync Log(("PGMR0SharedModuleCheck: check %s %s base=%RGv size=%x\n", pModule->szName, pModule->szVersion, pModule->Core.Key, pModule->cbModule));
addc480d0d7650db6323467bbdab6c21836a2928vboxsync PGM_LOCK_ASSERT_OWNER(pVM); /* This cannot fail as we grab the lock in pgmR3SharedModuleRegRendezvous before calling into ring-0. */
5f4259f329a2073f6644399b6922077adca01529vboxsync * Check every region of the shared module.
5f4259f329a2073f6644399b6922077adca01529vboxsync for (uint32_t idxRegion = 0; idxRegion < pModule->cRegions; idxRegion++)
5f4259f329a2073f6644399b6922077adca01529vboxsync RTGCPTR GCPtrPage = paRegionsGCPtrs[idxRegion] & ~(RTGCPTR)PAGE_OFFSET_MASK;
5f4259f329a2073f6644399b6922077adca01529vboxsync uint32_t cbLeft = pModule->aRegions[idxRegion].cb; Assert(!(cbLeft & PAGE_OFFSET_MASK));
5f4259f329a2073f6644399b6922077adca01529vboxsync /** @todo inefficient to fetch each guest page like this... */
5f4259f329a2073f6644399b6922077adca01529vboxsync rc = PGMGstGetPage(pVCpu, GCPtrPage, &fFlags, &GCPhys);
760446f710619a9daa6cedc7f0601f49e4ea3442vboxsync && !(fFlags & X86_PTE_RW)) /* important as we make assumptions about this below! */
5f4259f329a2073f6644399b6922077adca01529vboxsync && PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED
ec21c063515d0931111f0c1f8d6f4bc8e7a6c882vboxsync rc = GMMR0SharedModuleCheckPage(pGVM, pModule, idxRegion, idxPage, &PageDesc);
5f4259f329a2073f6644399b6922077adca01529vboxsync * Any change for this page?
5f4259f329a2073f6644399b6922077adca01529vboxsync Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
5f4259f329a2073f6644399b6922077adca01529vboxsync Log(("PGMR0SharedModuleCheck: shared page gst virt=%RGv phys=%RGp host %RHp->%RHp\n",
5f4259f329a2073f6644399b6922077adca01529vboxsync GCPtrPage, PageDesc.GCPhys, PGM_PAGE_GET_HCPHYS(pPage), PageDesc.HCPhys));
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync /* Page was either replaced by an existing shared
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync version of it or converted into a read-only shared
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync page, so, clear all references. */
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync bool fFlush = false;
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync rc = pgmPoolTrackUpdateGCPhys(pVM, PageDesc.GCPhys, pPage, true /* clear the entries */, &fFlush);
12c8c9f6f737f5ec482fce4d07f44537451c6478vboxsync && (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_CLEAR_PGM_POOL)));
5f4259f329a2073f6644399b6922077adca01529vboxsync /* Update the physical address and page id now. */
5f4259f329a2073f6644399b6922077adca01529vboxsync /* Invalidate page map TLB entry for this page too. */
5f4259f329a2073f6644399b6922077adca01529vboxsync pgmPhysInvalidatePageMapTLBEntry(pVM, PageDesc.GCPhys);
5f4259f329a2073f6644399b6922077adca01529vboxsync /* else: nothing changed (== this page is now a shared
5f4259f329a2073f6644399b6922077adca01529vboxsync page), so no need to flush anything. */
5f4259f329a2073f6644399b6922077adca01529vboxsync PGM_PAGE_SET_STATE(pVM, pPage, PGM_PAGE_STATE_SHARED);
05aea370c2b0e20fb84a962ed30a8c22c16d51ccvboxsync pPage->s.u2Unused0 = PageDesc.u32StrictChecksum & 3;
05aea370c2b0e20fb84a962ed30a8c22c16d51ccvboxsync pPage->s.u2Unused1 = (PageDesc.u32StrictChecksum >> 8) & 3;
5f4259f329a2073f6644399b6922077adca01529vboxsync * Do TLB flushing if necessary.
5f4259f329a2073f6644399b6922077adca01529vboxsync for (VMCPUID idCurCpu = 0; idCurCpu < pVM->cCpus; idCurCpu++)
5f4259f329a2073f6644399b6922077adca01529vboxsync CPUMSetChangedFlags(&pVM->aCpus[idCurCpu], CPUM_CHANGED_GLOBAL_TLB_FLUSH);
4ace9bce00c6d792391a0e064131716659e3a922vboxsync#endif /* VBOX_WITH_PAGE_SHARING */