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