VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/PGMR0DynMap.cpp@ 14176

Last change on this file since 14176 was 14114, checked in by vboxsync, 16 years ago

#1865: Some structures and external API for the ring-0 dynamic mapping cache (Darwin only). Some of these APIs will be / are shared with RC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: PGMR0DynMap.cpp 14114 2008-11-11 23:37:04Z vboxsync $ */
2/** @file
3 * PGM - Page Manager and Monitor, ring-0 dynamic mapping cache.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
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
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.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Internal Functions *
24*******************************************************************************/
25#include <VBox/pgm.h>
26#include "../PGMInternal.h"
27#include <VBox/vm.h>
28#include <VBox/err.h>
29
30
31/*******************************************************************************
32* Structures and Typedefs *
33*******************************************************************************/
34/**
35 * Ring-0 dynamic mapping cache segment.
36 *
37 * The dynamic mapping cache can be extended with additional segments if the
38 * load is found to be too high. This done the next time a VM is created, under
39 * the protection of the init mutex. The arrays is reallocated and the new
40 * segment is added to the end of these. Nothing is rehashed of course, as the
41 * indexes / addresses must remain unchanged.
42 *
43 * This structure is only modified while owning the init mutex or during module
44 * init / term.
45 */
46typedef struct PGMR0DYNMAPSEG
47{
48 /** Pointer to the next segment. */
49 struct PGMR0DYNMAPSEG *pNext;
50 /** The memory object for the virtual address range that we're abusing. */
51 RTR0MEMOBJ hMemObj;
52 /** The memory object for the page tables. */
53 RTR0MEMOBJ hMemObjPT;
54 /** The start page in the cache. (I.e. index into the arrays.) */
55 uint32_t iPage;
56 /** The number of pages this segment contributes. */
57 uint32_t cPages;
58} PGMR0DYNMAPSEG;
59/** Pointer to a ring-0 dynamic mapping cache segment. */
60typedef PGMR0DYNMAPSEG *PPGMR0DYNMAPSEG;
61
62
63/**
64 * Ring-0 dynamic mapping cache entry.
65 *
66 * This structure tracks
67 */
68typedef struct PGMR0DYNMAPENTRY
69{
70 /** The physical address of the currently mapped page.
71 * This is duplicate for three reasons: cache locality, cache policy of the PT
72 * mappings and sanity checks. */
73 RTHCPHYS HCPhys;
74 /** The number of references. */
75 uint32_t volatile cRefs;
76 /** PTE pointer union. */
77 union PGMR0DYNMAPENTRY_PPTE
78 {
79 /** PTE pointer, 32-bit legacy version. */
80 PX86PTE pLegacy;
81 /** PTE pointer, PAE version. */
82 PX86PTEPAE pPae;
83 } uPte;
84 /** CPUs that haven't invalidated this entry after it's last update. */
85 RTCPUSET PendingSet;
86} PGMR0DYNMAPENTRY;
87/** Pointer to a ring-0 dynamic mapping cache entry. */
88typedef PGMR0DYNMAPENTRY *PPGMR0DYNMAPENTRY;
89
90
91/**
92 * Ring-0 dynamic mapping cache.
93 *
94 * This is initialized during VMMR0 module init but no segments are allocated at
95 * that time. Segments will be added when the first VM is started and removed
96 * again when the last VM shuts down, thus avoid consuming memory while dormant.
97 * At module termination, the remaining bits will be freed up.
98 */
99typedef struct PGMR0DYNMAP
100{
101 /** The usual magic number / eye catcher. */
102 uint32_t u32Magic;
103 /** Spinlock serializing the normal operation of the cache. */
104 RTSPINLOCK hSpinLock;
105 /** Array for tracking and managing the pages. */
106 PPGMR0DYNMAPENTRY paPages;
107 /** The cache size given as a number of pages. */
108 uint32_t cPages;
109 /** Whether it's 32-bit legacy or PAE/AMD64 paging mode. */
110 bool fLegacyMode;
111 /** The current load. */
112 uint32_t cLoad;
113 /** The max load.
114 * This is maintained to get trigger adding of more mapping space. */
115 uint32_t cMaxLoad;
116 /** Initialization / termination lock. */
117 RTSEMFASTMUTEX hInitLock;
118 /** The number of users (protected by hInitLock). */
119 uint32_t cUsers;
120 /** Array containing a copy of the original page tables.
121 * The entries are either X86PTE or X86PTEPAE according to fLegacyMode. */
122 void *pvSavedPTs;
123} PGMR0DYNMAP;
124/** Pointer to the ring-0 dynamic mapping cache */
125typedef PGMR0DYNMAP *PPGMR0DYNMAP;
126
127
128/*******************************************************************************
129* Global Variables *
130*******************************************************************************/
131/** Pointer to the ring-0 dynamic mapping cache. */
132static PPGMR0DYNMAP *g_pPGMR0DynMap;
133
134
135
136
137/**
138 * Initializes the ring-0 dynamic mapping cache.
139 *
140 * @returns VBox status code.
141 */
142VMMR0DECL(int) PGMR0DynMapInit(void)
143{
144 return VINF_SUCCESS;
145}
146
147
148
149/**
150 * Terminates the ring-0 dynamic mapping cache.
151 */
152VMMR0DECL(void) PGMR0DynMapTerm(void)
153{
154}
155
156
157
158/**
159 * Initializes the dynamic mapping cache for a new VM.
160 *
161 * @returns VBox status code.
162 * @param pVM Pointer to the shared VM structure.
163 */
164VMMR0DECL(int) PGMR0DynMapInitVM(PVM pVM)
165{
166 NOREF(pVM);
167 return VINF_SUCCESS;
168}
169
170
171/**
172 * Terminates the dynamic mapping cache usage for a VM.
173 *
174 * @param pVM Pointer to the shared VM structure.
175 */
176VMMR0DECL(void) PGMR0DynMapTermVM(PVM pVM)
177{
178 NOREF(pVM);
179}
180
181
182/**
183 * Signals the start of a new set of mappings.
184 *
185 * Mostly for strictness. PGMDynMapHCPage won't work unless this
186 * API is called.
187 *
188 * @param pVCpu The shared data for the current virtual CPU.
189 */
190VMMDECL(void) PGMDynMapStartAutoSet(PVMCPU pVCpu)
191{
192
193}
194
195
196/**
197 * Releases the dynamic memory mappings made by PGMDynMapHCPage and associates
198 * since the PGMDynMapStartAutoSet call.
199 *
200 * @param pVCpu The shared data for the current virtual CPU.
201 */
202VMMDECL(void) PGMDynMapReleaseAutoSet(PVMCPU pVCpu)
203{
204
205}
206
207
208/**
209 * Migrates the automatic mapping set of the current vCPU if necessary.
210 *
211 * This is called when re-entering the hardware assisted execution mode after a
212 * nip down to ring-3. We run the risk that the CPU might have change and we
213 * will therefore make sure all the cache entries currently in the auto set will
214 * be valid on the new CPU. If the cpu didn't change nothing will happen as all
215 * the entries will have been flagged as invalidated.
216 *
217 * @param pVCpu The shared data for the current virtual CPU.
218 * @thread EMT
219 */
220VMMDECL(void) PGMDynMapMigrateAutoSet(PVMCPU pVCpu)
221{
222
223}
224
225
226/* documented elsewhere - a bit of a mess. */
227VMMDECL(int) PGMDynMapHCPage(PVM pVM, RTHCPHYS HCPhys, void **ppv)
228{
229 AssertMsg(!(HCPhys & PAGE_OFFSET_MASK), ("HCPhys=%RHp\n", HCPhys));
230 AssertMsgFailed(("Not implemented\n"));
231 return VERR_NOT_IMPLEMENTED;
232}
233
234
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette