1 | /* $Id: NEMInternal.h 92356 2021-11-11 10:57:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NEM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018-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_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_PGM_NEM_MODE) && !defined(VBOX_WITH_NATIVE_NEM)
|
---|
47 | # error "VBOX_WITH_PGM_NEM_MODE requires VBOX_WITH_NATIVE_NEM to be defined"
|
---|
48 | #endif
|
---|
49 |
|
---|
50 |
|
---|
51 | #ifdef RT_OS_WINDOWS
|
---|
52 | /*
|
---|
53 | * Windows: Code configuration.
|
---|
54 | */
|
---|
55 | # ifndef VBOX_WITH_PGM_NEM_MODE
|
---|
56 | # define NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
57 | #endif
|
---|
58 | //# define NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS /**< Applies to ring-3 code only. Useful for testing VID API. */
|
---|
59 | //# define NEM_WIN_USE_OUR_OWN_RUN_API /**< Applies to ring-3 code only. Useful for testing VID API. */
|
---|
60 | //# define NEM_WIN_WITH_RING0_RUNLOOP /**< Enables the ring-0 runloop. */
|
---|
61 | //# define NEM_WIN_USE_RING0_RUNLOOP_BY_DEFAULT /**< For quickly testing ring-3 API without messing with CFGM. */
|
---|
62 | # if defined(NEM_WIN_USE_OUR_OWN_RUN_API) && !defined(NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS)
|
---|
63 | # error "NEM_WIN_USE_OUR_OWN_RUN_API requires NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS"
|
---|
64 | # endif
|
---|
65 | # if defined(NEM_WIN_USE_OUR_OWN_RUN_API) && !defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
|
---|
66 | # error "NEM_WIN_USE_OUR_OWN_RUN_API requires NEM_WIN_USE_HYPERCALLS_FOR_PAGES"
|
---|
67 | # endif
|
---|
68 | # if defined(NEM_WIN_WITH_RING0_RUNLOOP) && !defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
|
---|
69 | # error "NEM_WIN_WITH_RING0_RUNLOOP requires NEM_WIN_USE_HYPERCALLS_FOR_PAGES"
|
---|
70 | # endif
|
---|
71 | # if defined(VBOX_WITH_PGM_NEM_MODE) && defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
|
---|
72 | # error "VBOX_WITH_PGM_NEM_MODE cannot be used together with NEM_WIN_USE_HYPERCALLS_FOR_PAGES"
|
---|
73 | # endif
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Windows VID I/O control information.
|
---|
77 | */
|
---|
78 | typedef struct NEMWINIOCTL
|
---|
79 | {
|
---|
80 | /** The I/O control function number. */
|
---|
81 | uint32_t uFunction;
|
---|
82 | uint32_t cbInput;
|
---|
83 | uint32_t cbOutput;
|
---|
84 | } NEMWINIOCTL;
|
---|
85 |
|
---|
86 | /** @name Windows: Our two-bit physical page state for PGMPAGE
|
---|
87 | * @{ */
|
---|
88 | # define NEM_WIN_PAGE_STATE_NOT_SET 0
|
---|
89 | # define NEM_WIN_PAGE_STATE_UNMAPPED 1
|
---|
90 | # define NEM_WIN_PAGE_STATE_READABLE 2
|
---|
91 | # define NEM_WIN_PAGE_STATE_WRITABLE 3
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | /** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
|
---|
95 | # define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
|
---|
96 | /** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
|
---|
97 | # define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
|
---|
98 | ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
|
---|
99 |
|
---|
100 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
101 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_INT \
|
---|
102 | | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_NMI )
|
---|
103 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
104 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
105 |
|
---|
106 | /** @name Windows: Interrupt window flags (NEM_WIN_INTW_F_XXX).
|
---|
107 | * @{ */
|
---|
108 | # define NEM_WIN_INTW_F_NMI UINT8_C(0x01)
|
---|
109 | # define NEM_WIN_INTW_F_REGULAR UINT8_C(0x02)
|
---|
110 | # define NEM_WIN_INTW_F_PRIO_MASK UINT8_C(0x3c)
|
---|
111 | # define NEM_WIN_INTW_F_PRIO_SHIFT 2
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 | #endif /* RT_OS_WINDOWS */
|
---|
115 |
|
---|
116 |
|
---|
117 | #ifdef RT_OS_DARWIN
|
---|
118 | /** vCPU ID declaration to avoid dragging in HV headers here. */
|
---|
119 | typedef unsigned hv_vcpuid_t;
|
---|
120 | /** The HV VM memory space ID (ASID). */
|
---|
121 | typedef unsigned hv_vm_space_t;
|
---|
122 |
|
---|
123 |
|
---|
124 | /** @name Darwin: Our two-bit physical page state for PGMPAGE
|
---|
125 | * @{ */
|
---|
126 | # define NEM_DARWIN_PAGE_STATE_NOT_SET 0
|
---|
127 | # define NEM_DARWIN_PAGE_STATE_UNMAPPED 1
|
---|
128 | # define NEM_DARWIN_PAGE_STATE_READABLE 2
|
---|
129 | # define NEM_DARWIN_PAGE_STATE_WRITABLE 3
|
---|
130 | /** @} */
|
---|
131 |
|
---|
132 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
133 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_INT \
|
---|
134 | | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_NMI )
|
---|
135 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
136 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
137 |
|
---|
138 | #endif
|
---|
139 |
|
---|
140 |
|
---|
141 | /** Trick to make slickedit see the static functions in the template. */
|
---|
142 | #ifndef IN_SLICKEDIT
|
---|
143 | # define NEM_TMPL_STATIC static
|
---|
144 | #else
|
---|
145 | # define NEM_TMPL_STATIC
|
---|
146 | #endif
|
---|
147 |
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Generic NEM exit type enumeration for use with EMHistoryAddExit.
|
---|
151 | *
|
---|
152 | * On windows we've got two different set of exit types and they are both jumping
|
---|
153 | * around the place value wise, so EM can use their values.
|
---|
154 | *
|
---|
155 | * @note We only have exit types for exits not covered by EM here.
|
---|
156 | */
|
---|
157 | typedef enum NEMEXITTYPE
|
---|
158 | {
|
---|
159 | /* windows: */
|
---|
160 | NEMEXITTYPE_UNRECOVERABLE_EXCEPTION = 1,
|
---|
161 | NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
|
---|
162 | NEMEXITTYPE_INTTERRUPT_WINDOW,
|
---|
163 | NEMEXITTYPE_HALT,
|
---|
164 | NEMEXITTYPE_XCPT_UD,
|
---|
165 | NEMEXITTYPE_XCPT_DB,
|
---|
166 | NEMEXITTYPE_XCPT_BP,
|
---|
167 | NEMEXITTYPE_CANCELED,
|
---|
168 | NEMEXITTYPE_MEMORY_ACCESS
|
---|
169 | } NEMEXITTYPE;
|
---|
170 |
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * NEM VM Instance data.
|
---|
174 | */
|
---|
175 | typedef struct NEM
|
---|
176 | {
|
---|
177 | /** NEM_MAGIC. */
|
---|
178 | uint32_t u32Magic;
|
---|
179 |
|
---|
180 | /** Set if enabled. */
|
---|
181 | bool fEnabled;
|
---|
182 | /** Set if long mode guests are allowed. */
|
---|
183 | bool fAllow64BitGuests;
|
---|
184 | #ifdef RT_OS_WINDOWS
|
---|
185 | /** Set if we've created the EMTs. */
|
---|
186 | bool fCreatedEmts : 1;
|
---|
187 | /** WHvRunVpExitReasonX64Cpuid is supported. */
|
---|
188 | bool fExtendedMsrExit : 1;
|
---|
189 | /** WHvRunVpExitReasonX64MsrAccess is supported. */
|
---|
190 | bool fExtendedCpuIdExit : 1;
|
---|
191 | /** WHvRunVpExitReasonException is supported. */
|
---|
192 | bool fExtendedXcptExit : 1;
|
---|
193 | /** Set if we're using the ring-0 API to do the work. */
|
---|
194 | bool fUseRing0Runloop : 1;
|
---|
195 | # ifdef NEM_WIN_WITH_A20
|
---|
196 | /** Set if we've started more than one CPU and cannot mess with A20. */
|
---|
197 | bool fA20Fixed : 1;
|
---|
198 | /** Set if A20 is enabled. */
|
---|
199 | bool fA20Enabled : 1;
|
---|
200 | # endif
|
---|
201 | /** The reported CPU vendor. */
|
---|
202 | CPUMCPUVENDOR enmCpuVendor;
|
---|
203 | /** Cache line flush size as a power of two. */
|
---|
204 | uint8_t cCacheLineFlushShift;
|
---|
205 | /** The result of WHvCapabilityCodeProcessorFeatures. */
|
---|
206 | union
|
---|
207 | {
|
---|
208 | /** 64-bit view. */
|
---|
209 | uint64_t u64;
|
---|
210 | # ifdef _WINHVAPIDEFS_H_
|
---|
211 | /** Interpreed features. */
|
---|
212 | WHV_PROCESSOR_FEATURES u;
|
---|
213 | # endif
|
---|
214 | } uCpuFeatures;
|
---|
215 |
|
---|
216 | /** The partition handle. */
|
---|
217 | # ifdef _WINHVAPIDEFS_H_
|
---|
218 | WHV_PARTITION_HANDLE
|
---|
219 | # else
|
---|
220 | RTHCUINTPTR
|
---|
221 | # endif
|
---|
222 | hPartition;
|
---|
223 | /** The device handle for the partition, for use with Vid APIs or direct I/O
|
---|
224 | * controls. */
|
---|
225 | RTR3PTR hPartitionDevice;
|
---|
226 | /** The Hyper-V partition ID. */
|
---|
227 | uint64_t idHvPartition;
|
---|
228 |
|
---|
229 | /** Number of currently mapped pages. */
|
---|
230 | uint32_t volatile cMappedPages;
|
---|
231 | # ifndef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
232 | /** Max number of pages we dare map at once. */
|
---|
233 | uint32_t cMaxMappedPages;
|
---|
234 | # endif
|
---|
235 | STAMCOUNTER StatMapPage;
|
---|
236 | STAMCOUNTER StatUnmapPage;
|
---|
237 | # ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
238 | STAMCOUNTER StatRemapPage;
|
---|
239 | STAMCOUNTER StatRemapPageFailed;
|
---|
240 | # elif !defined(VBOX_WITH_PGM_NEM_MODE)
|
---|
241 | STAMCOUNTER StatUnmapAllPages;
|
---|
242 | # endif
|
---|
243 | STAMCOUNTER StatMapPageFailed;
|
---|
244 | STAMCOUNTER StatUnmapPageFailed;
|
---|
245 | # ifdef VBOX_WITH_PGM_NEM_MODE
|
---|
246 | STAMPROFILE StatProfMapGpaRange;
|
---|
247 | STAMPROFILE StatProfUnmapGpaRange;
|
---|
248 | # endif
|
---|
249 | # ifndef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
250 | STAMPROFILE StatProfMapGpaRangePage;
|
---|
251 | STAMPROFILE StatProfUnmapGpaRangePage;
|
---|
252 | # endif
|
---|
253 |
|
---|
254 | # ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
255 | /** Info about the VidGetHvPartitionId I/O control interface. */
|
---|
256 | NEMWINIOCTL IoCtlGetHvPartitionId;
|
---|
257 | /** Info about the VidGetPartitionProperty I/O control interface. */
|
---|
258 | NEMWINIOCTL IoCtlGetPartitionProperty;
|
---|
259 | # endif
|
---|
260 | # ifdef NEM_WIN_WITH_RING0_RUNLOOP
|
---|
261 | /** Info about the VidStartVirtualProcessor I/O control interface. */
|
---|
262 | NEMWINIOCTL IoCtlStartVirtualProcessor;
|
---|
263 | /** Info about the VidStopVirtualProcessor I/O control interface. */
|
---|
264 | NEMWINIOCTL IoCtlStopVirtualProcessor;
|
---|
265 | /** Info about the VidStopVirtualProcessor I/O control interface. */
|
---|
266 | NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
|
---|
267 | # endif
|
---|
268 |
|
---|
269 | /** Statistics updated by NEMR0UpdateStatistics. */
|
---|
270 | struct
|
---|
271 | {
|
---|
272 | uint64_t cPagesAvailable;
|
---|
273 | uint64_t cPagesInUse;
|
---|
274 | } R0Stats;
|
---|
275 | #elif defined(RT_OS_DARWIN)
|
---|
276 | /** Set if we've created the EMTs. */
|
---|
277 | bool fCreatedEmts : 1;
|
---|
278 | /** Set if hv_vm_create() was called successfully. */
|
---|
279 | bool fCreatedVm : 1;
|
---|
280 | /** Number of currently mapped pages. */
|
---|
281 | uint32_t volatile cMappedPages;
|
---|
282 | STAMCOUNTER StatMapPage;
|
---|
283 | STAMCOUNTER StatUnmapPage;
|
---|
284 | STAMCOUNTER StatMapPageFailed;
|
---|
285 | STAMCOUNTER StatUnmapPageFailed;
|
---|
286 | #endif /* RT_OS_WINDOWS */
|
---|
287 | } NEM;
|
---|
288 | /** Pointer to NEM VM instance data. */
|
---|
289 | typedef NEM *PNEM;
|
---|
290 |
|
---|
291 | /** NEM::u32Magic value. */
|
---|
292 | #define NEM_MAGIC UINT32_C(0x004d454e)
|
---|
293 | /** NEM::u32Magic value after termination. */
|
---|
294 | #define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
|
---|
295 |
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * NEM VMCPU Instance data.
|
---|
299 | */
|
---|
300 | typedef struct NEMCPU
|
---|
301 | {
|
---|
302 | /** NEMCPU_MAGIC. */
|
---|
303 | uint32_t u32Magic;
|
---|
304 | /** Whether \#UD needs to be intercepted and presented to GIM. */
|
---|
305 | bool fGIMTrapXcptUD : 1;
|
---|
306 | /** Whether \#GP needs to be intercept for mesa driver workaround. */
|
---|
307 | bool fTrapXcptGpForLovelyMesaDrv: 1;
|
---|
308 | #ifdef RT_OS_WINDOWS
|
---|
309 | /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
310 | uint8_t fCurrentInterruptWindows;
|
---|
311 | /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
312 | uint8_t fDesiredInterruptWindows;
|
---|
313 | /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
|
---|
314 | bool fLastInterruptShadow : 1;
|
---|
315 | # ifdef NEM_WIN_WITH_RING0_RUNLOOP
|
---|
316 | /** Pending VINF_NEM_FLUSH_TLB. */
|
---|
317 | int32_t rcPending;
|
---|
318 | # else
|
---|
319 | uint32_t uPadding;
|
---|
320 | # endif
|
---|
321 | /** The VID_MSHAGN_F_XXX flags.
|
---|
322 | * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
|
---|
323 | uint32_t fHandleAndGetFlags;
|
---|
324 | /** What VidMessageSlotMap returns and is used for passing exit info. */
|
---|
325 | RTR3PTR pvMsgSlotMapping;
|
---|
326 | /** The windows thread handle. */
|
---|
327 | RTR3PTR hNativeThreadHandle;
|
---|
328 | /** Parameters for making Hyper-V hypercalls. */
|
---|
329 | union
|
---|
330 | {
|
---|
331 | uint8_t ab[64];
|
---|
332 | /** Arguments for NEMR0MapPages (HvCallMapGpaPages). */
|
---|
333 | struct
|
---|
334 | {
|
---|
335 | RTGCPHYS GCPhysSrc;
|
---|
336 | RTGCPHYS GCPhysDst; /**< Same as GCPhysSrc except maybe when the A20 gate is disabled. */
|
---|
337 | uint32_t cPages;
|
---|
338 | HV_MAP_GPA_FLAGS fFlags;
|
---|
339 | } MapPages;
|
---|
340 | /** Arguments for NEMR0UnmapPages (HvCallUnmapGpaPages). */
|
---|
341 | struct
|
---|
342 | {
|
---|
343 | RTGCPHYS GCPhys;
|
---|
344 | uint32_t cPages;
|
---|
345 | } UnmapPages;
|
---|
346 | /** Result from NEMR0QueryCpuTick. */
|
---|
347 | struct
|
---|
348 | {
|
---|
349 | uint64_t cTicks;
|
---|
350 | uint32_t uAux;
|
---|
351 | } QueryCpuTick;
|
---|
352 | /** Input and output for NEMR0DoExperiment. */
|
---|
353 | struct
|
---|
354 | {
|
---|
355 | uint32_t uItem;
|
---|
356 | bool fSuccess;
|
---|
357 | uint64_t uStatus;
|
---|
358 | uint64_t uLoValue;
|
---|
359 | uint64_t uHiValue;
|
---|
360 | } Experiment;
|
---|
361 | } Hypercall;
|
---|
362 | /** I/O control buffer, we always use this for I/O controls. */
|
---|
363 | union
|
---|
364 | {
|
---|
365 | uint8_t ab[64];
|
---|
366 | HV_PARTITION_ID idPartition;
|
---|
367 | HV_VP_INDEX idCpu;
|
---|
368 | struct
|
---|
369 | {
|
---|
370 | uint64_t enmProperty;
|
---|
371 | uint64_t uValue;
|
---|
372 | } GetProp;
|
---|
373 | # ifdef VID_MSHAGN_F_GET_NEXT_MESSAGE
|
---|
374 | VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT MsgSlotHandleAndGetNext;
|
---|
375 | # endif
|
---|
376 | } uIoCtlBuf;
|
---|
377 |
|
---|
378 | /** @name Statistics
|
---|
379 | * @{ */
|
---|
380 | STAMCOUNTER StatExitPortIo;
|
---|
381 | STAMCOUNTER StatExitMemUnmapped;
|
---|
382 | STAMCOUNTER StatExitMemIntercept;
|
---|
383 | STAMCOUNTER StatExitHalt;
|
---|
384 | STAMCOUNTER StatExitInterruptWindow;
|
---|
385 | STAMCOUNTER StatExitCpuId;
|
---|
386 | STAMCOUNTER StatExitMsr;
|
---|
387 | STAMCOUNTER StatExitException;
|
---|
388 | STAMCOUNTER StatExitExceptionBp;
|
---|
389 | STAMCOUNTER StatExitExceptionDb;
|
---|
390 | STAMCOUNTER StatExitExceptionGp;
|
---|
391 | STAMCOUNTER StatExitExceptionGpMesa;
|
---|
392 | STAMCOUNTER StatExitExceptionUd;
|
---|
393 | STAMCOUNTER StatExitExceptionUdHandled;
|
---|
394 | STAMCOUNTER StatExitUnrecoverable;
|
---|
395 | STAMCOUNTER StatGetMsgTimeout;
|
---|
396 | STAMCOUNTER StatStopCpuSuccess;
|
---|
397 | STAMCOUNTER StatStopCpuPending;
|
---|
398 | STAMCOUNTER StatStopCpuPendingAlerts;
|
---|
399 | STAMCOUNTER StatStopCpuPendingOdd;
|
---|
400 | STAMCOUNTER StatCancelChangedState;
|
---|
401 | STAMCOUNTER StatCancelAlertedThread;
|
---|
402 | STAMCOUNTER StatBreakOnCancel;
|
---|
403 | STAMCOUNTER StatBreakOnFFPre;
|
---|
404 | STAMCOUNTER StatBreakOnFFPost;
|
---|
405 | STAMCOUNTER StatBreakOnStatus;
|
---|
406 | STAMCOUNTER StatImportOnDemand;
|
---|
407 | STAMCOUNTER StatImportOnReturn;
|
---|
408 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
409 | STAMCOUNTER StatQueryCpuTick;
|
---|
410 | /** @} */
|
---|
411 | #elif defined(RT_OS_DARWIN)
|
---|
412 | /** The vCPU handle associated with the EMT executing this vCPU. */
|
---|
413 | hv_vcpuid_t hVCpuId;
|
---|
414 |
|
---|
415 | /** @name State shared with the VT-x code.
|
---|
416 | * @{ */
|
---|
417 | /** Whether we should use the debug loop because of single stepping or special
|
---|
418 | * debug breakpoints / events are armed. */
|
---|
419 | bool fUseDebugLoop;
|
---|
420 | /** Whether we're executing a single instruction. */
|
---|
421 | bool fSingleInstruction;
|
---|
422 |
|
---|
423 | bool afAlignment0[2];
|
---|
424 |
|
---|
425 | /** An additional error code used for some gurus. */
|
---|
426 | uint32_t u32HMError;
|
---|
427 | /** The last exit-to-ring-3 reason. */
|
---|
428 | int32_t rcLastExitToR3;
|
---|
429 | /** CPU-context changed flags (see HM_CHANGED_xxx). */
|
---|
430 | uint64_t fCtxChanged;
|
---|
431 |
|
---|
432 | /** The guest VMCS information. */
|
---|
433 | VMXVMCSINFO VmcsInfo;
|
---|
434 |
|
---|
435 | /** VT-x data. */
|
---|
436 | struct HMCPUVMX
|
---|
437 | {
|
---|
438 | /** @name Guest information.
|
---|
439 | * @{ */
|
---|
440 | /** Guest VMCS information shared with ring-3. */
|
---|
441 | VMXVMCSINFOSHARED VmcsInfo;
|
---|
442 | /** Nested-guest VMCS information shared with ring-3. */
|
---|
443 | VMXVMCSINFOSHARED VmcsInfoNstGst;
|
---|
444 | /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
|
---|
445 | * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
|
---|
446 | bool fSwitchedToNstGstVmcsCopyForRing3;
|
---|
447 | /** Whether the static guest VMCS controls has been merged with the
|
---|
448 | * nested-guest VMCS controls. */
|
---|
449 | bool fMergedNstGstCtls;
|
---|
450 | /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
|
---|
451 | bool fCopiedNstGstToShadowVmcs;
|
---|
452 | /** Whether flushing the TLB is required due to switching to/from the
|
---|
453 | * nested-guest. */
|
---|
454 | bool fSwitchedNstGstFlushTlb;
|
---|
455 | /** Alignment. */
|
---|
456 | bool afAlignment0[4];
|
---|
457 | /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
|
---|
458 | uint64_t u64GstMsrApicBase;
|
---|
459 | /** @} */
|
---|
460 |
|
---|
461 | /** @name Error reporting and diagnostics.
|
---|
462 | * @{ */
|
---|
463 | /** VT-x error-reporting (mainly for ring-3 propagation). */
|
---|
464 | struct
|
---|
465 | {
|
---|
466 | RTCPUID idCurrentCpu;
|
---|
467 | RTCPUID idEnteredCpu;
|
---|
468 | RTHCPHYS HCPhysCurrentVmcs;
|
---|
469 | uint32_t u32VmcsRev;
|
---|
470 | uint32_t u32InstrError;
|
---|
471 | uint32_t u32ExitReason;
|
---|
472 | uint32_t u32GuestIntrState;
|
---|
473 | } LastError;
|
---|
474 | /** @} */
|
---|
475 | } vmx;
|
---|
476 |
|
---|
477 | /** Event injection state. */
|
---|
478 | HMEVENT Event;
|
---|
479 |
|
---|
480 | /** Current shadow paging mode for updating CR4.
|
---|
481 | * @todo move later (@bugref{9217}). */
|
---|
482 | PGMMODE enmShadowMode;
|
---|
483 | uint32_t u32TemporaryPadding;
|
---|
484 |
|
---|
485 | /** The PAE PDPEs used with Nested Paging (only valid when
|
---|
486 | * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
|
---|
487 | X86PDPE aPdpes[4];
|
---|
488 | /** Pointer to the VMX statistics. */
|
---|
489 | PVMXSTATISTICS pVmxStats;
|
---|
490 |
|
---|
491 | /** @name Statistics
|
---|
492 | * @{ */
|
---|
493 | STAMCOUNTER StatBreakOnCancel;
|
---|
494 | STAMCOUNTER StatBreakOnFFPre;
|
---|
495 | STAMCOUNTER StatBreakOnFFPost;
|
---|
496 | STAMCOUNTER StatBreakOnStatus;
|
---|
497 | STAMCOUNTER StatImportOnDemand;
|
---|
498 | STAMCOUNTER StatImportOnReturn;
|
---|
499 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
500 | STAMCOUNTER StatQueryCpuTick;
|
---|
501 | /** @} */
|
---|
502 |
|
---|
503 | /** @} */
|
---|
504 | #endif /* RT_OS_DARWIN */
|
---|
505 | } NEMCPU;
|
---|
506 | /** Pointer to NEM VMCPU instance data. */
|
---|
507 | typedef NEMCPU *PNEMCPU;
|
---|
508 |
|
---|
509 | /** NEMCPU::u32Magic value. */
|
---|
510 | #define NEMCPU_MAGIC UINT32_C(0x4d454e20)
|
---|
511 | /** NEMCPU::u32Magic value after termination. */
|
---|
512 | #define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
|
---|
513 |
|
---|
514 |
|
---|
515 | #ifdef IN_RING0
|
---|
516 | # ifdef RT_OS_WINDOWS
|
---|
517 | /**
|
---|
518 | * Windows: Hypercall input/ouput page info.
|
---|
519 | */
|
---|
520 | typedef struct NEMR0HYPERCALLDATA
|
---|
521 | {
|
---|
522 | /** Host physical address of the hypercall input/output page. */
|
---|
523 | RTHCPHYS HCPhysPage;
|
---|
524 | /** Pointer to the hypercall input/output page. */
|
---|
525 | uint8_t *pbPage;
|
---|
526 | /** Handle to the memory object of the hypercall input/output page. */
|
---|
527 | RTR0MEMOBJ hMemObj;
|
---|
528 | } NEMR0HYPERCALLDATA;
|
---|
529 | /** Pointer to a Windows hypercall input/output page info. */
|
---|
530 | typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
|
---|
531 | # endif /* RT_OS_WINDOWS */
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * NEM GVMCPU instance data.
|
---|
535 | */
|
---|
536 | typedef struct NEMR0PERVCPU
|
---|
537 | {
|
---|
538 | # if defined(RT_OS_WINDOWS) && defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
|
---|
539 | /** Hypercall input/ouput page. */
|
---|
540 | NEMR0HYPERCALLDATA HypercallData;
|
---|
541 | /** Delta to add to convert a ring-0 pointer to a ring-3 one. */
|
---|
542 | uintptr_t offRing3ConversionDelta;
|
---|
543 | # else
|
---|
544 | uint32_t uDummy;
|
---|
545 | # endif
|
---|
546 | } NEMR0PERVCPU;
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * NEM GVM instance data.
|
---|
550 | */
|
---|
551 | typedef struct NEMR0PERVM
|
---|
552 | {
|
---|
553 | # ifdef RT_OS_WINDOWS
|
---|
554 | # ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
555 | /** The partition ID. */
|
---|
556 | uint64_t idHvPartition;
|
---|
557 | /** I/O control context. */
|
---|
558 | PSUPR0IOCTLCTX pIoCtlCtx;
|
---|
559 | /** Info about the VidGetHvPartitionId I/O control interface. */
|
---|
560 | NEMWINIOCTL IoCtlGetHvPartitionId;
|
---|
561 | /** Info about the VidGetPartitionProperty I/O control interface. */
|
---|
562 | NEMWINIOCTL IoCtlGetPartitionProperty;
|
---|
563 | # endif
|
---|
564 | # ifdef NEM_WIN_WITH_RING0_RUNLOOP
|
---|
565 | /** Info about the VidStartVirtualProcessor I/O control interface. */
|
---|
566 | NEMWINIOCTL IoCtlStartVirtualProcessor;
|
---|
567 | /** Info about the VidStopVirtualProcessor I/O control interface. */
|
---|
568 | NEMWINIOCTL IoCtlStopVirtualProcessor;
|
---|
569 | /** Info about the VidStopVirtualProcessor I/O control interface. */
|
---|
570 | NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
|
---|
571 | /** Whether we may use the ring-0 runloop or not. */
|
---|
572 | bool fMayUseRing0Runloop;
|
---|
573 | # endif
|
---|
574 |
|
---|
575 | # ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
|
---|
576 | /** Hypercall input/ouput page for non-EMT. */
|
---|
577 | NEMR0HYPERCALLDATA HypercallData;
|
---|
578 | /** Critical section protecting use of HypercallData. */
|
---|
579 | RTCRITSECT HypercallDataCritSect;
|
---|
580 | # endif
|
---|
581 |
|
---|
582 | # else
|
---|
583 | uint32_t uDummy;
|
---|
584 | # endif
|
---|
585 | } NEMR0PERVM;
|
---|
586 |
|
---|
587 | #endif /* IN_RING*/
|
---|
588 |
|
---|
589 |
|
---|
590 | #ifdef IN_RING3
|
---|
591 | int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
|
---|
592 | int nemR3NativeInitAfterCPUM(PVM pVM);
|
---|
593 | int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
|
---|
594 | int nemR3NativeTerm(PVM pVM);
|
---|
595 | void nemR3NativeReset(PVM pVM);
|
---|
596 | void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
|
---|
597 | VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
|
---|
598 | bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
|
---|
599 | bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
|
---|
600 | void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
|
---|
601 | #endif
|
---|
602 |
|
---|
603 | void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
|
---|
604 | void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
|
---|
605 | RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
|
---|
606 | int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
|
---|
607 | PGMPAGETYPE enmType, uint8_t *pu2State);
|
---|
608 |
|
---|
609 |
|
---|
610 | #ifdef RT_OS_WINDOWS
|
---|
611 | /** Maximum number of pages we can map in a single NEMR0MapPages call. */
|
---|
612 | # define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
|
---|
613 | /** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
|
---|
614 | # define NEM_MAX_UNMAP_PAGES 4095
|
---|
615 |
|
---|
616 | #endif
|
---|
617 | /** @} */
|
---|
618 |
|
---|
619 | RT_C_DECLS_END
|
---|
620 |
|
---|
621 | #endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
|
---|
622 |
|
---|