VirtualBox

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

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

VMM/NEM-linux: Fixed the flushing of stateful exits for larger MMIO operations. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.4 KB
Line 
1/* $Id: NEMInternal.h 92555 2021-11-22 18:51:43Z 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
351 /** @name Statistics
352 * @{ */
353 STAMCOUNTER StatExitTotal;
354 STAMCOUNTER StatExitIo;
355 STAMCOUNTER StatExitMmio;
356 STAMCOUNTER StatExitSetTpr;
357 STAMCOUNTER StatExitTprAccess;
358 STAMCOUNTER StatExitRdMsr;
359 STAMCOUNTER StatExitWrMsr;
360 STAMCOUNTER StatExitIrqWindowOpen;
361 STAMCOUNTER StatExitHalt;
362 STAMCOUNTER StatExitIntr;
363 STAMCOUNTER StatExitHypercall;
364 STAMCOUNTER StatExitDebug;
365 STAMCOUNTER StatExitBusLock;
366 STAMCOUNTER StatExitInternalErrorEmulation;
367 STAMCOUNTER StatExitInternalErrorFatal;
368# if 0
369 STAMCOUNTER StatExitCpuId;
370 STAMCOUNTER StatExitUnrecoverable;
371 STAMCOUNTER StatGetMsgTimeout;
372 STAMCOUNTER StatStopCpuSuccess;
373 STAMCOUNTER StatStopCpuPending;
374 STAMCOUNTER StatStopCpuPendingAlerts;
375 STAMCOUNTER StatStopCpuPendingOdd;
376 STAMCOUNTER StatCancelChangedState;
377 STAMCOUNTER StatCancelAlertedThread;
378# endif
379 STAMCOUNTER StatBreakOnCancel;
380 STAMCOUNTER StatBreakOnFFPre;
381 STAMCOUNTER StatBreakOnFFPost;
382 STAMCOUNTER StatBreakOnStatus;
383 STAMCOUNTER StatFlushExitOnReturn;
384 STAMCOUNTER StatFlushExitOnReturn1Loop;
385 STAMCOUNTER StatFlushExitOnReturn2Loops;
386 STAMCOUNTER StatFlushExitOnReturn3Loops;
387 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
388 STAMCOUNTER StatImportOnDemand;
389 STAMCOUNTER StatImportOnReturn;
390 STAMCOUNTER StatImportOnReturnSkipped;
391 STAMCOUNTER StatImportPendingInterrupt;
392 STAMCOUNTER StatExportPendingInterrupt;
393 STAMCOUNTER StatQueryCpuTick;
394 /** @} */
395
396
397#elif defined(RT_OS_WINDOWS)
398 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
399 uint8_t fCurrentInterruptWindows;
400 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
401 uint8_t fDesiredInterruptWindows;
402 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
403 bool fLastInterruptShadow : 1;
404# ifdef NEM_WIN_WITH_RING0_RUNLOOP
405 /** Pending VINF_NEM_FLUSH_TLB. */
406 int32_t rcPending;
407# else
408 uint32_t uPadding;
409# endif
410 /** The VID_MSHAGN_F_XXX flags.
411 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
412 uint32_t fHandleAndGetFlags;
413 /** What VidMessageSlotMap returns and is used for passing exit info. */
414 RTR3PTR pvMsgSlotMapping;
415 /** The windows thread handle. */
416 RTR3PTR hNativeThreadHandle;
417 /** Parameters for making Hyper-V hypercalls. */
418 union
419 {
420 uint8_t ab[64];
421 /** Arguments for NEMR0MapPages (HvCallMapGpaPages). */
422 struct
423 {
424 RTGCPHYS GCPhysSrc;
425 RTGCPHYS GCPhysDst; /**< Same as GCPhysSrc except maybe when the A20 gate is disabled. */
426 uint32_t cPages;
427 HV_MAP_GPA_FLAGS fFlags;
428 } MapPages;
429 /** Arguments for NEMR0UnmapPages (HvCallUnmapGpaPages). */
430 struct
431 {
432 RTGCPHYS GCPhys;
433 uint32_t cPages;
434 } UnmapPages;
435 /** Result from NEMR0QueryCpuTick. */
436 struct
437 {
438 uint64_t cTicks;
439 uint32_t uAux;
440 } QueryCpuTick;
441 /** Input and output for NEMR0DoExperiment. */
442 struct
443 {
444 uint32_t uItem;
445 bool fSuccess;
446 uint64_t uStatus;
447 uint64_t uLoValue;
448 uint64_t uHiValue;
449 } Experiment;
450 } Hypercall;
451 /** I/O control buffer, we always use this for I/O controls. */
452 union
453 {
454 uint8_t ab[64];
455 HV_PARTITION_ID idPartition;
456 HV_VP_INDEX idCpu;
457 struct
458 {
459 uint64_t enmProperty;
460 uint64_t uValue;
461 } GetProp;
462# ifdef VID_MSHAGN_F_GET_NEXT_MESSAGE
463 VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT MsgSlotHandleAndGetNext;
464# endif
465 } uIoCtlBuf;
466
467 /** @name Statistics
468 * @{ */
469 STAMCOUNTER StatExitPortIo;
470 STAMCOUNTER StatExitMemUnmapped;
471 STAMCOUNTER StatExitMemIntercept;
472 STAMCOUNTER StatExitHalt;
473 STAMCOUNTER StatExitInterruptWindow;
474 STAMCOUNTER StatExitCpuId;
475 STAMCOUNTER StatExitMsr;
476 STAMCOUNTER StatExitException;
477 STAMCOUNTER StatExitExceptionBp;
478 STAMCOUNTER StatExitExceptionDb;
479 STAMCOUNTER StatExitExceptionGp;
480 STAMCOUNTER StatExitExceptionGpMesa;
481 STAMCOUNTER StatExitExceptionUd;
482 STAMCOUNTER StatExitExceptionUdHandled;
483 STAMCOUNTER StatExitUnrecoverable;
484 STAMCOUNTER StatGetMsgTimeout;
485 STAMCOUNTER StatStopCpuSuccess;
486 STAMCOUNTER StatStopCpuPending;
487 STAMCOUNTER StatStopCpuPendingAlerts;
488 STAMCOUNTER StatStopCpuPendingOdd;
489 STAMCOUNTER StatCancelChangedState;
490 STAMCOUNTER StatCancelAlertedThread;
491 STAMCOUNTER StatBreakOnCancel;
492 STAMCOUNTER StatBreakOnFFPre;
493 STAMCOUNTER StatBreakOnFFPost;
494 STAMCOUNTER StatBreakOnStatus;
495 STAMCOUNTER StatImportOnDemand;
496 STAMCOUNTER StatImportOnReturn;
497 STAMCOUNTER StatImportOnReturnSkipped;
498 STAMCOUNTER StatQueryCpuTick;
499 /** @} */
500
501#elif defined(RT_OS_DARWIN)
502 /** The vCPU handle associated with the EMT executing this vCPU. */
503 hv_vcpuid_t hVCpuId;
504
505 /** @name State shared with the VT-x code.
506 * @{ */
507 /** Whether we should use the debug loop because of single stepping or special
508 * debug breakpoints / events are armed. */
509 bool fUseDebugLoop;
510 /** Whether we're executing a single instruction. */
511 bool fSingleInstruction;
512
513 bool afAlignment0[2];
514
515 /** An additional error code used for some gurus. */
516 uint32_t u32HMError;
517 /** The last exit-to-ring-3 reason. */
518 int32_t rcLastExitToR3;
519 /** CPU-context changed flags (see HM_CHANGED_xxx). */
520 uint64_t fCtxChanged;
521
522 /** The guest VMCS information. */
523 VMXVMCSINFO VmcsInfo;
524
525 /** VT-x data. */
526 struct HMCPUVMX
527 {
528 /** @name Guest information.
529 * @{ */
530 /** Guest VMCS information shared with ring-3. */
531 VMXVMCSINFOSHARED VmcsInfo;
532 /** Nested-guest VMCS information shared with ring-3. */
533 VMXVMCSINFOSHARED VmcsInfoNstGst;
534 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
535 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
536 bool fSwitchedToNstGstVmcsCopyForRing3;
537 /** Whether the static guest VMCS controls has been merged with the
538 * nested-guest VMCS controls. */
539 bool fMergedNstGstCtls;
540 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
541 bool fCopiedNstGstToShadowVmcs;
542 /** Whether flushing the TLB is required due to switching to/from the
543 * nested-guest. */
544 bool fSwitchedNstGstFlushTlb;
545 /** Alignment. */
546 bool afAlignment0[4];
547 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
548 uint64_t u64GstMsrApicBase;
549 /** @} */
550
551 /** @name Error reporting and diagnostics.
552 * @{ */
553 /** VT-x error-reporting (mainly for ring-3 propagation). */
554 struct
555 {
556 RTCPUID idCurrentCpu;
557 RTCPUID idEnteredCpu;
558 RTHCPHYS HCPhysCurrentVmcs;
559 uint32_t u32VmcsRev;
560 uint32_t u32InstrError;
561 uint32_t u32ExitReason;
562 uint32_t u32GuestIntrState;
563 } LastError;
564 /** @} */
565 } vmx;
566
567 /** Event injection state. */
568 HMEVENT Event;
569
570 /** Current shadow paging mode for updating CR4.
571 * @todo move later (@bugref{9217}). */
572 PGMMODE enmShadowMode;
573 uint32_t u32TemporaryPadding;
574
575 /** The PAE PDPEs used with Nested Paging (only valid when
576 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
577 X86PDPE aPdpes[4];
578 /** Pointer to the VMX statistics. */
579 PVMXSTATISTICS pVmxStats;
580
581 /** @name Statistics
582 * @{ */
583 STAMCOUNTER StatExitAll;
584 STAMCOUNTER StatBreakOnCancel;
585 STAMCOUNTER StatBreakOnFFPre;
586 STAMCOUNTER StatBreakOnFFPost;
587 STAMCOUNTER StatBreakOnStatus;
588 STAMCOUNTER StatImportOnDemand;
589 STAMCOUNTER StatImportOnReturn;
590 STAMCOUNTER StatImportOnReturnSkipped;
591 STAMCOUNTER StatQueryCpuTick;
592#ifdef VBOX_WITH_STATISTICS
593 STAMPROFILEADV StatProfGstStateImport;
594 STAMPROFILEADV StatProfGstStateExport;
595#endif
596 /** @} */
597
598 /** @} */
599#endif /* RT_OS_DARWIN */
600} NEMCPU;
601/** Pointer to NEM VMCPU instance data. */
602typedef NEMCPU *PNEMCPU;
603
604/** NEMCPU::u32Magic value. */
605#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
606/** NEMCPU::u32Magic value after termination. */
607#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
608
609
610#ifdef IN_RING0
611# ifdef RT_OS_WINDOWS
612/**
613 * Windows: Hypercall input/ouput page info.
614 */
615typedef struct NEMR0HYPERCALLDATA
616{
617 /** Host physical address of the hypercall input/output page. */
618 RTHCPHYS HCPhysPage;
619 /** Pointer to the hypercall input/output page. */
620 uint8_t *pbPage;
621 /** Handle to the memory object of the hypercall input/output page. */
622 RTR0MEMOBJ hMemObj;
623} NEMR0HYPERCALLDATA;
624/** Pointer to a Windows hypercall input/output page info. */
625typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
626# endif /* RT_OS_WINDOWS */
627
628/**
629 * NEM GVMCPU instance data.
630 */
631typedef struct NEMR0PERVCPU
632{
633# if defined(RT_OS_WINDOWS) && defined(NEM_WIN_USE_HYPERCALLS_FOR_PAGES)
634 /** Hypercall input/ouput page. */
635 NEMR0HYPERCALLDATA HypercallData;
636 /** Delta to add to convert a ring-0 pointer to a ring-3 one. */
637 uintptr_t offRing3ConversionDelta;
638# else
639 uint32_t uDummy;
640# endif
641} NEMR0PERVCPU;
642
643/**
644 * NEM GVM instance data.
645 */
646typedef struct NEMR0PERVM
647{
648# ifdef RT_OS_WINDOWS
649# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
650 /** The partition ID. */
651 uint64_t idHvPartition;
652 /** I/O control context. */
653 PSUPR0IOCTLCTX pIoCtlCtx;
654 /** Info about the VidGetHvPartitionId I/O control interface. */
655 NEMWINIOCTL IoCtlGetHvPartitionId;
656 /** Info about the VidGetPartitionProperty I/O control interface. */
657 NEMWINIOCTL IoCtlGetPartitionProperty;
658# endif
659# ifdef NEM_WIN_WITH_RING0_RUNLOOP
660 /** Info about the VidStartVirtualProcessor I/O control interface. */
661 NEMWINIOCTL IoCtlStartVirtualProcessor;
662 /** Info about the VidStopVirtualProcessor I/O control interface. */
663 NEMWINIOCTL IoCtlStopVirtualProcessor;
664 /** Info about the VidStopVirtualProcessor I/O control interface. */
665 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
666 /** Whether we may use the ring-0 runloop or not. */
667 bool fMayUseRing0Runloop;
668# endif
669
670# ifdef NEM_WIN_USE_HYPERCALLS_FOR_PAGES
671 /** Hypercall input/ouput page for non-EMT. */
672 NEMR0HYPERCALLDATA HypercallData;
673 /** Critical section protecting use of HypercallData. */
674 RTCRITSECT HypercallDataCritSect;
675# endif
676
677# else
678 uint32_t uDummy;
679# endif
680} NEMR0PERVM;
681
682#endif /* IN_RING*/
683
684
685#ifdef IN_RING3
686int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
687int nemR3NativeInitAfterCPUM(PVM pVM);
688int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
689int nemR3NativeTerm(PVM pVM);
690void nemR3NativeReset(PVM pVM);
691void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
692VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
693bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
694bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
695void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
696#endif
697
698void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
699void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
700 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
701int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
702 PGMPAGETYPE enmType, uint8_t *pu2State);
703
704
705#ifdef RT_OS_WINDOWS
706/** Maximum number of pages we can map in a single NEMR0MapPages call. */
707# define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
708/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
709# define NEM_MAX_UNMAP_PAGES 4095
710
711#endif
712/** @} */
713
714RT_C_DECLS_END
715
716#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
717
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