VirtualBox

source: vbox/trunk/src/VBox/VMM/include/NEMInternal.h@ 105447

Last change on this file since 105447 was 104672, checked in by vboxsync, 7 months ago

VMM/NEM: Pretty much work in progress Hyper-V on win.arm64 experiment, bugref:10392

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.6 KB
Line 
1/* $Id: NEMInternal.h 104672 2024-05-16 10:50:35Z vboxsync $ */
2/** @file
3 * NEM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2018-2023 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
51RT_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 */
74typedef 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. */
116typedef unsigned hv_vcpuid_t;
117/** The HV VM memory space ID (ASID). */
118typedef 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 */
147typedef 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. */
157typedef 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 */
179typedef 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 */
210typedef 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#elif defined(RT_OS_DARWIN)
319 /** Set if we've created the EMTs. */
320 bool fCreatedEmts : 1;
321 /** Set if hv_vm_create() was called successfully. */
322 bool fCreatedVm : 1;
323# if defined(VBOX_VMM_TARGET_ARMV8)
324 /** @name vTimer related state.
325 * @{ */
326 /** The counter frequency in Hz as obtained from CNTFRQ_EL0. */
327 uint64_t u64CntFrqHz;
328 /** The vTimer offset programmed. */
329 uint64_t u64VTimerOff;
330 /** Dirty tracking slots. */
331 NEMHVMMIO2REGION aMmio2DirtyTracking[8];
332 /** The vCPU config. */
333 hv_vcpu_config_t hVCpuCfg;
334 /** @} */
335# else
336 /** Set if hv_vm_space_create() was called successfully. */
337 bool fCreatedAsid : 1;
338 /** Set if Last Branch Record (LBR) is enabled. */
339 bool fLbr;
340 /** The ASID for this VM (only valid if fCreatedAsid is true). */
341 hv_vm_space_t uVmAsid;
342 /** Number of mach time units per NS, for hv_vcpu_run_until(). */
343 uint64_t cMachTimePerNs;
344 /** Pause-loop exiting (PLE) gap in ticks. */
345 uint32_t cPleGapTicks;
346 /** Pause-loop exiting (PLE) window in ticks. */
347 uint32_t cPleWindowTicks;
348
349 /** The host LBR TOS (top-of-stack) MSR id. */
350 uint32_t idLbrTosMsr;
351 /** The host LBR select MSR id. */
352 uint32_t idLbrSelectMsr;
353 /** The host last event record from IP MSR id. */
354 uint32_t idLerFromIpMsr;
355 /** The host last event record to IP MSR id. */
356 uint32_t idLerToIpMsr;
357
358 /** The first valid host LBR branch-from-IP stack range. */
359 uint32_t idLbrFromIpMsrFirst;
360 /** The last valid host LBR branch-from-IP stack range. */
361 uint32_t idLbrFromIpMsrLast;
362
363 /** The first valid host LBR branch-to-IP stack range. */
364 uint32_t idLbrToIpMsrFirst;
365 /** The last valid host LBR branch-to-IP stack range. */
366 uint32_t idLbrToIpMsrLast;
367
368 /** The first valid host LBR info stack range. */
369 uint32_t idLbrInfoMsrFirst;
370 /** The last valid host LBR info stack range. */
371 uint32_t idLbrInfoMsrLast;
372# endif
373
374 STAMCOUNTER StatMapPage;
375 STAMCOUNTER StatUnmapPage;
376 STAMCOUNTER StatMapPageFailed;
377 STAMCOUNTER StatUnmapPageFailed;
378#endif /* RT_OS_WINDOWS */
379} NEM;
380/** Pointer to NEM VM instance data. */
381typedef NEM *PNEM;
382
383/** NEM::u32Magic value. */
384#define NEM_MAGIC UINT32_C(0x004d454e)
385/** NEM::u32Magic value after termination. */
386#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
387
388
389/**
390 * NEM VMCPU Instance data.
391 */
392typedef struct NEMCPU
393{
394 /** NEMCPU_MAGIC. */
395 uint32_t u32Magic;
396 /** Whether \#UD needs to be intercepted and presented to GIM. */
397 bool fGIMTrapXcptUD : 1;
398 /** Whether \#GP needs to be intercept for mesa driver workaround. */
399 bool fTrapXcptGpForLovelyMesaDrv: 1;
400 /** Whether we should use the debug loop because of single stepping or special
401 * debug breakpoints / events are armed. */
402 bool fUseDebugLoop : 1;
403 /** Whether we're executing a single instruction. */
404 bool fSingleInstruction : 1;
405 /** Set if we using the debug loop and wish to intercept RDTSC. */
406 bool fDebugWantRdTscExit : 1;
407 /** Whether we are currently executing in the debug loop.
408 * Mainly for assertions. */
409 bool fUsingDebugLoop : 1;
410 /** Set if we need to clear the trap flag because of single stepping. */
411 bool fClearTrapFlag : 1;
412 /** Whether we're using the hyper DR7 or guest DR7. */
413 bool fUsingHyperDR7 : 1;
414 /** Whether \#DE needs to be intercepted for GIM. */
415 bool fGCMTrapXcptDE : 1;
416
417#if defined(RT_OS_LINUX)
418 uint8_t abPadding[3];
419 /** The KVM VCpu file descriptor. */
420 int32_t fdVCpu;
421 /** Pointer to the KVM_RUN data exchange region. */
422 R3PTRTYPE(struct kvm_run *) pRun;
423# if defined(VBOX_VMM_TARGET_ARMV8)
424 /** The IRQ device levels from device_irq_level. */
425 uint64_t fIrqDeviceLvls;
426 /** Status of the IRQ line when last seen. */
427 bool fIrqLastSeen;
428 /** Status of the FIQ line when last seen. */
429 bool fFiqLastSeen;
430# else
431 /** The MSR_IA32_APICBASE value known to KVM. */
432 uint64_t uKvmApicBase;
433#endif
434
435 /** @name Statistics
436 * @{ */
437 STAMCOUNTER StatExitTotal;
438 STAMCOUNTER StatExitIo;
439 STAMCOUNTER StatExitMmio;
440 STAMCOUNTER StatExitSetTpr;
441 STAMCOUNTER StatExitTprAccess;
442 STAMCOUNTER StatExitRdMsr;
443 STAMCOUNTER StatExitWrMsr;
444 STAMCOUNTER StatExitIrqWindowOpen;
445 STAMCOUNTER StatExitHalt;
446 STAMCOUNTER StatExitIntr;
447 STAMCOUNTER StatExitHypercall;
448 STAMCOUNTER StatExitDebug;
449 STAMCOUNTER StatExitBusLock;
450 STAMCOUNTER StatExitInternalErrorEmulation;
451 STAMCOUNTER StatExitInternalErrorFatal;
452# if 0
453 STAMCOUNTER StatExitCpuId;
454 STAMCOUNTER StatExitUnrecoverable;
455 STAMCOUNTER StatGetMsgTimeout;
456 STAMCOUNTER StatStopCpuSuccess;
457 STAMCOUNTER StatStopCpuPending;
458 STAMCOUNTER StatStopCpuPendingAlerts;
459 STAMCOUNTER StatStopCpuPendingOdd;
460 STAMCOUNTER StatCancelChangedState;
461 STAMCOUNTER StatCancelAlertedThread;
462# endif
463 STAMCOUNTER StatBreakOnCancel;
464 STAMCOUNTER StatBreakOnFFPre;
465 STAMCOUNTER StatBreakOnFFPost;
466 STAMCOUNTER StatBreakOnStatus;
467 STAMCOUNTER StatFlushExitOnReturn;
468 STAMCOUNTER StatFlushExitOnReturn1Loop;
469 STAMCOUNTER StatFlushExitOnReturn2Loops;
470 STAMCOUNTER StatFlushExitOnReturn3Loops;
471 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
472 STAMCOUNTER StatImportOnDemand;
473 STAMCOUNTER StatImportOnReturn;
474 STAMCOUNTER StatImportOnReturnSkipped;
475 STAMCOUNTER StatImportPendingInterrupt;
476 STAMCOUNTER StatExportPendingInterrupt;
477 STAMCOUNTER StatQueryCpuTick;
478 /** @} */
479
480
481#elif defined(RT_OS_WINDOWS)
482# ifdef VBOX_VMM_TARGET_ARMV8
483 /** Flag whether the ID registers were synced to the guest context
484 * (for first guest exec call on the EMT after loading the saved state). */
485 bool fIdRegsSynced;
486# else
487 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
488 uint8_t fCurrentInterruptWindows;
489 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
490 uint8_t fDesiredInterruptWindows;
491 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
492 bool fLastInterruptShadow : 1;
493 uint32_t uPadding;
494 /** The VID_MSHAGN_F_XXX flags.
495 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
496 uint32_t fHandleAndGetFlags;
497 /** What VidMessageSlotMap returns and is used for passing exit info. */
498 RTR3PTR pvMsgSlotMapping;
499 /** The windows thread handle. */
500 RTR3PTR hNativeThreadHandle;
501# endif
502
503 /** @name Statistics
504 * @{ */
505 STAMCOUNTER StatExitPortIo;
506 STAMCOUNTER StatExitMemUnmapped;
507 STAMCOUNTER StatExitMemIntercept;
508 STAMCOUNTER StatExitHalt;
509 STAMCOUNTER StatExitInterruptWindow;
510 STAMCOUNTER StatExitCpuId;
511 STAMCOUNTER StatExitMsr;
512 STAMCOUNTER StatExitException;
513 STAMCOUNTER StatExitExceptionBp;
514 STAMCOUNTER StatExitExceptionDb;
515 STAMCOUNTER StatExitExceptionGp;
516 STAMCOUNTER StatExitExceptionGpMesa;
517 STAMCOUNTER StatExitExceptionUd;
518 STAMCOUNTER StatExitExceptionUdHandled;
519 STAMCOUNTER StatExitUnrecoverable;
520 STAMCOUNTER StatGetMsgTimeout;
521 STAMCOUNTER StatStopCpuSuccess;
522 STAMCOUNTER StatStopCpuPending;
523 STAMCOUNTER StatStopCpuPendingAlerts;
524 STAMCOUNTER StatStopCpuPendingOdd;
525 STAMCOUNTER StatCancelChangedState;
526 STAMCOUNTER StatCancelAlertedThread;
527 STAMCOUNTER StatBreakOnCancel;
528 STAMCOUNTER StatBreakOnFFPre;
529 STAMCOUNTER StatBreakOnFFPost;
530 STAMCOUNTER StatBreakOnStatus;
531 STAMCOUNTER StatImportOnDemand;
532 STAMCOUNTER StatImportOnReturn;
533 STAMCOUNTER StatImportOnReturnSkipped;
534 STAMCOUNTER StatQueryCpuTick;
535 /** @} */
536
537#elif defined(RT_OS_DARWIN)
538# if defined(VBOX_VMM_TARGET_ARMV8)
539 /** The vCPU handle associated with the EMT executing this vCPU. */
540 hv_vcpu_t hVCpu;
541 /** Pointer to the exit information structure. */
542 hv_vcpu_exit_t *pHvExit;
543 /** Flag whether an event is pending. */
544 bool fEventPending;
545 /** Flag whether the vTimer got activated and is masked. */
546 bool fVTimerActivated;
547 /** Flag whether to update the vTimer offset. */
548 bool fVTimerOffUpdate;
549 /** Flag whether the ID registers were synced to the guest context
550 * (for first guest exec call on the EMT after loading the saved state). */
551 bool fIdRegsSynced;
552# else
553 /** The vCPU handle associated with the EMT executing this vCPU. */
554 hv_vcpuid_t hVCpuId;
555
556 /** @name State shared with the VT-x code.
557 * @{ */
558 /** An additional error code used for some gurus. */
559 uint32_t u32HMError;
560 /** The last exit-to-ring-3 reason. */
561 int32_t rcLastExitToR3;
562 /** CPU-context changed flags (see HM_CHANGED_xxx). */
563 uint64_t fCtxChanged;
564
565 /** The guest VMCS information. */
566 VMXVMCSINFO VmcsInfo;
567
568 /** VT-x data. */
569 struct HMCPUVMX
570 {
571 /** @name Guest information.
572 * @{ */
573 /** Guest VMCS information shared with ring-3. */
574 VMXVMCSINFOSHARED VmcsInfo;
575 /** Nested-guest VMCS information shared with ring-3. */
576 VMXVMCSINFOSHARED VmcsInfoNstGst;
577 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
578 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
579 bool fSwitchedToNstGstVmcsCopyForRing3;
580 /** Whether the static guest VMCS controls has been merged with the
581 * nested-guest VMCS controls. */
582 bool fMergedNstGstCtls;
583 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
584 bool fCopiedNstGstToShadowVmcs;
585 /** Whether flushing the TLB is required due to switching to/from the
586 * nested-guest. */
587 bool fSwitchedNstGstFlushTlb;
588 /** Alignment. */
589 bool afAlignment0[4];
590 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
591 uint64_t u64GstMsrApicBase;
592 /** @} */
593
594 /** @name Error reporting and diagnostics.
595 * @{ */
596 /** VT-x error-reporting (mainly for ring-3 propagation). */
597 struct
598 {
599 RTCPUID idCurrentCpu;
600 RTCPUID idEnteredCpu;
601 RTHCPHYS HCPhysCurrentVmcs;
602 uint32_t u32VmcsRev;
603 uint32_t u32InstrError;
604 uint32_t u32ExitReason;
605 uint32_t u32GuestIntrState;
606 } LastError;
607 /** @} */
608 } vmx;
609
610 /** Event injection state. */
611 HMEVENT Event;
612
613 /** Current shadow paging mode for updating CR4.
614 * @todo move later (@bugref{9217}). */
615 PGMMODE enmShadowMode;
616 uint32_t u32TemporaryPadding;
617
618 /** The PAE PDPEs used with Nested Paging (only valid when
619 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
620 X86PDPE aPdpes[4];
621 /** Pointer to the VMX statistics. */
622 PVMXSTATISTICS pVmxStats;
623# endif
624
625 /** @name Statistics
626 * @{ */
627 STAMCOUNTER StatExitAll;
628 STAMCOUNTER StatBreakOnCancel;
629 STAMCOUNTER StatBreakOnFFPre;
630 STAMCOUNTER StatBreakOnFFPost;
631 STAMCOUNTER StatBreakOnStatus;
632 STAMCOUNTER StatImportOnDemand;
633 STAMCOUNTER StatImportOnReturn;
634 STAMCOUNTER StatImportOnReturnSkipped;
635 STAMCOUNTER StatQueryCpuTick;
636#ifdef VBOX_WITH_STATISTICS
637 STAMPROFILEADV StatProfGstStateImport;
638 STAMPROFILEADV StatProfGstStateExport;
639#endif
640 /** @} */
641
642 /** @} */
643#endif /* RT_OS_DARWIN */
644} NEMCPU;
645/** Pointer to NEM VMCPU instance data. */
646typedef NEMCPU *PNEMCPU;
647
648/** NEMCPU::u32Magic value. */
649#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
650/** NEMCPU::u32Magic value after termination. */
651#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
652
653
654#ifdef IN_RING0
655# ifdef RT_OS_WINDOWS
656/**
657 * Windows: Hypercall input/ouput page info.
658 */
659typedef struct NEMR0HYPERCALLDATA
660{
661 /** Host physical address of the hypercall input/output page. */
662 RTHCPHYS HCPhysPage;
663 /** Pointer to the hypercall input/output page. */
664 uint8_t *pbPage;
665 /** Handle to the memory object of the hypercall input/output page. */
666 RTR0MEMOBJ hMemObj;
667} NEMR0HYPERCALLDATA;
668/** Pointer to a Windows hypercall input/output page info. */
669typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
670# endif /* RT_OS_WINDOWS */
671
672/**
673 * NEM GVMCPU instance data.
674 */
675typedef struct NEMR0PERVCPU
676{
677 uint32_t uDummy;
678} NEMR0PERVCPU;
679
680/**
681 * NEM GVM instance data.
682 */
683typedef struct NEMR0PERVM
684{
685 uint32_t uDummy;
686} NEMR0PERVM;
687
688#endif /* IN_RING*/
689
690
691#ifdef IN_RING3
692
693int nemR3DisableCpuIsaExt(PVM pVM, const char *pszIsaExt);
694
695int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
696int nemR3NativeInitAfterCPUM(PVM pVM);
697int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
698int nemR3NativeTerm(PVM pVM);
699void nemR3NativeReset(PVM pVM);
700void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
701VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
702bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
703bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
704
705/**
706 * Forced flag notification call from VMEmt.h.
707 *
708 * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
709 *
710 * @param pVM The cross context VM structure.
711 * @param pVCpu The cross context virtual CPU structure of the CPU
712 * to be notified.
713 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
714 */
715void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
716
717/**
718 * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
719 * on whether to switch to the debug loop.
720 *
721 * @returns Final flag whether to switch to the debug loop.
722 * @param pVM The VM cross context VM structure.
723 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
724 * @thread EMT(0)
725 */
726DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
727
728
729/**
730 * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
731 * on whether to switch to the debug loop.
732 *
733 * @returns Final flag whether to switch to the debug loop.
734 * @param pVM The VM cross context VM structure.
735 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
736 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
737 */
738DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
739
740#endif /* IN_RING3 */
741
742void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
743void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
744 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
745int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
746 PGMPAGETYPE enmType, uint8_t *pu2State);
747
748
749#ifdef RT_OS_WINDOWS
750/** Maximum number of pages we can map in a single NEMR0MapPages call. */
751# define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
752/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
753# define NEM_MAX_UNMAP_PAGES 4095
754
755#endif
756/** @} */
757
758RT_C_DECLS_END
759
760#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
761
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette