1 | /* $Id: VMMInternal.h 91244 2021-09-15 10:19:42Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
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 |
|
---|
18 | #ifndef VMM_INCLUDED_SRC_include_VMMInternal_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_VMMInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/sup.h>
|
---|
26 | #include <VBox/vmm/stam.h>
|
---|
27 | #include <VBox/vmm/vmm.h>
|
---|
28 | #include <VBox/param.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <iprt/critsect.h>
|
---|
31 |
|
---|
32 | #if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_RC)
|
---|
33 | # error "Not in VMM! This is an internal header!"
|
---|
34 | #endif
|
---|
35 | #if HC_ARCH_BITS == 32
|
---|
36 | # error "32-bit hosts are no longer supported. Go back to 6.0 or earlier!"
|
---|
37 | #endif
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | /** @defgroup grp_vmm_int Internals
|
---|
42 | * @ingroup grp_vmm
|
---|
43 | * @internal
|
---|
44 | * @{
|
---|
45 | */
|
---|
46 |
|
---|
47 | /** @def VBOX_WITH_RC_RELEASE_LOGGING
|
---|
48 | * Enables RC release logging. */
|
---|
49 | #define VBOX_WITH_RC_RELEASE_LOGGING
|
---|
50 |
|
---|
51 | /** @def VBOX_WITH_R0_LOGGING
|
---|
52 | * Enables Ring-0 logging (non-release).
|
---|
53 | *
|
---|
54 | * Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
|
---|
55 | * so you have to sign up here by adding your defined(DEBUG_<userid>) to the
|
---|
56 | * \#if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
|
---|
57 | */
|
---|
58 | #if defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(DEBUG_ramshankar) || defined(DOXYGEN_RUNNING)
|
---|
59 | # define VBOX_WITH_R0_LOGGING
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | /** @def VBOX_STRICT_VMM_STACK
|
---|
63 | * Enables VMM stack guard pages to catch stack over- and underruns. */
|
---|
64 | #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
|
---|
65 | # define VBOX_STRICT_VMM_STACK
|
---|
66 | #endif
|
---|
67 |
|
---|
68 |
|
---|
69 | /** Number of buffers per logger. */
|
---|
70 | #define VMMLOGGER_BUFFER_COUNT 4
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * R0 logger data (ring-0 only data).
|
---|
74 | */
|
---|
75 | typedef struct VMMR0PERVCPULOGGER
|
---|
76 | {
|
---|
77 | /** Pointer to the logger instance.
|
---|
78 | * The RTLOGGER::u32UserValue1 member is used for flags and magic, while the
|
---|
79 | * RTLOGGER::u64UserValue2 member is the corresponding PGVMCPU value.
|
---|
80 | * RTLOGGER::u64UserValue3 is currently and set to the PGVMCPU value too. */
|
---|
81 | R0PTRTYPE(PRTLOGGER) pLogger;
|
---|
82 | /** Log buffer descriptor.
|
---|
83 | * The buffer is allocated in a common block for all VCpus, see VMMR0PERVM. */
|
---|
84 | RTLOGBUFFERDESC aBufDescs[VMMLOGGER_BUFFER_COUNT];
|
---|
85 | /** Flag indicating whether we've registered the instance already. */
|
---|
86 | bool fRegistered;
|
---|
87 | /** Set if the EMT is waiting on hEventFlushWait. */
|
---|
88 | bool fEmtWaiting;
|
---|
89 | /** Set while we're inside vmmR0LoggerFlushCommon to prevent recursion. */
|
---|
90 | bool fFlushing;
|
---|
91 | bool afPadding[1];
|
---|
92 | /** Number of buffers currently queued for flushing. */
|
---|
93 | uint32_t volatile cFlushing;
|
---|
94 | /** The event semaphore the EMT waits on while the buffer is being flushed. */
|
---|
95 | RTSEMEVENT hEventFlushWait;
|
---|
96 | } VMMR0PERVCPULOGGER;
|
---|
97 | /** Pointer to the R0 logger data (ring-0 only). */
|
---|
98 | typedef VMMR0PERVCPULOGGER *PVMMR0PERVCPULOGGER;
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * R0 logger data shared with ring-3 (per CPU).
|
---|
103 | */
|
---|
104 | typedef struct VMMR3CPULOGGER
|
---|
105 | {
|
---|
106 | /** Buffer info. */
|
---|
107 | struct
|
---|
108 | {
|
---|
109 | /** Auxiliary buffer descriptor. */
|
---|
110 | RTLOGBUFFERAUXDESC AuxDesc;
|
---|
111 | /** Ring-3 mapping of the logging buffer. */
|
---|
112 | R3PTRTYPE(char *) pchBufR3;
|
---|
113 | } aBufs[VMMLOGGER_BUFFER_COUNT];
|
---|
114 | /** The current buffer. */
|
---|
115 | uint32_t idxBuf;
|
---|
116 | /** Number of buffers currently queued for flushing (copy of
|
---|
117 | * VMMR0PERVCPULOGGER::cFlushing). */
|
---|
118 | uint32_t volatile cFlushing;
|
---|
119 | /** The buffer size. */
|
---|
120 | uint32_t cbBuf;
|
---|
121 | /** Number of bytes dropped because the flush context didn't allow waiting. */
|
---|
122 | uint32_t cbDropped;
|
---|
123 | STAMCOUNTER StatFlushes;
|
---|
124 | STAMCOUNTER StatCannotBlock;
|
---|
125 | STAMPROFILE StatWait;
|
---|
126 | STAMPROFILE StatRaces;
|
---|
127 | STAMCOUNTER StatRacesToR0;
|
---|
128 | } VMMR3CPULOGGER;
|
---|
129 | /** Pointer to r0 logger data shared with ring-3. */
|
---|
130 | typedef VMMR3CPULOGGER *PVMMR3CPULOGGER;
|
---|
131 |
|
---|
132 | /** @name Logger indexes for VMMR0PERVCPU::u.aLoggers and VMMCPU::u.aLoggers.
|
---|
133 | * @{ */
|
---|
134 | #define VMMLOGGER_IDX_REGULAR 0
|
---|
135 | #define VMMLOGGER_IDX_RELEASE 1
|
---|
136 | #define VMMLOGGER_IDX_MAX 2
|
---|
137 | /** @} */
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Jump buffer for the setjmp/longjmp like constructs used to
|
---|
142 | * quickly 'call' back into Ring-3.
|
---|
143 | */
|
---|
144 | typedef struct VMMR0JMPBUF
|
---|
145 | {
|
---|
146 | /** Traditional jmp_buf stuff
|
---|
147 | * @{ */
|
---|
148 | #if HC_ARCH_BITS == 32
|
---|
149 | uint32_t ebx;
|
---|
150 | uint32_t esi;
|
---|
151 | uint32_t edi;
|
---|
152 | uint32_t ebp;
|
---|
153 | uint32_t esp;
|
---|
154 | uint32_t eip;
|
---|
155 | uint32_t eflags;
|
---|
156 | #endif
|
---|
157 | #if HC_ARCH_BITS == 64
|
---|
158 | uint64_t rbx;
|
---|
159 | # ifdef RT_OS_WINDOWS
|
---|
160 | uint64_t rsi;
|
---|
161 | uint64_t rdi;
|
---|
162 | # endif
|
---|
163 | uint64_t rbp;
|
---|
164 | uint64_t r12;
|
---|
165 | uint64_t r13;
|
---|
166 | uint64_t r14;
|
---|
167 | uint64_t r15;
|
---|
168 | uint64_t rsp;
|
---|
169 | uint64_t rip;
|
---|
170 | # ifdef RT_OS_WINDOWS
|
---|
171 | uint128_t xmm6;
|
---|
172 | uint128_t xmm7;
|
---|
173 | uint128_t xmm8;
|
---|
174 | uint128_t xmm9;
|
---|
175 | uint128_t xmm10;
|
---|
176 | uint128_t xmm11;
|
---|
177 | uint128_t xmm12;
|
---|
178 | uint128_t xmm13;
|
---|
179 | uint128_t xmm14;
|
---|
180 | uint128_t xmm15;
|
---|
181 | # endif
|
---|
182 | uint64_t rflags;
|
---|
183 | #endif
|
---|
184 | /** @} */
|
---|
185 |
|
---|
186 | /** Flag that indicates that we've done a ring-3 call. */
|
---|
187 | bool fInRing3Call;
|
---|
188 | /** The number of bytes we've saved. */
|
---|
189 | uint32_t cbSavedStack;
|
---|
190 | /** Pointer to the buffer used to save the stack.
|
---|
191 | * This is assumed to be 8KB. */
|
---|
192 | RTR0PTR pvSavedStack;
|
---|
193 | /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
|
---|
194 | RTHCUINTREG SpCheck;
|
---|
195 | /** The esp we should resume execution with after the restore. */
|
---|
196 | RTHCUINTREG SpResume;
|
---|
197 | /** ESP/RSP at the time of the jump to ring 3. */
|
---|
198 | RTHCUINTREG SavedEsp;
|
---|
199 | /** EBP/RBP at the time of the jump to ring 3. */
|
---|
200 | RTHCUINTREG SavedEbp;
|
---|
201 | /** EIP/RIP within vmmR0CallRing3LongJmp for assisting unwinding. */
|
---|
202 | RTHCUINTREG SavedEipForUnwind;
|
---|
203 | /** Unwind: The vmmR0CallRing3SetJmp return address value. */
|
---|
204 | RTHCUINTREG UnwindRetPcValue;
|
---|
205 | /** Unwind: The vmmR0CallRing3SetJmp return address stack location. */
|
---|
206 | RTHCUINTREG UnwindRetPcLocation;
|
---|
207 |
|
---|
208 | /** The function last being executed here. */
|
---|
209 | RTHCUINTREG pfn;
|
---|
210 | /** The first argument to the function. */
|
---|
211 | RTHCUINTREG pvUser1;
|
---|
212 | /** The second argument to the function. */
|
---|
213 | RTHCUINTREG pvUser2;
|
---|
214 |
|
---|
215 | #if HC_ARCH_BITS == 32
|
---|
216 | /** Alignment padding. */
|
---|
217 | uint32_t uPadding;
|
---|
218 | #endif
|
---|
219 |
|
---|
220 | /** Stats: Max amount of stack used. */
|
---|
221 | uint32_t cbUsedMax;
|
---|
222 | /** Stats: Average stack usage. (Avg = cbUsedTotal / cUsedTotal) */
|
---|
223 | uint32_t cbUsedAvg;
|
---|
224 | /** Stats: Total amount of stack used. */
|
---|
225 | uint64_t cbUsedTotal;
|
---|
226 | /** Stats: Number of stack usages. */
|
---|
227 | uint64_t cUsedTotal;
|
---|
228 | } VMMR0JMPBUF;
|
---|
229 | /** Pointer to a ring-0 jump buffer. */
|
---|
230 | typedef VMMR0JMPBUF *PVMMR0JMPBUF;
|
---|
231 |
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Log flusher job.
|
---|
235 | *
|
---|
236 | * There is a ring buffer of these in ring-0 (VMMR0PERVM::aLogFlushRing) and a
|
---|
237 | * copy of the current one in the shared VM structure (VMM::LogFlusherItem).
|
---|
238 | */
|
---|
239 | typedef union VMMLOGFLUSHERENTRY
|
---|
240 | {
|
---|
241 | struct
|
---|
242 | {
|
---|
243 | /** The virtual CPU ID. */
|
---|
244 | uint32_t idCpu : 16;
|
---|
245 | /** The logger: 0 for release, 1 for debug. */
|
---|
246 | uint32_t idxLogger : 8;
|
---|
247 | /** The buffer to be flushed. */
|
---|
248 | uint32_t idxBuffer : 7;
|
---|
249 | /** Set by the flusher thread once it fetched the entry and started
|
---|
250 | * processing it. */
|
---|
251 | uint32_t fProcessing : 1;
|
---|
252 | } s;
|
---|
253 | uint32_t u32;
|
---|
254 | } VMMLOGFLUSHERENTRY;
|
---|
255 |
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * VMM Data (part of VM)
|
---|
259 | */
|
---|
260 | typedef struct VMM
|
---|
261 | {
|
---|
262 | /** Whether we should use the periodic preemption timers. */
|
---|
263 | bool fUsePeriodicPreemptionTimers;
|
---|
264 | /** Alignment padding. */
|
---|
265 | bool afPadding0[7];
|
---|
266 |
|
---|
267 | #if 0 /* pointless when timers doesn't run on EMT */
|
---|
268 | /** The EMT yield timer. */
|
---|
269 | TMTIMERHANDLE hYieldTimer;
|
---|
270 | /** The period to the next timeout when suspended or stopped.
|
---|
271 | * This is 0 when running. */
|
---|
272 | uint32_t cYieldResumeMillies;
|
---|
273 | /** The EMT yield timer interval (milliseconds). */
|
---|
274 | uint32_t cYieldEveryMillies;
|
---|
275 | /** The timestamp of the previous yield. (nano) */
|
---|
276 | uint64_t u64LastYield;
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | /** @name EMT Rendezvous
|
---|
280 | * @{ */
|
---|
281 | /** Semaphore to wait on upon entering ordered execution. */
|
---|
282 | R3PTRTYPE(PRTSEMEVENT) pahEvtRendezvousEnterOrdered;
|
---|
283 | /** Semaphore to wait on upon entering for one-by-one execution. */
|
---|
284 | RTSEMEVENT hEvtRendezvousEnterOneByOne;
|
---|
285 | /** Semaphore to wait on upon entering for all-at-once execution. */
|
---|
286 | RTSEMEVENTMULTI hEvtMulRendezvousEnterAllAtOnce;
|
---|
287 | /** Semaphore to wait on when done. */
|
---|
288 | RTSEMEVENTMULTI hEvtMulRendezvousDone;
|
---|
289 | /** Semaphore the VMMR3EmtRendezvous caller waits on at the end. */
|
---|
290 | RTSEMEVENT hEvtRendezvousDoneCaller;
|
---|
291 | /** Semaphore to wait on upon recursing. */
|
---|
292 | RTSEMEVENTMULTI hEvtMulRendezvousRecursionPush;
|
---|
293 | /** Semaphore to wait on after done with recursion (caller restoring state). */
|
---|
294 | RTSEMEVENTMULTI hEvtMulRendezvousRecursionPop;
|
---|
295 | /** Semaphore the initiator waits on while the EMTs are getting into position
|
---|
296 | * on hEvtMulRendezvousRecursionPush. */
|
---|
297 | RTSEMEVENT hEvtRendezvousRecursionPushCaller;
|
---|
298 | /** Semaphore the initiator waits on while the EMTs sitting on
|
---|
299 | * hEvtMulRendezvousRecursionPop wakes up and leave. */
|
---|
300 | RTSEMEVENT hEvtRendezvousRecursionPopCaller;
|
---|
301 | /** Callback. */
|
---|
302 | R3PTRTYPE(PFNVMMEMTRENDEZVOUS) volatile pfnRendezvous;
|
---|
303 | /** The user argument for the callback. */
|
---|
304 | RTR3PTR volatile pvRendezvousUser;
|
---|
305 | /** Flags. */
|
---|
306 | volatile uint32_t fRendezvousFlags;
|
---|
307 | /** The number of EMTs that has entered. */
|
---|
308 | volatile uint32_t cRendezvousEmtsEntered;
|
---|
309 | /** The number of EMTs that has done their job. */
|
---|
310 | volatile uint32_t cRendezvousEmtsDone;
|
---|
311 | /** The number of EMTs that has returned. */
|
---|
312 | volatile uint32_t cRendezvousEmtsReturned;
|
---|
313 | /** The status code. */
|
---|
314 | volatile int32_t i32RendezvousStatus;
|
---|
315 | /** Spin lock. */
|
---|
316 | volatile uint32_t u32RendezvousLock;
|
---|
317 | /** The recursion depth. */
|
---|
318 | volatile uint32_t cRendezvousRecursions;
|
---|
319 | /** The number of EMTs that have entered the recursion routine. */
|
---|
320 | volatile uint32_t cRendezvousEmtsRecursingPush;
|
---|
321 | /** The number of EMTs that have leaft the recursion routine. */
|
---|
322 | volatile uint32_t cRendezvousEmtsRecursingPop;
|
---|
323 | /** Triggers rendezvous recursion in the other threads. */
|
---|
324 | volatile bool fRendezvousRecursion;
|
---|
325 |
|
---|
326 | /** @} */
|
---|
327 |
|
---|
328 | /** RTThreadPreemptIsPendingTrusty() result, set by vmmR0InitVM() for
|
---|
329 | * release logging purposes. */
|
---|
330 | bool fIsPreemptPendingApiTrusty : 1;
|
---|
331 | /** The RTThreadPreemptIsPossible() result, set by vmmR0InitVM() for
|
---|
332 | * release logging purposes. */
|
---|
333 | bool fIsPreemptPossible : 1;
|
---|
334 | /** Set if ring-0 uses context hooks. */
|
---|
335 | bool fIsUsingContextHooks : 1;
|
---|
336 |
|
---|
337 | bool afAlignment2[2]; /**< Alignment padding. */
|
---|
338 |
|
---|
339 | /** Buffer for storing the standard assertion message for a ring-0 assertion.
|
---|
340 | * Used for saving the assertion message text for the release log and guru
|
---|
341 | * meditation dump. */
|
---|
342 | char szRing0AssertMsg1[512];
|
---|
343 | /** Buffer for storing the custom message for a ring-0 assertion. */
|
---|
344 | char szRing0AssertMsg2[256];
|
---|
345 |
|
---|
346 | /** @name Logging
|
---|
347 | * @{ */
|
---|
348 | /** Used when setting up ring-0 logger. */
|
---|
349 | uint64_t nsProgramStart;
|
---|
350 | /** Log flusher thread. */
|
---|
351 | RTTHREAD hLogFlusherThread;
|
---|
352 | /** Copy of the current work log flusher work item. */
|
---|
353 | VMMLOGFLUSHERENTRY volatile LogFlusherItem;
|
---|
354 | STAMCOUNTER StatLogFlusherFlushes;
|
---|
355 | STAMCOUNTER StatLogFlusherNoWakeUp;
|
---|
356 | /** @} */
|
---|
357 |
|
---|
358 | /** Number of VMMR0_DO_HM_RUN or VMMR0_DO_NEM_RUN calls. */
|
---|
359 | STAMCOUNTER StatRunGC;
|
---|
360 |
|
---|
361 | /** Statistics for each of the RC/R0 return codes.
|
---|
362 | * @{ */
|
---|
363 | STAMCOUNTER StatRZRetNormal;
|
---|
364 | STAMCOUNTER StatRZRetInterrupt;
|
---|
365 | STAMCOUNTER StatRZRetInterruptHyper;
|
---|
366 | STAMCOUNTER StatRZRetGuestTrap;
|
---|
367 | STAMCOUNTER StatRZRetRingSwitch;
|
---|
368 | STAMCOUNTER StatRZRetRingSwitchInt;
|
---|
369 | STAMCOUNTER StatRZRetStaleSelector;
|
---|
370 | STAMCOUNTER StatRZRetIRETTrap;
|
---|
371 | STAMCOUNTER StatRZRetEmulate;
|
---|
372 | STAMCOUNTER StatRZRetPatchEmulate;
|
---|
373 | STAMCOUNTER StatRZRetIORead;
|
---|
374 | STAMCOUNTER StatRZRetIOWrite;
|
---|
375 | STAMCOUNTER StatRZRetIOCommitWrite;
|
---|
376 | STAMCOUNTER StatRZRetMMIORead;
|
---|
377 | STAMCOUNTER StatRZRetMMIOWrite;
|
---|
378 | STAMCOUNTER StatRZRetMMIOCommitWrite;
|
---|
379 | STAMCOUNTER StatRZRetMMIOPatchRead;
|
---|
380 | STAMCOUNTER StatRZRetMMIOPatchWrite;
|
---|
381 | STAMCOUNTER StatRZRetMMIOReadWrite;
|
---|
382 | STAMCOUNTER StatRZRetMSRRead;
|
---|
383 | STAMCOUNTER StatRZRetMSRWrite;
|
---|
384 | STAMCOUNTER StatRZRetLDTFault;
|
---|
385 | STAMCOUNTER StatRZRetGDTFault;
|
---|
386 | STAMCOUNTER StatRZRetIDTFault;
|
---|
387 | STAMCOUNTER StatRZRetTSSFault;
|
---|
388 | STAMCOUNTER StatRZRetCSAMTask;
|
---|
389 | STAMCOUNTER StatRZRetSyncCR3;
|
---|
390 | STAMCOUNTER StatRZRetMisc;
|
---|
391 | STAMCOUNTER StatRZRetPatchInt3;
|
---|
392 | STAMCOUNTER StatRZRetPatchPF;
|
---|
393 | STAMCOUNTER StatRZRetPatchGP;
|
---|
394 | STAMCOUNTER StatRZRetPatchIretIRQ;
|
---|
395 | STAMCOUNTER StatRZRetRescheduleREM;
|
---|
396 | STAMCOUNTER StatRZRetToR3Total;
|
---|
397 | STAMCOUNTER StatRZRetToR3FF;
|
---|
398 | STAMCOUNTER StatRZRetToR3Unknown;
|
---|
399 | STAMCOUNTER StatRZRetToR3TMVirt;
|
---|
400 | STAMCOUNTER StatRZRetToR3HandyPages;
|
---|
401 | STAMCOUNTER StatRZRetToR3PDMQueues;
|
---|
402 | STAMCOUNTER StatRZRetToR3Rendezvous;
|
---|
403 | STAMCOUNTER StatRZRetToR3Timer;
|
---|
404 | STAMCOUNTER StatRZRetToR3DMA;
|
---|
405 | STAMCOUNTER StatRZRetToR3CritSect;
|
---|
406 | STAMCOUNTER StatRZRetToR3Iem;
|
---|
407 | STAMCOUNTER StatRZRetToR3Iom;
|
---|
408 | STAMCOUNTER StatRZRetTimerPending;
|
---|
409 | STAMCOUNTER StatRZRetInterruptPending;
|
---|
410 | STAMCOUNTER StatRZRetCallRing3;
|
---|
411 | STAMCOUNTER StatRZRetPATMDuplicateFn;
|
---|
412 | STAMCOUNTER StatRZRetPGMChangeMode;
|
---|
413 | STAMCOUNTER StatRZRetPendingRequest;
|
---|
414 | STAMCOUNTER StatRZRetPGMFlushPending;
|
---|
415 | STAMCOUNTER StatRZRetPatchTPR;
|
---|
416 | STAMCOUNTER StatRZCallPGMMapChunk;
|
---|
417 | STAMCOUNTER StatRZCallPGMAllocHandy;
|
---|
418 | /** @} */
|
---|
419 | } VMM;
|
---|
420 | /** Pointer to VMM. */
|
---|
421 | typedef VMM *PVMM;
|
---|
422 |
|
---|
423 |
|
---|
424 | /**
|
---|
425 | * VMMCPU Data (part of VMCPU)
|
---|
426 | */
|
---|
427 | typedef struct VMMCPU
|
---|
428 | {
|
---|
429 | /** The last RC/R0 return code. */
|
---|
430 | int32_t iLastGZRc;
|
---|
431 | /** Alignment padding. */
|
---|
432 | uint32_t u32Padding0;
|
---|
433 |
|
---|
434 | /** VMM stack, pointer to the top of the stack in R3.
|
---|
435 | * Stack is allocated from the hypervisor heap and is page aligned
|
---|
436 | * and always writable in RC. */
|
---|
437 | R3PTRTYPE(uint8_t *) pbEMTStackR3;
|
---|
438 |
|
---|
439 | /** @name Rendezvous
|
---|
440 | * @{ */
|
---|
441 | /** Whether the EMT is executing a rendezvous right now. For detecting
|
---|
442 | * attempts at recursive rendezvous. */
|
---|
443 | bool volatile fInRendezvous;
|
---|
444 | bool afPadding1[2];
|
---|
445 | /** @} */
|
---|
446 |
|
---|
447 | /** Whether we can HLT in VMMR0 rather than having to return to EM.
|
---|
448 | * Updated by vmR3SetHaltMethodU(). */
|
---|
449 | bool fMayHaltInRing0;
|
---|
450 | /** The minimum delta for which we can HLT in ring-0 for.
|
---|
451 | * The deadlines we can calculate are from TM, so, if it's too close
|
---|
452 | * we should just return to ring-3 and run the timer wheel, no point
|
---|
453 | * in spinning in ring-0.
|
---|
454 | * Updated by vmR3SetHaltMethodU(). */
|
---|
455 | uint32_t cNsSpinBlockThreshold;
|
---|
456 | /** Number of ring-0 halts (used for depreciating following values). */
|
---|
457 | uint32_t cR0Halts;
|
---|
458 | /** Number of ring-0 halts succeeding (VINF_SUCCESS) recently. */
|
---|
459 | uint32_t cR0HaltsSucceeded;
|
---|
460 | /** Number of ring-0 halts failing (VINF_EM_HALT) recently. */
|
---|
461 | uint32_t cR0HaltsToRing3;
|
---|
462 | /** Padding */
|
---|
463 | uint32_t u32Padding2;
|
---|
464 |
|
---|
465 | /** @name Raw-mode context tracing data.
|
---|
466 | * @{ */
|
---|
467 | SUPDRVTRACERUSRCTX TracerCtx;
|
---|
468 | /** @} */
|
---|
469 |
|
---|
470 | /** Alignment padding, making sure u64CallRing3Arg and CallRing3JmpBufR0 are nicely aligned. */
|
---|
471 | uint32_t au32Padding3[1];
|
---|
472 |
|
---|
473 | /** @name Call Ring-3
|
---|
474 | * Formerly known as host calls.
|
---|
475 | * @{ */
|
---|
476 | /** The disable counter. */
|
---|
477 | uint32_t cCallRing3Disabled;
|
---|
478 | /** The pending operation. */
|
---|
479 | VMMCALLRING3 enmCallRing3Operation;
|
---|
480 | /** The result of the last operation. */
|
---|
481 | int32_t rcCallRing3;
|
---|
482 | /** The argument to the operation. */
|
---|
483 | uint64_t u64CallRing3Arg;
|
---|
484 | /** The Ring-0 notification callback. */
|
---|
485 | R0PTRTYPE(PFNVMMR0CALLRING3NOTIFICATION) pfnCallRing3CallbackR0;
|
---|
486 | /** The Ring-0 notification callback user argument. */
|
---|
487 | R0PTRTYPE(void *) pvCallRing3CallbackUserR0;
|
---|
488 | /** The Ring-0 jmp buffer.
|
---|
489 | * @remarks The size of this type isn't stable in assembly, so don't put
|
---|
490 | * anything that needs to be accessed from assembly after it. */
|
---|
491 | VMMR0JMPBUF CallRing3JmpBufR0;
|
---|
492 | /** @} */
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * Loggers.
|
---|
496 | */
|
---|
497 | union
|
---|
498 | {
|
---|
499 | struct
|
---|
500 | {
|
---|
501 | /** The R0 logger data shared with ring-3. */
|
---|
502 | VMMR3CPULOGGER Logger;
|
---|
503 | /** The R0 release logger data shared with ring-3. */
|
---|
504 | VMMR3CPULOGGER RelLogger;
|
---|
505 | } s;
|
---|
506 | /** Array view. */
|
---|
507 | VMMR3CPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
|
---|
508 | } u;
|
---|
509 |
|
---|
510 | STAMPROFILE StatR0HaltBlock;
|
---|
511 | STAMPROFILE StatR0HaltBlockOnTime;
|
---|
512 | STAMPROFILE StatR0HaltBlockOverslept;
|
---|
513 | STAMPROFILE StatR0HaltBlockInsomnia;
|
---|
514 | STAMCOUNTER StatR0HaltExec;
|
---|
515 | STAMCOUNTER StatR0HaltExecFromBlock;
|
---|
516 | STAMCOUNTER StatR0HaltExecFromSpin;
|
---|
517 | STAMCOUNTER StatR0HaltToR3;
|
---|
518 | STAMCOUNTER StatR0HaltToR3FromSpin;
|
---|
519 | STAMCOUNTER StatR0HaltToR3Other;
|
---|
520 | STAMCOUNTER StatR0HaltToR3PendingFF;
|
---|
521 | STAMCOUNTER StatR0HaltToR3SmallDelta;
|
---|
522 | STAMCOUNTER StatR0HaltToR3PostNoInt;
|
---|
523 | STAMCOUNTER StatR0HaltToR3PostPendingFF;
|
---|
524 | } VMMCPU;
|
---|
525 | AssertCompileMemberAlignment(VMMCPU, TracerCtx, 8);
|
---|
526 | AssertCompile( RTASSERT_OFFSET_OF(VMMCPU, u.s.Logger)
|
---|
527 | == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_REGULAR);
|
---|
528 | AssertCompile(RTASSERT_OFFSET_OF(VMMCPU, u.s.RelLogger)
|
---|
529 | == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_RELEASE);
|
---|
530 |
|
---|
531 | /** Pointer to VMMCPU. */
|
---|
532 | typedef VMMCPU *PVMMCPU;
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * VMM per-VCpu ring-0 only instance data.
|
---|
536 | */
|
---|
537 | typedef struct VMMR0PERVCPU
|
---|
538 | {
|
---|
539 | /** The EMT hash table index. */
|
---|
540 | uint16_t idxEmtHash;
|
---|
541 | /** Flag indicating whether we've disabled flushing (world switch) or not. */
|
---|
542 | bool fLogFlushingDisabled;
|
---|
543 | bool afPadding1[5];
|
---|
544 | /** Pointer to the VMMR0EntryFast preemption state structure.
|
---|
545 | * This is used to temporarily restore preemption before blocking. */
|
---|
546 | R0PTRTYPE(PRTTHREADPREEMPTSTATE) pPreemptState;
|
---|
547 | /** Thread context switching hook (ring-0). */
|
---|
548 | RTTHREADCTXHOOK hCtxHook;
|
---|
549 |
|
---|
550 | /** @name Arguments passed by VMMR0EntryEx via vmmR0CallRing3SetJmpEx.
|
---|
551 | * @note Cannot be put on the stack as the location may change and upset the
|
---|
552 | * validation of resume-after-ring-3-call logic.
|
---|
553 | * @{ */
|
---|
554 | PGVM pGVM;
|
---|
555 | VMCPUID idCpu;
|
---|
556 | VMMR0OPERATION enmOperation;
|
---|
557 | PSUPVMMR0REQHDR pReq;
|
---|
558 | uint64_t u64Arg;
|
---|
559 | PSUPDRVSESSION pSession;
|
---|
560 | /** @} */
|
---|
561 |
|
---|
562 | /**
|
---|
563 | * Loggers
|
---|
564 | */
|
---|
565 | union
|
---|
566 | {
|
---|
567 | struct
|
---|
568 | {
|
---|
569 | /** The R0 logger data. */
|
---|
570 | VMMR0PERVCPULOGGER Logger;
|
---|
571 | /** The R0 release logger data. */
|
---|
572 | VMMR0PERVCPULOGGER RelLogger;
|
---|
573 | } s;
|
---|
574 | /** Array view. */
|
---|
575 | VMMR0PERVCPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
|
---|
576 | } u;
|
---|
577 | } VMMR0PERVCPU;
|
---|
578 | AssertCompile( RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.Logger)
|
---|
579 | == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_REGULAR);
|
---|
580 | AssertCompile(RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.RelLogger)
|
---|
581 | == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_RELEASE);
|
---|
582 | /** Pointer to VMM ring-0 VMCPU instance data. */
|
---|
583 | typedef VMMR0PERVCPU *PVMMR0PERVCPU;
|
---|
584 |
|
---|
585 | /** @name RTLOGGER::u32UserValue1 Flags
|
---|
586 | * @{ */
|
---|
587 | /** The magic value. */
|
---|
588 | #define VMMR0_LOGGER_FLAGS_MAGIC_VALUE UINT32_C(0x7d297f05)
|
---|
589 | /** Part of the flags value used for the magic. */
|
---|
590 | #define VMMR0_LOGGER_FLAGS_MAGIC_MASK UINT32_C(0xffffff0f)
|
---|
591 | /** @} */
|
---|
592 |
|
---|
593 |
|
---|
594 | /**
|
---|
595 | * VMM data kept in the ring-0 GVM.
|
---|
596 | */
|
---|
597 | typedef struct VMMR0PERVM
|
---|
598 | {
|
---|
599 | /** Set if vmmR0InitVM has been called. */
|
---|
600 | bool fCalledInitVm;
|
---|
601 | bool afPadding1[7];
|
---|
602 |
|
---|
603 | /** @name Logging
|
---|
604 | * @{ */
|
---|
605 | /** Logger (debug) buffer allocation.
|
---|
606 | * This covers all CPUs. */
|
---|
607 | RTR0MEMOBJ hMemObjLogger;
|
---|
608 | /** The ring-3 mapping object for hMemObjLogger. */
|
---|
609 | RTR0MEMOBJ hMapObjLogger;
|
---|
610 |
|
---|
611 | /** Release logger buffer allocation.
|
---|
612 | * This covers all CPUs. */
|
---|
613 | RTR0MEMOBJ hMemObjReleaseLogger;
|
---|
614 | /** The ring-3 mapping object for hMemObjReleaseLogger. */
|
---|
615 | RTR0MEMOBJ hMapObjReleaseLogger;
|
---|
616 |
|
---|
617 | struct
|
---|
618 | {
|
---|
619 | /** Spinlock protecting the logger ring buffer and associated variables. */
|
---|
620 | R0PTRTYPE(RTSPINLOCK) hSpinlock;
|
---|
621 | /** The log flusher thread handle to make sure there is only one. */
|
---|
622 | RTNATIVETHREAD hThread;
|
---|
623 | /** The handle to the event semaphore the log flusher waits on. */
|
---|
624 | RTSEMEVENT hEvent;
|
---|
625 | /** The index of the log flusher queue head (flusher thread side). */
|
---|
626 | uint32_t volatile idxRingHead;
|
---|
627 | /** The index of the log flusher queue tail (EMT side). */
|
---|
628 | uint32_t volatile idxRingTail;
|
---|
629 | /** Set if the log flusher thread is waiting for work and needs poking. */
|
---|
630 | bool volatile fThreadWaiting;
|
---|
631 | /** Set when the log flusher thread should shut down. */
|
---|
632 | bool volatile fThreadShutdown;
|
---|
633 | /** Indicates that the log flusher thread is running. */
|
---|
634 | bool volatile fThreadRunning;
|
---|
635 | bool afPadding2[5];
|
---|
636 | STAMCOUNTER StatFlushes;
|
---|
637 | STAMCOUNTER StatNoWakeUp;
|
---|
638 | /** Logger ring buffer.
|
---|
639 | * This is for communicating with the log flusher thread. */
|
---|
640 | VMMLOGFLUSHERENTRY aRing[VMM_MAX_CPU_COUNT * 2 /*loggers*/ * 1 /*buffer*/ + 16 /*fudge*/];
|
---|
641 | } LogFlusher;
|
---|
642 | /** @} */
|
---|
643 | } VMMR0PERVM;
|
---|
644 |
|
---|
645 | RT_C_DECLS_BEGIN
|
---|
646 |
|
---|
647 | int vmmInitFormatTypes(void);
|
---|
648 | void vmmTermFormatTypes(void);
|
---|
649 | uint32_t vmmGetBuildType(void);
|
---|
650 |
|
---|
651 | #ifdef IN_RING3
|
---|
652 | int vmmR3SwitcherInit(PVM pVM);
|
---|
653 | void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
654 | #endif /* IN_RING3 */
|
---|
655 |
|
---|
656 | #ifdef IN_RING0
|
---|
657 |
|
---|
658 | /**
|
---|
659 | * World switcher assembly routine.
|
---|
660 | * It will call VMMRCEntry().
|
---|
661 | *
|
---|
662 | * @returns return code from VMMRCEntry().
|
---|
663 | * @param pVM The cross context VM structure.
|
---|
664 | * @param uArg See VMMRCEntry().
|
---|
665 | * @internal
|
---|
666 | */
|
---|
667 | DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * Callback function for vmmR0CallRing3SetJmp.
|
---|
671 | *
|
---|
672 | * @returns VBox status code.
|
---|
673 | * @param pVM The cross context VM structure.
|
---|
674 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
675 | */
|
---|
676 | typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP,(PVMCC pVM, PVMCPUCC pVCpu));
|
---|
677 | /** Pointer to FNVMMR0SETJMP(). */
|
---|
678 | typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
|
---|
679 |
|
---|
680 | /**
|
---|
681 | * The setjmp variant used for calling Ring-3.
|
---|
682 | *
|
---|
683 | * This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
|
---|
684 | * in the middle of a ring-3 call. Another differences is the function pointer and
|
---|
685 | * argument. This has to do with resuming code and the stack frame of the caller.
|
---|
686 | *
|
---|
687 | * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
|
---|
688 | * @param pJmpBuf The jmp_buf to set.
|
---|
689 | * @param pfn The function to be called when not resuming.
|
---|
690 | * @param pVM The cross context VM structure.
|
---|
691 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
692 | */
|
---|
693 | DECLASM(int) vmmR0CallRing3SetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
|
---|
694 |
|
---|
695 |
|
---|
696 | /**
|
---|
697 | * Callback function for vmmR0CallRing3SetJmp2.
|
---|
698 | *
|
---|
699 | * @returns VBox status code.
|
---|
700 | * @param pGVM The ring-0 VM structure.
|
---|
701 | * @param idCpu The ID of the calling EMT.
|
---|
702 | */
|
---|
703 | typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP2,(PGVM pGVM, VMCPUID idCpu));
|
---|
704 | /** Pointer to FNVMMR0SETJMP2(). */
|
---|
705 | typedef FNVMMR0SETJMP2 *PFNVMMR0SETJMP2;
|
---|
706 |
|
---|
707 | /**
|
---|
708 | * Same as vmmR0CallRing3SetJmp except for the function signature.
|
---|
709 | *
|
---|
710 | * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
|
---|
711 | * @param pJmpBuf The jmp_buf to set.
|
---|
712 | * @param pfn The function to be called when not resuming.
|
---|
713 | * @param pGVM The ring-0 VM structure.
|
---|
714 | * @param idCpu The ID of the calling EMT.
|
---|
715 | */
|
---|
716 | DECLASM(int) vmmR0CallRing3SetJmp2(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP2 pfn, PGVM pGVM, VMCPUID idCpu);
|
---|
717 |
|
---|
718 |
|
---|
719 | /**
|
---|
720 | * Callback function for vmmR0CallRing3SetJmpEx.
|
---|
721 | *
|
---|
722 | * @returns VBox status code.
|
---|
723 | * @param pvUser The user argument.
|
---|
724 | */
|
---|
725 | typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMPEX,(void *pvUser));
|
---|
726 | /** Pointer to FNVMMR0SETJMPEX(). */
|
---|
727 | typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
|
---|
728 |
|
---|
729 | /**
|
---|
730 | * Same as vmmR0CallRing3SetJmp except for the function signature.
|
---|
731 | *
|
---|
732 | * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
|
---|
733 | * @param pJmpBuf The jmp_buf to set.
|
---|
734 | * @param pfn The function to be called when not resuming.
|
---|
735 | * @param pvUser The argument of that function.
|
---|
736 | * @param uCallKey Unused call parameter that should be used to help
|
---|
737 | * uniquely identify the call.
|
---|
738 | */
|
---|
739 | DECLASM(int) vmmR0CallRing3SetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser, uintptr_t uCallKey);
|
---|
740 |
|
---|
741 |
|
---|
742 | /**
|
---|
743 | * Worker for VMMRZCallRing3.
|
---|
744 | * This will save the stack and registers.
|
---|
745 | *
|
---|
746 | * @returns rc.
|
---|
747 | * @param pJmpBuf Pointer to the jump buffer.
|
---|
748 | * @param rc The return code.
|
---|
749 | */
|
---|
750 | DECLASM(int) vmmR0CallRing3LongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
|
---|
751 |
|
---|
752 | # ifdef VBOX_WITH_TRIPLE_FAULT_HACK
|
---|
753 | int vmmR0TripleFaultHackInit(void);
|
---|
754 | void vmmR0TripleFaultHackTerm(void);
|
---|
755 | # endif
|
---|
756 |
|
---|
757 | #endif /* IN_RING0 */
|
---|
758 |
|
---|
759 | RT_C_DECLS_END
|
---|
760 |
|
---|
761 | /** @} */
|
---|
762 |
|
---|
763 | #endif /* !VMM_INCLUDED_SRC_include_VMMInternal_h */
|
---|