VirtualBox

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

Last change on this file since 92444 was 92444, checked in by vboxsync, 3 years ago

VMM/NEM-linux: Some very early bits. bugref:9044

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