[23] | 1 | /* $Id: PGMPool.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * PGM Shadow Page Pool.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[82968] | 7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 | /** @page pg_pgm_pool PGM Shadow Page Pool
|
---|
| 19 | *
|
---|
| 20 | * Motivations:
|
---|
| 21 | * -# Relationship between shadow page tables and physical guest pages. This
|
---|
| 22 | * should allow us to skip most of the global flushes now following access
|
---|
| 23 | * handler changes. The main expense is flushing shadow pages.
|
---|
[13543] | 24 | * -# Limit the pool size if necessary (default is kind of limitless).
|
---|
| 25 | * -# Allocate shadow pages from RC. We use to only do this in SyncCR3.
|
---|
[1] | 26 | * -# Required for 64-bit guests.
|
---|
| 27 | * -# Combining the PD cache and page pool in order to simplify caching.
|
---|
| 28 | *
|
---|
| 29 | *
|
---|
| 30 | * @section sec_pgm_pool_outline Design Outline
|
---|
| 31 | *
|
---|
[13543] | 32 | * The shadow page pool tracks pages used for shadowing paging structures (i.e.
|
---|
| 33 | * page tables, page directory, page directory pointer table and page map
|
---|
| 34 | * level-4). Each page in the pool has an unique identifier. This identifier is
|
---|
| 35 | * used to link a guest physical page to a shadow PT. The identifier is a
|
---|
| 36 | * non-zero value and has a relativly low max value - say 14 bits. This makes it
|
---|
| 37 | * possible to fit it into the upper bits of the of the aHCPhys entries in the
|
---|
| 38 | * ram range.
|
---|
[1] | 39 | *
|
---|
[13543] | 40 | * By restricting host physical memory to the first 48 bits (which is the
|
---|
| 41 | * announced physical memory range of the K8L chip (scheduled for 2008)), we
|
---|
| 42 | * can safely use the upper 16 bits for shadow page ID and reference counting.
|
---|
[1] | 43 | *
|
---|
[13543] | 44 | * Update: The 48 bit assumption will be lifted with the new physical memory
|
---|
| 45 | * management (PGMPAGE), so we won't have any trouble when someone stuffs 2TB
|
---|
| 46 | * into a box in some years.
|
---|
[1] | 47 | *
|
---|
[13543] | 48 | * Now, it's possible for a page to be aliased, i.e. mapped by more than one PT
|
---|
| 49 | * or PD. This is solved by creating a list of physical cross reference extents
|
---|
| 50 | * when ever this happens. Each node in the list (extent) is can contain 3 page
|
---|
| 51 | * pool indexes. The list it self is chained using indexes into the paPhysExt
|
---|
| 52 | * array.
|
---|
[1] | 53 | *
|
---|
[13543] | 54 | *
|
---|
[1] | 55 | * @section sec_pgm_pool_life Life Cycle of a Shadow Page
|
---|
| 56 | *
|
---|
| 57 | * -# The SyncPT function requests a page from the pool.
|
---|
| 58 | * The request includes the kind of page it is (PT/PD, PAE/legacy), the
|
---|
| 59 | * address of the page it's shadowing, and more.
|
---|
| 60 | * -# The pool responds to the request by allocating a new page.
|
---|
| 61 | * When the cache is enabled, it will first check if it's in the cache.
|
---|
| 62 | * Should the pool be exhausted, one of two things can be done:
|
---|
| 63 | * -# Flush the whole pool and current CR3.
|
---|
| 64 | * -# Use the cache to find a page which can be flushed (~age).
|
---|
| 65 | * -# The SyncPT function will sync one or more pages and insert it into the
|
---|
| 66 | * shadow PD.
|
---|
| 67 | * -# The SyncPage function may sync more pages on a later \#PFs.
|
---|
| 68 | * -# The page is freed / flushed in SyncCR3 (perhaps) and some other cases.
|
---|
| 69 | * When caching is enabled, the page isn't flush but remains in the cache.
|
---|
| 70 | *
|
---|
| 71 | *
|
---|
[58116] | 72 | * @section sec_pgm_pool_monitoring Monitoring
|
---|
[1] | 73 | *
|
---|
| 74 | * We always monitor PAGE_SIZE chunks of memory. When we've got multiple shadow
|
---|
| 75 | * pages for the same PAGE_SIZE of guest memory (PAE and mixed PD/PT) the pages
|
---|
| 76 | * sharing the monitor get linked using the iMonitoredNext/Prev. The head page
|
---|
| 77 | * is the pvUser to the access handlers.
|
---|
| 78 | *
|
---|
| 79 | *
|
---|
| 80 | * @section sec_pgm_pool_impl Implementation
|
---|
| 81 | *
|
---|
[13543] | 82 | * The pool will take pages from the MM page pool. The tracking data
|
---|
| 83 | * (attributes, bitmaps and so on) are allocated from the hypervisor heap. The
|
---|
| 84 | * pool content can be accessed both by using the page id and the physical
|
---|
| 85 | * address (HC). The former is managed by means of an array, the latter by an
|
---|
| 86 | * offset based AVL tree.
|
---|
[1] | 87 | *
|
---|
| 88 | * Flushing of a pool page means that we iterate the content (we know what kind
|
---|
| 89 | * it is) and updates the link information in the ram range.
|
---|
| 90 | *
|
---|
| 91 | * ...
|
---|
| 92 | */
|
---|
| 93 |
|
---|
| 94 |
|
---|
[57358] | 95 | /*********************************************************************************************************************************
|
---|
| 96 | * Header Files *
|
---|
| 97 | *********************************************************************************************************************************/
|
---|
[1] | 98 | #define LOG_GROUP LOG_GROUP_PGM_POOL
|
---|
[35346] | 99 | #include <VBox/vmm/pgm.h>
|
---|
| 100 | #include <VBox/vmm/mm.h>
|
---|
[1] | 101 | #include "PGMInternal.h"
|
---|
[35346] | 102 | #include <VBox/vmm/vm.h>
|
---|
[44399] | 103 | #include <VBox/vmm/uvm.h>
|
---|
[26150] | 104 | #include "PGMInline.h"
|
---|
[1] | 105 |
|
---|
| 106 | #include <VBox/log.h>
|
---|
| 107 | #include <VBox/err.h>
|
---|
| 108 | #include <iprt/asm.h>
|
---|
| 109 | #include <iprt/string.h>
|
---|
[22716] | 110 | #include <VBox/dbg.h>
|
---|
[1] | 111 |
|
---|
| 112 |
|
---|
[57358] | 113 | /*********************************************************************************************************************************
|
---|
| 114 | * Internal Functions *
|
---|
| 115 | *********************************************************************************************************************************/
|
---|
[22716] | 116 | #ifdef VBOX_WITH_DEBUGGER
|
---|
[44399] | 117 | static FNDBGCCMD pgmR3PoolCmdCheck;
|
---|
[22716] | 118 | #endif
|
---|
[1] | 119 |
|
---|
[22716] | 120 | #ifdef VBOX_WITH_DEBUGGER
|
---|
| 121 | /** Command descriptors. */
|
---|
| 122 | static const DBGCCMD g_aCmds[] =
|
---|
| 123 | {
|
---|
[35696] | 124 | /* pszCmd, cArgsMin, cArgsMax, paArgDesc, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
|
---|
| 125 | { "pgmpoolcheck", 0, 0, NULL, 0, 0, pgmR3PoolCmdCheck, "", "Check the pgm pool pages." },
|
---|
[22716] | 126 | };
|
---|
| 127 | #endif
|
---|
[1] | 128 |
|
---|
| 129 | /**
|
---|
[33540] | 130 | * Initializes the pool
|
---|
[1] | 131 | *
|
---|
| 132 | * @returns VBox status code.
|
---|
[58122] | 133 | * @param pVM The cross context VM structure.
|
---|
[1] | 134 | */
|
---|
| 135 | int pgmR3PoolInit(PVM pVM)
|
---|
| 136 | {
|
---|
[36960] | 137 | int rc;
|
---|
| 138 |
|
---|
[19141] | 139 | AssertCompile(NIL_PGMPOOL_IDX == 0);
|
---|
[19631] | 140 | /* pPage->cLocked is an unsigned byte. */
|
---|
| 141 | AssertCompile(VMM_MAX_CPU_COUNT <= 255);
|
---|
[19141] | 142 |
|
---|
[1] | 143 | /*
|
---|
| 144 | * Query Pool config.
|
---|
| 145 | */
|
---|
| 146 | PCFGMNODE pCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "/PGM/Pool");
|
---|
[13543] | 147 |
|
---|
[36960] | 148 | /* Default pgm pool size is 1024 pages (4MB). */
|
---|
| 149 | uint16_t cMaxPages = 1024;
|
---|
[33008] | 150 |
|
---|
[36960] | 151 | /* Adjust it up relative to the RAM size, using the nested paging formula. */
|
---|
| 152 | uint64_t cbRam;
|
---|
| 153 | rc = CFGMR3QueryU64Def(CFGMR3GetRoot(pVM), "RamSize", &cbRam, 0); AssertRCReturn(rc, rc);
|
---|
| 154 | uint64_t u64MaxPages = (cbRam >> 9)
|
---|
| 155 | + (cbRam >> 18)
|
---|
| 156 | + (cbRam >> 27)
|
---|
| 157 | + 32 * PAGE_SIZE;
|
---|
| 158 | u64MaxPages >>= PAGE_SHIFT;
|
---|
| 159 | if (u64MaxPages > PGMPOOL_IDX_LAST)
|
---|
| 160 | cMaxPages = PGMPOOL_IDX_LAST;
|
---|
| 161 | else
|
---|
| 162 | cMaxPages = (uint16_t)u64MaxPages;
|
---|
[33008] | 163 |
|
---|
[58126] | 164 | /** @cfgm{/PGM/Pool/MaxPages, uint16_t, \#pages, 16, 0x3fff, F(ram-size)}
|
---|
[13543] | 165 | * The max size of the shadow page pool in pages. The pool will grow dynamically
|
---|
| 166 | * up to this limit.
|
---|
| 167 | */
|
---|
[36960] | 168 | rc = CFGMR3QueryU16Def(pCfg, "MaxPages", &cMaxPages, cMaxPages);
|
---|
[13543] | 169 | AssertLogRelRCReturn(rc, rc);
|
---|
| 170 | AssertLogRelMsgReturn(cMaxPages <= PGMPOOL_IDX_LAST && cMaxPages >= RT_ALIGN(PGMPOOL_IDX_FIRST, 16),
|
---|
| 171 | ("cMaxPages=%u (%#x)\n", cMaxPages, cMaxPages), VERR_INVALID_PARAMETER);
|
---|
[82555] | 172 | AssertCompile(RT_IS_POWER_OF_TWO(PGMPOOL_CFG_MAX_GROW));
|
---|
| 173 | if (cMaxPages < PGMPOOL_IDX_LAST)
|
---|
| 174 | cMaxPages = RT_ALIGN(cMaxPages, PGMPOOL_CFG_MAX_GROW / 2);
|
---|
[36960] | 175 | if (cMaxPages > PGMPOOL_IDX_LAST)
|
---|
| 176 | cMaxPages = PGMPOOL_IDX_LAST;
|
---|
[55174] | 177 | LogRel(("PGM: PGMPool: cMaxPages=%u (u64MaxPages=%llu)\n", cMaxPages, u64MaxPages));
|
---|
[1] | 178 |
|
---|
[63560] | 179 | /** @todo
|
---|
[33163] | 180 | * We need to be much more careful with our allocation strategy here.
|
---|
[36960] | 181 | * For nested paging we don't need pool user info nor extents at all, but
|
---|
| 182 | * we can't check for nested paging here (too early during init to get a
|
---|
| 183 | * confirmation it can be used). The default for large memory configs is a
|
---|
| 184 | * bit large for shadow paging, so I've restricted the extent maximum to 8k
|
---|
| 185 | * (8k * 16 = 128k of hyper heap).
|
---|
[33333] | 186 | *
|
---|
| 187 | * Also when large page support is enabled, we typically don't need so much,
|
---|
| 188 | * although that depends on the availability of 2 MB chunks on the host.
|
---|
[33163] | 189 | */
|
---|
| 190 |
|
---|
[58126] | 191 | /** @cfgm{/PGM/Pool/MaxUsers, uint16_t, \#users, MaxUsers, 32K, MaxPages*2}
|
---|
[13543] | 192 | * The max number of shadow page user tracking records. Each shadow page has
|
---|
| 193 | * zero of other shadow pages (or CR3s) that references it, or uses it if you
|
---|
| 194 | * like. The structures describing these relationships are allocated from a
|
---|
| 195 | * fixed sized pool. This configuration variable defines the pool size.
|
---|
| 196 | */
|
---|
[1] | 197 | uint16_t cMaxUsers;
|
---|
[13543] | 198 | rc = CFGMR3QueryU16Def(pCfg, "MaxUsers", &cMaxUsers, cMaxPages * 2);
|
---|
| 199 | AssertLogRelRCReturn(rc, rc);
|
---|
| 200 | AssertLogRelMsgReturn(cMaxUsers >= cMaxPages && cMaxPages <= _32K,
|
---|
| 201 | ("cMaxUsers=%u (%#x)\n", cMaxUsers, cMaxUsers), VERR_INVALID_PARAMETER);
|
---|
[1] | 202 |
|
---|
[58126] | 203 | /** @cfgm{/PGM/Pool/MaxPhysExts, uint16_t, \#extents, 16, MaxPages * 2, MIN(MaxPages*2\,8192)}
|
---|
[13543] | 204 | * The max number of extents for tracking aliased guest pages.
|
---|
| 205 | */
|
---|
[1] | 206 | uint16_t cMaxPhysExts;
|
---|
[36960] | 207 | rc = CFGMR3QueryU16Def(pCfg, "MaxPhysExts", &cMaxPhysExts,
|
---|
| 208 | RT_MIN(cMaxPages * 2, 8192 /* 8Ki max as this eat too much hyper heap */));
|
---|
[13543] | 209 | AssertLogRelRCReturn(rc, rc);
|
---|
[36960] | 210 | AssertLogRelMsgReturn(cMaxPhysExts >= 16 && cMaxPhysExts <= PGMPOOL_IDX_LAST,
|
---|
[13543] | 211 | ("cMaxPhysExts=%u (%#x)\n", cMaxPhysExts, cMaxPhysExts), VERR_INVALID_PARAMETER);
|
---|
[1] | 212 |
|
---|
[13543] | 213 | /** @cfgm{/PGM/Pool/ChacheEnabled, bool, true}
|
---|
[33192] | 214 | * Enables or disabling caching of shadow pages. Caching means that we will try
|
---|
[13543] | 215 | * reuse shadow pages instead of recreating them everything SyncCR3, SyncPT or
|
---|
| 216 | * SyncPage requests one. When reusing a shadow page, we can save time
|
---|
| 217 | * reconstructing it and it's children.
|
---|
| 218 | */
|
---|
[1] | 219 | bool fCacheEnabled;
|
---|
[13543] | 220 | rc = CFGMR3QueryBoolDef(pCfg, "CacheEnabled", &fCacheEnabled, true);
|
---|
| 221 | AssertLogRelRCReturn(rc, rc);
|
---|
[1] | 222 |
|
---|
[55174] | 223 | LogRel(("PGM: pgmR3PoolInit: cMaxPages=%#RX16 cMaxUsers=%#RX16 cMaxPhysExts=%#RX16 fCacheEnable=%RTbool\n",
|
---|
[33008] | 224 | cMaxPages, cMaxUsers, cMaxPhysExts, fCacheEnabled));
|
---|
[1] | 225 |
|
---|
| 226 | /*
|
---|
| 227 | * Allocate the data structures.
|
---|
| 228 | */
|
---|
[73097] | 229 | uint32_t cb = RT_UOFFSETOF_DYN(PGMPOOL, aPages[cMaxPages]);
|
---|
[1] | 230 | cb += cMaxUsers * sizeof(PGMPOOLUSER);
|
---|
| 231 | cb += cMaxPhysExts * sizeof(PGMPOOLPHYSEXT);
|
---|
| 232 | PPGMPOOL pPool;
|
---|
| 233 | rc = MMR3HyperAllocOnceNoRel(pVM, cb, 0, MM_TAG_PGM_POOL, (void **)&pPool);
|
---|
[13816] | 234 | if (RT_FAILURE(rc))
|
---|
[1] | 235 | return rc;
|
---|
[13060] | 236 | pVM->pgm.s.pPoolR3 = pPool;
|
---|
| 237 | pVM->pgm.s.pPoolR0 = MMHyperR3ToR0(pVM, pPool);
|
---|
[1] | 238 |
|
---|
| 239 | /*
|
---|
| 240 | * Initialize it.
|
---|
| 241 | */
|
---|
[13062] | 242 | pPool->pVMR3 = pVM;
|
---|
[80281] | 243 | pPool->pVMR0 = pVM->pVMR0ForCall;
|
---|
[1] | 244 | pPool->cMaxPages = cMaxPages;
|
---|
| 245 | pPool->cCurPages = PGMPOOL_IDX_FIRST;
|
---|
| 246 | pPool->iUserFreeHead = 0;
|
---|
| 247 | pPool->cMaxUsers = cMaxUsers;
|
---|
| 248 | PPGMPOOLUSER paUsers = (PPGMPOOLUSER)&pPool->aPages[pPool->cMaxPages];
|
---|
[13062] | 249 | pPool->paUsersR3 = paUsers;
|
---|
| 250 | pPool->paUsersR0 = MMHyperR3ToR0(pVM, paUsers);
|
---|
[1] | 251 | for (unsigned i = 0; i < cMaxUsers; i++)
|
---|
| 252 | {
|
---|
| 253 | paUsers[i].iNext = i + 1;
|
---|
| 254 | paUsers[i].iUser = NIL_PGMPOOL_IDX;
|
---|
[9881] | 255 | paUsers[i].iUserTable = 0xfffffffe;
|
---|
[1] | 256 | }
|
---|
| 257 | paUsers[cMaxUsers - 1].iNext = NIL_PGMPOOL_USER_INDEX;
|
---|
| 258 | pPool->iPhysExtFreeHead = 0;
|
---|
| 259 | pPool->cMaxPhysExts = cMaxPhysExts;
|
---|
| 260 | PPGMPOOLPHYSEXT paPhysExts = (PPGMPOOLPHYSEXT)&paUsers[cMaxUsers];
|
---|
[13062] | 261 | pPool->paPhysExtsR3 = paPhysExts;
|
---|
| 262 | pPool->paPhysExtsR0 = MMHyperR3ToR0(pVM, paPhysExts);
|
---|
[1] | 263 | for (unsigned i = 0; i < cMaxPhysExts; i++)
|
---|
| 264 | {
|
---|
| 265 | paPhysExts[i].iNext = i + 1;
|
---|
| 266 | paPhysExts[i].aidx[0] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 267 | paPhysExts[i].apte[0] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[1] | 268 | paPhysExts[i].aidx[1] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 269 | paPhysExts[i].apte[1] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[1] | 270 | paPhysExts[i].aidx[2] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 271 | paPhysExts[i].apte[2] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[1] | 272 | }
|
---|
| 273 | paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
|
---|
[11311] | 274 | for (unsigned i = 0; i < RT_ELEMENTS(pPool->aiHash); i++)
|
---|
[1] | 275 | pPool->aiHash[i] = NIL_PGMPOOL_IDX;
|
---|
| 276 | pPool->iAgeHead = NIL_PGMPOOL_IDX;
|
---|
| 277 | pPool->iAgeTail = NIL_PGMPOOL_IDX;
|
---|
| 278 | pPool->fCacheEnabled = fCacheEnabled;
|
---|
[55493] | 279 |
|
---|
| 280 | pPool->hAccessHandlerType = NIL_PGMPHYSHANDLERTYPE;
|
---|
| 281 | rc = PGMR3HandlerPhysicalTypeRegister(pVM, PGMPHYSHANDLERKIND_WRITE,
|
---|
[55909] | 282 | pgmPoolAccessHandler,
|
---|
[65531] | 283 | NULL, "pgmPoolAccessHandler", "pgmRZPoolAccessPfHandler",
|
---|
| 284 | NULL, "pgmPoolAccessHandler", "pgmRZPoolAccessPfHandler",
|
---|
[55493] | 285 | "Guest Paging Access Handler",
|
---|
| 286 | &pPool->hAccessHandlerType);
|
---|
| 287 | AssertLogRelRCReturn(rc, rc);
|
---|
| 288 |
|
---|
[1] | 289 | pPool->HCPhysTree = 0;
|
---|
| 290 |
|
---|
[45103] | 291 | /*
|
---|
| 292 | * The NIL entry.
|
---|
| 293 | */
|
---|
[1] | 294 | Assert(NIL_PGMPOOL_IDX == 0);
|
---|
[43163] | 295 | pPool->aPages[NIL_PGMPOOL_IDX].enmKind = PGMPOOLKIND_INVALID;
|
---|
| 296 | pPool->aPages[NIL_PGMPOOL_IDX].idx = NIL_PGMPOOL_IDX;
|
---|
[45103] | 297 | pPool->aPages[NIL_PGMPOOL_IDX].Core.Key = NIL_RTHCPHYS;
|
---|
| 298 | pPool->aPages[NIL_PGMPOOL_IDX].GCPhys = NIL_RTGCPHYS;
|
---|
| 299 | pPool->aPages[NIL_PGMPOOL_IDX].iNext = NIL_PGMPOOL_IDX;
|
---|
| 300 | /* pPool->aPages[NIL_PGMPOOL_IDX].cLocked = INT32_MAX; - test this out... */
|
---|
| 301 | pPool->aPages[NIL_PGMPOOL_IDX].pvPageR3 = 0;
|
---|
| 302 | pPool->aPages[NIL_PGMPOOL_IDX].iUserHead = NIL_PGMPOOL_USER_INDEX;
|
---|
| 303 | pPool->aPages[NIL_PGMPOOL_IDX].iModifiedNext = NIL_PGMPOOL_IDX;
|
---|
| 304 | pPool->aPages[NIL_PGMPOOL_IDX].iModifiedPrev = NIL_PGMPOOL_IDX;
|
---|
| 305 | pPool->aPages[NIL_PGMPOOL_IDX].iMonitoredNext = NIL_PGMPOOL_IDX;
|
---|
[52810] | 306 | pPool->aPages[NIL_PGMPOOL_IDX].iMonitoredPrev = NIL_PGMPOOL_IDX;
|
---|
[45103] | 307 | pPool->aPages[NIL_PGMPOOL_IDX].iAgeNext = NIL_PGMPOOL_IDX;
|
---|
| 308 | pPool->aPages[NIL_PGMPOOL_IDX].iAgePrev = NIL_PGMPOOL_IDX;
|
---|
[1] | 309 |
|
---|
[45103] | 310 | Assert(pPool->aPages[NIL_PGMPOOL_IDX].idx == NIL_PGMPOOL_IDX);
|
---|
| 311 | Assert(pPool->aPages[NIL_PGMPOOL_IDX].GCPhys == NIL_RTGCPHYS);
|
---|
| 312 | Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fSeenNonGlobal);
|
---|
| 313 | Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fMonitored);
|
---|
| 314 | Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fCached);
|
---|
| 315 | Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fZeroed);
|
---|
| 316 | Assert(!pPool->aPages[NIL_PGMPOOL_IDX].fReusedFlushPending);
|
---|
[1] | 317 |
|
---|
| 318 | /*
|
---|
| 319 | * Register statistics.
|
---|
| 320 | */
|
---|
[82555] | 321 | STAM_REL_REG(pVM, &pPool->StatGrow, STAMTYPE_PROFILE, "/PGM/Pool/Grow", STAMUNIT_TICKS, "Profiling PGMR0PoolGrow");
|
---|
| 322 | #ifdef VBOX_WITH_STATISTICS
|
---|
[1] | 323 | STAM_REG(pVM, &pPool->cCurPages, STAMTYPE_U16, "/PGM/Pool/cCurPages", STAMUNIT_PAGES, "Current pool size.");
|
---|
| 324 | STAM_REG(pVM, &pPool->cMaxPages, STAMTYPE_U16, "/PGM/Pool/cMaxPages", STAMUNIT_PAGES, "Max pool size.");
|
---|
| 325 | STAM_REG(pVM, &pPool->cUsedPages, STAMTYPE_U16, "/PGM/Pool/cUsedPages", STAMUNIT_PAGES, "The number of pages currently in use.");
|
---|
| 326 | STAM_REG(pVM, &pPool->cUsedPagesHigh, STAMTYPE_U16_RESET, "/PGM/Pool/cUsedPagesHigh", STAMUNIT_PAGES, "The high watermark for cUsedPages.");
|
---|
| 327 | STAM_REG(pVM, &pPool->StatAlloc, STAMTYPE_PROFILE_ADV, "/PGM/Pool/Alloc", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolAlloc.");
|
---|
[23372] | 328 | STAM_REG(pVM, &pPool->StatClearAll, STAMTYPE_PROFILE, "/PGM/Pool/ClearAll", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmR3PoolClearAll.");
|
---|
| 329 | STAM_REG(pVM, &pPool->StatR3Reset, STAMTYPE_PROFILE, "/PGM/Pool/R3Reset", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmR3PoolReset.");
|
---|
[1] | 330 | STAM_REG(pVM, &pPool->StatFlushPage, STAMTYPE_PROFILE, "/PGM/Pool/FlushPage", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolFlushPage.");
|
---|
| 331 | STAM_REG(pVM, &pPool->StatFree, STAMTYPE_PROFILE, "/PGM/Pool/Free", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolFree.");
|
---|
[23011] | 332 | STAM_REG(pVM, &pPool->StatForceFlushPage, STAMTYPE_COUNTER, "/PGM/Pool/FlushForce", STAMUNIT_OCCURENCES, "Counting explicit flushes by PGMPoolFlushPage().");
|
---|
| 333 | STAM_REG(pVM, &pPool->StatForceFlushDirtyPage, STAMTYPE_COUNTER, "/PGM/Pool/FlushForceDirty", STAMUNIT_OCCURENCES, "Counting explicit flushes of dirty pages by PGMPoolFlushPage().");
|
---|
[22775] | 334 | STAM_REG(pVM, &pPool->StatForceFlushReused, STAMTYPE_COUNTER, "/PGM/Pool/FlushReused", STAMUNIT_OCCURENCES, "Counting flushes for reused pages.");
|
---|
[15225] | 335 | STAM_REG(pVM, &pPool->StatZeroPage, STAMTYPE_PROFILE, "/PGM/Pool/ZeroPage", STAMUNIT_TICKS_PER_CALL, "Profiling time spent zeroing pages. Overlaps with Alloc.");
|
---|
[1] | 336 | STAM_REG(pVM, &pPool->cMaxUsers, STAMTYPE_U16, "/PGM/Pool/Track/cMaxUsers", STAMUNIT_COUNT, "Max user tracking records.");
|
---|
| 337 | STAM_REG(pVM, &pPool->cPresent, STAMTYPE_U32, "/PGM/Pool/Track/cPresent", STAMUNIT_COUNT, "Number of present page table entries.");
|
---|
[23100] | 338 | STAM_REG(pVM, &pPool->StatTrackDeref, STAMTYPE_PROFILE, "/PGM/Pool/Track/Deref", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolTrackDeref.");
|
---|
| 339 | STAM_REG(pVM, &pPool->StatTrackFlushGCPhysPT, STAMTYPE_PROFILE, "/PGM/Pool/Track/FlushGCPhysPT", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolTrackFlushGCPhysPT.");
|
---|
| 340 | STAM_REG(pVM, &pPool->StatTrackFlushGCPhysPTs, STAMTYPE_PROFILE, "/PGM/Pool/Track/FlushGCPhysPTs", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolTrackFlushGCPhysPTs.");
|
---|
| 341 | STAM_REG(pVM, &pPool->StatTrackFlushGCPhysPTsSlow, STAMTYPE_PROFILE, "/PGM/Pool/Track/FlushGCPhysPTsSlow", STAMUNIT_TICKS_PER_CALL, "Profiling of pgmPoolTrackFlushGCPhysPTsSlow.");
|
---|
[23121] | 342 | STAM_REG(pVM, &pPool->StatTrackFlushEntry, STAMTYPE_COUNTER, "/PGM/Pool/Track/Entry/Flush", STAMUNIT_COUNT, "Nr of flushed entries.");
|
---|
| 343 | STAM_REG(pVM, &pPool->StatTrackFlushEntryKeep, STAMTYPE_COUNTER, "/PGM/Pool/Track/Entry/Update", STAMUNIT_COUNT, "Nr of updated entries.");
|
---|
[23100] | 344 | STAM_REG(pVM, &pPool->StatTrackFreeUpOneUser, STAMTYPE_COUNTER, "/PGM/Pool/Track/FreeUpOneUser", STAMUNIT_TICKS_PER_CALL, "The number of times we were out of user tracking records.");
|
---|
| 345 | STAM_REG(pVM, &pPool->StatTrackDerefGCPhys, STAMTYPE_PROFILE, "/PGM/Pool/Track/DrefGCPhys", STAMUNIT_TICKS_PER_CALL, "Profiling deref activity related tracking GC physical pages.");
|
---|
[1] | 346 | STAM_REG(pVM, &pPool->StatTrackLinearRamSearches, STAMTYPE_COUNTER, "/PGM/Pool/Track/LinearRamSearches", STAMUNIT_OCCURENCES, "The number of times we had to do linear ram searches.");
|
---|
| 347 | STAM_REG(pVM, &pPool->StamTrackPhysExtAllocFailures,STAMTYPE_COUNTER, "/PGM/Pool/Track/PhysExtAllocFailures", STAMUNIT_OCCURENCES, "The number of failing pgmPoolTrackPhysExtAlloc calls.");
|
---|
[65531] | 348 |
|
---|
| 349 | STAM_REG(pVM, &pPool->StatMonitorPfRZ, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/#PF", STAMUNIT_TICKS_PER_CALL, "Profiling the RC/R0 #PF access handler.");
|
---|
| 350 | STAM_REG(pVM, &pPool->StatMonitorPfRZEmulateInstr, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/EmulateInstr", STAMUNIT_OCCURENCES, "Times we've failed interpreting the instruction.");
|
---|
| 351 | STAM_REG(pVM, &pPool->StatMonitorPfRZFlushPage, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/#PF/FlushPage", STAMUNIT_TICKS_PER_CALL, "Profiling the pgmPoolFlushPage calls made from the RC/R0 access handler.");
|
---|
| 352 | STAM_REG(pVM, &pPool->StatMonitorPfRZFlushReinit, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/FlushReinit", STAMUNIT_OCCURENCES, "Times we've detected a page table reinit.");
|
---|
| 353 | STAM_REG(pVM, &pPool->StatMonitorPfRZFlushModOverflow,STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/FlushOverflow", STAMUNIT_OCCURENCES, "Counting flushes for pages that are modified too often.");
|
---|
| 354 | STAM_REG(pVM, &pPool->StatMonitorPfRZFork, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/Fork", STAMUNIT_OCCURENCES, "Times we've detected fork().");
|
---|
| 355 | STAM_REG(pVM, &pPool->StatMonitorPfRZHandled, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/#PF/Handled", STAMUNIT_TICKS_PER_CALL, "Profiling the RC/R0 #PF access we've handled (except REP STOSD).");
|
---|
| 356 | STAM_REG(pVM, &pPool->StatMonitorPfRZIntrFailPatch1, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/IntrFailPatch1", STAMUNIT_OCCURENCES, "Times we've failed interpreting a patch code instruction.");
|
---|
| 357 | STAM_REG(pVM, &pPool->StatMonitorPfRZIntrFailPatch2, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/IntrFailPatch2", STAMUNIT_OCCURENCES, "Times we've failed interpreting a patch code instruction during flushing.");
|
---|
| 358 | STAM_REG(pVM, &pPool->StatMonitorPfRZRepPrefix, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/#PF/RepPrefix", STAMUNIT_OCCURENCES, "The number of times we've seen rep prefixes we can't handle.");
|
---|
| 359 | STAM_REG(pVM, &pPool->StatMonitorPfRZRepStosd, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/#PF/RepStosd", STAMUNIT_TICKS_PER_CALL, "Profiling the REP STOSD cases we've handled.");
|
---|
| 360 |
|
---|
| 361 | STAM_REG(pVM, &pPool->StatMonitorRZ, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM", STAMUNIT_TICKS_PER_CALL, "Profiling the regular access handler.");
|
---|
| 362 | STAM_REG(pVM, &pPool->StatMonitorRZFlushPage, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/FlushPage", STAMUNIT_TICKS_PER_CALL, "Profiling the pgmPoolFlushPage calls made from the regular access handler.");
|
---|
| 363 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[0], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size01", STAMUNIT_OCCURENCES, "Number of 1 byte accesses.");
|
---|
| 364 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[1], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size02", STAMUNIT_OCCURENCES, "Number of 2 byte accesses.");
|
---|
| 365 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[2], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size03", STAMUNIT_OCCURENCES, "Number of 3 byte accesses.");
|
---|
| 366 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[3], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size04", STAMUNIT_OCCURENCES, "Number of 4 byte accesses.");
|
---|
| 367 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[4], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size05", STAMUNIT_OCCURENCES, "Number of 5 byte accesses.");
|
---|
| 368 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[5], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size06", STAMUNIT_OCCURENCES, "Number of 6 byte accesses.");
|
---|
| 369 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[6], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size07", STAMUNIT_OCCURENCES, "Number of 7 byte accesses.");
|
---|
| 370 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[7], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size08", STAMUNIT_OCCURENCES, "Number of 8 byte accesses.");
|
---|
| 371 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[8], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size09", STAMUNIT_OCCURENCES, "Number of 9 byte accesses.");
|
---|
| 372 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[9], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0a", STAMUNIT_OCCURENCES, "Number of 10 byte accesses.");
|
---|
| 373 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[10], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0b", STAMUNIT_OCCURENCES, "Number of 11 byte accesses.");
|
---|
| 374 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[11], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0c", STAMUNIT_OCCURENCES, "Number of 12 byte accesses.");
|
---|
| 375 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[12], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0d", STAMUNIT_OCCURENCES, "Number of 13 byte accesses.");
|
---|
| 376 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[13], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0e", STAMUNIT_OCCURENCES, "Number of 14 byte accesses.");
|
---|
| 377 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[14], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size0f", STAMUNIT_OCCURENCES, "Number of 15 byte accesses.");
|
---|
| 378 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[15], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size10", STAMUNIT_OCCURENCES, "Number of 16 byte accesses.");
|
---|
| 379 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[16], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size11-2f", STAMUNIT_OCCURENCES, "Number of 17-31 byte accesses.");
|
---|
| 380 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[17], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size20-3f", STAMUNIT_OCCURENCES, "Number of 32-63 byte accesses.");
|
---|
| 381 | STAM_REG(pVM, &pPool->aStatMonitorRZSizes[18], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Size40+", STAMUNIT_OCCURENCES, "Number of 64+ byte accesses.");
|
---|
| 382 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[0], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned1", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 1.");
|
---|
| 383 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[1], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned2", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 2.");
|
---|
| 384 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[2], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned3", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 3.");
|
---|
| 385 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[3], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned4", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 4.");
|
---|
| 386 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[4], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned5", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 5.");
|
---|
| 387 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[5], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned6", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 6.");
|
---|
| 388 | STAM_REG(pVM, &pPool->aStatMonitorRZMisaligned[6], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/RZ/IEM/Misaligned7", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 7.");
|
---|
| 389 |
|
---|
| 390 | STAM_REG(pVM, &pPool->StatMonitorRZFaultPT, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/Fault/PT", STAMUNIT_OCCURENCES, "Nr of handled PT faults.");
|
---|
| 391 | STAM_REG(pVM, &pPool->StatMonitorRZFaultPD, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/Fault/PD", STAMUNIT_OCCURENCES, "Nr of handled PD faults.");
|
---|
| 392 | STAM_REG(pVM, &pPool->StatMonitorRZFaultPDPT, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/Fault/PDPT", STAMUNIT_OCCURENCES, "Nr of handled PDPT faults.");
|
---|
| 393 | STAM_REG(pVM, &pPool->StatMonitorRZFaultPML4, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/RZ/Fault/PML4", STAMUNIT_OCCURENCES, "Nr of handled PML4 faults.");
|
---|
| 394 |
|
---|
| 395 | STAM_REG(pVM, &pPool->StatMonitorR3, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3", STAMUNIT_TICKS_PER_CALL, "Profiling the R3 access handler.");
|
---|
| 396 | STAM_REG(pVM, &pPool->StatMonitorR3FlushPage, STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/FlushPage", STAMUNIT_TICKS_PER_CALL, "Profiling the pgmPoolFlushPage calls made from the R3 access handler.");
|
---|
| 397 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[0], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size01", STAMUNIT_OCCURENCES, "Number of 1 byte accesses (R3).");
|
---|
| 398 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[1], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size02", STAMUNIT_OCCURENCES, "Number of 2 byte accesses (R3).");
|
---|
| 399 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[2], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size03", STAMUNIT_OCCURENCES, "Number of 3 byte accesses (R3).");
|
---|
| 400 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[3], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size04", STAMUNIT_OCCURENCES, "Number of 4 byte accesses (R3).");
|
---|
| 401 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[4], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size05", STAMUNIT_OCCURENCES, "Number of 5 byte accesses (R3).");
|
---|
| 402 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[5], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size06", STAMUNIT_OCCURENCES, "Number of 6 byte accesses (R3).");
|
---|
| 403 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[6], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size07", STAMUNIT_OCCURENCES, "Number of 7 byte accesses (R3).");
|
---|
| 404 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[7], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size08", STAMUNIT_OCCURENCES, "Number of 8 byte accesses (R3).");
|
---|
| 405 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[8], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size09", STAMUNIT_OCCURENCES, "Number of 9 byte accesses (R3).");
|
---|
| 406 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[9], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0a", STAMUNIT_OCCURENCES, "Number of 10 byte accesses (R3).");
|
---|
| 407 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[10], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0b", STAMUNIT_OCCURENCES, "Number of 11 byte accesses (R3).");
|
---|
| 408 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[11], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0c", STAMUNIT_OCCURENCES, "Number of 12 byte accesses (R3).");
|
---|
| 409 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[12], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0d", STAMUNIT_OCCURENCES, "Number of 13 byte accesses (R3).");
|
---|
| 410 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[13], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0e", STAMUNIT_OCCURENCES, "Number of 14 byte accesses (R3).");
|
---|
| 411 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[14], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size0f", STAMUNIT_OCCURENCES, "Number of 15 byte accesses (R3).");
|
---|
| 412 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[15], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size10", STAMUNIT_OCCURENCES, "Number of 16 byte accesses (R3).");
|
---|
| 413 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[16], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size11-2f", STAMUNIT_OCCURENCES, "Number of 17-31 byte accesses.");
|
---|
| 414 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[17], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size20-3f", STAMUNIT_OCCURENCES, "Number of 32-63 byte accesses.");
|
---|
| 415 | STAM_REG(pVM, &pPool->aStatMonitorR3Sizes[18], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Size40+", STAMUNIT_OCCURENCES, "Number of 64+ byte accesses.");
|
---|
| 416 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[0], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned1", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 1 in R3.");
|
---|
| 417 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[1], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned2", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 2 in R3.");
|
---|
| 418 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[2], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned3", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 3 in R3.");
|
---|
| 419 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[3], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned4", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 4 in R3.");
|
---|
| 420 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[4], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned5", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 5 in R3.");
|
---|
| 421 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[5], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned6", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 6 in R3.");
|
---|
| 422 | STAM_REG(pVM, &pPool->aStatMonitorR3Misaligned[6], STAMTYPE_PROFILE, "/PGM/Pool/Monitor/R3/Misaligned7", STAMUNIT_OCCURENCES, "Number of misaligned access with offset 7 in R3.");
|
---|
| 423 |
|
---|
[23121] | 424 | STAM_REG(pVM, &pPool->StatMonitorR3FaultPT, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/R3/Fault/PT", STAMUNIT_OCCURENCES, "Nr of handled PT faults.");
|
---|
| 425 | STAM_REG(pVM, &pPool->StatMonitorR3FaultPD, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/R3/Fault/PD", STAMUNIT_OCCURENCES, "Nr of handled PD faults.");
|
---|
| 426 | STAM_REG(pVM, &pPool->StatMonitorR3FaultPDPT, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/R3/Fault/PDPT", STAMUNIT_OCCURENCES, "Nr of handled PDPT faults.");
|
---|
| 427 | STAM_REG(pVM, &pPool->StatMonitorR3FaultPML4, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/R3/Fault/PML4", STAMUNIT_OCCURENCES, "Nr of handled PML4 faults.");
|
---|
[65531] | 428 |
|
---|
[1] | 429 | STAM_REG(pVM, &pPool->cModifiedPages, STAMTYPE_U16, "/PGM/Pool/Monitor/cModifiedPages", STAMUNIT_PAGES, "The current cModifiedPages value.");
|
---|
| 430 | STAM_REG(pVM, &pPool->cModifiedPagesHigh, STAMTYPE_U16_RESET, "/PGM/Pool/Monitor/cModifiedPagesHigh", STAMUNIT_PAGES, "The high watermark for cModifiedPages.");
|
---|
[22473] | 431 | STAM_REG(pVM, &pPool->StatResetDirtyPages, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/Dirty/Resets", STAMUNIT_OCCURENCES, "Times we've called pgmPoolResetDirtyPages (and there were dirty page).");
|
---|
| 432 | STAM_REG(pVM, &pPool->StatDirtyPage, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/Dirty/Pages", STAMUNIT_OCCURENCES, "Times we've called pgmPoolAddDirtyPage.");
|
---|
[22510] | 433 | STAM_REG(pVM, &pPool->StatDirtyPageDupFlush, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/Dirty/FlushDup", STAMUNIT_OCCURENCES, "Times we've had to flush duplicates for dirty page management.");
|
---|
[22783] | 434 | STAM_REG(pVM, &pPool->StatDirtyPageOverFlowFlush, STAMTYPE_COUNTER, "/PGM/Pool/Monitor/Dirty/FlushOverflow",STAMUNIT_OCCURENCES, "Times we've had to flush because of overflow.");
|
---|
[1] | 435 | STAM_REG(pVM, &pPool->StatCacheHits, STAMTYPE_COUNTER, "/PGM/Pool/Cache/Hits", STAMUNIT_OCCURENCES, "The number of pgmPoolAlloc calls satisfied by the cache.");
|
---|
| 436 | STAM_REG(pVM, &pPool->StatCacheMisses, STAMTYPE_COUNTER, "/PGM/Pool/Cache/Misses", STAMUNIT_OCCURENCES, "The number of pgmPoolAlloc calls not statisfied by the cache.");
|
---|
| 437 | STAM_REG(pVM, &pPool->StatCacheKindMismatches, STAMTYPE_COUNTER, "/PGM/Pool/Cache/KindMismatches", STAMUNIT_OCCURENCES, "The number of shadow page kind mismatches. (Better be low, preferably 0!)");
|
---|
| 438 | STAM_REG(pVM, &pPool->StatCacheFreeUpOne, STAMTYPE_COUNTER, "/PGM/Pool/Cache/FreeUpOne", STAMUNIT_OCCURENCES, "The number of times the cache was asked to free up a page.");
|
---|
| 439 | STAM_REG(pVM, &pPool->StatCacheCacheable, STAMTYPE_COUNTER, "/PGM/Pool/Cache/Cacheable", STAMUNIT_OCCURENCES, "The number of cacheable allocations.");
|
---|
| 440 | STAM_REG(pVM, &pPool->StatCacheUncacheable, STAMTYPE_COUNTER, "/PGM/Pool/Cache/Uncacheable", STAMUNIT_OCCURENCES, "The number of uncacheable allocations.");
|
---|
| 441 | #endif /* VBOX_WITH_STATISTICS */
|
---|
| 442 |
|
---|
[22716] | 443 | #ifdef VBOX_WITH_DEBUGGER
|
---|
| 444 | /*
|
---|
| 445 | * Debugger commands.
|
---|
| 446 | */
|
---|
| 447 | static bool s_fRegisteredCmds = false;
|
---|
| 448 | if (!s_fRegisteredCmds)
|
---|
| 449 | {
|
---|
[25229] | 450 | rc = DBGCRegisterCommands(&g_aCmds[0], RT_ELEMENTS(g_aCmds));
|
---|
[22716] | 451 | if (RT_SUCCESS(rc))
|
---|
| 452 | s_fRegisteredCmds = true;
|
---|
| 453 | }
|
---|
| 454 | #endif
|
---|
| 455 |
|
---|
[1] | 456 | return VINF_SUCCESS;
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 |
|
---|
| 460 | /**
|
---|
| 461 | * Relocate the page pool data.
|
---|
| 462 | *
|
---|
[58122] | 463 | * @param pVM The cross context VM structure.
|
---|
[1] | 464 | */
|
---|
| 465 | void pgmR3PoolRelocate(PVM pVM)
|
---|
| 466 | {
|
---|
[80181] | 467 | RT_NOREF(pVM);
|
---|
[1] | 468 | }
|
---|
| 469 |
|
---|
| 470 |
|
---|
| 471 | /**
|
---|
| 472 | * Grows the shadow page pool.
|
---|
| 473 | *
|
---|
| 474 | * I.e. adds more pages to it, assuming that hasn't reached cMaxPages yet.
|
---|
| 475 | *
|
---|
| 476 | * @returns VBox status code.
|
---|
[58122] | 477 | * @param pVM The cross context VM structure.
|
---|
[82555] | 478 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
[1] | 479 | */
|
---|
[82555] | 480 | VMMR3_INT_DECL(int) PGMR3PoolGrow(PVM pVM, PVMCPU pVCpu)
|
---|
[1] | 481 | {
|
---|
[82555] | 482 | /* This used to do a lot of stuff, but it has moved to ring-0 (PGMR0PoolGrow). */
|
---|
| 483 | AssertReturn(pVM->pgm.s.pPoolR3->cCurPages < pVM->pgm.s.pPoolR3->cMaxPages, VERR_PGM_POOL_MAXED_OUT_ALREADY);
|
---|
[82896] | 484 | int rc = VMMR3CallR0Emt(pVM, pVCpu, VMMR0_DO_PGM_POOL_GROW, 0, NULL);
|
---|
| 485 | if (rc == VINF_SUCCESS)
|
---|
| 486 | return rc;
|
---|
| 487 | LogRel(("PGMR3PoolGrow: rc=%Rrc cCurPages=%#x cMaxPages=%#x\n",
|
---|
| 488 | rc, pVM->pgm.s.pPoolR3->cCurPages, pVM->pgm.s.pPoolR3->cMaxPages));
|
---|
[82897] | 489 | if (pVM->pgm.s.pPoolR3->cCurPages > 128 && RT_FAILURE_NP(rc))
|
---|
| 490 | return -rc;
|
---|
[82896] | 491 | return rc;
|
---|
[1] | 492 | }
|
---|
| 493 |
|
---|
| 494 |
|
---|
| 495 | /**
|
---|
[23374] | 496 | * Rendezvous callback used by pgmR3PoolClearAll that clears all shadow pages
|
---|
| 497 | * and all modification counters.
|
---|
| 498 | *
|
---|
| 499 | * This is only called on one of the EMTs while the other ones are waiting for
|
---|
| 500 | * it to complete this function.
|
---|
| 501 | *
|
---|
| 502 | * @returns VINF_SUCCESS (VBox strict status code).
|
---|
[58122] | 503 | * @param pVM The cross context VM structure.
|
---|
[58123] | 504 | * @param pVCpu The cross context virtual CPU structure of the calling EMT. Unused.
|
---|
[30301] | 505 | * @param fpvFlushRemTlb When not NULL, we'll flush the REM TLB as well.
|
---|
| 506 | * (This is the pvUser, so it has to be void *.)
|
---|
[23374] | 507 | *
|
---|
| 508 | */
|
---|
[58126] | 509 | DECLCALLBACK(VBOXSTRICTRC) pgmR3PoolClearAllRendezvous(PVM pVM, PVMCPU pVCpu, void *fpvFlushRemTlb)
|
---|
[23374] | 510 | {
|
---|
| 511 | PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
|
---|
| 512 | STAM_PROFILE_START(&pPool->StatClearAll, c);
|
---|
[39078] | 513 | NOREF(pVCpu);
|
---|
[23374] | 514 |
|
---|
| 515 | pgmLock(pVM);
|
---|
[58126] | 516 | Log(("pgmR3PoolClearAllRendezvous: cUsedPages=%d fpvFlushRemTlb=%RTbool\n", pPool->cUsedPages, !!fpvFlushRemTlb));
|
---|
[23374] | 517 |
|
---|
| 518 | /*
|
---|
| 519 | * Iterate all the pages until we've encountered all that are in use.
|
---|
[29704] | 520 | * This is a simple but not quite optimal solution.
|
---|
[23374] | 521 | */
|
---|
| 522 | unsigned cModifiedPages = 0; NOREF(cModifiedPages);
|
---|
| 523 | unsigned cLeft = pPool->cUsedPages;
|
---|
[36891] | 524 | uint32_t iPage = pPool->cCurPages;
|
---|
[23374] | 525 | while (--iPage >= PGMPOOL_IDX_FIRST)
|
---|
| 526 | {
|
---|
| 527 | PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
|
---|
| 528 | if (pPage->GCPhys != NIL_RTGCPHYS)
|
---|
| 529 | {
|
---|
| 530 | switch (pPage->enmKind)
|
---|
| 531 | {
|
---|
| 532 | /*
|
---|
[33343] | 533 | * We only care about shadow page tables that reference physical memory
|
---|
[23374] | 534 | */
|
---|
[33343] | 535 | #ifdef PGM_WITH_LARGE_PAGES
|
---|
| 536 | case PGMPOOLKIND_EPT_PD_FOR_PHYS: /* Large pages reference 2 MB of physical memory, so we must clear them. */
|
---|
| 537 | if (pPage->cPresent)
|
---|
| 538 | {
|
---|
| 539 | PX86PDPAE pShwPD = (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pPool->CTX_SUFF(pVM), pVCpu, pPage);
|
---|
| 540 | for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
|
---|
| 541 | {
|
---|
| 542 | if ( pShwPD->a[i].n.u1Present
|
---|
| 543 | && pShwPD->a[i].b.u1Size)
|
---|
| 544 | {
|
---|
| 545 | Assert(!(pShwPD->a[i].u & PGM_PDFLAGS_MAPPING));
|
---|
| 546 | pShwPD->a[i].u = 0;
|
---|
| 547 | Assert(pPage->cPresent);
|
---|
| 548 | pPage->cPresent--;
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 | if (pPage->cPresent == 0)
|
---|
| 552 | pPage->iFirstPresent = NIL_PGMPOOL_PRESENT_INDEX;
|
---|
| 553 | }
|
---|
| 554 | goto default_case;
|
---|
| 555 |
|
---|
| 556 | case PGMPOOLKIND_PAE_PD_PHYS: /* Large pages reference 2 MB of physical memory, so we must clear them. */
|
---|
| 557 | if (pPage->cPresent)
|
---|
| 558 | {
|
---|
| 559 | PEPTPD pShwPD = (PEPTPD)PGMPOOL_PAGE_2_PTR_V2(pPool->CTX_SUFF(pVM), pVCpu, pPage);
|
---|
| 560 | for (unsigned i = 0; i < RT_ELEMENTS(pShwPD->a); i++)
|
---|
| 561 | {
|
---|
| 562 | Assert((pShwPD->a[i].u & UINT64_C(0xfff0000000000f80)) == 0);
|
---|
| 563 | if ( pShwPD->a[i].n.u1Present
|
---|
| 564 | && pShwPD->a[i].b.u1Size)
|
---|
| 565 | {
|
---|
| 566 | Assert(!(pShwPD->a[i].u & PGM_PDFLAGS_MAPPING));
|
---|
| 567 | pShwPD->a[i].u = 0;
|
---|
| 568 | Assert(pPage->cPresent);
|
---|
| 569 | pPage->cPresent--;
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 | if (pPage->cPresent == 0)
|
---|
| 573 | pPage->iFirstPresent = NIL_PGMPOOL_PRESENT_INDEX;
|
---|
| 574 | }
|
---|
| 575 | goto default_case;
|
---|
| 576 | #endif /* PGM_WITH_LARGE_PAGES */
|
---|
| 577 |
|
---|
[23374] | 578 | case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
|
---|
| 579 | case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
|
---|
| 580 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
|
---|
| 581 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
|
---|
| 582 | case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
|
---|
| 583 | case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
|
---|
| 584 | case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
|
---|
| 585 | case PGMPOOLKIND_PAE_PT_FOR_PHYS:
|
---|
[26064] | 586 | case PGMPOOLKIND_EPT_PT_FOR_PHYS:
|
---|
[23374] | 587 | {
|
---|
| 588 | if (pPage->cPresent)
|
---|
| 589 | {
|
---|
[31170] | 590 | void *pvShw = PGMPOOL_PAGE_2_PTR_V2(pPool->CTX_SUFF(pVM), pVCpu, pPage);
|
---|
[23374] | 591 | STAM_PROFILE_START(&pPool->StatZeroPage, z);
|
---|
[27285] | 592 | #if 0
|
---|
| 593 | /* Useful check for leaking references; *very* expensive though. */
|
---|
[27271] | 594 | switch (pPage->enmKind)
|
---|
| 595 | {
|
---|
| 596 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
|
---|
| 597 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
|
---|
| 598 | case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
|
---|
| 599 | case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
|
---|
| 600 | case PGMPOOLKIND_PAE_PT_FOR_PHYS:
|
---|
| 601 | {
|
---|
| 602 | bool fFoundFirst = false;
|
---|
[31775] | 603 | PPGMSHWPTPAE pPT = (PPGMSHWPTPAE)pvShw;
|
---|
[27976] | 604 | for (unsigned ptIndex = 0; ptIndex < RT_ELEMENTS(pPT->a); ptIndex++)
|
---|
[27271] | 605 | {
|
---|
[27976] | 606 | if (pPT->a[ptIndex].u)
|
---|
[27271] | 607 | {
|
---|
[27976] | 608 | if (!fFoundFirst)
|
---|
[27271] | 609 | {
|
---|
| 610 | AssertFatalMsg(pPage->iFirstPresent <= ptIndex, ("ptIndex = %d first present = %d\n", ptIndex, pPage->iFirstPresent));
|
---|
[27976] | 611 | if (pPage->iFirstPresent != ptIndex)
|
---|
[27271] | 612 | Log(("ptIndex = %d first present = %d\n", ptIndex, pPage->iFirstPresent));
|
---|
| 613 | fFoundFirst = true;
|
---|
| 614 | }
|
---|
[31775] | 615 | if (PGMSHWPTEPAE_IS_P(pPT->a[ptIndex]))
|
---|
[27271] | 616 | {
|
---|
[31775] | 617 | pgmPoolTracDerefGCPhysHint(pPool, pPage, PGMSHWPTEPAE_GET_HCPHYS(pPT->a[ptIndex]), NIL_RTGCPHYS);
|
---|
[27976] | 618 | if (pPage->iFirstPresent == ptIndex)
|
---|
[27271] | 619 | pPage->iFirstPresent = NIL_PGMPOOL_PRESENT_INDEX;
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 | }
|
---|
[27272] | 623 | AssertFatalMsg(pPage->cPresent == 0, ("cPresent = %d pPage = %RGv\n", pPage->cPresent, pPage->GCPhys));
|
---|
[27271] | 624 | break;
|
---|
| 625 | }
|
---|
| 626 | default:
|
---|
| 627 | break;
|
---|
| 628 | }
|
---|
| 629 | #endif
|
---|
[23374] | 630 | ASMMemZeroPage(pvShw);
|
---|
| 631 | STAM_PROFILE_STOP(&pPool->StatZeroPage, z);
|
---|
| 632 | pPage->cPresent = 0;
|
---|
| 633 | pPage->iFirstPresent = NIL_PGMPOOL_PRESENT_INDEX;
|
---|
| 634 | }
|
---|
| 635 | }
|
---|
[69046] | 636 | RT_FALL_THRU();
|
---|
[33343] | 637 | #ifdef PGM_WITH_LARGE_PAGES
|
---|
| 638 | default_case:
|
---|
| 639 | #endif
|
---|
[23374] | 640 | default:
|
---|
| 641 | Assert(!pPage->cModifications || ++cModifiedPages);
|
---|
| 642 | Assert(pPage->iModifiedNext == NIL_PGMPOOL_IDX || pPage->cModifications);
|
---|
| 643 | Assert(pPage->iModifiedPrev == NIL_PGMPOOL_IDX || pPage->cModifications);
|
---|
| 644 | pPage->iModifiedNext = NIL_PGMPOOL_IDX;
|
---|
| 645 | pPage->iModifiedPrev = NIL_PGMPOOL_IDX;
|
---|
| 646 | pPage->cModifications = 0;
|
---|
| 647 | break;
|
---|
| 648 |
|
---|
| 649 | }
|
---|
| 650 | if (!--cLeft)
|
---|
| 651 | break;
|
---|
| 652 | }
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | #ifndef DEBUG_michael
|
---|
| 656 | AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
|
---|
| 657 | #endif
|
---|
| 658 | pPool->iModifiedHead = NIL_PGMPOOL_IDX;
|
---|
| 659 | pPool->cModifiedPages = 0;
|
---|
| 660 |
|
---|
| 661 | /*
|
---|
| 662 | * Clear all the GCPhys links and rebuild the phys ext free list.
|
---|
| 663 | */
|
---|
[36891] | 664 | for (PPGMRAMRANGE pRam = pPool->CTX_SUFF(pVM)->pgm.s.CTX_SUFF(pRamRangesX);
|
---|
[23374] | 665 | pRam;
|
---|
| 666 | pRam = pRam->CTX_SUFF(pNext))
|
---|
| 667 | {
|
---|
[25229] | 668 | iPage = pRam->cb >> PAGE_SHIFT;
|
---|
[23374] | 669 | while (iPage-- > 0)
|
---|
[37354] | 670 | PGM_PAGE_SET_TRACKING(pVM, &pRam->aPages[iPage], 0);
|
---|
[23374] | 671 | }
|
---|
| 672 |
|
---|
| 673 | pPool->iPhysExtFreeHead = 0;
|
---|
| 674 | PPGMPOOLPHYSEXT paPhysExts = pPool->CTX_SUFF(paPhysExts);
|
---|
| 675 | const unsigned cMaxPhysExts = pPool->cMaxPhysExts;
|
---|
| 676 | for (unsigned i = 0; i < cMaxPhysExts; i++)
|
---|
| 677 | {
|
---|
| 678 | paPhysExts[i].iNext = i + 1;
|
---|
| 679 | paPhysExts[i].aidx[0] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 680 | paPhysExts[i].apte[0] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[23374] | 681 | paPhysExts[i].aidx[1] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 682 | paPhysExts[i].apte[1] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[23374] | 683 | paPhysExts[i].aidx[2] = NIL_PGMPOOL_IDX;
|
---|
[28639] | 684 | paPhysExts[i].apte[2] = NIL_PGMPOOL_PHYSEXT_IDX_PTE;
|
---|
[23374] | 685 | }
|
---|
| 686 | paPhysExts[cMaxPhysExts - 1].iNext = NIL_PGMPOOL_PHYSEXT_INDEX;
|
---|
| 687 |
|
---|
[29704] | 688 |
|
---|
[23374] | 689 | #ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
|
---|
[29704] | 690 | /* Reset all dirty pages to reactivate the page monitoring. */
|
---|
| 691 | /* Note: we must do this *after* clearing all page references and shadow page tables as there might be stale references to
|
---|
| 692 | * recently removed MMIO ranges around that might otherwise end up asserting in pgmPoolTracDerefGCPhysHint
|
---|
| 693 | */
|
---|
[32362] | 694 | for (unsigned i = 0; i < RT_ELEMENTS(pPool->aDirtyPages); i++)
|
---|
[30013] | 695 | {
|
---|
[77240] | 696 | unsigned idxPage = pPool->aidxDirtyPages[i];
|
---|
| 697 | if (idxPage == NIL_PGMPOOL_IDX)
|
---|
[29888] | 698 | continue;
|
---|
[29887] | 699 |
|
---|
[77240] | 700 | PPGMPOOLPAGE pPage = &pPool->aPages[idxPage];
|
---|
[29888] | 701 | Assert(pPage->idx == idxPage);
|
---|
| 702 | Assert(pPage->iMonitoredNext == NIL_PGMPOOL_IDX && pPage->iMonitoredPrev == NIL_PGMPOOL_IDX);
|
---|
[29887] | 703 |
|
---|
[29888] | 704 | AssertMsg(pPage->fDirty, ("Page %RGp (slot=%d) not marked dirty!", pPage->GCPhys, i));
|
---|
[29887] | 705 |
|
---|
[29888] | 706 | Log(("Reactivate dirty page %RGp\n", pPage->GCPhys));
|
---|
[29887] | 707 |
|
---|
[29888] | 708 | /* First write protect the page again to catch all write accesses. (before checking for changes -> SMP) */
|
---|
[32550] | 709 | int rc = PGMHandlerPhysicalReset(pVM, pPage->GCPhys & PAGE_BASE_GC_MASK);
|
---|
[39034] | 710 | AssertRCSuccess(rc);
|
---|
[29888] | 711 | pPage->fDirty = false;
|
---|
[29887] | 712 |
|
---|
[77240] | 713 | pPool->aidxDirtyPages[i] = NIL_PGMPOOL_IDX;
|
---|
[30013] | 714 | }
|
---|
[29887] | 715 |
|
---|
[23374] | 716 | /* Clear all dirty pages. */
|
---|
| 717 | pPool->idxFreeDirtyPage = 0;
|
---|
| 718 | pPool->cDirtyPages = 0;
|
---|
| 719 | #endif
|
---|
| 720 |
|
---|
| 721 | /* Clear the PGM_SYNC_CLEAR_PGM_POOL flag on all VCPUs to prevent redundant flushes. */
|
---|
| 722 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
[80191] | 723 | pVM->apCpusR3[idCpu]->pgm.s.fSyncFlags &= ~PGM_SYNC_CLEAR_PGM_POOL;
|
---|
[23374] | 724 |
|
---|
[26066] | 725 | /* Flush job finished. */
|
---|
| 726 | VM_FF_CLEAR(pVM, VM_FF_PGM_POOL_FLUSH_PENDING);
|
---|
[23374] | 727 | pPool->cPresent = 0;
|
---|
| 728 | pgmUnlock(pVM);
|
---|
[30301] | 729 |
|
---|
[23374] | 730 | PGM_INVL_ALL_VCPU_TLBS(pVM);
|
---|
[30301] | 731 |
|
---|
[58126] | 732 | if (fpvFlushRemTlb)
|
---|
[30301] | 733 | for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
|
---|
[80191] | 734 | CPUMSetChangedFlags(pVM->apCpusR3[idCpu], CPUM_CHANGED_GLOBAL_TLB_FLUSH);
|
---|
[30301] | 735 |
|
---|
[23374] | 736 | STAM_PROFILE_STOP(&pPool->StatClearAll, c);
|
---|
| 737 | return VINF_SUCCESS;
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 |
|
---|
| 741 | /**
|
---|
| 742 | * Clears the shadow page pool.
|
---|
| 743 | *
|
---|
[58122] | 744 | * @param pVM The cross context VM structure.
|
---|
[30301] | 745 | * @param fFlushRemTlb When set, the REM TLB is scheduled for flushing as
|
---|
| 746 | * well.
|
---|
[23374] | 747 | */
|
---|
[30301] | 748 | void pgmR3PoolClearAll(PVM pVM, bool fFlushRemTlb)
|
---|
[23374] | 749 | {
|
---|
[30301] | 750 | int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3PoolClearAllRendezvous, &fFlushRemTlb);
|
---|
[23374] | 751 | AssertRC(rc);
|
---|
| 752 | }
|
---|
| 753 |
|
---|
[41456] | 754 |
|
---|
[31895] | 755 | /**
|
---|
| 756 | * Protect all pgm pool page table entries to monitor writes
|
---|
| 757 | *
|
---|
[58122] | 758 | * @param pVM The cross context VM structure.
|
---|
[31895] | 759 | *
|
---|
[41456] | 760 | * @remarks ASSUMES the caller will flush all TLBs!!
|
---|
[31996] | 761 | */
|
---|
[31895] | 762 | void pgmR3PoolWriteProtectPages(PVM pVM)
|
---|
| 763 | {
|
---|
[37354] | 764 | PGM_LOCK_ASSERT_OWNER(pVM);
|
---|
[31895] | 765 | PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
|
---|
| 766 | unsigned cLeft = pPool->cUsedPages;
|
---|
| 767 | unsigned iPage = pPool->cCurPages;
|
---|
| 768 | while (--iPage >= PGMPOOL_IDX_FIRST)
|
---|
| 769 | {
|
---|
| 770 | PPGMPOOLPAGE pPage = &pPool->aPages[iPage];
|
---|
| 771 | if ( pPage->GCPhys != NIL_RTGCPHYS
|
---|
| 772 | && pPage->cPresent)
|
---|
| 773 | {
|
---|
| 774 | union
|
---|
| 775 | {
|
---|
| 776 | void *pv;
|
---|
| 777 | PX86PT pPT;
|
---|
| 778 | PPGMSHWPTPAE pPTPae;
|
---|
| 779 | PEPTPT pPTEpt;
|
---|
| 780 | } uShw;
|
---|
[32098] | 781 | uShw.pv = PGMPOOL_PAGE_2_PTR(pVM, pPage);
|
---|
[1] | 782 |
|
---|
[31895] | 783 | switch (pPage->enmKind)
|
---|
| 784 | {
|
---|
| 785 | /*
|
---|
| 786 | * We only care about shadow page tables.
|
---|
| 787 | */
|
---|
| 788 | case PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT:
|
---|
| 789 | case PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB:
|
---|
| 790 | case PGMPOOLKIND_32BIT_PT_FOR_PHYS:
|
---|
[31897] | 791 | for (unsigned iShw = 0; iShw < RT_ELEMENTS(uShw.pPT->a); iShw++)
|
---|
[31895] | 792 | {
|
---|
| 793 | if (uShw.pPT->a[iShw].n.u1Present)
|
---|
| 794 | uShw.pPT->a[iShw].n.u1Write = 0;
|
---|
| 795 | }
|
---|
| 796 | break;
|
---|
| 797 |
|
---|
| 798 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_PT:
|
---|
| 799 | case PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB:
|
---|
| 800 | case PGMPOOLKIND_PAE_PT_FOR_PAE_PT:
|
---|
| 801 | case PGMPOOLKIND_PAE_PT_FOR_PAE_2MB:
|
---|
| 802 | case PGMPOOLKIND_PAE_PT_FOR_PHYS:
|
---|
[31897] | 803 | for (unsigned iShw = 0; iShw < RT_ELEMENTS(uShw.pPTPae->a); iShw++)
|
---|
[31895] | 804 | {
|
---|
[32043] | 805 | if (PGMSHWPTEPAE_IS_P(uShw.pPTPae->a[iShw]))
|
---|
| 806 | PGMSHWPTEPAE_SET_RO(uShw.pPTPae->a[iShw]);
|
---|
[31895] | 807 | }
|
---|
| 808 | break;
|
---|
| 809 |
|
---|
| 810 | case PGMPOOLKIND_EPT_PT_FOR_PHYS:
|
---|
[31897] | 811 | for (unsigned iShw = 0; iShw < RT_ELEMENTS(uShw.pPTEpt->a); iShw++)
|
---|
[31895] | 812 | {
|
---|
| 813 | if (uShw.pPTEpt->a[iShw].n.u1Present)
|
---|
| 814 | uShw.pPTEpt->a[iShw].n.u1Write = 0;
|
---|
| 815 | }
|
---|
| 816 | break;
|
---|
| 817 |
|
---|
| 818 | default:
|
---|
| 819 | break;
|
---|
| 820 | }
|
---|
| 821 | if (!--cLeft)
|
---|
| 822 | break;
|
---|
| 823 | }
|
---|
| 824 | }
|
---|
| 825 | }
|
---|
| 826 |
|
---|
[22716] | 827 | #ifdef VBOX_WITH_DEBUGGER
|
---|
| 828 | /**
|
---|
[44399] | 829 | * @callback_method_impl{FNDBGCCMD, The '.pgmpoolcheck' command.}
|
---|
[22716] | 830 | */
|
---|
[44399] | 831 | static DECLCALLBACK(int) pgmR3PoolCmdCheck(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
[22716] | 832 | {
|
---|
[44399] | 833 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
| 834 | PVM pVM = pUVM->pVM;
|
---|
| 835 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[35696] | 836 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 0);
|
---|
| 837 | uint32_t cErrors = 0;
|
---|
[39078] | 838 | NOREF(paArgs);
|
---|
[22716] | 839 |
|
---|
| 840 | PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
|
---|
| 841 | for (unsigned i = 0; i < pPool->cCurPages; i++)
|
---|
| 842 | {
|
---|
[35696] | 843 | PPGMPOOLPAGE pPage = &pPool->aPages[i];
|
---|
| 844 | bool fFirstMsg = true;
|
---|
[22716] | 845 |
|
---|
[63560] | 846 | /** @todo cover other paging modes too. */
|
---|
[22716] | 847 | if (pPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
|
---|
| 848 | {
|
---|
[31775] | 849 | PPGMSHWPTPAE pShwPT = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
|
---|
[30574] | 850 | {
|
---|
[35696] | 851 | PX86PTPAE pGstPT;
|
---|
| 852 | PGMPAGEMAPLOCK LockPage;
|
---|
[30574] | 853 | int rc = PGMPhysGCPhys2CCPtrReadOnly(pVM, pPage->GCPhys, (const void **)&pGstPT, &LockPage); AssertReleaseRC(rc);
|
---|
[22716] | 854 |
|
---|
[30574] | 855 | /* Check if any PTEs are out of sync. */
|
---|
| 856 | for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
|
---|
[22716] | 857 | {
|
---|
[31775] | 858 | if (PGMSHWPTEPAE_IS_P(pShwPT->a[j]))
|
---|
[22716] | 859 | {
|
---|
[30574] | 860 | RTHCPHYS HCPhys = NIL_RTHCPHYS;
|
---|
[32036] | 861 | rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[j].u & X86_PTE_PAE_PG_MASK, &HCPhys);
|
---|
[31775] | 862 | if ( rc != VINF_SUCCESS
|
---|
| 863 | || PGMSHWPTEPAE_GET_HCPHYS(pShwPT->a[j]) != HCPhys)
|
---|
[22718] | 864 | {
|
---|
[30574] | 865 | if (fFirstMsg)
|
---|
| 866 | {
|
---|
[35696] | 867 | DBGCCmdHlpPrintf(pCmdHlp, "Check pool page %RGp\n", pPage->GCPhys);
|
---|
[30574] | 868 | fFirstMsg = false;
|
---|
| 869 | }
|
---|
[35696] | 870 | DBGCCmdHlpPrintf(pCmdHlp, "Mismatch HCPhys: rc=%Rrc idx=%d guest %RX64 shw=%RX64 vs %RHp\n", rc, j, pGstPT->a[j].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), HCPhys);
|
---|
| 871 | cErrors++;
|
---|
[22718] | 872 | }
|
---|
[31775] | 873 | else if ( PGMSHWPTEPAE_IS_RW(pShwPT->a[j])
|
---|
| 874 | && !pGstPT->a[j].n.u1Write)
|
---|
[22719] | 875 | {
|
---|
[30574] | 876 | if (fFirstMsg)
|
---|
| 877 | {
|
---|
[35696] | 878 | DBGCCmdHlpPrintf(pCmdHlp, "Check pool page %RGp\n", pPage->GCPhys);
|
---|
[30574] | 879 | fFirstMsg = false;
|
---|
| 880 | }
|
---|
[35696] | 881 | DBGCCmdHlpPrintf(pCmdHlp, "Mismatch r/w gst/shw: idx=%d guest %RX64 shw=%RX64 vs %RHp\n", j, pGstPT->a[j].u, PGMSHWPTEPAE_GET_LOG(pShwPT->a[j]), HCPhys);
|
---|
| 882 | cErrors++;
|
---|
[22719] | 883 | }
|
---|
| 884 | }
|
---|
[22717] | 885 | }
|
---|
[30574] | 886 | PGMPhysReleasePageMappingLock(pVM, &LockPage);
|
---|
[22717] | 887 | }
|
---|
| 888 |
|
---|
| 889 | /* Make sure this page table can't be written to from any shadow mapping. */
|
---|
[26261] | 890 | RTHCPHYS HCPhysPT = NIL_RTHCPHYS;
|
---|
[30574] | 891 | int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pPage->GCPhys, &HCPhysPT);
|
---|
[22721] | 892 | AssertMsgRC(rc, ("PGMPhysGCPhys2HCPhys failed with rc=%d for %RGp\n", rc, pPage->GCPhys));
|
---|
[22718] | 893 | if (rc == VINF_SUCCESS)
|
---|
[22717] | 894 | {
|
---|
[22718] | 895 | for (unsigned j = 0; j < pPool->cCurPages; j++)
|
---|
[22717] | 896 | {
|
---|
[22718] | 897 | PPGMPOOLPAGE pTempPage = &pPool->aPages[j];
|
---|
[22717] | 898 |
|
---|
[22718] | 899 | if (pTempPage->enmKind == PGMPOOLKIND_PAE_PT_FOR_PAE_PT)
|
---|
[22717] | 900 | {
|
---|
[31775] | 901 | PPGMSHWPTPAE pShwPT2 = (PPGMSHWPTPAE)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pTempPage);
|
---|
[22718] | 902 |
|
---|
| 903 | for (unsigned k = 0; k < RT_ELEMENTS(pShwPT->a); k++)
|
---|
| 904 | {
|
---|
[31775] | 905 | if ( PGMSHWPTEPAE_IS_P_RW(pShwPT2->a[k])
|
---|
[22716] | 906 | # ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
|
---|
[22718] | 907 | && !pPage->fDirty
|
---|
[22716] | 908 | # endif
|
---|
[31775] | 909 | && PGMSHWPTEPAE_GET_HCPHYS(pShwPT2->a[k]) == HCPhysPT)
|
---|
[22718] | 910 | {
|
---|
| 911 | if (fFirstMsg)
|
---|
| 912 | {
|
---|
[35696] | 913 | DBGCCmdHlpPrintf(pCmdHlp, "Check pool page %RGp\n", pPage->GCPhys);
|
---|
[22718] | 914 | fFirstMsg = false;
|
---|
| 915 | }
|
---|
[35696] | 916 | DBGCCmdHlpPrintf(pCmdHlp, "Mismatch: r/w: GCPhys=%RGp idx=%d shw %RX64 %RX64\n", pTempPage->GCPhys, k, PGMSHWPTEPAE_GET_LOG(pShwPT->a[k]), PGMSHWPTEPAE_GET_LOG(pShwPT2->a[k]));
|
---|
| 917 | cErrors++;
|
---|
[22718] | 918 | }
|
---|
[22717] | 919 | }
|
---|
[22716] | 920 | }
|
---|
| 921 | }
|
---|
| 922 | }
|
---|
| 923 | }
|
---|
| 924 | }
|
---|
[35696] | 925 | if (cErrors > 0)
|
---|
| 926 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Found %#x errors", cErrors);
|
---|
[22716] | 927 | return VINF_SUCCESS;
|
---|
| 928 | }
|
---|
[23374] | 929 | #endif /* VBOX_WITH_DEBUGGER */
|
---|