1 | /* $Id: NEMInternal.h 93355 2022-01-20 00:57:12Z 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_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 | #if defined(VBOX_WITH_NATIVE_NEM) && !defined(VBOX_WITH_PGM_NEM_MODE)
|
---|
50 | # error "VBOX_WITH_NATIVE_NEM requires VBOX_WITH_PGM_NEM_MODE to be defined"
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | #ifdef RT_OS_WINDOWS
|
---|
55 | /*
|
---|
56 | * Windows: Code configuration.
|
---|
57 | */
|
---|
58 | /* nothing at the moment */
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Windows VID I/O control information.
|
---|
62 | */
|
---|
63 | typedef struct NEMWINIOCTL
|
---|
64 | {
|
---|
65 | /** The I/O control function number. */
|
---|
66 | uint32_t uFunction;
|
---|
67 | uint32_t cbInput;
|
---|
68 | uint32_t cbOutput;
|
---|
69 | } NEMWINIOCTL;
|
---|
70 |
|
---|
71 | /** @name Windows: Our two-bit physical page state for PGMPAGE
|
---|
72 | * @{ */
|
---|
73 | # define NEM_WIN_PAGE_STATE_NOT_SET 0
|
---|
74 | # define NEM_WIN_PAGE_STATE_UNMAPPED 1
|
---|
75 | # define NEM_WIN_PAGE_STATE_READABLE 2
|
---|
76 | # define NEM_WIN_PAGE_STATE_WRITABLE 3
|
---|
77 | /** @} */
|
---|
78 |
|
---|
79 | /** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
|
---|
80 | # define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
|
---|
81 | /** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
|
---|
82 | # define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
|
---|
83 | ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
|
---|
84 |
|
---|
85 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
86 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
|
---|
87 | | CPUMCTX_EXTRN_INHIBIT_NMI )
|
---|
88 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
89 | # define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
90 |
|
---|
91 | /** @name Windows: Interrupt window flags (NEM_WIN_INTW_F_XXX).
|
---|
92 | * @{ */
|
---|
93 | # define NEM_WIN_INTW_F_NMI UINT8_C(0x01)
|
---|
94 | # define NEM_WIN_INTW_F_REGULAR UINT8_C(0x02)
|
---|
95 | # define NEM_WIN_INTW_F_PRIO_MASK UINT8_C(0x3c)
|
---|
96 | # define NEM_WIN_INTW_F_PRIO_SHIFT 2
|
---|
97 | /** @} */
|
---|
98 |
|
---|
99 | #endif /* RT_OS_WINDOWS */
|
---|
100 |
|
---|
101 |
|
---|
102 | #ifdef RT_OS_DARWIN
|
---|
103 | /** vCPU ID declaration to avoid dragging in HV headers here. */
|
---|
104 | typedef unsigned hv_vcpuid_t;
|
---|
105 | /** The HV VM memory space ID (ASID). */
|
---|
106 | typedef unsigned hv_vm_space_t;
|
---|
107 |
|
---|
108 |
|
---|
109 | /** @name Darwin: Our two-bit physical page state for PGMPAGE
|
---|
110 | * @{ */
|
---|
111 | # define NEM_DARWIN_PAGE_STATE_NOT_SET 0
|
---|
112 | # define NEM_DARWIN_PAGE_STATE_UNMAPPED 1
|
---|
113 | # define NEM_DARWIN_PAGE_STATE_READABLE 2
|
---|
114 | # define NEM_DARWIN_PAGE_STATE_WRITABLE 3
|
---|
115 | /** @} */
|
---|
116 |
|
---|
117 | /** The CPUMCTX_EXTRN_XXX mask for IEM. */
|
---|
118 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
|
---|
119 | | CPUMCTX_EXTRN_INHIBIT_NMI )
|
---|
120 | /** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
|
---|
121 | # define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
|
---|
122 |
|
---|
123 | #endif
|
---|
124 |
|
---|
125 |
|
---|
126 | /** Trick to make slickedit see the static functions in the template. */
|
---|
127 | #ifndef IN_SLICKEDIT
|
---|
128 | # define NEM_TMPL_STATIC static
|
---|
129 | #else
|
---|
130 | # define NEM_TMPL_STATIC
|
---|
131 | #endif
|
---|
132 |
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Generic NEM exit type enumeration for use with EMHistoryAddExit.
|
---|
136 | *
|
---|
137 | * On windows we've got two different set of exit types and they are both jumping
|
---|
138 | * around the place value wise, so EM can use their values.
|
---|
139 | *
|
---|
140 | * @note We only have exit types for exits not covered by EM here.
|
---|
141 | */
|
---|
142 | typedef enum NEMEXITTYPE
|
---|
143 | {
|
---|
144 | NEMEXITTYPE_INVALID = 0,
|
---|
145 |
|
---|
146 | /* Common: */
|
---|
147 | NEMEXITTYPE_INTTERRUPT_WINDOW,
|
---|
148 | NEMEXITTYPE_HALT,
|
---|
149 |
|
---|
150 | /* Windows: */
|
---|
151 | NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
|
---|
152 | NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
|
---|
153 | NEMEXITTYPE_XCPT_UD,
|
---|
154 | NEMEXITTYPE_XCPT_DB,
|
---|
155 | NEMEXITTYPE_XCPT_BP,
|
---|
156 | NEMEXITTYPE_CANCELED,
|
---|
157 | NEMEXITTYPE_MEMORY_ACCESS,
|
---|
158 |
|
---|
159 | /* Linux: */
|
---|
160 | NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
|
---|
161 | NEMEXITTYPE_INTERNAL_ERROR_FATAL,
|
---|
162 | NEMEXITTYPE_INTERRUPTED,
|
---|
163 | NEMEXITTYPE_FAILED_ENTRY,
|
---|
164 |
|
---|
165 | /* End of valid types. */
|
---|
166 | NEMEXITTYPE_END
|
---|
167 | } NEMEXITTYPE;
|
---|
168 |
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * NEM VM Instance data.
|
---|
172 | */
|
---|
173 | typedef struct NEM
|
---|
174 | {
|
---|
175 | /** NEM_MAGIC. */
|
---|
176 | uint32_t u32Magic;
|
---|
177 |
|
---|
178 | /** Set if enabled. */
|
---|
179 | bool fEnabled;
|
---|
180 | /** Set if long mode guests are allowed. */
|
---|
181 | bool fAllow64BitGuests;
|
---|
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 | /** The ASID for this VM (only valid if fCreatedAsid is true). */
|
---|
269 | hv_vm_space_t uVmAsid;
|
---|
270 | STAMCOUNTER StatMapPage;
|
---|
271 | STAMCOUNTER StatUnmapPage;
|
---|
272 | STAMCOUNTER StatMapPageFailed;
|
---|
273 | STAMCOUNTER StatUnmapPageFailed;
|
---|
274 | #endif /* RT_OS_WINDOWS */
|
---|
275 | } NEM;
|
---|
276 | /** Pointer to NEM VM instance data. */
|
---|
277 | typedef NEM *PNEM;
|
---|
278 |
|
---|
279 | /** NEM::u32Magic value. */
|
---|
280 | #define NEM_MAGIC UINT32_C(0x004d454e)
|
---|
281 | /** NEM::u32Magic value after termination. */
|
---|
282 | #define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
|
---|
283 |
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * NEM VMCPU Instance data.
|
---|
287 | */
|
---|
288 | typedef struct NEMCPU
|
---|
289 | {
|
---|
290 | /** NEMCPU_MAGIC. */
|
---|
291 | uint32_t u32Magic;
|
---|
292 | /** Whether \#UD needs to be intercepted and presented to GIM. */
|
---|
293 | bool fGIMTrapXcptUD : 1;
|
---|
294 | /** Whether \#GP needs to be intercept for mesa driver workaround. */
|
---|
295 | bool fTrapXcptGpForLovelyMesaDrv: 1;
|
---|
296 |
|
---|
297 | #if defined(RT_OS_LINUX)
|
---|
298 | uint8_t abPadding[3];
|
---|
299 | /** The KVM VCpu file descriptor. */
|
---|
300 | int32_t fdVCpu;
|
---|
301 | /** Pointer to the KVM_RUN data exchange region. */
|
---|
302 | R3PTRTYPE(struct kvm_run *) pRun;
|
---|
303 | /** The MSR_IA32_APICBASE value known to KVM. */
|
---|
304 | uint64_t uKvmApicBase;
|
---|
305 |
|
---|
306 | /** @name Statistics
|
---|
307 | * @{ */
|
---|
308 | STAMCOUNTER StatExitTotal;
|
---|
309 | STAMCOUNTER StatExitIo;
|
---|
310 | STAMCOUNTER StatExitMmio;
|
---|
311 | STAMCOUNTER StatExitSetTpr;
|
---|
312 | STAMCOUNTER StatExitTprAccess;
|
---|
313 | STAMCOUNTER StatExitRdMsr;
|
---|
314 | STAMCOUNTER StatExitWrMsr;
|
---|
315 | STAMCOUNTER StatExitIrqWindowOpen;
|
---|
316 | STAMCOUNTER StatExitHalt;
|
---|
317 | STAMCOUNTER StatExitIntr;
|
---|
318 | STAMCOUNTER StatExitHypercall;
|
---|
319 | STAMCOUNTER StatExitDebug;
|
---|
320 | STAMCOUNTER StatExitBusLock;
|
---|
321 | STAMCOUNTER StatExitInternalErrorEmulation;
|
---|
322 | STAMCOUNTER StatExitInternalErrorFatal;
|
---|
323 | # if 0
|
---|
324 | STAMCOUNTER StatExitCpuId;
|
---|
325 | STAMCOUNTER StatExitUnrecoverable;
|
---|
326 | STAMCOUNTER StatGetMsgTimeout;
|
---|
327 | STAMCOUNTER StatStopCpuSuccess;
|
---|
328 | STAMCOUNTER StatStopCpuPending;
|
---|
329 | STAMCOUNTER StatStopCpuPendingAlerts;
|
---|
330 | STAMCOUNTER StatStopCpuPendingOdd;
|
---|
331 | STAMCOUNTER StatCancelChangedState;
|
---|
332 | STAMCOUNTER StatCancelAlertedThread;
|
---|
333 | # endif
|
---|
334 | STAMCOUNTER StatBreakOnCancel;
|
---|
335 | STAMCOUNTER StatBreakOnFFPre;
|
---|
336 | STAMCOUNTER StatBreakOnFFPost;
|
---|
337 | STAMCOUNTER StatBreakOnStatus;
|
---|
338 | STAMCOUNTER StatFlushExitOnReturn;
|
---|
339 | STAMCOUNTER StatFlushExitOnReturn1Loop;
|
---|
340 | STAMCOUNTER StatFlushExitOnReturn2Loops;
|
---|
341 | STAMCOUNTER StatFlushExitOnReturn3Loops;
|
---|
342 | STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
|
---|
343 | STAMCOUNTER StatImportOnDemand;
|
---|
344 | STAMCOUNTER StatImportOnReturn;
|
---|
345 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
346 | STAMCOUNTER StatImportPendingInterrupt;
|
---|
347 | STAMCOUNTER StatExportPendingInterrupt;
|
---|
348 | STAMCOUNTER StatQueryCpuTick;
|
---|
349 | /** @} */
|
---|
350 |
|
---|
351 |
|
---|
352 | #elif defined(RT_OS_WINDOWS)
|
---|
353 | /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
354 | uint8_t fCurrentInterruptWindows;
|
---|
355 | /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
|
---|
356 | uint8_t fDesiredInterruptWindows;
|
---|
357 | /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
|
---|
358 | bool fLastInterruptShadow : 1;
|
---|
359 | uint32_t uPadding;
|
---|
360 | /** The VID_MSHAGN_F_XXX flags.
|
---|
361 | * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
|
---|
362 | uint32_t fHandleAndGetFlags;
|
---|
363 | /** What VidMessageSlotMap returns and is used for passing exit info. */
|
---|
364 | RTR3PTR pvMsgSlotMapping;
|
---|
365 | /** The windows thread handle. */
|
---|
366 | RTR3PTR hNativeThreadHandle;
|
---|
367 |
|
---|
368 | /** @name Statistics
|
---|
369 | * @{ */
|
---|
370 | STAMCOUNTER StatExitPortIo;
|
---|
371 | STAMCOUNTER StatExitMemUnmapped;
|
---|
372 | STAMCOUNTER StatExitMemIntercept;
|
---|
373 | STAMCOUNTER StatExitHalt;
|
---|
374 | STAMCOUNTER StatExitInterruptWindow;
|
---|
375 | STAMCOUNTER StatExitCpuId;
|
---|
376 | STAMCOUNTER StatExitMsr;
|
---|
377 | STAMCOUNTER StatExitException;
|
---|
378 | STAMCOUNTER StatExitExceptionBp;
|
---|
379 | STAMCOUNTER StatExitExceptionDb;
|
---|
380 | STAMCOUNTER StatExitExceptionGp;
|
---|
381 | STAMCOUNTER StatExitExceptionGpMesa;
|
---|
382 | STAMCOUNTER StatExitExceptionUd;
|
---|
383 | STAMCOUNTER StatExitExceptionUdHandled;
|
---|
384 | STAMCOUNTER StatExitUnrecoverable;
|
---|
385 | STAMCOUNTER StatGetMsgTimeout;
|
---|
386 | STAMCOUNTER StatStopCpuSuccess;
|
---|
387 | STAMCOUNTER StatStopCpuPending;
|
---|
388 | STAMCOUNTER StatStopCpuPendingAlerts;
|
---|
389 | STAMCOUNTER StatStopCpuPendingOdd;
|
---|
390 | STAMCOUNTER StatCancelChangedState;
|
---|
391 | STAMCOUNTER StatCancelAlertedThread;
|
---|
392 | STAMCOUNTER StatBreakOnCancel;
|
---|
393 | STAMCOUNTER StatBreakOnFFPre;
|
---|
394 | STAMCOUNTER StatBreakOnFFPost;
|
---|
395 | STAMCOUNTER StatBreakOnStatus;
|
---|
396 | STAMCOUNTER StatImportOnDemand;
|
---|
397 | STAMCOUNTER StatImportOnReturn;
|
---|
398 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
399 | STAMCOUNTER StatQueryCpuTick;
|
---|
400 | /** @} */
|
---|
401 |
|
---|
402 | #elif defined(RT_OS_DARWIN)
|
---|
403 | /** The vCPU handle associated with the EMT executing this vCPU. */
|
---|
404 | hv_vcpuid_t hVCpuId;
|
---|
405 |
|
---|
406 | /** @name State shared with the VT-x code.
|
---|
407 | * @{ */
|
---|
408 | /** Whether we should use the debug loop because of single stepping or special
|
---|
409 | * debug breakpoints / events are armed. */
|
---|
410 | bool fUseDebugLoop;
|
---|
411 | /** Whether we're executing a single instruction. */
|
---|
412 | bool fSingleInstruction;
|
---|
413 |
|
---|
414 | bool afAlignment0[2];
|
---|
415 |
|
---|
416 | /** An additional error code used for some gurus. */
|
---|
417 | uint32_t u32HMError;
|
---|
418 | /** The last exit-to-ring-3 reason. */
|
---|
419 | int32_t rcLastExitToR3;
|
---|
420 | /** CPU-context changed flags (see HM_CHANGED_xxx). */
|
---|
421 | uint64_t fCtxChanged;
|
---|
422 |
|
---|
423 | /** The guest VMCS information. */
|
---|
424 | VMXVMCSINFO VmcsInfo;
|
---|
425 |
|
---|
426 | /** VT-x data. */
|
---|
427 | struct HMCPUVMX
|
---|
428 | {
|
---|
429 | /** @name Guest information.
|
---|
430 | * @{ */
|
---|
431 | /** Guest VMCS information shared with ring-3. */
|
---|
432 | VMXVMCSINFOSHARED VmcsInfo;
|
---|
433 | /** Nested-guest VMCS information shared with ring-3. */
|
---|
434 | VMXVMCSINFOSHARED VmcsInfoNstGst;
|
---|
435 | /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
|
---|
436 | * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
|
---|
437 | bool fSwitchedToNstGstVmcsCopyForRing3;
|
---|
438 | /** Whether the static guest VMCS controls has been merged with the
|
---|
439 | * nested-guest VMCS controls. */
|
---|
440 | bool fMergedNstGstCtls;
|
---|
441 | /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
|
---|
442 | bool fCopiedNstGstToShadowVmcs;
|
---|
443 | /** Whether flushing the TLB is required due to switching to/from the
|
---|
444 | * nested-guest. */
|
---|
445 | bool fSwitchedNstGstFlushTlb;
|
---|
446 | /** Alignment. */
|
---|
447 | bool afAlignment0[4];
|
---|
448 | /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
|
---|
449 | uint64_t u64GstMsrApicBase;
|
---|
450 | /** @} */
|
---|
451 |
|
---|
452 | /** @name Error reporting and diagnostics.
|
---|
453 | * @{ */
|
---|
454 | /** VT-x error-reporting (mainly for ring-3 propagation). */
|
---|
455 | struct
|
---|
456 | {
|
---|
457 | RTCPUID idCurrentCpu;
|
---|
458 | RTCPUID idEnteredCpu;
|
---|
459 | RTHCPHYS HCPhysCurrentVmcs;
|
---|
460 | uint32_t u32VmcsRev;
|
---|
461 | uint32_t u32InstrError;
|
---|
462 | uint32_t u32ExitReason;
|
---|
463 | uint32_t u32GuestIntrState;
|
---|
464 | } LastError;
|
---|
465 | /** @} */
|
---|
466 | } vmx;
|
---|
467 |
|
---|
468 | /** Event injection state. */
|
---|
469 | HMEVENT Event;
|
---|
470 |
|
---|
471 | /** Current shadow paging mode for updating CR4.
|
---|
472 | * @todo move later (@bugref{9217}). */
|
---|
473 | PGMMODE enmShadowMode;
|
---|
474 | uint32_t u32TemporaryPadding;
|
---|
475 |
|
---|
476 | /** The PAE PDPEs used with Nested Paging (only valid when
|
---|
477 | * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
|
---|
478 | X86PDPE aPdpes[4];
|
---|
479 | /** Pointer to the VMX statistics. */
|
---|
480 | PVMXSTATISTICS pVmxStats;
|
---|
481 |
|
---|
482 | /** @name Statistics
|
---|
483 | * @{ */
|
---|
484 | STAMCOUNTER StatExitAll;
|
---|
485 | STAMCOUNTER StatBreakOnCancel;
|
---|
486 | STAMCOUNTER StatBreakOnFFPre;
|
---|
487 | STAMCOUNTER StatBreakOnFFPost;
|
---|
488 | STAMCOUNTER StatBreakOnStatus;
|
---|
489 | STAMCOUNTER StatImportOnDemand;
|
---|
490 | STAMCOUNTER StatImportOnReturn;
|
---|
491 | STAMCOUNTER StatImportOnReturnSkipped;
|
---|
492 | STAMCOUNTER StatQueryCpuTick;
|
---|
493 | #ifdef VBOX_WITH_STATISTICS
|
---|
494 | STAMPROFILEADV StatProfGstStateImport;
|
---|
495 | STAMPROFILEADV StatProfGstStateExport;
|
---|
496 | #endif
|
---|
497 | /** @} */
|
---|
498 |
|
---|
499 | /** @} */
|
---|
500 | #endif /* RT_OS_DARWIN */
|
---|
501 | } NEMCPU;
|
---|
502 | /** Pointer to NEM VMCPU instance data. */
|
---|
503 | typedef NEMCPU *PNEMCPU;
|
---|
504 |
|
---|
505 | /** NEMCPU::u32Magic value. */
|
---|
506 | #define NEMCPU_MAGIC UINT32_C(0x4d454e20)
|
---|
507 | /** NEMCPU::u32Magic value after termination. */
|
---|
508 | #define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
|
---|
509 |
|
---|
510 |
|
---|
511 | #ifdef IN_RING0
|
---|
512 | # ifdef RT_OS_WINDOWS
|
---|
513 | /**
|
---|
514 | * Windows: Hypercall input/ouput page info.
|
---|
515 | */
|
---|
516 | typedef struct NEMR0HYPERCALLDATA
|
---|
517 | {
|
---|
518 | /** Host physical address of the hypercall input/output page. */
|
---|
519 | RTHCPHYS HCPhysPage;
|
---|
520 | /** Pointer to the hypercall input/output page. */
|
---|
521 | uint8_t *pbPage;
|
---|
522 | /** Handle to the memory object of the hypercall input/output page. */
|
---|
523 | RTR0MEMOBJ hMemObj;
|
---|
524 | } NEMR0HYPERCALLDATA;
|
---|
525 | /** Pointer to a Windows hypercall input/output page info. */
|
---|
526 | typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
|
---|
527 | # endif /* RT_OS_WINDOWS */
|
---|
528 |
|
---|
529 | /**
|
---|
530 | * NEM GVMCPU instance data.
|
---|
531 | */
|
---|
532 | typedef struct NEMR0PERVCPU
|
---|
533 | {
|
---|
534 | uint32_t uDummy;
|
---|
535 | } NEMR0PERVCPU;
|
---|
536 |
|
---|
537 | /**
|
---|
538 | * NEM GVM instance data.
|
---|
539 | */
|
---|
540 | typedef struct NEMR0PERVM
|
---|
541 | {
|
---|
542 | uint32_t uDummy;
|
---|
543 | } NEMR0PERVM;
|
---|
544 |
|
---|
545 | #endif /* IN_RING*/
|
---|
546 |
|
---|
547 |
|
---|
548 | #ifdef IN_RING3
|
---|
549 | int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
|
---|
550 | int nemR3NativeInitAfterCPUM(PVM pVM);
|
---|
551 | int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
|
---|
552 | int nemR3NativeTerm(PVM pVM);
|
---|
553 | void nemR3NativeReset(PVM pVM);
|
---|
554 | void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
|
---|
555 | VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
|
---|
556 | bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
|
---|
557 | bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
|
---|
558 | void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
|
---|
559 | #endif
|
---|
560 |
|
---|
561 | void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
|
---|
562 | void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
|
---|
563 | RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
|
---|
564 | int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
|
---|
565 | PGMPAGETYPE enmType, uint8_t *pu2State);
|
---|
566 |
|
---|
567 |
|
---|
568 | #ifdef RT_OS_WINDOWS
|
---|
569 | /** Maximum number of pages we can map in a single NEMR0MapPages call. */
|
---|
570 | # define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
|
---|
571 | /** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
|
---|
572 | # define NEM_MAX_UNMAP_PAGES 4095
|
---|
573 |
|
---|
574 | #endif
|
---|
575 | /** @} */
|
---|
576 |
|
---|
577 | RT_C_DECLS_END
|
---|
578 |
|
---|
579 | #endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
|
---|
580 |
|
---|