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/hm_vmx.h>
|
---|
34 | #include <VBox/vmm/trpm.h>
|
---|
35 | #include <iprt/mp.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /** @defgroup grp_hm The Hardware Assisted Virtualization Manager API
|
---|
39 | * @ingroup grp_vmm
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | RT_C_DECLS_BEGIN
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Checks whether HM (VT-x/AMD-V) is being used by this VM.
|
---|
47 | *
|
---|
48 | * @retval true if used.
|
---|
49 | * @retval false if software virtualization (raw-mode) or NEM is used.
|
---|
50 | *
|
---|
51 | * @param a_pVM The cross context VM structure.
|
---|
52 | * @deprecated Please use VM_IS_RAW_MODE_ENABLED, VM_IS_HM_OR_NEM_ENABLED, or
|
---|
53 | * VM_IS_HM_ENABLED instead.
|
---|
54 | * @internal
|
---|
55 | */
|
---|
56 | #if defined(VBOX_STRICT) && defined(IN_RING3)
|
---|
57 | # define HMIsEnabled(a_pVM) HMIsEnabledNotMacro(a_pVM)
|
---|
58 | #else
|
---|
59 | # define HMIsEnabled(a_pVM) ((a_pVM)->fHMEnabled)
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Checks whether raw-mode context is required for HM purposes
|
---|
64 | *
|
---|
65 | * @retval true if required by HM for doing switching the cpu to 64-bit mode.
|
---|
66 | * @retval false if not required by HM.
|
---|
67 | *
|
---|
68 | * @param a_pVM The cross context VM structure.
|
---|
69 | * @internal
|
---|
70 | */
|
---|
71 | #if HC_ARCH_BITS == 64
|
---|
72 | # define HMIsRawModeCtxNeeded(a_pVM) (false)
|
---|
73 | #else
|
---|
74 | # define HMIsRawModeCtxNeeded(a_pVM) ((a_pVM)->fHMNeedRawModeCtx)
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Checks whether we're in the special hardware virtualization context.
|
---|
79 | * @returns true / false.
|
---|
80 | * @param a_pVCpu The caller's cross context virtual CPU structure.
|
---|
81 | * @thread EMT
|
---|
82 | */
|
---|
83 | #ifdef IN_RING0
|
---|
84 | # define HMIsInHwVirtCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_HM)
|
---|
85 | #else
|
---|
86 | # define HMIsInHwVirtCtx(a_pVCpu) (false)
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Checks whether we're in the special hardware virtualization context and we
|
---|
91 | * cannot perform long jump without guru meditating and possibly messing up the
|
---|
92 | * host and/or guest state.
|
---|
93 | *
|
---|
94 | * This is after we've turned interrupts off and such.
|
---|
95 | *
|
---|
96 | * @returns true / false.
|
---|
97 | * @param a_pVCpu The caller's cross context virtual CPU structure.
|
---|
98 | * @thread EMT
|
---|
99 | */
|
---|
100 | #ifdef IN_RING0
|
---|
101 | # define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_EXEC)
|
---|
102 | #else
|
---|
103 | # define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (false)
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * 64-bit raw-mode (intermediate memory context) operations.
|
---|
108 | *
|
---|
109 | * These are special hypervisor eip values used when running 64-bit guests on
|
---|
110 | * 32-bit hosts. Each operation corresponds to a routine.
|
---|
111 | *
|
---|
112 | * @note Duplicated in the assembly code!
|
---|
113 | */
|
---|
114 | typedef enum HM64ON32OP
|
---|
115 | {
|
---|
116 | HM64ON32OP_INVALID = 0,
|
---|
117 | HM64ON32OP_VMXRCStartVM64,
|
---|
118 | HM64ON32OP_SVMRCVMRun64,
|
---|
119 | HM64ON32OP_HMRCSaveGuestFPU64,
|
---|
120 | HM64ON32OP_HMRCSaveGuestDebug64,
|
---|
121 | HM64ON32OP_HMRCTestSwitcher64,
|
---|
122 | HM64ON32OP_END,
|
---|
123 | HM64ON32OP_32BIT_HACK = 0x7fffffff
|
---|
124 | } HM64ON32OP;
|
---|
125 |
|
---|
126 | /** @name All-context HM API.
|
---|
127 | * @{ */
|
---|
128 | VMMDECL(bool) HMIsEnabledNotMacro(PVM pVM);
|
---|
129 | VMMDECL(bool) HMCanExecuteGuest(PVMCPU pVCpu, PCCPUMCTX pCtx);
|
---|
130 | VMM_INT_DECL(int) HMInvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt);
|
---|
131 | VMM_INT_DECL(bool) HMHasPendingIrq(PVM pVM);
|
---|
132 | VMM_INT_DECL(PX86PDPE) HMGetPaePdpes(PVMCPU pVCpu);
|
---|
133 | VMM_INT_DECL(bool) HMSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
|
---|
134 | VMM_INT_DECL(bool) HMIsSvmActive(PVM pVM);
|
---|
135 | VMM_INT_DECL(bool) HMIsVmxActive(PVM pVM);
|
---|
136 | VMM_INT_DECL(bool) HMIsVmxSupported(PVM pVM);
|
---|
137 | VMM_INT_DECL(const char *) HMVmxGetDiagDesc(VMXVDIAG enmDiag);
|
---|
138 | VMM_INT_DECL(const char *) HMVmxGetAbortDesc(VMXABORT enmAbort);
|
---|
139 | VMM_INT_DECL(void) HMHCPagingModeChanged(PVM pVM, PVMCPU pVCpu, PGMMODE enmShadowMode, PGMMODE enmGuestMode);
|
---|
140 | /** @} */
|
---|
141 |
|
---|
142 | /** @name All-context VMX helpers.
|
---|
143 | * These are VMX functions (based on VMX specs.) that may be used by IEM/REM and
|
---|
144 | * not VirtualBox functions that are used for hardware-assisted VMX. Those are
|
---|
145 | * declared below under the !IN_RC section.
|
---|
146 | * @{ */
|
---|
147 | VMM_INT_DECL(int) HMVmxGetHostMsrs(PVM pVM, PVMXMSRS pVmxMsrs);
|
---|
148 | VMM_INT_DECL(int) HMVmxGetHostMsr(PVM pVM, uint32_t idMsr, uint64_t *puValue);
|
---|
149 | VMM_INT_DECL(bool) HMVmxCanExecuteGuest(PVMCPU pVCpu, PCCPUMCTX pCtx);
|
---|
150 | VMM_INT_DECL(int) HMVmxEntryIntInfoInjectTrpmEvent(PVMCPU pVCpu, uint32_t uEntryIntInfo, uint32_t uErrCode,
|
---|
151 | uint32_t cbInstr, RTGCUINTPTR GCPtrFaultAddress);
|
---|
152 | VMM_INT_DECL(int) HMVmxGetMsrPermission(void const *pvMsrBitmap, uint32_t idMsr, PVMXMSREXITREAD penmRead,
|
---|
153 | PVMXMSREXITWRITE penmWrite);
|
---|
154 | VMM_INT_DECL(bool) HMVmxGetIoBitmapPermission(void const *pvIoBitmapA, void const *pvIoBitmapB, uint16_t uPort,
|
---|
155 | uint8_t cbAccess);
|
---|
156 | /** @} */
|
---|
157 |
|
---|
158 | /** @name All-context SVM helpers.
|
---|
159 | *
|
---|
160 | * These are SVM functions (based on AMD specs.) that may be used by IEM/REM and
|
---|
161 | * not VirtualBox functions that are used for hardware-assisted SVM. Those are
|
---|
162 | * declared below under the !IN_RC section.
|
---|
163 | * @{ */
|
---|
164 | VMM_INT_DECL(TRPMEVENT) HMSvmEventToTrpmEventType(PCSVMEVENT pSvmEvent);
|
---|
165 | VMM_INT_DECL(int) HMSvmGetMsrpmOffsetAndBit(uint32_t idMsr, uint16_t *pbOffMsrpm, uint8_t *puMsrpmBit);
|
---|
166 | VMM_INT_DECL(bool) HMSvmIsIOInterceptActive(void *pvIoBitmap, uint16_t u16Port, SVMIOIOTYPE enmIoType, uint8_t cbReg,
|
---|
167 | uint8_t cAddrSizeBits, uint8_t iEffSeg, bool fRep, bool fStrIo,
|
---|
168 | PSVMIOIOEXITINFO pIoExitInfo);
|
---|
169 | /** @} */
|
---|
170 |
|
---|
171 | #ifndef IN_RC
|
---|
172 |
|
---|
173 | /** @name R0, R3 HM (VMX/SVM agnostic) handlers.
|
---|
174 | * @{ */
|
---|
175 | VMM_INT_DECL(int) HMFlushTLB(PVMCPU pVCpu);
|
---|
176 | VMM_INT_DECL(int) HMFlushTLBOnAllVCpus(PVM pVM);
|
---|
177 | VMM_INT_DECL(int) HMInvalidatePageOnAllVCpus(PVM pVM, RTGCPTR GCVirt);
|
---|
178 | VMM_INT_DECL(int) HMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys);
|
---|
179 | VMM_INT_DECL(bool) HMAreNestedPagingAndFullGuestExecEnabled(PVM pVM);
|
---|
180 | VMM_INT_DECL(bool) HMIsLongModeAllowed(PVM pVM);
|
---|
181 | VMM_INT_DECL(bool) HMIsNestedPagingActive(PVM pVM);
|
---|
182 | VMM_INT_DECL(bool) HMIsMsrBitmapActive(PVM pVM);
|
---|
183 | /** @} */
|
---|
184 |
|
---|
185 | /** @name R0, R3 SVM handlers.
|
---|
186 | * @{ */
|
---|
187 | VMM_INT_DECL(bool) HMSvmIsVGifActive(PVM pVM);
|
---|
188 | VMM_INT_DECL(uint64_t) HMSvmNstGstApplyTscOffset(PVMCPU pVCpu, uint64_t uTicks);
|
---|
189 | # ifdef VBOX_WITH_NESTED_HWVIRT_SVM
|
---|
190 | VMM_INT_DECL(void) HMSvmNstGstVmExitNotify(PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
191 | # endif
|
---|
192 | VMM_INT_DECL(int) HMSvmIsSubjectToErratum170(uint32_t *pu32Family, uint32_t *pu32Model, uint32_t *pu32Stepping);
|
---|
193 | VMM_INT_DECL(int) HMHCSvmMaybeMovTprHypercall(PVMCPU pVCpu);
|
---|
194 | /** @} */
|
---|
195 |
|
---|
196 | #else /* Nops in RC: */
|
---|
197 |
|
---|
198 | /** @name RC HM (VMX/SVM agnostic) handlers.
|
---|
199 | * @{ */
|
---|
200 | # define HMFlushTLB(pVCpu) do { } while (0)
|
---|
201 | # define HMFlushTLBOnAllVCpus(pVM) do { } while (0)
|
---|
202 | # define HMInvalidatePageOnAllVCpus(pVM, GCVirt) do { } while (0)
|
---|
203 | # define HMInvalidatePhysPage(pVM, GCVirt) do { } while (0)
|
---|
204 | # define HMAreNestedPagingAndFullGuestExecEnabled(pVM) false
|
---|
205 | # define HMIsLongModeAllowed(pVM) false
|
---|
206 | # define HMIsNestedPagingActive(pVM) false
|
---|
207 | # define HMIsMsrBitmapsActive(pVM) false
|
---|
208 | /** @} */
|
---|
209 |
|
---|
210 | /** @name RC SVM handlers.
|
---|
211 | * @{ */
|
---|
212 | # define HMSvmIsVGifActive(pVM) false
|
---|
213 | # define HMSvmNstGstApplyTscOffset(pVCpu, uTicks) (uTicks)
|
---|
214 | # define HMSvmNstGstVmExitNotify(pVCpu, pCtx) do { } while (0)
|
---|
215 | # define HMSvmIsSubjectToErratum170(puFamily, puModel, puStepping) false
|
---|
216 | # define HMHCSvmMaybeMovTprHypercall(pVCpu) do { } while (0)
|
---|
217 | /** @} */
|
---|
218 |
|
---|
219 | #endif
|
---|
220 |
|
---|
221 | #ifdef IN_RING0
|
---|
222 | /** @defgroup grp_hm_r0 The HM ring-0 Context API
|
---|
223 | * @{
|
---|
224 | */
|
---|
225 | VMMR0_INT_DECL(int) HMR0Init(void);
|
---|
226 | VMMR0_INT_DECL(int) HMR0Term(void);
|
---|
227 | VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM);
|
---|
228 | VMMR0_INT_DECL(int) HMR0TermVM(PVM pVM);
|
---|
229 | VMMR0_INT_DECL(int) HMR0EnableAllCpus(PVM pVM);
|
---|
230 | # ifdef VBOX_WITH_RAW_MODE
|
---|
231 | VMMR0_INT_DECL(int) HMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled);
|
---|
232 | VMMR0_INT_DECL(void) HMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled);
|
---|
233 | # endif
|
---|
234 |
|
---|
235 | VMMR0_INT_DECL(int) HMR0SetupVM(PVM pVM);
|
---|
236 | VMMR0_INT_DECL(int) HMR0RunGuestCode(PVM pVM, PVMCPU pVCpu);
|
---|
237 | VMMR0_INT_DECL(int) HMR0Enter(PVMCPU pVCpu);
|
---|
238 | VMMR0_INT_DECL(int) HMR0LeaveCpu(PVMCPU pVCpu);
|
---|
239 | VMMR0_INT_DECL(void) HMR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser);
|
---|
240 | VMMR0_INT_DECL(void) HMR0NotifyCpumUnloadedGuestFpuState(PVMCPU VCpu);
|
---|
241 | VMMR0_INT_DECL(void) HMR0NotifyCpumModifiedHostCr0(PVMCPU VCpu);
|
---|
242 | VMMR0_INT_DECL(bool) HMR0SuspendPending(void);
|
---|
243 | VMMR0_INT_DECL(int) HMR0InvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt);
|
---|
244 | VMMR0_INT_DECL(int) HMR0ImportStateOnDemand(PVMCPU pVCpu, uint64_t fWhat);
|
---|
245 |
|
---|
246 | # if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
|
---|
247 | VMMR0_INT_DECL(int) HMR0SaveFPUState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
248 | VMMR0_INT_DECL(int) HMR0SaveDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
249 | VMMR0_INT_DECL(int) HMR0TestSwitcher3264(PVM pVM);
|
---|
250 | # endif
|
---|
251 |
|
---|
252 | /** @} */
|
---|
253 | #endif /* IN_RING0 */
|
---|
254 |
|
---|
255 |
|
---|
256 | #ifdef IN_RING3
|
---|
257 | /** @defgroup grp_hm_r3 The HM ring-3 Context API
|
---|
258 | * @{
|
---|
259 | */
|
---|
260 | VMMR3DECL(bool) HMR3IsEnabled(PUVM pUVM);
|
---|
261 | VMMR3DECL(bool) HMR3IsNestedPagingActive(PUVM pUVM);
|
---|
262 | VMMR3DECL(bool) HMR3IsVirtApicRegsEnabled(PUVM pUVM);
|
---|
263 | VMMR3DECL(bool) HMR3IsPostedIntrsEnabled(PUVM pUVM);
|
---|
264 | VMMR3DECL(bool) HMR3IsVpidActive(PUVM pUVM);
|
---|
265 | VMMR3DECL(bool) HMR3IsUXActive(PUVM pUVM);
|
---|
266 | VMMR3DECL(bool) HMR3IsSvmEnabled(PUVM pUVM);
|
---|
267 | VMMR3DECL(bool) HMR3IsVmxEnabled(PUVM pUVM);
|
---|
268 |
|
---|
269 | VMMR3_INT_DECL(bool) HMR3IsEventPending(PVMCPU pVCpu);
|
---|
270 | VMMR3_INT_DECL(int) HMR3Init(PVM pVM);
|
---|
271 | VMMR3_INT_DECL(int) HMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
|
---|
272 | VMMR3_INT_DECL(void) HMR3Relocate(PVM pVM);
|
---|
273 | VMMR3_INT_DECL(int) HMR3Term(PVM pVM);
|
---|
274 | VMMR3_INT_DECL(void) HMR3Reset(PVM pVM);
|
---|
275 | VMMR3_INT_DECL(void) HMR3ResetCpu(PVMCPU pVCpu);
|
---|
276 | VMMR3_INT_DECL(void) HMR3CheckError(PVM pVM, int iStatusCode);
|
---|
277 | VMMR3_INT_DECL(void) HMR3NotifyDebugEventChanged(PVM pVM);
|
---|
278 | VMMR3_INT_DECL(void) HMR3NotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu);
|
---|
279 | VMMR3_INT_DECL(bool) HMR3IsActive(PVMCPU pVCpu);
|
---|
280 | VMMR3_INT_DECL(int) HMR3EnablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
|
---|
281 | VMMR3_INT_DECL(int) HMR3DisablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
|
---|
282 | VMMR3_INT_DECL(int) HMR3PatchTprInstr(PVM pVM, PVMCPU pVCpu);
|
---|
283 | VMMR3_INT_DECL(bool) HMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx);
|
---|
284 | VMMR3_INT_DECL(bool) HMR3IsVmxPreemptionTimerUsed(PVM pVM);
|
---|
285 | VMMR3DECL(const char *) HMR3GetVmxExitName(uint32_t uExit);
|
---|
286 | VMMR3DECL(const char *) HMR3GetSvmExitName(uint32_t uExit);
|
---|
287 | /** @} */
|
---|
288 | #endif /* IN_RING3 */
|
---|
289 |
|
---|
290 | /** @} */
|
---|
291 | RT_C_DECLS_END
|
---|
292 |
|
---|
293 |
|
---|
294 | #endif
|
---|
295 |
|
---|