VirtualBox

source: vbox/trunk/include/VBox/vmm/hm.h@ 72746

Last change on this file since 72746 was 72746, checked in by vboxsync, 6 years ago

VMM: Extend HM changed flags. ​​bugref:9193 [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/** @file
2 * HM - Intel/AMD VM Hardware Assisted Virtualization Manager (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_vmm_hm_h
27#define ___VBox_vmm_hm_h
28
29#include <VBox/vmm/pgm.h>
30#include <VBox/vmm/cpum.h>
31#include <VBox/vmm/vmm.h>
32#include <VBox/vmm/hm_svm.h>
33#include <VBox/vmm/trpm.h>
34#include <iprt/mp.h>
35
36
37/** @defgroup grp_hm The Hardware Assisted Virtualization Manager API
38 * @ingroup grp_vmm
39 * @{
40 */
41
42RT_C_DECLS_BEGIN
43
44/**
45 * Checks whether HM (VT-x/AMD-V) is being used by this VM.
46 *
47 * @retval true if used.
48 * @retval false if software virtualization (raw-mode) or NEM is used.
49 *
50 * @param a_pVM The cross context VM structure.
51 * @deprecated Please use VM_IS_RAW_MODE_ENABLED, VM_IS_HM_OR_NEM_ENABLED, or
52 * VM_IS_HM_ENABLED instead.
53 * @internal
54 */
55#if defined(VBOX_STRICT) && defined(IN_RING3)
56# define HMIsEnabled(a_pVM) HMIsEnabledNotMacro(a_pVM)
57#else
58# define HMIsEnabled(a_pVM) ((a_pVM)->fHMEnabled)
59#endif
60
61/**
62 * Checks whether raw-mode context is required for any purpose.
63 *
64 * @retval true if required either by raw-mode itself or by HM for doing
65 * switching the cpu to 64-bit mode.
66 * @retval false if not required.
67 *
68 * @param a_pVM The cross context VM structure.
69 * @internal
70 */
71#if HC_ARCH_BITS == 64
72# define HMIsRawModeCtxNeeded(a_pVM) (!HMIsEnabled(a_pVM))
73#else
74# define HMIsRawModeCtxNeeded(a_pVM) (!HMIsEnabled(a_pVM) || (a_pVM)->fHMNeedRawModeCtx)
75#endif
76
77 /**
78 * Check if the current CPU state is valid for emulating IO blocks in the recompiler
79 *
80 * @returns boolean
81 * @param a_pVCpu Pointer to the shared virtual CPU structure.
82 * @internal
83 */
84#define HMCanEmulateIoBlock(a_pVCpu) (!CPUMIsGuestInPagedProtectedMode(a_pVCpu))
85
86 /**
87 * Check if the current CPU state is valid for emulating IO blocks in the recompiler
88 *
89 * @returns boolean
90 * @param a_pCtx Pointer to the CPU context (within PVM).
91 * @internal
92 */
93#define HMCanEmulateIoBlockEx(a_pCtx) (!CPUMIsGuestInPagedProtectedModeEx(a_pCtx))
94
95/**
96 * Checks whether we're in the special hardware virtualization context.
97 * @returns true / false.
98 * @param a_pVCpu The caller's cross context virtual CPU structure.
99 * @thread EMT
100 */
101#ifdef IN_RING0
102# define HMIsInHwVirtCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_HM)
103#else
104# define HMIsInHwVirtCtx(a_pVCpu) (false)
105#endif
106
107/**
108 * Checks whether we're in the special hardware virtualization context and we
109 * cannot perform long jump without guru meditating and possibly messing up the
110 * host and/or guest state.
111 *
112 * This is after we've turned interrupts off and such.
113 *
114 * @returns true / false.
115 * @param a_pVCpu The caller's cross context virtual CPU structure.
116 * @thread EMT
117 */
118#ifdef IN_RING0
119# define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_EXEC)
120#else
121# define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (false)
122#endif
123
124/**
125 * 64-bit raw-mode (intermediate memory context) operations.
126 *
127 * These are special hypervisor eip values used when running 64-bit guests on
128 * 32-bit hosts. Each operation corresponds to a routine.
129 *
130 * @note Duplicated in the assembly code!
131 */
132typedef enum HM64ON32OP
133{
134 HM64ON32OP_INVALID = 0,
135 HM64ON32OP_VMXRCStartVM64,
136 HM64ON32OP_SVMRCVMRun64,
137 HM64ON32OP_HMRCSaveGuestFPU64,
138 HM64ON32OP_HMRCSaveGuestDebug64,
139 HM64ON32OP_HMRCTestSwitcher64,
140 HM64ON32OP_END,
141 HM64ON32OP_32BIT_HACK = 0x7fffffff
142} HM64ON32OP;
143
144/** @name All-context HM API.
145 * @{ */
146VMMDECL(bool) HMIsEnabledNotMacro(PVM pVM);
147VMM_INT_DECL(int) HMInvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt);
148VMM_INT_DECL(bool) HMHasPendingIrq(PVM pVM);
149VMM_INT_DECL(PX86PDPE) HMGetPaePdpes(PVMCPU pVCpu);
150VMM_INT_DECL(int) HMAmdIsSubjectToErratum170(uint32_t *pu32Family, uint32_t *pu32Model, uint32_t *pu32Stepping);
151VMM_INT_DECL(bool) HMSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
152/** @} */
153
154/** @name All-context SVM helpers.
155 *
156 * These are SVM functions (based on AMD specs.) that may be used by IEM/REM and
157 * not VirtualBox functions that are used for hardware-assisted SVM. Those are
158 * declared below under the !IN_RC section.
159 * @{ */
160VMM_INT_DECL(TRPMEVENT) HMSvmEventToTrpmEventType(PCSVMEVENT pSvmEvent);
161VMM_INT_DECL(int) HMSvmGetMsrpmOffsetAndBit(uint32_t idMsr, uint16_t *pbOffMsrpm, uint8_t *puMsrpmBit);
162VMM_INT_DECL(bool) HMSvmIsIOInterceptActive(void *pvIoBitmap, uint16_t u16Port, SVMIOIOTYPE enmIoType, uint8_t cbReg,
163 uint8_t cAddrSizeBits, uint8_t iEffSeg, bool fRep, bool fStrIo,
164 PSVMIOIOEXITINFO pIoExitInfo);
165VMM_INT_DECL(int) HMHCSvmMaybeMovTprHypercall(PVMCPU pVCpu, PCPUMCTX pCtx);
166/** @} */
167
168#ifndef IN_RC
169VMM_INT_DECL(int) HMFlushTLB(PVMCPU pVCpu);
170VMM_INT_DECL(int) HMFlushTLBOnAllVCpus(PVM pVM);
171VMM_INT_DECL(int) HMInvalidatePageOnAllVCpus(PVM pVM, RTGCPTR GCVirt);
172VMM_INT_DECL(int) HMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys);
173VMM_INT_DECL(bool) HMIsNestedPagingActive(PVM pVM);
174VMM_INT_DECL(bool) HMAreNestedPagingAndFullGuestExecEnabled(PVM pVM);
175VMM_INT_DECL(bool) HMIsLongModeAllowed(PVM pVM);
176VMM_INT_DECL(bool) HMAreMsrBitmapsAvailable(PVM pVM);
177VMM_INT_DECL(PGMMODE) HMGetShwPagingMode(PVM pVM);
178VMM_INT_DECL(bool) HMSvmIsVGifActive(PVM pVM);
179VMM_INT_DECL(uint64_t) HMSvmNstGstApplyTscOffset(PVMCPU pVCpu, uint64_t uTicks);
180# ifdef VBOX_WITH_NESTED_HWVIRT_SVM
181VMM_INT_DECL(void) HMSvmNstGstVmExitNotify(PVMCPU pVCpu, PCPUMCTX pCtx);
182# endif
183#else /* Nops in RC: */
184# define HMFlushTLB(pVCpu) do { } while (0)
185# define HMIsNestedPagingActive(pVM) false
186# define HMAreNestedPagingAndFullGuestExecEnabled(pVM) false
187# define HMIsLongModeAllowed(pVM) false
188# define HMAreMsrBitmapsAvailable(pVM) false
189# define HMFlushTLBOnAllVCpus(pVM) do { } while (0)
190# define HMSvmNstGstVmExitNotify(pVCpu, pCtx) do { } while (0)
191# define HMSvmIsVGifActive(pVM) false
192# define HMSvmNstGstApplyTscOffset(pVCpu, uTicks) (uTicks)
193#endif
194
195#ifdef IN_RING0
196/** @defgroup grp_hm_r0 The HM ring-0 Context API
197 * @{
198 */
199VMMR0_INT_DECL(int) HMR0Init(void);
200VMMR0_INT_DECL(int) HMR0Term(void);
201VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM);
202VMMR0_INT_DECL(int) HMR0TermVM(PVM pVM);
203VMMR0_INT_DECL(int) HMR0EnableAllCpus(PVM pVM);
204# ifdef VBOX_WITH_RAW_MODE
205VMMR0_INT_DECL(int) HMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled);
206VMMR0_INT_DECL(void) HMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled);
207# endif
208
209VMMR0_INT_DECL(void) HMR0SavePendingIOPortRead(PVMCPU pVCpu, RTGCPTR GCPtrRip, RTGCPTR GCPtrRipNext,
210 unsigned uPort, unsigned uAndVal, unsigned cbSize);
211VMMR0_INT_DECL(int) HMR0SetupVM(PVM pVM);
212VMMR0_INT_DECL(int) HMR0RunGuestCode(PVM pVM, PVMCPU pVCpu);
213VMMR0_INT_DECL(int) HMR0Enter(PVM pVM, PVMCPU pVCpu);
214VMMR0_INT_DECL(int) HMR0EnterCpu(PVMCPU pVCpu);
215VMMR0_INT_DECL(int) HMR0LeaveCpu(PVMCPU pVCpu);
216VMMR0_INT_DECL(void) HMR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser);
217VMMR0_INT_DECL(void) HMR0NotifyCpumUnloadedGuestFpuState(PVMCPU VCpu);
218VMMR0_INT_DECL(void) HMR0NotifyCpumModifiedHostCr0(PVMCPU VCpu);
219VMMR0_INT_DECL(bool) HMR0SuspendPending(void);
220VMMR0_INT_DECL(int) HMR0InvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt);
221VMMR0_INT_DECL(int) HMR0ImportStateOnDemand(PVMCPU pVCpu, uint64_t fWhat);
222
223# if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
224VMMR0_INT_DECL(int) HMR0SaveFPUState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
225VMMR0_INT_DECL(int) HMR0SaveDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
226VMMR0_INT_DECL(int) HMR0TestSwitcher3264(PVM pVM);
227# endif
228
229/** @} */
230#endif /* IN_RING0 */
231
232
233#ifdef IN_RING3
234/** @defgroup grp_hm_r3 The HM ring-3 Context API
235 * @{
236 */
237VMMR3DECL(bool) HMR3IsEnabled(PUVM pUVM);
238VMMR3DECL(bool) HMR3IsNestedPagingActive(PUVM pUVM);
239VMMR3DECL(bool) HMR3IsVirtApicRegsEnabled(PUVM pUVM);
240VMMR3DECL(bool) HMR3IsPostedIntrsEnabled(PUVM pUVM);
241VMMR3DECL(bool) HMR3IsVpidActive(PUVM pUVM);
242VMMR3DECL(bool) HMR3IsUXActive(PUVM pUVM);
243VMMR3DECL(bool) HMR3IsSvmEnabled(PUVM pUVM);
244VMMR3DECL(bool) HMR3IsVmxEnabled(PUVM pUVM);
245
246VMMR3_INT_DECL(bool) HMR3IsEventPending(PVMCPU pVCpu);
247VMMR3_INT_DECL(int) HMR3Init(PVM pVM);
248VMMR3_INT_DECL(int) HMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
249VMMR3_INT_DECL(void) HMR3Relocate(PVM pVM);
250VMMR3_INT_DECL(int) HMR3Term(PVM pVM);
251VMMR3_INT_DECL(void) HMR3Reset(PVM pVM);
252VMMR3_INT_DECL(void) HMR3ResetCpu(PVMCPU pVCpu);
253VMMR3_INT_DECL(void) HMR3CheckError(PVM pVM, int iStatusCode);
254VMMR3DECL(bool) HMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx);
255VMMR3_INT_DECL(void) HMR3NotifyScheduled(PVMCPU pVCpu);
256VMMR3_INT_DECL(void) HMR3NotifyEmulated(PVMCPU pVCpu);
257VMMR3_INT_DECL(void) HMR3NotifyDebugEventChanged(PVM pVM);
258VMMR3_INT_DECL(void) HMR3NotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu);
259VMMR3_INT_DECL(bool) HMR3IsActive(PVMCPU pVCpu);
260VMMR3_INT_DECL(void) HMR3PagingModeChanged(PVM pVM, PVMCPU pVCpu, PGMMODE enmShadowMode, PGMMODE enmGuestMode);
261VMMR3_INT_DECL(int) HMR3EmulateIoBlock(PVM pVM, PCPUMCTX pCtx);
262VMMR3_INT_DECL(bool) HMR3HasPendingIOInstr(PVMCPU pVCpu);
263VMMR3_INT_DECL(VBOXSTRICTRC) HMR3RestartPendingIOInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
264VMMR3_INT_DECL(int) HMR3EnablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
265VMMR3_INT_DECL(int) HMR3DisablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
266VMMR3_INT_DECL(int) HMR3PatchTprInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
267VMMR3_INT_DECL(bool) HMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx);
268VMMR3_INT_DECL(bool) HMR3IsVmxPreemptionTimerUsed(PVM pVM);
269VMMR3DECL(const char *) HMR3GetVmxExitName(uint32_t uExit);
270VMMR3DECL(const char *) HMR3GetSvmExitName(uint32_t uExit);
271
272/** @} */
273#endif /* IN_RING3 */
274
275/** @} */
276RT_C_DECLS_END
277
278
279#endif
280
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