VirtualBox

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

Last change on this file was 108758, checked in by vboxsync, 6 weeks ago

VMM/Arm: Add ACTLR_EL1 to the CPU state, bugref:10392

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.6 KB
Line 
1/* $Id: NEMInternal.h 108758 2025-03-26 16:05:20Z 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.215389.xyz.
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# ifdef 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# ifndef 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/** The CPUMCTX_EXTRN_XXX mask for IEM. */
131# ifdef VBOX_VMM_TARGET_ARMV8
132# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK )
133# else
134# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK \
135 | CPUMCTX_EXTRN_INHIBIT_INT | CPUMCTX_EXTRN_INHIBIT_NMI )
136# endif
137
138/** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
139# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
140
141
142# ifdef VBOX_VMM_TARGET_ARMV8
143/**
144 * MMIO2 tracking region.
145 */
146typedef struct
147{
148 /* Start of the region. */
149 RTGCPHYS GCPhysStart;
150 /** End of the region. */
151 RTGCPHYS GCPhysLast;
152 /** Whether the region was accessed since last time. */
153 bool fDirty;
154} NEMHVMMIO2REGION;
155/** Pointer to a MMIO2 tracking region. */
156typedef NEMHVMMIO2REGION *PNEMHVMMIO2REGION;
157# endif
158
159#endif
160
161
162/** Trick to make slickedit see the static functions in the template. */
163#ifndef IN_SLICKEDIT
164# define NEM_TMPL_STATIC static
165#else
166# define NEM_TMPL_STATIC
167#endif
168
169
170/**
171 * Generic NEM exit type enumeration for use with EMHistoryAddExit.
172 *
173 * On windows we've got two different set of exit types and they are both jumping
174 * around the place value wise, so EM can use their values.
175 *
176 * @note We only have exit types for exits not covered by EM here.
177 */
178typedef enum NEMEXITTYPE
179{
180 NEMEXITTYPE_INVALID = 0,
181
182 /* Common: */
183 NEMEXITTYPE_INTTERRUPT_WINDOW,
184 NEMEXITTYPE_HALT,
185
186 /* Windows: */
187 NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
188 NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
189 NEMEXITTYPE_XCPT_UD,
190 NEMEXITTYPE_XCPT_DB,
191 NEMEXITTYPE_XCPT_BP,
192 NEMEXITTYPE_CANCELED,
193 NEMEXITTYPE_MEMORY_ACCESS,
194
195 /* Linux: */
196 NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
197 NEMEXITTYPE_INTERNAL_ERROR_FATAL,
198 NEMEXITTYPE_INTERRUPTED,
199 NEMEXITTYPE_FAILED_ENTRY,
200
201 /* End of valid types. */
202 NEMEXITTYPE_END
203} NEMEXITTYPE;
204
205
206/**
207 * NEM VM Instance data.
208 */
209typedef struct NEM
210{
211 /** NEM_MAGIC. */
212 uint32_t u32Magic;
213
214 /** Set if enabled. */
215 bool fEnabled;
216 /** Set if long mode guests are allowed. */
217 bool fAllow64BitGuests;
218 /** Set when the debug facility has breakpoints/events enabled that requires
219 * us to use the debug execution loop. */
220 bool fUseDebugLoop;
221
222#ifdef VBOX_VMM_TARGET_ARMV8
223 /** The PPI interrupt number of the vTimer. */
224 uint32_t u32GicPpiVTimer;
225#endif
226
227#if defined(RT_OS_LINUX)
228 /** The '/dev/kvm' file descriptor. */
229 int32_t fdKvm;
230 /** The KVM_CREATE_VM file descriptor. */
231 int32_t fdVm;
232
233 /** KVM_GET_VCPU_MMAP_SIZE. */
234 uint32_t cbVCpuMmap;
235 /** KVM_CAP_NR_MEMSLOTS. */
236 uint32_t cMaxMemSlots;
237# ifdef RT_ARCH_ARM64
238 /** KVM_CAP_ARM_VM_IPA_SIZE. */
239 uint32_t cIpaBits;
240# else
241 /** KVM_CAP_X86_ROBUST_SINGLESTEP. */
242 bool fRobustSingleStep;
243# endif
244
245 /** Hint where there might be a free slot. */
246 uint16_t idPrevSlot;
247 /** Memory slot ID allocation bitmap. */
248 uint64_t bmSlotIds[_32K / 8 / sizeof(uint64_t)];
249
250#elif defined(RT_OS_WINDOWS)
251 /** Set if we've created the EMTs. */
252 bool fCreatedEmts : 1;
253# ifdef VBOX_VMM_TARGET_ARMV8
254 bool fHypercallExit : 1;
255 bool fGpaAccessFaultExit : 1;
256 /** Cache line flush size as a power of two. */
257 uint8_t cPhysicalAddressWidth;
258# elif defined(VBOX_VMM_TARGET_X86)
259 /** WHvRunVpExitReasonX64Cpuid is supported. */
260 bool fExtendedMsrExit : 1;
261 /** WHvRunVpExitReasonX64MsrAccess is supported. */
262 bool fExtendedCpuIdExit : 1;
263 /** WHvRunVpExitReasonException is supported. */
264 bool fExtendedXcptExit : 1;
265 /** Copy of WHV_CAPABILITY_FEATURES::SpeculationControl. */
266 bool fSpeculationControl : 1;
267 /** Whether to export/import IA32_SPEC_CTRL. */
268 bool fDoIa32SpecCtrl : 1;
269 /** WHvX64LocalApicEmulationModeXApic is used. */
270 bool fLocalApicEmulation : 1;
271# ifdef NEM_WIN_WITH_A20
272 /** Set if we've started more than one CPU and cannot mess with A20. */
273 bool fA20Fixed : 1;
274 /** Set if A20 is enabled. */
275 bool fA20Enabled : 1;
276# endif
277# endif
278 /** The reported CPU vendor. */
279 CPUMCPUVENDOR enmCpuVendor;
280 /** Cache line flush size as a power of two. */
281 uint8_t cCacheLineFlushShift;
282 /** The result of WHvCapabilityCodeProcessorFeatures. */
283 union
284 {
285 /** 64-bit view. */
286 uint64_t u64;
287# ifdef _WINHVAPIDEFS_H_
288 /** Interpreted features. */
289 WHV_PROCESSOR_FEATURES u;
290# endif
291 } uCpuFeatures;
292
293 /** The partition handle. */
294# ifdef _WINHVAPIDEFS_H_
295 WHV_PARTITION_HANDLE
296# else
297 RTHCUINTPTR
298# endif
299 hPartition;
300 /** The device handle for the partition, for use with Vid APIs or direct I/O
301 * controls. */
302 RTR3PTR hPartitionDevice;
303
304 /** Number of currently mapped pages. */
305 uint32_t volatile cMappedPages;
306 uint32_t u32Padding;
307 STAMCOUNTER StatMapPage;
308 STAMCOUNTER StatUnmapPage;
309 STAMCOUNTER StatMapPageFailed;
310 STAMCOUNTER StatUnmapPageFailed;
311 STAMPROFILE StatProfMapGpaRange;
312 STAMPROFILE StatProfUnmapGpaRange;
313 STAMPROFILE StatProfMapGpaRangePage;
314 STAMPROFILE StatProfUnmapGpaRangePage;
315
316 /** Statistics updated by NEMR0UpdateStatistics. */
317 struct
318 {
319 uint64_t cPagesAvailable;
320 uint64_t cPagesInUse;
321 } R0Stats;
322
323# ifdef VBOX_VMM_TARGET_ARMV8
324 /** Re-distributor memory region for all vCPUs. */
325 RTGCPHYS GCPhysMmioBaseReDist;
326 /** Number of breakpoints supported (for syncing registers). */
327 uint32_t cBreakpoints;
328 /** Number of watchpoints supported (for syncing registers). */
329 uint32_t cWatchpoints;
330# endif
331
332#elif defined(RT_OS_DARWIN)
333 /** Set if we've created the EMTs. */
334 bool fCreatedEmts : 1;
335 /** Set if hv_vm_create() was called successfully. */
336 bool fCreatedVm : 1;
337 /** Set if EL2 is enabled. */
338 bool fEl2Enabled : 1;
339 /** Set if we are running at least on macOS Sequioa 15.0. */
340 bool fMacOsSequia : 1;
341# ifdef VBOX_VMM_TARGET_ARMV8
342 /** @name vTimer related state.
343 * @{ */
344 /** The counter frequency in Hz as obtained from CNTFRQ_EL0. */
345 uint64_t u64CntFrqHz;
346 /** The vTimer offset programmed. */
347 uint64_t u64VTimerOff;
348 /** Dirty tracking slots. */
349 NEMHVMMIO2REGION aMmio2DirtyTracking[8];
350 /** The vCPU config. */
351 hv_vcpu_config_t hVCpuCfg;
352 /** @} */
353# elif defined(VBOX_VMM_TARGET_X86)
354 /** Set if hv_vm_space_create() was called successfully. */
355 bool fCreatedAsid : 1;
356 /** Set if Last Branch Record (LBR) is enabled. */
357 bool fLbr;
358 /** The ASID for this VM (only valid if fCreatedAsid is true). */
359 hv_vm_space_t uVmAsid;
360 /** Number of mach time units per NS, for hv_vcpu_run_until(). */
361 uint64_t cMachTimePerNs;
362 /** Pause-loop exiting (PLE) gap in ticks. */
363 uint32_t cPleGapTicks;
364 /** Pause-loop exiting (PLE) window in ticks. */
365 uint32_t cPleWindowTicks;
366
367 /** The host LBR TOS (top-of-stack) MSR id. */
368 uint32_t idLbrTosMsr;
369 /** The host LBR select MSR id. */
370 uint32_t idLbrSelectMsr;
371 /** The host last event record from IP MSR id. */
372 uint32_t idLerFromIpMsr;
373 /** The host last event record to IP MSR id. */
374 uint32_t idLerToIpMsr;
375
376 /** The first valid host LBR branch-from-IP stack range. */
377 uint32_t idLbrFromIpMsrFirst;
378 /** The last valid host LBR branch-from-IP stack range. */
379 uint32_t idLbrFromIpMsrLast;
380
381 /** The first valid host LBR branch-to-IP stack range. */
382 uint32_t idLbrToIpMsrFirst;
383 /** The last valid host LBR branch-to-IP stack range. */
384 uint32_t idLbrToIpMsrLast;
385
386 /** The first valid host LBR info stack range. */
387 uint32_t idLbrInfoMsrFirst;
388 /** The last valid host LBR info stack range. */
389 uint32_t idLbrInfoMsrLast;
390# endif /* VBOX_VMM_TARGET_X86 */
391
392 STAMCOUNTER StatMapPage;
393 STAMCOUNTER StatUnmapPage;
394 STAMCOUNTER StatMapPageFailed;
395 STAMCOUNTER StatUnmapPageFailed;
396#endif /* RT_OS_DARWIN */
397} NEM;
398/** Pointer to NEM VM instance data. */
399typedef NEM *PNEM;
400
401/** NEM::u32Magic value. */
402#define NEM_MAGIC UINT32_C(0x004d454e)
403/** NEM::u32Magic value after termination. */
404#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
405
406
407/**
408 * NEM VMCPU Instance data.
409 */
410typedef struct NEMCPU
411{
412 /** NEMCPU_MAGIC. */
413 uint32_t u32Magic;
414 /** Whether \#UD needs to be intercepted and presented to GIM. */
415 bool fGIMTrapXcptUD : 1;
416 /** Whether \#GP needs to be intercept for mesa driver workaround. */
417 bool fTrapXcptGpForLovelyMesaDrv: 1;
418 /** Whether we should use the debug loop because of single stepping or special
419 * debug breakpoints / events are armed. */
420 bool fUseDebugLoop : 1;
421 /** Whether we're executing a single instruction. */
422 bool fSingleInstruction : 1;
423 /** Set if we using the debug loop and wish to intercept RDTSC. */
424 bool fDebugWantRdTscExit : 1;
425 /** Whether we are currently executing in the debug loop.
426 * Mainly for assertions. */
427 bool fUsingDebugLoop : 1;
428 /** Set if we need to clear the trap flag because of single stepping. */
429 bool fClearTrapFlag : 1;
430 /** Whether we're using the hyper DR7 or guest DR7. */
431 bool fUsingHyperDR7 : 1;
432 /** Whether \#DE needs to be intercepted for GIM. */
433 bool fGCMTrapXcptDE : 1;
434#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
435 /** Set if indirect branch prediction barrier on VM exit. */
436 bool fIbpbOnVmExit : 1;
437 /** Set if indirect branch prediction barrier on VM entry. */
438 bool fIbpbOnVmEntry : 1;
439 /** Set if level 1 data cache should be flushed on VM entry. */
440 bool fL1dFlushOnVmEntry : 1;
441 /** Set if level 1 data cache should be flushed on EMT scheduling. */
442 bool fL1dFlushOnSched : 1;
443 /** Set if MDS related buffers should be cleared on VM entry. */
444 bool fMdsClearOnVmEntry : 1;
445 /** Set if MDS related buffers should be cleared on EMT scheduling. */
446 bool fMdsClearOnSched : 1;
447#endif
448
449#if defined(RT_OS_LINUX)
450 uint8_t abPadding[3];
451 /** The KVM VCpu file descriptor. */
452 int32_t fdVCpu;
453 /** Pointer to the KVM_RUN data exchange region. */
454 R3PTRTYPE(struct kvm_run *) pRun;
455# ifdef VBOX_VMM_TARGET_ARMV8
456 /** The IRQ device levels from device_irq_level. */
457 uint64_t fIrqDeviceLvls;
458 /** Status of the IRQ line when last seen. */
459 bool fIrqLastSeen;
460 /** Status of the FIQ line when last seen. */
461 bool fFiqLastSeen;
462# elif defined(VBOX_VMM_TARGET_X86)
463 /** The MSR_IA32_APICBASE value known to KVM. */
464 uint64_t uKvmApicBase;
465# endif
466
467 /** @name Statistics
468 * @{ */
469 STAMCOUNTER StatExitTotal;
470 STAMCOUNTER StatExitIo;
471 STAMCOUNTER StatExitMmio;
472 STAMCOUNTER StatExitSetTpr;
473 STAMCOUNTER StatExitTprAccess;
474 STAMCOUNTER StatExitRdMsr;
475 STAMCOUNTER StatExitWrMsr;
476 STAMCOUNTER StatExitIrqWindowOpen;
477 STAMCOUNTER StatExitHalt;
478 STAMCOUNTER StatExitIntr;
479 STAMCOUNTER StatExitHypercall;
480 STAMCOUNTER StatExitDebug;
481 STAMCOUNTER StatExitBusLock;
482 STAMCOUNTER StatExitInternalErrorEmulation;
483 STAMCOUNTER StatExitInternalErrorFatal;
484# if 0
485 STAMCOUNTER StatExitCpuId;
486 STAMCOUNTER StatExitUnrecoverable;
487 STAMCOUNTER StatGetMsgTimeout;
488 STAMCOUNTER StatStopCpuSuccess;
489 STAMCOUNTER StatStopCpuPending;
490 STAMCOUNTER StatStopCpuPendingAlerts;
491 STAMCOUNTER StatStopCpuPendingOdd;
492 STAMCOUNTER StatCancelChangedState;
493 STAMCOUNTER StatCancelAlertedThread;
494# endif
495 STAMCOUNTER StatBreakOnCancel;
496 STAMCOUNTER StatBreakOnFFPre;
497 STAMCOUNTER StatBreakOnFFPost;
498 STAMCOUNTER StatBreakOnStatus;
499 STAMCOUNTER StatFlushExitOnReturn;
500 STAMCOUNTER StatFlushExitOnReturn1Loop;
501 STAMCOUNTER StatFlushExitOnReturn2Loops;
502 STAMCOUNTER StatFlushExitOnReturn3Loops;
503 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
504 STAMCOUNTER StatImportOnDemand;
505 STAMCOUNTER StatImportOnReturn;
506 STAMCOUNTER StatImportOnReturnSkipped;
507 STAMCOUNTER StatImportPendingInterrupt;
508 STAMCOUNTER StatExportPendingInterrupt;
509 STAMCOUNTER StatQueryCpuTick;
510 /** @} */
511
512
513#elif defined(RT_OS_WINDOWS)
514# ifdef VBOX_VMM_TARGET_X86
515 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
516 uint8_t fCurrentInterruptWindows;
517 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
518 uint8_t fDesiredInterruptWindows;
519 /** Cached TPR value. */
520 uint8_t bTpr;
521 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
522 bool fLastInterruptShadow : 1;
523 /** Flag whether the IRQ window notification was registered (for injecting PIC interrupts). */
524 bool fIrqWindowRegistered: 1;
525 /** Flag whether it is possible inject a PIC interrupt. */
526 bool fPicReadyForInterrupt: 1;
527 uint32_t uPadding;
528 /** The VID_MSHAGN_F_XXX flags.
529 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
530 uint32_t fHandleAndGetFlags;
531 /** What VidMessageSlotMap returns and is used for passing exit info. */
532 RTR3PTR pvMsgSlotMapping;
533 /** The windows thread handle. */
534 RTR3PTR hNativeThreadHandle;
535# elif defined(VBOX_VMM_TARGET_ARMV8)
536 /** Flag whether syncing the CNTV_CTL_EL0/CNTV_CVAL_EL0 registers to Hyper-V is required. */
537 bool fSyncCntvRegs;
538# endif
539
540 /** @name Statistics
541 * @{ */
542 STAMCOUNTER StatExitPortIo;
543 STAMCOUNTER StatExitMemUnmapped;
544 STAMCOUNTER StatExitMemIntercept;
545 STAMCOUNTER StatExitHalt;
546 STAMCOUNTER StatExitInterruptWindow;
547 STAMCOUNTER StatExitCpuId;
548 STAMCOUNTER StatExitMsr;
549 STAMCOUNTER StatExitException;
550 STAMCOUNTER StatExitExceptionBp;
551 STAMCOUNTER StatExitExceptionDb;
552 STAMCOUNTER StatExitExceptionGp;
553 STAMCOUNTER StatExitExceptionGpMesa;
554 STAMCOUNTER StatExitExceptionUd;
555 STAMCOUNTER StatExitExceptionUdHandled;
556 STAMCOUNTER StatExitUnrecoverable;
557 STAMCOUNTER StatGetMsgTimeout;
558 STAMCOUNTER StatStopCpuSuccess;
559 STAMCOUNTER StatStopCpuPending;
560 STAMCOUNTER StatStopCpuPendingAlerts;
561 STAMCOUNTER StatStopCpuPendingOdd;
562 STAMCOUNTER StatCancelChangedState;
563 STAMCOUNTER StatCancelAlertedThread;
564 STAMCOUNTER StatBreakOnCancel;
565 STAMCOUNTER StatBreakOnFFPre;
566 STAMCOUNTER StatBreakOnFFPost;
567 STAMCOUNTER StatBreakOnStatus;
568 STAMCOUNTER StatImportOnDemand;
569 STAMCOUNTER StatImportOnReturn;
570 STAMCOUNTER StatImportOnReturnSkipped;
571 STAMCOUNTER StatQueryCpuTick;
572 /** @} */
573
574#elif defined(RT_OS_DARWIN)
575# ifdef VBOX_VMM_TARGET_ARMV8
576 /** The vCPU handle associated with the EMT executing this vCPU. */
577 hv_vcpu_t hVCpu;
578 /** Pointer to the exit information structure. */
579 hv_vcpu_exit_t *pHvExit;
580 /** Flag whether an event is pending. */
581 bool fEventPending;
582 /** Flag whether the vTimer got activated and is masked. */
583 bool fVTimerActivated;
584 /** Flag whether to update the vTimer offset. */
585 bool fVTimerOffUpdate;
586 /** Flag whether the ID registers were synced to the guest context
587 * (for first guest exec call on the EMT after loading the saved state). */
588 bool fIdRegsSynced;
589
590# elif defined(VBOX_VMM_TARGET_X86)
591 /** The vCPU handle associated with the EMT executing this vCPU. */
592 hv_vcpuid_t hVCpuId;
593
594 /** @name State shared with the VT-x code.
595 * @{ */
596 /** An additional error code used for some gurus. */
597 uint32_t u32HMError;
598 /** The last exit-to-ring-3 reason. */
599 int32_t rcLastExitToR3;
600 /** CPU-context changed flags (see HM_CHANGED_xxx). */
601 uint64_t fCtxChanged;
602
603 /** The guest VMCS information. */
604 VMXVMCSINFO VmcsInfo;
605
606 /** VT-x data. */
607 struct HMCPUVMX
608 {
609 /** @name Guest information.
610 * @{ */
611 /** Guest VMCS information shared with ring-3. */
612 VMXVMCSINFOSHARED VmcsInfo;
613 /** Nested-guest VMCS information shared with ring-3. */
614 VMXVMCSINFOSHARED VmcsInfoNstGst;
615 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
616 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
617 bool fSwitchedToNstGstVmcsCopyForRing3;
618 /** Whether the static guest VMCS controls has been merged with the
619 * nested-guest VMCS controls. */
620 bool fMergedNstGstCtls;
621 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
622 bool fCopiedNstGstToShadowVmcs;
623 /** Whether flushing the TLB is required due to switching to/from the
624 * nested-guest. */
625 bool fSwitchedNstGstFlushTlb;
626 /** Alignment. */
627 bool afAlignment0[4];
628 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
629 uint64_t u64GstMsrApicBase;
630 /** @} */
631
632 /** @name Error reporting and diagnostics.
633 * @{ */
634 /** VT-x error-reporting (mainly for ring-3 propagation). */
635 struct
636 {
637 RTCPUID idCurrentCpu;
638 RTCPUID idEnteredCpu;
639 RTHCPHYS HCPhysCurrentVmcs;
640 uint32_t u32VmcsRev;
641 uint32_t u32InstrError;
642 uint32_t u32ExitReason;
643 uint32_t u32GuestIntrState;
644 } LastError;
645 /** @} */
646 } vmx;
647
648 /** Event injection state. */
649 HMEVENT Event;
650
651 /** Current shadow paging mode for updating CR4.
652 * @todo move later (@bugref{9217}). */
653 PGMMODE enmShadowMode;
654 uint32_t u32TemporaryPadding;
655
656 /** The PAE PDPEs used with Nested Paging (only valid when
657 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
658 X86PDPE aPdpes[4];
659 /** Pointer to the VMX statistics. */
660 PVMXSTATISTICS pVmxStats;
661# endif /* VBOX_VMM_TARGET_X86 */
662
663 /** @name Statistics
664 * @{ */
665 STAMCOUNTER StatExitAll;
666 STAMCOUNTER StatBreakOnCancel;
667 STAMCOUNTER StatBreakOnFFPre;
668 STAMCOUNTER StatBreakOnFFPost;
669 STAMCOUNTER StatBreakOnStatus;
670 STAMCOUNTER StatImportOnDemand;
671 STAMCOUNTER StatImportOnReturn;
672 STAMCOUNTER StatImportOnReturnSkipped;
673 STAMCOUNTER StatQueryCpuTick;
674# ifdef VBOX_WITH_STATISTICS
675 STAMPROFILEADV StatProfGstStateImport;
676 STAMPROFILEADV StatProfGstStateExport;
677# endif
678 /** @} */
679
680 /** @} */
681#endif /* RT_OS_DARWIN */
682} NEMCPU;
683/** Pointer to NEM VMCPU instance data. */
684typedef NEMCPU *PNEMCPU;
685
686/** NEMCPU::u32Magic value. */
687#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
688/** NEMCPU::u32Magic value after termination. */
689#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
690
691
692#ifdef IN_RING0
693# ifdef RT_OS_WINDOWS
694/**
695 * Windows: Hypercall input/ouput page info.
696 */
697typedef struct NEMR0HYPERCALLDATA
698{
699 /** Host physical address of the hypercall input/output page. */
700 RTHCPHYS HCPhysPage;
701 /** Pointer to the hypercall input/output page. */
702 uint8_t *pbPage;
703 /** Handle to the memory object of the hypercall input/output page. */
704 RTR0MEMOBJ hMemObj;
705} NEMR0HYPERCALLDATA;
706/** Pointer to a Windows hypercall input/output page info. */
707typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
708# endif /* RT_OS_WINDOWS */
709
710/**
711 * NEM GVMCPU instance data.
712 */
713typedef struct NEMR0PERVCPU
714{
715 uint32_t uDummy;
716} NEMR0PERVCPU;
717
718/**
719 * NEM GVM instance data.
720 */
721typedef struct NEMR0PERVM
722{
723 uint32_t uDummy;
724} NEMR0PERVM;
725
726#endif /* IN_RING*/
727
728
729#ifdef IN_RING3
730
731int nemR3DisableCpuIsaExt(PVM pVM, const char *pszIsaExt);
732
733int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
734int nemR3NativeInitAfterCPUM(PVM pVM);
735int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
736int nemR3NativeTerm(PVM pVM);
737void nemR3NativeReset(PVM pVM);
738void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
739VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
740bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
741bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
742
743
744/**
745 * Forced flag notification call from VMEmt.h.
746 *
747 * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
748 *
749 * @param pVM The cross context VM structure.
750 * @param pVCpu The cross context virtual CPU structure of the CPU
751 * to be notified.
752 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
753 */
754void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
755
756/**
757 * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
758 * on whether to switch to the debug loop.
759 *
760 * @returns Final flag whether to switch to the debug loop.
761 * @param pVM The VM cross context VM structure.
762 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
763 * @thread EMT(0)
764 */
765DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
766
767
768/**
769 * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
770 * on whether to switch to the debug loop.
771 *
772 * @returns Final flag whether to switch to the debug loop.
773 * @param pVM The VM cross context VM structure.
774 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
775 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
776 */
777DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
778
779#endif /* IN_RING3 */
780
781void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
782void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
783 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
784int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
785 PGMPAGETYPE enmType, uint8_t *pu2State);
786
787
788#ifdef RT_OS_WINDOWS
789/** Maximum number of pages we can map in a single NEMR0MapPages call. */
790# define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
791/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
792# define NEM_MAX_UNMAP_PAGES 4095
793
794#endif
795/** @} */
796
797RT_C_DECLS_END
798
799#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
800
Note: See TracBrowser for help on using the repository browser.

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