1 | /* $Id: NEMInternal.h 94791 2022-05-03 09:36:11Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NEM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018-2022 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_NEMInternal_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_NEMInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #include <VBox/vmm/nem.h>
|
---|
27 | #include <VBox/vmm/cpum.h> /* For CPUMCPUVENDOR. */
|
---|
28 | #include <VBox/vmm/stam.h>
|
---|
29 | #include <VBox/vmm/vmapi.h>
|
---|
30 | #ifdef RT_OS_WINDOWS
|
---|
31 | #include <iprt/nt/hyperv.h>
|
---|
32 | #include <iprt/critsect.h>
|
---|
33 | #elif defined(RT_OS_DARWIN)
|
---|
34 | # include "VMXInternal.h"
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 |
|
---|
40 | /** @defgroup grp_nem_int Internal
|
---|
41 | * @ingroup grp_nem
|
---|
42 | * @internal
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | #if defined(VBOX_WITH_NATIVE_NEM) && !defined(VBOX_WITH_PGM_NEM_MODE)
|
---|
47 | # error "VBOX_WITH_NATIVE_NEM requires VBOX_WITH_PGM_NEM_MODE to be defined"
|
---|
48 | #endif
|
---|
49 |
|
---|
50 |
|
---|
51 | #ifdef RT_OS_WINDOWS
|
---|
52 | /*
|
---|
53 | * Windows: Code configuration.
|
---|
54 | */
|
---|
55 | /* nothing at the moment */
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Windows VID I/O control information.
|
---|
59 | */
|
---|
60 | typedef struct NEMWINIOCTL
|
---|
61 | {
|
---|
62 | /** The I/O control function number. */
|
---|
63 | uint32_t uFunction;
|
---|
64 | uint32_t cbInput;
|
---|
65 | uint32_t cbOutput;
|
---|
66 | } NEMWINIOCTL;
|
---|
67 |
|
---|
68 | /** @name Windows: Our two-bit physical page state for PGMPAGE
|
---|
69 | * @{ */
|
---|
70 | # define NEM_WIN_PAGE_STATE_NOT_SET 0
|
---|
71 | # define NEM_WIN_PAGE_STATE_UNMAPPED 1
|
---|
72 | # define NEM_WIN_PAGE_STATE_READABLE 2
|
---|
73 | # define NEM_WIN_PAGE_STATE_WRITABLE 3
|
---|
74 | /** @} */
|
---|
75 |
|
---|
76 | /** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
|
---|
77 | # define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
|
---|
78 | /** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
|
---|
79 | # define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
|
---|
80 | ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
|
---|
81 |
|
---|
82 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
83 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
|
---|
84 | | CPUMCTX_EXTRN_INHIBIT_NMI )
|
---|
85 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
86 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
87 |
|
---|
88 | /** @name Windows: Interrupt window flags (NEM_WIN_INTW_F_XXX).
|
---|
89 | * @{ */
|
---|
90 | # define NEM_WIN_INTW_F_NMI UINT8_C(0x01)
|
---|
91 | # define NEM_WIN_INTW_F_REGULAR UINT8_C(0x02)
|
---|
92 | # define NEM_WIN_INTW_F_PRIO_MASK UINT8_C(0x3c)
|
---|
93 | # define NEM_WIN_INTW_F_PRIO_SHIFT 2
|
---|
94 | /** @} */
|
---|
95 |
|
---|
96 | #endif /* RT_OS_WINDOWS */
|
---|
97 |
|
---|
98 |
|
---|
99 | #ifdef RT_OS_DARWIN
|
---|
100 | /** vCPU ID declaration to avoid dragging in HV headers here. */
|
---|
101 | typedef unsigned hv_vcpuid_t;
|
---|
102 | /** The HV VM memory space ID (ASID). */
|
---|
103 | typedef unsigned hv_vm_space_t;
|
---|
104 |
|
---|
105 |
|
---|
106 | /** @name Darwin: Our two-bit physical page state for PGMPAGE
|
---|
107 | * @{ */
|
---|
108 | # define NEM_DARWIN_PAGE_STATE_NOT_SET 0
|
---|
109 | # define NEM_DARWIN_PAGE_STATE_UNMAPPED 1
|
---|
110 | # define NEM_DARWIN_PAGE_STATE_READABLE 2
|
---|
111 | # define NEM_DARWIN_PAGE_STATE_WRITABLE 3
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
115 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
|
---|
116 | | CPUMCTX_EXTRN_INHIBIT_NMI )
|
---|
117 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
118 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
119 |
|
---|
120 | #endif
|
---|
121 |
|
---|
122 |
|
---|
123 | /** Trick to make slickedit see the static functions in the template. */
|
---|
124 | #ifndef IN_SLICKEDIT
|
---|
125 | # define NEM_TMPL_STATIC static
|
---|
126 | #else
|
---|
127 | # define NEM_TMPL_STATIC
|
---|
128 | #endif
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Generic NEM exit type enumeration for use with EMHistoryAddExit.
|
---|
133 | *
|
---|
134 | * On windows we've got two different set of exit types and they are both jumping
|
---|
135 | * around the place value wise, so EM can use their values.
|
---|
136 | *
|
---|
137 | * @note We only have exit types for exits not covered by EM here.
|
---|
138 | */
|
---|
139 | typedef enum NEMEXITTYPE
|
---|
140 | {
|
---|
141 | NEMEXITTYPE_INVALID = 0,
|
---|
142 |
|
---|
143 | /* Common: */
|
---|
144 | NEMEXITTYPE_INTTERRUPT_WINDOW,
|
---|
145 | NEMEXITTYPE_HALT,
|
---|
146 |
|
---|
147 | /* Windows: */
|
---|
148 | NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
|
---|
149 | NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
|
---|
150 | NEMEXITTYPE_XCPT_UD,
|
---|
151 | NEMEXITTYPE_XCPT_DB,
|
---|
152 | NEMEXITTYPE_XCPT_BP,
|
---|
153 | NEMEXITTYPE_CANCELED,
|
---|
154 | NEMEXITTYPE_MEMORY_ACCESS,
|
---|
155 |
|
---|
156 | /* Linux: */
|
---|
157 | NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
|
---|
158 | NEMEXITTYPE_INTERNAL_ERROR_FATAL,
|
---|
159 | NEMEXITTYPE_INTERRUPTED,
|
---|
160 | NEMEXITTYPE_FAILED_ENTRY,
|
---|
161 |
|
---|
162 | /* End of valid types. */
|
---|
163 | NEMEXITTYPE_END
|
---|
164 | } NEMEXITTYPE;
|
---|
165 |
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * NEM VM Instance data.
|
---|
169 | */
|
---|
170 | typedef struct NEM
|
---|
171 | {
|
---|
172 | /** NEM_MAGIC. */
|
---|
173 | uint32_t u32Magic;
|
---|
174 |
|
---|
175 | /** Set if enabled. */
|
---|
176 | bool fEnabled;
|
---|
177 | /** Set if long mode guests are allowed. */
|
---|
178 | bool fAllow64BitGuests;
|
---|
179 | /** Set when the debug facility has breakpoints/events enabled that requires
|
---|
180 | * us to use the debug execution loop. */
|
---|
181 | bool fUseDebugLoop;
|
---|
182 |
|
---|
183 | #if defined(RT_OS_LINUX)
|
---|
184 | /** The '/dev/kvm' file descriptor. */
|
---|
185 | int32_t fdKvm;
|
---|
186 | /** The KVM_CREATE_VM file descriptor. */
|
---|
187 | int32_t fdVm;
|
---|
188 |
|
---|
189 | /** KVM_GET_VCPU_MMAP_SIZE. */
|
---|
190 | uint32_t cbVCpuMmap;
|
---|
191 | /** KVM_CAP_NR_MEMSLOTS. */
|
---|
192 | uint32_t cMaxMemSlots;
|
---|
193 | /** KVM_CAP_X86_ROBUST_SINGLESTEP. */
|
---|
194 | bool fRobustSingleStep;
|
---|
195 |
|
---|
196 | /** Hint where there might be a free slot. */
|
---|
197 | uint16_t idPrevSlot;
|
---|
198 | /** Memory slot ID allocation bitmap. */
|
---|
199 | uint64_t bmSlotIds[_32K / 8 / sizeof(uint64_t)];
|
---|
200 |
|
---|
201 | #elif defined(RT_OS_WINDOWS)
|
---|
202 | /** Set if we've created the EMTs. */
|
---|
203 | bool fCreatedEmts : 1;
|
---|
204 | /** WHvRunVpExitReasonX64Cpuid is supported. */
|
---|
205 | bool fExtendedMsrExit : 1;
|
---|
206 | /** WHvRunVpExitReasonX64MsrAccess is supported. */
|
---|
207 | bool fExtendedCpuIdExit : 1;
|
---|
208 | /** WHvRunVpExitReasonException is supported. */
|
---|
209 | bool fExtendedXcptExit : 1;
|
---|
210 | # ifdef NEM_WIN_WITH_A20
|
---|
211 | /** Set if we've started more than one CPU and cannot mess with A20. */
|
---|
212 | bool fA20Fixed : 1;
|
---|
213 | /** Set if A20 is enabled. */
|
---|
214 | bool fA20Enabled : 1;
|
---|
215 | # endif
|
---|
216 | /** The reported CPU vendor. */
|
---|
217 | CPUMCPUVENDOR enmCpuVendor;
|
---|
218 | /** Cache line flush size as a power of two. */
|
---|
219 | uint8_t cCacheLineFlushShift;
|
---|
220 | /** The result of WHvCapabilityCodeProcessorFeatures. */
|
---|
221 | union
|
---|
222 | {
|
---|
223 | /** 64-bit view. */
|
---|
224 | uint64_t u64;
|
---|
225 | # ifdef _WINHVAPIDEFS_H_
|
---|
226 | /** Interpreed features. */
|
---|
227 | WHV_PROCESSOR_FEATURES u;
|
---|
228 | # endif
|
---|
229 | } uCpuFeatures;
|
---|
230 |
|
---|
231 | /** The partition handle. */
|
---|
232 | # ifdef _WINHVAPIDEFS_H_
|
---|
233 | WHV_PARTITION_HANDLE
|
---|
234 | # else
|
---|
235 | RTHCUINTPTR
|
---|
236 | # endif
|
---|
237 | hPartition;
|
---|
238 | /** The device handle for the partition, for use with Vid APIs or direct I/O
|
---|
239 | * controls. */
|
---|
240 | RTR3PTR hPartitionDevice;
|
---|
241 |
|
---|
242 | /** Number of currently mapped pages. */
|
---|
243 | uint32_t volatile cMappedPages;
|
---|
244 | uint32_t u32Padding;
|
---|
245 | STAMCOUNTER StatMapPage;
|
---|
246 | STAMCOUNTER StatUnmapPage;
|
---|
247 | STAMCOUNTER StatMapPageFailed;
|
---|
248 | STAMCOUNTER StatUnmapPageFailed;
|
---|
249 | STAMPROFILE StatProfMapGpaRange;
|
---|
250 | STAMPROFILE StatProfUnmapGpaRange;
|
---|
251 | STAMPROFILE StatProfMapGpaRangePage;
|
---|
252 | STAMPROFILE StatProfUnmapGpaRangePage;
|
---|
253 |
|
---|
254 | /** Statistics updated by NEMR0UpdateStatistics. */
|
---|
255 | struct
|
---|
256 | {
|
---|
257 | uint64_t cPagesAvailable;
|
---|
258 | uint64_t cPagesInUse;
|
---|
259 | } R0Stats;
|
---|
260 |
|
---|
261 | #elif defined(RT_OS_DARWIN)
|
---|
262 | /** Set if we've created the EMTs. */
|
---|
263 | bool fCreatedEmts : 1;
|
---|
264 | /** Set if hv_vm_create() was called successfully. */
|
---|
265 | bool fCreatedVm : 1;
|
---|
266 | /** Set if hv_vm_space_create() was called successfully. */
|
---|
267 | bool fCreatedAsid : 1;
|
---|
268 | /** Set if Last Branch Record (LBR) is enabled. */
|
---|
269 | bool fLbr;
|
---|
270 | /** The ASID for this VM (only valid if fCreatedAsid is true). */
|
---|
271 | hv_vm_space_t uVmAsid;
|
---|
272 | /** Number of mach time units per NS, for hv_vcpu_run_until(). */
|
---|
273 | uint64_t cMachTimePerNs;
|
---|
274 | /** Pause-loop exiting (PLE) gap in ticks. */
|
---|
275 | uint32_t cPleGapTicks;
|
---|
276 | /** Pause-loop exiting (PLE) window in ticks. */
|
---|
277 | uint32_t cPleWindowTicks;
|
---|
278 |
|
---|
279 | /** The host LBR TOS (top-of-stack) MSR id. */
|
---|
280 | uint32_t idLbrTosMsr;
|
---|
281 | /** The host LBR select MSR id. */
|
---|
282 | uint32_t idLbrSelectMsr;
|
---|
283 | /** The host last event record from IP MSR id. */
|
---|
284 | uint32_t idLerFromIpMsr;
|
---|
285 | /** The host last event record to IP MSR id. */
|
---|
286 | uint32_t idLerToIpMsr;
|
---|
287 |
|
---|
288 | /** The first valid host LBR branch-from-IP stack range. */
|
---|
289 | uint32_t idLbrFromIpMsrFirst;
|
---|
290 | /** The last valid host LBR branch-from-IP stack range. */
|
---|
291 | uint32_t idLbrFromIpMsrLast;
|
---|
292 |
|
---|
293 | /** The first valid host LBR branch-to-IP stack range. */
|
---|
294 | uint32_t idLbrToIpMsrFirst;
|
---|
295 | /** The last valid host LBR branch-to-IP stack range. */
|
---|
296 | uint32_t idLbrToIpMsrLast;
|
---|
297 |
|
---|
298 | /** The first valid host LBR info stack range. */
|
---|
299 | uint32_t idLbrInfoMsrFirst;
|
---|
300 | /** The last valid host LBR info stack range. */
|
---|
301 | uint32_t idLbrInfoMsrLast;
|
---|
302 |
|
---|
303 | STAMCOUNTER StatMapPage;
|
---|
304 | STAMCOUNTER StatUnmapPage;
|
---|
305 | STAMCOUNTER StatMapPageFailed;
|
---|
306 | STAMCOUNTER StatUnmapPageFailed;
|
---|
307 | #endif /* RT_OS_WINDOWS */
|
---|
308 | } NEM;
|
---|
309 | /** Pointer to NEM VM instance data. */
|
---|
310 | typedef NEM *PNEM;
|
---|
311 |
|
---|
312 | /** NEM::u32Magic value. */
|
---|
313 | #define NEM_MAGIC UINT32_C(0x004d454e)
|
---|
314 | /** NEM::u32Magic value after termination. */
|
---|
315 | #define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
|
---|
316 |
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * NEM VMCPU Instance data.
|
---|
320 | */
|
---|
321 | typedef struct NEMCPU
|
---|
322 | {
|
---|
323 | /** NEMCPU_MAGIC. */
|
---|
324 | uint32_t u32Magic;
|
---|
325 | /** Whether \#UD needs to be intercepted and presented to GIM. */
|
---|
326 | bool fGIMTrapXcptUD : 1;
|
---|
327 | /** Whether \#GP needs to be intercept for mesa driver workaround. */
|
---|
328 | bool fTrapXcptGpForLovelyMesaDrv: 1;
|
---|
329 | /** Whether we should use the debug loop because of single stepping or special
|
---|
330 | * debug breakpoints / events are armed. */
|
---|
331 | bool fUseDebugLoop : 1;
|
---|
332 | /** Whether we're executing a single instruction. */
|
---|
333 | bool fSingleInstruction : 1;
|
---|
334 | /** Set if we using the debug loop and wish to intercept RDTSC. */
|
---|
335 | bool fDebugWantRdTscExit : 1;
|
---|
336 | /** Whether we are currently executing in the debug loop.
|
---|
337 | * Mainly for assertions. */
|
---|
338 | bool fUsingDebugLoop : 1;
|
---|
339 | /** Set if we need to clear the trap flag because of single stepping. */
|
---|
340 | bool fClearTrapFlag : 1;
|
---|
341 | /** Whether we're using the hyper DR7 or guest DR7. */
|
---|
342 | bool fUsingHyperDR7 : 1;
|
---|
343 |
|
---|
344 | #if defined(RT_OS_LINUX)
|
---|
345 | uint8_t abPadding[3];
|
---|
346 | /** The KVM VCpu file descriptor. */
|
---|
347 | int32_t fdVCpu;
|
---|
348 | /** Pointer to the KVM_RUN data exchange region. */
|
---|
349 | R3PTRTYPE(struct kvm_run *) pRun;
|
---|
350 | /** The MSR_IA32_APICBASE value known to KVM. */
|
---|
351 | uint64_t uKvmApicBase;
|
---|
352 |
|
---|
353 | /** @name Statistics
|
---|
354 | * @{ */
|
---|
355 | STAMCOUNTER StatExitTotal;
|
---|
356 | STAMCOUNTER StatExitIo;
|
---|
357 | STAMCOUNTER StatExitMmio;
|
---|
358 | STAMCOUNTER StatExitSetTpr;
|
---|
359 | STAMCOUNTER StatExitTprAccess;
|
---|
360 | STAMCOUNTER StatExitRdMsr;
|
---|
361 | STAMCOUNTER StatExitWrMsr;
|
---|
362 | STAMCOUNTER StatExitIrqWindowOpen;
|
---|
363 | STAMCOUNTER StatExitHalt;
|
---|
364 | STAMCOUNTER StatExitIntr;
|
---|
365 | STAMCOUNTER StatExitHypercall;
|
---|
366 | STAMCOUNTER StatExitDebug;
|
---|
367 | STAMCOUNTER StatExitBusLock;
|
---|
368 | STAMCOUNTER StatExitInternalErrorEmulation;
|
---|
369 | STAMCOUNTER StatExitInternalErrorFatal;
|
---|
370 | # if 0
|
---|
371 | STAMCOUNTER StatExitCpuId;
|
---|
372 | STAMCOUNTER StatExitUnrecoverable;
|
---|
373 | STAMCOUNTER StatGetMsgTimeout;
|
---|
374 | STAMCOUNTER StatStopCpuSuccess;
|
---|
375 | STAMCOUNTER StatStopCpuPending;
|
---|
376 | STAMCOUNTER StatStopCpuPendingAlerts;
|
---|
377 | STAMCOUNTER StatStopCpuPendingOdd;
|
---|
378 | STAMCOUNTER StatCancelChangedState;
|
---|
379 | STAMCOUNTER StatCancelAlertedThread;
|
---|
380 | # endif
|
---|
381 | STAMCOUNTER StatBreakOnCancel;
|
---|
382 | STAMCOUNTER StatBreakOnFFPre;
|
---|
383 | STAMCOUNTER StatBreakOnFFPost;
|
---|
384 | STAMCOUNTER StatBreakOnStatus;
|
---|
385 | STAMCOUNTER StatFlushExitOnReturn;
|
---|
386 | STAMCOUNTER StatFlushExitOnReturn1Loop;
|
---|
387 | STAMCOUNTER StatFlushExitOnReturn2Loops;
|
---|
388 | STAMCOUNTER StatFlushExitOnReturn3Loops;
|
---|
389 | STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
|
---|
390 | STAMCOUNTER StatImportOnDemand;
|
---|
391 | STAMCOUNTER StatImportOnReturn;
|
---|
392 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
393 | STAMCOUNTER StatImportPendingInterrupt;
|
---|
394 | STAMCOUNTER StatExportPendingInterrupt;
|
---|
395 | STAMCOUNTER StatQueryCpuTick;
|
---|
396 | /** @} */
|
---|
397 |
|
---|
398 |
|
---|
399 | #elif defined(RT_OS_WINDOWS)
|
---|
400 | /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
401 | uint8_t fCurrentInterruptWindows;
|
---|
402 | /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
403 | uint8_t fDesiredInterruptWindows;
|
---|
404 | /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
|
---|
405 | bool fLastInterruptShadow : 1;
|
---|
406 | uint32_t uPadding;
|
---|
407 | /** The VID_MSHAGN_F_XXX flags.
|
---|
408 | * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
|
---|
409 | uint32_t fHandleAndGetFlags;
|
---|
410 | /** What VidMessageSlotMap returns and is used for passing exit info. */
|
---|
411 | RTR3PTR pvMsgSlotMapping;
|
---|
412 | /** The windows thread handle. */
|
---|
413 | RTR3PTR hNativeThreadHandle;
|
---|
414 |
|
---|
415 | /** @name Statistics
|
---|
416 | * @{ */
|
---|
417 | STAMCOUNTER StatExitPortIo;
|
---|
418 | STAMCOUNTER StatExitMemUnmapped;
|
---|
419 | STAMCOUNTER StatExitMemIntercept;
|
---|
420 | STAMCOUNTER StatExitHalt;
|
---|
421 | STAMCOUNTER StatExitInterruptWindow;
|
---|
422 | STAMCOUNTER StatExitCpuId;
|
---|
423 | STAMCOUNTER StatExitMsr;
|
---|
424 | STAMCOUNTER StatExitException;
|
---|
425 | STAMCOUNTER StatExitExceptionBp;
|
---|
426 | STAMCOUNTER StatExitExceptionDb;
|
---|
427 | STAMCOUNTER StatExitExceptionGp;
|
---|
428 | STAMCOUNTER StatExitExceptionGpMesa;
|
---|
429 | STAMCOUNTER StatExitExceptionUd;
|
---|
430 | STAMCOUNTER StatExitExceptionUdHandled;
|
---|
431 | STAMCOUNTER StatExitUnrecoverable;
|
---|
432 | STAMCOUNTER StatGetMsgTimeout;
|
---|
433 | STAMCOUNTER StatStopCpuSuccess;
|
---|
434 | STAMCOUNTER StatStopCpuPending;
|
---|
435 | STAMCOUNTER StatStopCpuPendingAlerts;
|
---|
436 | STAMCOUNTER StatStopCpuPendingOdd;
|
---|
437 | STAMCOUNTER StatCancelChangedState;
|
---|
438 | STAMCOUNTER StatCancelAlertedThread;
|
---|
439 | STAMCOUNTER StatBreakOnCancel;
|
---|
440 | STAMCOUNTER StatBreakOnFFPre;
|
---|
441 | STAMCOUNTER StatBreakOnFFPost;
|
---|
442 | STAMCOUNTER StatBreakOnStatus;
|
---|
443 | STAMCOUNTER StatImportOnDemand;
|
---|
444 | STAMCOUNTER StatImportOnReturn;
|
---|
445 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
446 | STAMCOUNTER StatQueryCpuTick;
|
---|
447 | /** @} */
|
---|
448 |
|
---|
449 | #elif defined(RT_OS_DARWIN)
|
---|
450 | /** The vCPU handle associated with the EMT executing this vCPU. */
|
---|
451 | hv_vcpuid_t hVCpuId;
|
---|
452 |
|
---|
453 | /** @name State shared with the VT-x code.
|
---|
454 | * @{ */
|
---|
455 | /** An additional error code used for some gurus. */
|
---|
456 | uint32_t u32HMError;
|
---|
457 | /** The last exit-to-ring-3 reason. */
|
---|
458 | int32_t rcLastExitToR3;
|
---|
459 | /** CPU-context changed flags (see HM_CHANGED_xxx). */
|
---|
460 | uint64_t fCtxChanged;
|
---|
461 |
|
---|
462 | /** The guest VMCS information. */
|
---|
463 | VMXVMCSINFO VmcsInfo;
|
---|
464 |
|
---|
465 | /** VT-x data. */
|
---|
466 | struct HMCPUVMX
|
---|
467 | {
|
---|
468 | /** @name Guest information.
|
---|
469 | * @{ */
|
---|
470 | /** Guest VMCS information shared with ring-3. */
|
---|
471 | VMXVMCSINFOSHARED VmcsInfo;
|
---|
472 | /** Nested-guest VMCS information shared with ring-3. */
|
---|
473 | VMXVMCSINFOSHARED VmcsInfoNstGst;
|
---|
474 | /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
|
---|
475 | * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
|
---|
476 | bool fSwitchedToNstGstVmcsCopyForRing3;
|
---|
477 | /** Whether the static guest VMCS controls has been merged with the
|
---|
478 | * nested-guest VMCS controls. */
|
---|
479 | bool fMergedNstGstCtls;
|
---|
480 | /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
|
---|
481 | bool fCopiedNstGstToShadowVmcs;
|
---|
482 | /** Whether flushing the TLB is required due to switching to/from the
|
---|
483 | * nested-guest. */
|
---|
484 | bool fSwitchedNstGstFlushTlb;
|
---|
485 | /** Alignment. */
|
---|
486 | bool afAlignment0[4];
|
---|
487 | /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
|
---|
488 | uint64_t u64GstMsrApicBase;
|
---|
489 | /** @} */
|
---|
490 |
|
---|
491 | /** @name Error reporting and diagnostics.
|
---|
492 | * @{ */
|
---|
493 | /** VT-x error-reporting (mainly for ring-3 propagation). */
|
---|
494 | struct
|
---|
495 | {
|
---|
496 | RTCPUID idCurrentCpu;
|
---|
497 | RTCPUID idEnteredCpu;
|
---|
498 | RTHCPHYS HCPhysCurrentVmcs;
|
---|
499 | uint32_t u32VmcsRev;
|
---|
500 | uint32_t u32InstrError;
|
---|
501 | uint32_t u32ExitReason;
|
---|
502 | uint32_t u32GuestIntrState;
|
---|
503 | } LastError;
|
---|
504 | /** @} */
|
---|
505 | } vmx;
|
---|
506 |
|
---|
507 | /** Event injection state. */
|
---|
508 | HMEVENT Event;
|
---|
509 |
|
---|
510 | /** Current shadow paging mode for updating CR4.
|
---|
511 | * @todo move later (@bugref{9217}). */
|
---|
512 | PGMMODE enmShadowMode;
|
---|
513 | uint32_t u32TemporaryPadding;
|
---|
514 |
|
---|
515 | /** The PAE PDPEs used with Nested Paging (only valid when
|
---|
516 | * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
|
---|
517 | X86PDPE aPdpes[4];
|
---|
518 | /** Pointer to the VMX statistics. */
|
---|
519 | PVMXSTATISTICS pVmxStats;
|
---|
520 |
|
---|
521 | /** @name Statistics
|
---|
522 | * @{ */
|
---|
523 | STAMCOUNTER StatExitAll;
|
---|
524 | STAMCOUNTER StatBreakOnCancel;
|
---|
525 | STAMCOUNTER StatBreakOnFFPre;
|
---|
526 | STAMCOUNTER StatBreakOnFFPost;
|
---|
527 | STAMCOUNTER StatBreakOnStatus;
|
---|
528 | STAMCOUNTER StatImportOnDemand;
|
---|
529 | STAMCOUNTER StatImportOnReturn;
|
---|
530 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
531 | STAMCOUNTER StatQueryCpuTick;
|
---|
532 | #ifdef VBOX_WITH_STATISTICS
|
---|
533 | STAMPROFILEADV StatProfGstStateImport;
|
---|
534 | STAMPROFILEADV StatProfGstStateExport;
|
---|
535 | #endif
|
---|
536 | /** @} */
|
---|
537 |
|
---|
538 | /** @} */
|
---|
539 | #endif /* RT_OS_DARWIN */
|
---|
540 | } NEMCPU;
|
---|
541 | /** Pointer to NEM VMCPU instance data. */
|
---|
542 | typedef NEMCPU *PNEMCPU;
|
---|
543 |
|
---|
544 | /** NEMCPU::u32Magic value. */
|
---|
545 | #define NEMCPU_MAGIC UINT32_C(0x4d454e20)
|
---|
546 | /** NEMCPU::u32Magic value after termination. */
|
---|
547 | #define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
|
---|
548 |
|
---|
549 |
|
---|
550 | #ifdef IN_RING0
|
---|
551 | # ifdef RT_OS_WINDOWS
|
---|
552 | /**
|
---|
553 | * Windows: Hypercall input/ouput page info.
|
---|
554 | */
|
---|
555 | typedef struct NEMR0HYPERCALLDATA
|
---|
556 | {
|
---|
557 | /** Host physical address of the hypercall input/output page. */
|
---|
558 | RTHCPHYS HCPhysPage;
|
---|
559 | /** Pointer to the hypercall input/output page. */
|
---|
560 | uint8_t *pbPage;
|
---|
561 | /** Handle to the memory object of the hypercall input/output page. */
|
---|
562 | RTR0MEMOBJ hMemObj;
|
---|
563 | } NEMR0HYPERCALLDATA;
|
---|
564 | /** Pointer to a Windows hypercall input/output page info. */
|
---|
565 | typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
|
---|
566 | # endif /* RT_OS_WINDOWS */
|
---|
567 |
|
---|
568 | /**
|
---|
569 | * NEM GVMCPU instance data.
|
---|
570 | */
|
---|
571 | typedef struct NEMR0PERVCPU
|
---|
572 | {
|
---|
573 | uint32_t uDummy;
|
---|
574 | } NEMR0PERVCPU;
|
---|
575 |
|
---|
576 | /**
|
---|
577 | * NEM GVM instance data.
|
---|
578 | */
|
---|
579 | typedef struct NEMR0PERVM
|
---|
580 | {
|
---|
581 | uint32_t uDummy;
|
---|
582 | } NEMR0PERVM;
|
---|
583 |
|
---|
584 | #endif /* IN_RING*/
|
---|
585 |
|
---|
586 |
|
---|
587 | #ifdef IN_RING3
|
---|
588 | int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
|
---|
589 | int nemR3NativeInitAfterCPUM(PVM pVM);
|
---|
590 | int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
|
---|
591 | int nemR3NativeTerm(PVM pVM);
|
---|
592 | void nemR3NativeReset(PVM pVM);
|
---|
593 | void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
|
---|
594 | VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
|
---|
595 | bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
|
---|
596 | bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Forced flag notification call from VMEmt.h.
|
---|
600 | *
|
---|
601 | * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
|
---|
602 | *
|
---|
603 | * @param pVM The cross context VM structure.
|
---|
604 | * @param pVCpu The cross context virtual CPU structure of the CPU
|
---|
605 | * to be notified.
|
---|
606 | * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
|
---|
607 | */
|
---|
608 | void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
|
---|
612 | * on whether to switch to the debug loop.
|
---|
613 | *
|
---|
614 | * @returns Final flag whether to switch to the debug loop.
|
---|
615 | * @param pVM The VM cross context VM structure.
|
---|
616 | * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
|
---|
617 | * @thread EMT(0)
|
---|
618 | */
|
---|
619 | DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
|
---|
620 |
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
|
---|
624 | * on whether to switch to the debug loop.
|
---|
625 | *
|
---|
626 | * @returns Final flag whether to switch to the debug loop.
|
---|
627 | * @param pVM The VM cross context VM structure.
|
---|
628 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
629 | * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
|
---|
630 | */
|
---|
631 | DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
|
---|
632 | #endif
|
---|
633 |
|
---|
634 | void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
|
---|
635 | void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
|
---|
636 | RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
|
---|
637 | int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
|
---|
638 | PGMPAGETYPE enmType, uint8_t *pu2State);
|
---|
639 |
|
---|
640 |
|
---|
641 | #ifdef RT_OS_WINDOWS
|
---|
642 | /** Maximum number of pages we can map in a single NEMR0MapPages call. */
|
---|
643 | # define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
|
---|
644 | /** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
|
---|
645 | # define NEM_MAX_UNMAP_PAGES 4095
|
---|
646 |
|
---|
647 | #endif
|
---|
648 | /** @} */
|
---|
649 |
|
---|
650 | RT_C_DECLS_END
|
---|
651 |
|
---|
652 | #endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
|
---|
653 |
|
---|