VirtualBox

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

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

VMM/NEM-linux: Implemented the apic_base synchronization, ubuntu now boots with x2APIC. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.5 KB
Line 
1/* $Id: NEMInternal.h 92579 2021-11-24 03:04:08Z 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_INHIBIT_INT \
102 | CPUMCTX_EXTRN_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_INHIBIT_INT \
134 | CPUMCTX_EXTRN_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 NEMEXITTYPE_INVALID = 0,
160
161 /* Common: */
162 NEMEXITTYPE_INTTERRUPT_WINDOW,
163 NEMEXITTYPE_HALT,
164
165 /* Windows: */
166 NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
167 NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
168 NEMEXITTYPE_XCPT_UD,
169 NEMEXITTYPE_XCPT_DB,
170 NEMEXITTYPE_XCPT_BP,
171 NEMEXITTYPE_CANCELED,
172 NEMEXITTYPE_MEMORY_ACCESS,
173
174 /* Linux: */
175 NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
176 NEMEXITTYPE_INTERNAL_ERROR_FATAL,
177 NEMEXITTYPE_INTERRUPTED,
178 NEMEXITTYPE_FAILED_ENTRY,
179
180 /* End of valid types. */
181 NEMEXITTYPE_END
182} NEMEXITTYPE;
183
184
185/**
186 * NEM VM Instance data.
187 */
188typedef struct NEM
189{
190 /** NEM_MAGIC. */
191 uint32_t u32Magic;
192
193 /** Set if enabled. */
194 bool fEnabled;
195 /** Set if long mode guests are allowed. */
196 bool fAllow64BitGuests;
197
198#if defined(RT_OS_LINUX)
199 /** The '/dev/kvm' file descriptor. */
200 int32_t fdKvm;
201 /** The KVM_CREATE_VM file descriptor. */
202 int32_t fdVm;
203
204 /** KVM_GET_VCPU_MMAP_SIZE. */
205 uint32_t cbVCpuMmap;
206 /** KVM_CAP_NR_MEMSLOTS. */
207 uint32_t cMaxMemSlots;
208 /** KVM_CAP_X86_ROBUST_SINGLESTEP. */
209 bool fRobustSingleStep;
210
211 /** Hint where there might be a free slot. */
212 uint16_t idPrevSlot;
213 /** Memory slot ID allocation bitmap. */
214 uint64_t bmSlotIds[_32K / 8 / sizeof(uint64_t)];
215
216#elif defined(RT_OS_WINDOWS)
217 /** Set if we've created the EMTs. */
218 bool fCreatedEmts : 1;
219 /** WHvRunVpExitReasonX64Cpuid is supported. */
220 bool fExtendedMsrExit : 1;
221 /** WHvRunVpExitReasonX64MsrAccess is supported. */
222 bool fExtendedCpuIdExit : 1;
223 /** WHvRunVpExitReasonException is supported. */
224 bool fExtendedXcptExit : 1;
225 /** Set if we're using the ring-0 API to do the work. */
226 bool fUseRing0Runloop : 1;
227# ifdef NEM_WIN_WITH_A20
228 /** Set if we've started more than one CPU and cannot mess with A20. */
229 bool fA20Fixed : 1;
230 /** Set if A20 is enabled. */
231 bool fA20Enabled : 1;
232# endif
233 /** The reported CPU vendor. */
234 CPUMCPUVENDOR enmCpuVendor;
235 /** Cache line flush size as a power of two. */
236 uint8_t cCacheLineFlushShift;
237 /** The result of WHvCapabilityCodeProcessorFeatures. */
238 union
239 {
240 /** 64-bit view. */
241 uint64_t u64;
242# ifdef _WINHVAPIDEFS_H_
243 /** Interpreed features. */
244 WHV_PROCESSOR_FEATURES u;
245# endif
246 } uCpuFeatures;
247
248 /** The partition handle. */
249# ifdef _WINHVAPIDEFS_H_
250 WHV_PARTITION_HANDLE
251# else
252 RTHCUINTPTR
253# endif
254 hPartition;
255 /** The device handle for the partition, for use with Vid APIs or direct I/O
256 * controls. */
257 RTR3PTR hPartitionDevice;
258 /** The Hyper-V partition ID. */
259 uint64_t idHvPartition;
260
261 /** Number of currently mapped pages. */
262 uint32_t volatile cMappedPages;
263# ifndef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
264 /** Max number of pages we dare map at once. */
265 uint32_t cMaxMappedPages;
266# endif
267 STAMCOUNTER StatMapPage;
268 STAMCOUNTER StatUnmapPage;
269# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
270 STAMCOUNTER StatRemapPage;
271 STAMCOUNTER StatRemapPageFailed;
272# elif !defined(VBOX_WITH_PGM_NEM_MODE)
273 STAMCOUNTER StatUnmapAllPages;
274# endif
275 STAMCOUNTER StatMapPageFailed;
276 STAMCOUNTER StatUnmapPageFailed;
277# ifdef VBOX_WITH_PGM_NEM_MODE
278 STAMPROFILE StatProfMapGpaRange;
279 STAMPROFILE StatProfUnmapGpaRange;
280# endif
281# ifndef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
282 STAMPROFILE StatProfMapGpaRangePage;
283 STAMPROFILE StatProfUnmapGpaRangePage;
284# endif
285
286# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
287 /** Info about the VidGetHvPartitionId I/O control interface. */
288 NEMWINIOCTL IoCtlGetHvPartitionId;
289 /** Info about the VidGetPartitionProperty I/O control interface. */
290 NEMWINIOCTL IoCtlGetPartitionProperty;
291# endif
292# ifdef NEM_WIN_WITH_RING0_RUNLOOP
293 /** Info about the VidStartVirtualProcessor I/O control interface. */
294 NEMWINIOCTL IoCtlStartVirtualProcessor;
295 /** Info about the VidStopVirtualProcessor I/O control interface. */
296 NEMWINIOCTL IoCtlStopVirtualProcessor;
297 /** Info about the VidStopVirtualProcessor I/O control interface. */
298 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
299# endif
300
301 /** Statistics updated by NEMR0UpdateStatistics. */
302 struct
303 {
304 uint64_t cPagesAvailable;
305 uint64_t cPagesInUse;
306 } R0Stats;
307
308#elif defined(RT_OS_DARWIN)
309 /** Set if we've created the EMTs. */
310 bool fCreatedEmts : 1;
311 /** Set if hv_vm_create() was called successfully. */
312 bool fCreatedVm : 1;
313 /** Set if hv_vm_space_create() was called successfully. */
314 bool fCreatedAsid : 1;
315 /** The ASID for this VM (only valid if fCreatedAsid is true). */
316 hv_vm_space_t uVmAsid;
317 STAMCOUNTER StatMapPage;
318 STAMCOUNTER StatUnmapPage;
319 STAMCOUNTER StatMapPageFailed;
320 STAMCOUNTER StatUnmapPageFailed;
321#endif /* RT_OS_WINDOWS */
322} NEM;
323/** Pointer to NEM VM instance data. */
324typedef NEM *PNEM;
325
326/** NEM::u32Magic value. */
327#define NEM_MAGIC UINT32_C(0x004d454e)
328/** NEM::u32Magic value after termination. */
329#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
330
331
332/**
333 * NEM VMCPU Instance data.
334 */
335typedef struct NEMCPU
336{
337 /** NEMCPU_MAGIC. */
338 uint32_t u32Magic;
339 /** Whether \#UD needs to be intercepted and presented to GIM. */
340 bool fGIMTrapXcptUD : 1;
341 /** Whether \#GP needs to be intercept for mesa driver workaround. */
342 bool fTrapXcptGpForLovelyMesaDrv: 1;
343
344#if defined(RT_OS_LINUX)
345 uint8_t abPadding[3];
346 /** The KVM VCpu file descriptor. */
347 int32_t fdVCpu;
348 /** Pointer to the KVM_RUN data exchange region. */
349 R3PTRTYPE(struct kvm_run *) pRun;
350 /** The MSR_IA32_APICBASE value known to KVM. */
351 uint64_t uKvmApicBase;
352
353 /** @name Statistics
354 * @{ */
355 STAMCOUNTER StatExitTotal;
356 STAMCOUNTER StatExitIo;
357 STAMCOUNTER StatExitMmio;
358 STAMCOUNTER StatExitSetTpr;
359 STAMCOUNTER StatExitTprAccess;
360 STAMCOUNTER StatExitRdMsr;
361 STAMCOUNTER StatExitWrMsr;
362 STAMCOUNTER StatExitIrqWindowOpen;
363 STAMCOUNTER StatExitHalt;
364 STAMCOUNTER StatExitIntr;
365 STAMCOUNTER StatExitHypercall;
366 STAMCOUNTER StatExitDebug;
367 STAMCOUNTER StatExitBusLock;
368 STAMCOUNTER StatExitInternalErrorEmulation;
369 STAMCOUNTER StatExitInternalErrorFatal;
370# if 0
371 STAMCOUNTER StatExitCpuId;
372 STAMCOUNTER StatExitUnrecoverable;
373 STAMCOUNTER StatGetMsgTimeout;
374 STAMCOUNTER StatStopCpuSuccess;
375 STAMCOUNTER StatStopCpuPending;
376 STAMCOUNTER StatStopCpuPendingAlerts;
377 STAMCOUNTER StatStopCpuPendingOdd;
378 STAMCOUNTER StatCancelChangedState;
379 STAMCOUNTER StatCancelAlertedThread;
380# endif
381 STAMCOUNTER StatBreakOnCancel;
382 STAMCOUNTER StatBreakOnFFPre;
383 STAMCOUNTER StatBreakOnFFPost;
384 STAMCOUNTER StatBreakOnStatus;
385 STAMCOUNTER StatFlushExitOnReturn;
386 STAMCOUNTER StatFlushExitOnReturn1Loop;
387 STAMCOUNTER StatFlushExitOnReturn2Loops;
388 STAMCOUNTER StatFlushExitOnReturn3Loops;
389 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
390 STAMCOUNTER StatImportOnDemand;
391 STAMCOUNTER StatImportOnReturn;
392 STAMCOUNTER StatImportOnReturnSkipped;
393 STAMCOUNTER StatImportPendingInterrupt;
394 STAMCOUNTER StatExportPendingInterrupt;
395 STAMCOUNTER StatQueryCpuTick;
396 /** @} */
397
398
399#elif defined(RT_OS_WINDOWS)
400 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
401 uint8_t fCurrentInterruptWindows;
402 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
403 uint8_t fDesiredInterruptWindows;
404 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
405 bool fLastInterruptShadow : 1;
406# ifdef NEM_WIN_WITH_RING0_RUNLOOP
407 /** Pending VINF_NEM_FLUSH_TLB. */
408 int32_t rcPending;
409# else
410 uint32_t uPadding;
411# endif
412 /** The VID_MSHAGN_F_XXX flags.
413 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
414 uint32_t fHandleAndGetFlags;
415 /** What VidMessageSlotMap returns and is used for passing exit info. */
416 RTR3PTR pvMsgSlotMapping;
417 /** The windows thread handle. */
418 RTR3PTR hNativeThreadHandle;
419 /** Parameters for making Hyper-V hypercalls. */
420 union
421 {
422 uint8_t ab[64];
423 /** Arguments for NEMR0MapPages (HvCallMapGpaPages). */
424 struct
425 {
426 RTGCPHYS GCPhysSrc;
427 RTGCPHYS GCPhysDst; /**< Same as GCPhysSrc except maybe when the A20 gate is disabled. */
428 uint32_t cPages;
429 HV_MAP_GPA_FLAGS fFlags;
430 } MapPages;
431 /** Arguments for NEMR0UnmapPages (HvCallUnmapGpaPages). */
432 struct
433 {
434 RTGCPHYS GCPhys;
435 uint32_t cPages;
436 } UnmapPages;
437 /** Result from NEMR0QueryCpuTick. */
438 struct
439 {
440 uint64_t cTicks;
441 uint32_t uAux;
442 } QueryCpuTick;
443 /** Input and output for NEMR0DoExperiment. */
444 struct
445 {
446 uint32_t uItem;
447 bool fSuccess;
448 uint64_t uStatus;
449 uint64_t uLoValue;
450 uint64_t uHiValue;
451 } Experiment;
452 } Hypercall;
453 /** I/O control buffer, we always use this for I/O controls. */
454 union
455 {
456 uint8_t ab[64];
457 HV_PARTITION_ID idPartition;
458 HV_VP_INDEX idCpu;
459 struct
460 {
461 uint64_t enmProperty;
462 uint64_t uValue;
463 } GetProp;
464# ifdef VID_MSHAGN_F_GET_NEXT_MESSAGE
465 VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT MsgSlotHandleAndGetNext;
466# endif
467 } uIoCtlBuf;
468
469 /** @name Statistics
470 * @{ */
471 STAMCOUNTER StatExitPortIo;
472 STAMCOUNTER StatExitMemUnmapped;
473 STAMCOUNTER StatExitMemIntercept;
474 STAMCOUNTER StatExitHalt;
475 STAMCOUNTER StatExitInterruptWindow;
476 STAMCOUNTER StatExitCpuId;
477 STAMCOUNTER StatExitMsr;
478 STAMCOUNTER StatExitException;
479 STAMCOUNTER StatExitExceptionBp;
480 STAMCOUNTER StatExitExceptionDb;
481 STAMCOUNTER StatExitExceptionGp;
482 STAMCOUNTER StatExitExceptionGpMesa;
483 STAMCOUNTER StatExitExceptionUd;
484 STAMCOUNTER StatExitExceptionUdHandled;
485 STAMCOUNTER StatExitUnrecoverable;
486 STAMCOUNTER StatGetMsgTimeout;
487 STAMCOUNTER StatStopCpuSuccess;
488 STAMCOUNTER StatStopCpuPending;
489 STAMCOUNTER StatStopCpuPendingAlerts;
490 STAMCOUNTER StatStopCpuPendingOdd;
491 STAMCOUNTER StatCancelChangedState;
492 STAMCOUNTER StatCancelAlertedThread;
493 STAMCOUNTER StatBreakOnCancel;
494 STAMCOUNTER StatBreakOnFFPre;
495 STAMCOUNTER StatBreakOnFFPost;
496 STAMCOUNTER StatBreakOnStatus;
497 STAMCOUNTER StatImportOnDemand;
498 STAMCOUNTER StatImportOnReturn;
499 STAMCOUNTER StatImportOnReturnSkipped;
500 STAMCOUNTER StatQueryCpuTick;
501 /** @} */
502
503#elif defined(RT_OS_DARWIN)
504 /** The vCPU handle associated with the EMT executing this vCPU. */
505 hv_vcpuid_t hVCpuId;
506
507 /** @name State shared with the VT-x code.
508 * @{ */
509 /** Whether we should use the debug loop because of single stepping or special
510 * debug breakpoints / events are armed. */
511 bool fUseDebugLoop;
512 /** Whether we're executing a single instruction. */
513 bool fSingleInstruction;
514
515 bool afAlignment0[2];
516
517 /** An additional error code used for some gurus. */
518 uint32_t u32HMError;
519 /** The last exit-to-ring-3 reason. */
520 int32_t rcLastExitToR3;
521 /** CPU-context changed flags (see HM_CHANGED_xxx). */
522 uint64_t fCtxChanged;
523
524 /** The guest VMCS information. */
525 VMXVMCSINFO VmcsInfo;
526
527 /** VT-x data. */
528 struct HMCPUVMX
529 {
530 /** @name Guest information.
531 * @{ */
532 /** Guest VMCS information shared with ring-3. */
533 VMXVMCSINFOSHARED VmcsInfo;
534 /** Nested-guest VMCS information shared with ring-3. */
535 VMXVMCSINFOSHARED VmcsInfoNstGst;
536 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
537 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
538 bool fSwitchedToNstGstVmcsCopyForRing3;
539 /** Whether the static guest VMCS controls has been merged with the
540 * nested-guest VMCS controls. */
541 bool fMergedNstGstCtls;
542 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
543 bool fCopiedNstGstToShadowVmcs;
544 /** Whether flushing the TLB is required due to switching to/from the
545 * nested-guest. */
546 bool fSwitchedNstGstFlushTlb;
547 /** Alignment. */
548 bool afAlignment0[4];
549 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
550 uint64_t u64GstMsrApicBase;
551 /** @} */
552
553 /** @name Error reporting and diagnostics.
554 * @{ */
555 /** VT-x error-reporting (mainly for ring-3 propagation). */
556 struct
557 {
558 RTCPUID idCurrentCpu;
559 RTCPUID idEnteredCpu;
560 RTHCPHYS HCPhysCurrentVmcs;
561 uint32_t u32VmcsRev;
562 uint32_t u32InstrError;
563 uint32_t u32ExitReason;
564 uint32_t u32GuestIntrState;
565 } LastError;
566 /** @} */
567 } vmx;
568
569 /** Event injection state. */
570 HMEVENT Event;
571
572 /** Current shadow paging mode for updating CR4.
573 * @todo move later (@bugref{9217}). */
574 PGMMODE enmShadowMode;
575 uint32_t u32TemporaryPadding;
576
577 /** The PAE PDPEs used with Nested Paging (only valid when
578 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
579 X86PDPE aPdpes[4];
580 /** Pointer to the VMX statistics. */
581 PVMXSTATISTICS pVmxStats;
582
583 /** @name Statistics
584 * @{ */
585 STAMCOUNTER StatExitAll;
586 STAMCOUNTER StatBreakOnCancel;
587 STAMCOUNTER StatBreakOnFFPre;
588 STAMCOUNTER StatBreakOnFFPost;
589 STAMCOUNTER StatBreakOnStatus;
590 STAMCOUNTER StatImportOnDemand;
591 STAMCOUNTER StatImportOnReturn;
592 STAMCOUNTER StatImportOnReturnSkipped;
593 STAMCOUNTER StatQueryCpuTick;
594#ifdef VBOX_WITH_STATISTICS
595 STAMPROFILEADV StatProfGstStateImport;
596 STAMPROFILEADV StatProfGstStateExport;
597#endif
598 /** @} */
599
600 /** @} */
601#endif /* RT_OS_DARWIN */
602} NEMCPU;
603/** Pointer to NEM VMCPU instance data. */
604typedef NEMCPU *PNEMCPU;
605
606/** NEMCPU::u32Magic value. */
607#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
608/** NEMCPU::u32Magic value after termination. */
609#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
610
611
612#ifdef IN_RING0
613# ifdef RT_OS_WINDOWS
614/**
615 * Windows: Hypercall input/ouput page info.
616 */
617typedef struct NEMR0HYPERCALLDATA
618{
619 /** Host physical address of the hypercall input/output page. */
620 RTHCPHYS HCPhysPage;
621 /** Pointer to the hypercall input/output page. */
622 uint8_t *pbPage;
623 /** Handle to the memory object of the hypercall input/output page. */
624 RTR0MEMOBJ hMemObj;
625} NEMR0HYPERCALLDATA;
626/** Pointer to a Windows hypercall input/output page info. */
627typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
628# endif /* RT_OS_WINDOWS */
629
630/**
631 * NEM GVMCPU instance data.
632 */
633typedef struct NEMR0PERVCPU
634{
635# if defined(RT_OS_WINDOWS) && defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
636 /** Hypercall input/ouput page. */
637 NEMR0HYPERCALLDATA HypercallData;
638 /** Delta to add to convert a ring-0 pointer to a ring-3 one. */
639 uintptr_t offRing3ConversionDelta;
640# else
641 uint32_t uDummy;
642# endif
643} NEMR0PERVCPU;
644
645/**
646 * NEM GVM instance data.
647 */
648typedef struct NEMR0PERVM
649{
650# ifdef RT_OS_WINDOWS
651# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
652 /** The partition ID. */
653 uint64_t idHvPartition;
654 /** I/O control context. */
655 PSUPR0IOCTLCTX pIoCtlCtx;
656 /** Info about the VidGetHvPartitionId I/O control interface. */
657 NEMWINIOCTL IoCtlGetHvPartitionId;
658 /** Info about the VidGetPartitionProperty I/O control interface. */
659 NEMWINIOCTL IoCtlGetPartitionProperty;
660# endif
661# ifdef NEM_WIN_WITH_RING0_RUNLOOP
662 /** Info about the VidStartVirtualProcessor I/O control interface. */
663 NEMWINIOCTL IoCtlStartVirtualProcessor;
664 /** Info about the VidStopVirtualProcessor I/O control interface. */
665 NEMWINIOCTL IoCtlStopVirtualProcessor;
666 /** Info about the VidStopVirtualProcessor I/O control interface. */
667 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
668 /** Whether we may use the ring-0 runloop or not. */
669 bool fMayUseRing0Runloop;
670# endif
671
672# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
673 /** Hypercall input/ouput page for non-EMT. */
674 NEMR0HYPERCALLDATA HypercallData;
675 /** Critical section protecting use of HypercallData. */
676 RTCRITSECT HypercallDataCritSect;
677# endif
678
679# else
680 uint32_t uDummy;
681# endif
682} NEMR0PERVM;
683
684#endif /* IN_RING*/
685
686
687#ifdef IN_RING3
688int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
689int nemR3NativeInitAfterCPUM(PVM pVM);
690int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
691int nemR3NativeTerm(PVM pVM);
692void nemR3NativeReset(PVM pVM);
693void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
694VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
695bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
696bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
697void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
698#endif
699
700void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
701void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
702 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
703int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
704 PGMPAGETYPE enmType, uint8_t *pu2State);
705
706
707#ifdef RT_OS_WINDOWS
708/** Maximum number of pages we can map in a single NEMR0MapPages call. */
709# define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
710/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
711# define NEM_MAX_UNMAP_PAGES 4095
712
713#endif
714/** @} */
715
716RT_C_DECLS_END
717
718#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
719
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