VirtualBox

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

Last change on this file since 70917 was 70782, checked in by vboxsync, 7 years ago

VMM: Nested Hw.virt: Pick up the TSC offset from the original VMCB while applying the nested-guest TSC offset, rather
than the potentially modified VMCB.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 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) 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 *
157 * These are SVM functions (based on AMD specs.) that may be used by IEM/REM and
158 * not VirtualBox functions that are used for hardware-assisted SVM. Those are
159 * declared below under the !IN_RC section.
160 * @{ */
161VMM_INT_DECL(TRPMEVENT) HMSvmEventToTrpmEventType(PCSVMEVENT pSvmEvent);
162VMM_INT_DECL(int) HMSvmGetMsrpmOffsetAndBit(uint32_t idMsr, uint16_t *pbOffMsrpm, uint32_t *puMsrpmBit);
163VMM_INT_DECL(bool) HMSvmIsIOInterceptActive(void *pvIoBitmap, uint16_t u16Port, SVMIOIOTYPE enmIoType, uint8_t cbReg,
164 uint8_t cAddrSizeBits, uint8_t iEffSeg, bool fRep, bool fStrIo,
165 PSVMIOIOEXITINFO pIoExitInfo);
166VMM_INT_DECL(VBOXSTRICTRC) HMSvmVmmcall(PVMCPU pVCpu, PCPUMCTX pCtx, bool *pfRipUpdated);
167/** @} */
168
169#ifndef IN_RC
170VMM_INT_DECL(int) HMFlushTLB(PVMCPU pVCpu);
171VMM_INT_DECL(int) HMFlushTLBOnAllVCpus(PVM pVM);
172VMM_INT_DECL(int) HMInvalidatePageOnAllVCpus(PVM pVM, RTGCPTR GCVirt);
173VMM_INT_DECL(int) HMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys);
174VMM_INT_DECL(bool) HMIsNestedPagingActive(PVM pVM);
175VMM_INT_DECL(bool) HMAreNestedPagingAndFullGuestExecEnabled(PVM pVM);
176VMM_INT_DECL(bool) HMIsLongModeAllowed(PVM pVM);
177VMM_INT_DECL(bool) HMAreMsrBitmapsAvailable(PVM pVM);
178VMM_INT_DECL(PGMMODE) HMGetShwPagingMode(PVM pVM);
179VMM_INT_DECL(void) HMSvmNstGstVmExitNotify(PVMCPU pVCpu, PCPUMCTX pCtx);
180VMM_INT_DECL(bool) HMSvmIsVGifActive(PVM pVM);
181VMM_INT_DECL(uint64_t) HMSvmNstGstApplyTscOffset(PVMCPU pVCpu, uint64_t uTicks);
182#else /* Nops in RC: */
183# define HMFlushTLB(pVCpu) do { } while (0)
184# define HMIsNestedPagingActive(pVM) false
185# define HMAreNestedPagingAndFullGuestExecEnabled(pVM) false
186# define HMIsLongModeAllowed(pVM) false
187# define HMAreMsrBitmapsAvailable(pVM) false
188# define HMFlushTLBOnAllVCpus(pVM) do { } while (0)
189# define HMSvmNstGstVmExitNotify(pVCpu, pCtx) do { } while (0)
190# define HMSvmIsVGifActive(pVM) false
191# define HMSvmNstGstApplyTscOffset(pVCpu, uTicks) (uTicks)
192#endif
193
194#ifdef IN_RING0
195/** @defgroup grp_hm_r0 The HM ring-0 Context API
196 * @{
197 */
198VMMR0_INT_DECL(int) HMR0Init(void);
199VMMR0_INT_DECL(int) HMR0Term(void);
200VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM);
201VMMR0_INT_DECL(int) HMR0TermVM(PVM pVM);
202VMMR0_INT_DECL(int) HMR0EnableAllCpus(PVM pVM);
203# ifdef VBOX_WITH_RAW_MODE
204VMMR0_INT_DECL(int) HMR0EnterSwitcher(PVM pVM, VMMSWITCHER enmSwitcher, bool *pfVTxDisabled);
205VMMR0_INT_DECL(void) HMR0LeaveSwitcher(PVM pVM, bool fVTxDisabled);
206# endif
207
208VMMR0_INT_DECL(void) HMR0SavePendingIOPortRead(PVMCPU pVCpu, RTGCPTR GCPtrRip, RTGCPTR GCPtrRipNext,
209 unsigned uPort, unsigned uAndVal, unsigned cbSize);
210VMMR0_INT_DECL(int) HMR0SetupVM(PVM pVM);
211VMMR0_INT_DECL(int) HMR0RunGuestCode(PVM pVM, PVMCPU pVCpu);
212VMMR0_INT_DECL(int) HMR0Enter(PVM pVM, PVMCPU pVCpu);
213VMMR0_INT_DECL(int) HMR0EnterCpu(PVMCPU pVCpu);
214VMMR0_INT_DECL(int) HMR0LeaveCpu(PVMCPU pVCpu);
215VMMR0_INT_DECL(void) HMR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser);
216VMMR0_INT_DECL(void) HMR0NotifyCpumUnloadedGuestFpuState(PVMCPU VCpu);
217VMMR0_INT_DECL(void) HMR0NotifyCpumModifiedHostCr0(PVMCPU VCpu);
218VMMR0_INT_DECL(bool) HMR0SuspendPending(void);
219
220# if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
221VMMR0_INT_DECL(int) HMR0SaveFPUState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
222VMMR0_INT_DECL(int) HMR0SaveDebugState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
223VMMR0_INT_DECL(int) HMR0TestSwitcher3264(PVM pVM);
224# endif
225
226VMMR0_INT_DECL(int) HMR0EnsureCompleteBasicContext(PVMCPU pVCpu, PCPUMCTX pMixedCtx);
227
228/** @} */
229#endif /* IN_RING0 */
230
231
232#ifdef IN_RING3
233/** @defgroup grp_hm_r3 The HM ring-3 Context API
234 * @{
235 */
236VMMR3DECL(bool) HMR3IsEnabled(PUVM pUVM);
237VMMR3DECL(bool) HMR3IsNestedPagingActive(PUVM pUVM);
238VMMR3DECL(bool) HMR3IsVirtApicRegsEnabled(PUVM pUVM);
239VMMR3DECL(bool) HMR3IsPostedIntrsEnabled(PUVM pUVM);
240VMMR3DECL(bool) HMR3IsVpidActive(PUVM pUVM);
241VMMR3DECL(bool) HMR3IsUXActive(PUVM pUVM);
242VMMR3DECL(bool) HMR3IsSvmEnabled(PUVM pUVM);
243VMMR3DECL(bool) HMR3IsVmxEnabled(PUVM pUVM);
244
245VMMR3_INT_DECL(bool) HMR3IsEventPending(PVMCPU pVCpu);
246VMMR3_INT_DECL(int) HMR3Init(PVM pVM);
247VMMR3_INT_DECL(int) HMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
248VMMR3_INT_DECL(void) HMR3Relocate(PVM pVM);
249VMMR3_INT_DECL(int) HMR3Term(PVM pVM);
250VMMR3_INT_DECL(void) HMR3Reset(PVM pVM);
251VMMR3_INT_DECL(void) HMR3ResetCpu(PVMCPU pVCpu);
252VMMR3_INT_DECL(void) HMR3CheckError(PVM pVM, int iStatusCode);
253VMMR3DECL(bool) HMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx);
254VMMR3_INT_DECL(void) HMR3NotifyScheduled(PVMCPU pVCpu);
255VMMR3_INT_DECL(void) HMR3NotifyEmulated(PVMCPU pVCpu);
256VMMR3_INT_DECL(void) HMR3NotifyDebugEventChanged(PVM pVM);
257VMMR3_INT_DECL(void) HMR3NotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu);
258VMMR3_INT_DECL(bool) HMR3IsActive(PVMCPU pVCpu);
259VMMR3_INT_DECL(void) HMR3PagingModeChanged(PVM pVM, PVMCPU pVCpu, PGMMODE enmShadowMode, PGMMODE enmGuestMode);
260VMMR3_INT_DECL(int) HMR3EmulateIoBlock(PVM pVM, PCPUMCTX pCtx);
261VMMR3_INT_DECL(VBOXSTRICTRC) HMR3RestartPendingIOInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
262VMMR3_INT_DECL(int) HMR3EnablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
263VMMR3_INT_DECL(int) HMR3DisablePatching(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
264VMMR3_INT_DECL(int) HMR3PatchTprInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
265VMMR3_INT_DECL(bool) HMR3IsRescheduleRequired(PVM pVM, PCPUMCTX pCtx);
266VMMR3_INT_DECL(bool) HMR3IsVmxPreemptionTimerUsed(PVM pVM);
267/** @} */
268#endif /* IN_RING3 */
269
270/** @} */
271RT_C_DECLS_END
272
273
274#endif
275
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