VirtualBox

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

Last change on this file since 67937 was 67529, checked in by vboxsync, 7 years ago

VMM: Nested Hw.virt: Fixes and debugger info support for VCPU hwvirt state.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/** @file
2 * HM - Intel/AMD VM Hardware Assisted Virtualization Manager (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2016 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) is used.
49 *
50 * @param a_pVM The cross context VM structure.
51 * @sa HMIsEnabledNotMacro, HMR3IsEnabled
52 * @internal
53 */
54#if defined(VBOX_STRICT) && defined(IN_RING3)
55# define HMIsEnabled(a_pVM) HMIsEnabledNotMacro(a_pVM)
56#else
57# define HMIsEnabled(a_pVM) ((a_pVM)->fHMEnabled)
58#endif
59
60/**
61 * Checks whether raw-mode context is required for any purpose.
62 *
63 * @retval true if required either by raw-mode itself or by HM for doing
64 * switching the cpu to 64-bit mode.
65 * @retval false if not required.
66 *
67 * @param a_pVM The cross context VM structure.
68 * @internal
69 */
70#if HC_ARCH_BITS == 64
71# define HMIsRawModeCtxNeeded(a_pVM) (!HMIsEnabled(a_pVM))
72#else
73# define HMIsRawModeCtxNeeded(a_pVM) (!HMIsEnabled(a_pVM) || (a_pVM)->fHMNeedRawModeCtx)
74#endif
75
76 /**
77 * Check if the current CPU state is valid for emulating IO blocks in the recompiler
78 *
79 * @returns boolean
80 * @param a_pVCpu Pointer to the shared virtual CPU structure.
81 * @internal
82 */
83#define HMCanEmulateIoBlock(a_pVCpu) (!CPUMIsGuestInPagedProtectedMode(a_pVCpu))
84
85 /**
86 * Check if the current CPU state is valid for emulating IO blocks in the recompiler
87 *
88 * @returns boolean
89 * @param a_pCtx Pointer to the CPU context (within PVM).
90 * @internal
91 */
92#define HMCanEmulateIoBlockEx(a_pCtx) (!CPUMIsGuestInPagedProtectedModeEx(a_pCtx))
93
94/**
95 * Checks whether we're in the special hardware virtualization context.
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 HMIsInHwVirtCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_HM)
102#else
103# define HMIsInHwVirtCtx(a_pVCpu) (false)
104#endif
105
106/**
107 * Checks whether we're in the special hardware virtualization context and we
108 * cannot perform long jump without guru meditating and possibly messing up the
109 * host and/or guest state.
110 *
111 * This is after we've turned interrupts off and such.
112 *
113 * @returns true / false.
114 * @param a_pVCpu The caller's cross context virtual CPU structure.
115 * @thread EMT
116 */
117#ifdef IN_RING0
118# define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (VMCPU_GET_STATE(a_pVCpu) == VMCPUSTATE_STARTED_EXEC)
119#else
120# define HMIsInHwVirtNoLongJmpCtx(a_pVCpu) (false)
121#endif
122
123/**
124 * 64-bit raw-mode (intermediate memory context) operations.
125 *
126 * These are special hypervisor eip values used when running 64-bit guests on
127 * 32-bit hosts. Each operation corresponds to a routine.
128 *
129 * @note Duplicated in the assembly code!
130 */
131typedef enum HM64ON32OP
132{
133 HM64ON32OP_INVALID = 0,
134 HM64ON32OP_VMXRCStartVM64,
135 HM64ON32OP_SVMRCVMRun64,
136 HM64ON32OP_HMRCSaveGuestFPU64,
137 HM64ON32OP_HMRCSaveGuestDebug64,
138 HM64ON32OP_HMRCTestSwitcher64,
139 HM64ON32OP_END,
140 HM64ON32OP_32BIT_HACK = 0x7fffffff
141} HM64ON32OP;
142
143/** @name All-context HM API.
144 * @{ */
145VMMDECL(bool) HMIsEnabledNotMacro(PVM pVM);
146VMM_INT_DECL(int) HMInvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt);
147VMM_INT_DECL(bool) HMHasPendingIrq(PVM pVM);
148VMM_INT_DECL(PX86PDPE) HMGetPaePdpes(PVMCPU pVCpu);
149VMM_INT_DECL(int) HMAmdIsSubjectToErratum170(uint32_t *pu32Family, uint32_t *pu32Model, uint32_t *pu32Stepping);
150VMM_INT_DECL(bool) HMSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
151VMM_INT_DECL(void) HMHypercallsEnable(PVMCPU pVCpu);
152VMM_INT_DECL(void) HMHypercallsDisable(PVMCPU pVCpu);
153/** @} */
154
155/** @name All-context SVM helpers.
156 * @{ */
157VMM_INT_DECL(TRPMEVENT) HMSvmEventToTrpmEventType(PCSVMEVENT pSvmEvent);
158VMM_INT_DECL(int) HMSvmGetMsrpmOffsetAndBit(uint32_t idMsr, uint16_t *pbOffMsrpm, uint32_t *puMsrpmBit);
159/** @} */
160
161/** @name Nested hardware virtualization.
162 * @{
163 */
164VMM_INT_DECL(VBOXSTRICTRC) HMSvmNstGstVmExit(PVMCPU pVCpu, PCPUMCTX pCtx, uint64_t uExitCode, uint64_t uExitInfo1,
165 uint64_t uExitInfo2);
166VMM_INT_DECL(void) HMVmxNstGstVmExit(PVMCPU pVCpu, uint16_t uBasicExitReason);
167VMM_INT_DECL(VBOXSTRICTRC) HMSvmVmmcall(PVMCPU pVCpu, PCPUMCTX pCtx, bool *pfRipUpdated);
168VMM_INT_DECL(VBOXSTRICTRC) HMSvmVmrun(PVMCPU pVCpu, PCPUMCTX pCtx, uint8_t cbInstr, RTGCPHYS GCPhysVmcb);
169VMM_INT_DECL(uint8_t) HMSvmNstGstGetInterrupt(PCCPUMCTX pCtx);
170VMM_INT_DECL(bool) HMSvmNstGstCanTakePhysInterrupt(PVMCPU pVCpu, PCCPUMCTX pCtx);
171VMM_INT_DECL(bool) HMSvmNstGstCanTakeVirtInterrupt(PVMCPU pVCpu, PCCPUMCTX pCtx);
172VMM_INT_DECL(VBOXSTRICTRC) HMSvmNstGstHandleCtrlIntercept(PVMCPU pVCpu, PCPUMCTX pCtx, uint64_t uExitCode,
173 uint64_t uExitInfo1, uint64_t uExitInfo2);
174VMM_INT_DECL(VBOXSTRICTRC) HMSvmNstGstHandleMsrIntercept(PVMCPU pVCpu, PCPUMCTX pCtx, uint32_t idMsr, bool fWrite);
175VMM_INT_DECL(VBOXSTRICTRC) HMSvmNstGstHandleIOIntercept(PVMCPU pVCpu, PCPUMCTX pCtx, PCSVMIOIOEXITINFO pIoExitInfo,
176 uint64_t uNextRip);
177/** @} */
178
179#ifndef IN_RC
180VMM_INT_DECL(int) HMFlushTLB(PVMCPU pVCpu);
181VMM_INT_DECL(int) HMFlushTLBOnAllVCpus(PVM pVM);
182VMM_INT_DECL(int) HMInvalidatePageOnAllVCpus(PVM pVM, RTGCPTR GCVirt);
183VMM_INT_DECL(int) HMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys);
184VMM_INT_DECL(bool) HMIsNestedPagingActive(PVM pVM);
185VMM_INT_DECL(bool) HMAreNestedPagingAndFullGuestExecEnabled(PVM pVM);
186VMM_INT_DECL(bool) HMIsLongModeAllowed(PVM pVM);
187VMM_INT_DECL(bool) HMAreMsrBitmapsAvailable(PVM pVM);
188VMM_INT_DECL(PGMMODE) HMGetShwPagingMode(PVM pVM);
189#else /* Nops in RC: */
190# define HMFlushTLB(pVCpu) do { } while (0)
191# define HMIsNestedPagingActive(pVM) false
192# define HMAreNestedPagingAndFullGuestExecEnabled(pVM) false
193# define HMIsLongModeAllowed(pVM) false
194# define HMAreMsrBitmapsAvailable(pVM) false
195# define HMFlushTLBOnAllVCpus(pVM) do { } while (0)
196#endif
197
198#ifdef IN_RING0
199/** @defgroup grp_hm_r0 The HM ring-0 Context API
200 * @{
201 */
202VMMR0_INT_DECL(int) HMR0Init(void);
203VMMR0_INT_DECL(int) HMR0Term(void);
204VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM);
205VMMR0_INT_DECL(int) HMR0TermVM(PVM pVM);
206VMMR0_INT_DECL(int) HMR0EnableAllCpus(PVM pVM);
207# ifdef VBOX_WITH_RAW_MODE
208VMMR0_INT_DECL(int) HMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled);
209VMMR0_INT_DECL(void) HMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled);
210# endif
211
212VMMR0_INT_DECL(void) HMR0SavePendingIOPortRead(PVMCPU pVCpu, RTGCPTR GCPtrRip, RTGCPTR GCPtrRipNext,
213 unsigned uPort, unsigned uAndVal, unsigned cbSize);
214VMMR0_INT_DECL(int) HMR0SetupVM(PVM pVM);
215VMMR0_INT_DECL(int) HMR0RunGuestCode(PVM pVM, PVMCPU pVCpu);
216VMMR0_INT_DECL(int) HMR0Enter(PVM pVM, PVMCPU pVCpu);
217VMMR0_INT_DECL(int) HMR0EnterCpu(PVMCPU pVCpu);
218VMMR0_INT_DECL(int) HMR0LeaveCpu(PVMCPU pVCpu);
219VMMR0_INT_DECL(void) HMR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser);
220VMMR0_INT_DECL(void) HMR0NotifyCpumUnloadedGuestFpuState(PVMCPU VCpu);
221VMMR0_INT_DECL(void) HMR0NotifyCpumModifiedHostCr0(PVMCPU VCpu);
222VMMR0_INT_DECL(bool) HMR0SuspendPending(void);
223
224# if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
225VMMR0_INT_DECL(int) HMR0SaveFPUState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
226VMMR0_INT_DECL(int) HMR0SaveDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
227VMMR0_INT_DECL(int) HMR0TestSwitcher3264(PVM pVM);
228# endif
229
230VMMR0_INT_DECL(int) HMR0EnsureCompleteBasicContext(PVMCPU pVCpu, PCPUMCTX pMixedCtx);
231
232/** @} */
233#endif /* IN_RING0 */
234
235
236#ifdef IN_RING3
237/** @defgroup grp_hm_r3 The HM ring-3 Context API
238 * @{
239 */
240VMMR3DECL(bool) HMR3IsEnabled(PUVM pUVM);
241VMMR3DECL(bool) HMR3IsNestedPagingActive(PUVM pUVM);
242VMMR3DECL(bool) HMR3IsVirtApicRegsEnabled(PUVM pUVM);
243VMMR3DECL(bool) HMR3IsPostedIntrsEnabled(PUVM pUVM);
244VMMR3DECL(bool) HMR3IsVpidActive(PUVM pUVM);
245VMMR3DECL(bool) HMR3IsUXActive(PUVM pUVM);
246VMMR3DECL(bool) HMR3IsSvmEnabled(PUVM pUVM);
247VMMR3DECL(bool) HMR3IsVmxEnabled(PUVM pUVM);
248
249VMMR3_INT_DECL(bool) HMR3IsEventPending(PVMCPU pVCpu);
250VMMR3_INT_DECL(int) HMR3Init(PVM pVM);
251VMMR3_INT_DECL(int) HMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
252VMMR3_INT_DECL(void) HMR3Relocate(PVM pVM);
253VMMR3_INT_DECL(int) HMR3Term(PVM pVM);
254VMMR3_INT_DECL(void) HMR3Reset(PVM pVM);
255VMMR3_INT_DECL(void) HMR3ResetCpu(PVMCPU pVCpu);
256VMMR3_INT_DECL(void) HMR3CheckError(PVM pVM, int iStatusCode);
257VMMR3DECL(bool) HMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx);
258VMMR3_INT_DECL(void) HMR3NotifyScheduled(PVMCPU pVCpu);
259VMMR3_INT_DECL(void) HMR3NotifyEmulated(PVMCPU pVCpu);
260VMMR3_INT_DECL(void) HMR3NotifyDebugEventChanged(PVM pVM);
261VMMR3_INT_DECL(void) HMR3NotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu);
262VMMR3_INT_DECL(bool) HMR3IsActive(PVMCPU pVCpu);
263VMMR3_INT_DECL(void) HMR3PagingModeChanged(PVM pVM, PVMCPU pVCpu, PGMMODE enmShadowMode, PGMMODE enmGuestMode);
264VMMR3_INT_DECL(int) HMR3EmulateIoBlock(PVM pVM, PCPUMCTX pCtx);
265VMMR3_INT_DECL(VBOXSTRICTRC) HMR3RestartPendingIOInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
266VMMR3_INT_DECL(int) HMR3EnablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
267VMMR3_INT_DECL(int) HMR3DisablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
268VMMR3_INT_DECL(int) HMR3PatchTprInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
269VMMR3_INT_DECL(bool) HMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx);
270VMMR3_INT_DECL(bool) HMR3IsVmxPreemptionTimerUsed(PVM pVM);
271VMMR3_INT_DECL(void) HMR3InfoSvmVmcbCtrl(PCDBGFINFOHLP pHlp, PCSVMVMCBCTRL pVmcbCtrl, const char *pszPrefix);
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