VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/GIMAll.cpp@ 58311

Last change on this file since 58311 was 58126, checked in by vboxsync, 9 years ago

VMM: Fixed almost all the Doxygen warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: GIMAll.cpp 58126 2015-10-08 20:59:48Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager - All Contexts.
4 */
5
6/*
7 * Copyright (C) 2014-2015 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_GIM
23#include "GIMInternal.h"
24#include <VBox/err.h>
25#include <VBox/vmm/vm.h>
26
27/* Include all the providers. */
28#include "GIMHvInternal.h"
29#include "GIMMinimalInternal.h"
30
31
32/**
33 * Checks whether GIM is being used by this VM.
34 *
35 * @retval true if used.
36 * @retval false if no GIM provider ("none") is used.
37 *
38 * @param pVM The cross context VM structure.
39 */
40VMMDECL(bool) GIMIsEnabled(PVM pVM)
41{
42 return pVM->gim.s.enmProviderId != GIMPROVIDERID_NONE;
43}
44
45
46/**
47 * Gets the GIM provider configured for this VM.
48 *
49 * @returns The GIM provider Id.
50 * @param pVM The cross context VM structure.
51 */
52VMMDECL(GIMPROVIDERID) GIMGetProvider(PVM pVM)
53{
54 return pVM->gim.s.enmProviderId;
55}
56
57
58/**
59 * Returns whether the guest has configured and enabled calls to the hypervisor.
60 *
61 * @returns true if hypercalls are enabled and usable, false otherwise.
62 * @param pVCpu The cross context virtual CPU structure.
63 */
64VMM_INT_DECL(bool) GIMAreHypercallsEnabled(PVMCPU pVCpu)
65{
66 PVM pVM = pVCpu->CTX_SUFF(pVM);
67 if (!GIMIsEnabled(pVM))
68 return false;
69
70 switch (pVM->gim.s.enmProviderId)
71 {
72 case GIMPROVIDERID_HYPERV:
73 return gimHvAreHypercallsEnabled(pVCpu);
74
75 case GIMPROVIDERID_KVM:
76 return gimKvmAreHypercallsEnabled(pVCpu);
77
78 default:
79 return false;
80 }
81}
82
83
84/**
85 * Implements a GIM hypercall with the provider configured for the VM.
86 *
87 * @returns VBox status code.
88 * @param pVCpu The cross context virtual CPU structure.
89 * @param pCtx Pointer to the guest-CPU context.
90 *
91 * @thread EMT.
92 */
93VMM_INT_DECL(int) GIMHypercall(PVMCPU pVCpu, PCPUMCTX pCtx)
94{
95 PVM pVM = pVCpu->CTX_SUFF(pVM);
96 VMCPU_ASSERT_EMT(pVCpu);
97
98 if (RT_UNLIKELY(!GIMIsEnabled(pVM)))
99 return VERR_GIM_NOT_ENABLED;
100
101 switch (pVM->gim.s.enmProviderId)
102 {
103 case GIMPROVIDERID_HYPERV:
104 return gimHvHypercall(pVCpu, pCtx);
105
106 case GIMPROVIDERID_KVM:
107 return gimKvmHypercall(pVCpu, pCtx);
108
109 default:
110 AssertMsgFailed(("GIMHypercall: for provider %u not available/implemented\n", pVM->gim.s.enmProviderId));
111 return VERR_GIM_HYPERCALLS_NOT_AVAILABLE;
112 }
113}
114
115
116/**
117 * Returns whether the guest has configured and setup the use of paravirtualized
118 * TSC.
119 *
120 * Paravirtualized TSCs are per-VM and the rest of the execution engine logic
121 * relies on that.
122 *
123 * @returns true if enabled and usable, false otherwise.
124 * @param pVM The cross context VM structure.
125 */
126VMM_INT_DECL(bool) GIMIsParavirtTscEnabled(PVM pVM)
127{
128 switch (pVM->gim.s.enmProviderId)
129 {
130 case GIMPROVIDERID_HYPERV:
131 return gimHvIsParavirtTscEnabled(pVM);
132
133 case GIMPROVIDERID_KVM:
134 return gimKvmIsParavirtTscEnabled(pVM);
135
136 default:
137 break;
138 }
139 return false;
140}
141
142
143/**
144 * Whether \#UD exceptions in the guest needs to be intercepted by the GIM
145 * provider.
146 *
147 * At the moment, the reason why this isn't a more generic interface wrt to
148 * exceptions is because of performance (each VM-exit would have to manually
149 * check whether or not GIM needs to be notified). Left as a todo for later if
150 * really required.
151 *
152 * @returns true if needed, false otherwise.
153 * @param pVCpu The cross context virtual CPU structure.
154 */
155VMM_INT_DECL(bool) GIMShouldTrapXcptUD(PVMCPU pVCpu)
156{
157 PVM pVM = pVCpu->CTX_SUFF(pVM);
158 if (!GIMIsEnabled(pVM))
159 return false;
160
161 switch (pVM->gim.s.enmProviderId)
162 {
163 case GIMPROVIDERID_KVM:
164 return gimKvmShouldTrapXcptUD(pVCpu);
165
166 case GIMPROVIDERID_HYPERV:
167 return gimHvShouldTrapXcptUD(pVCpu);
168
169 default:
170 return false;
171 }
172}
173
174
175/**
176 * Exception handler for \#UD when requested by the GIM provider.
177 *
178 * @param pVCpu The cross context virtual CPU structure.
179 * @param pCtx Pointer to the guest-CPU context.
180 * @param pDis Pointer to the disassembled instruction state at RIP.
181 * Optional, can be NULL.
182 */
183VMM_INT_DECL(int) GIMXcptUD(PVMCPU pVCpu, PCPUMCTX pCtx, PDISCPUSTATE pDis)
184{
185 PVM pVM = pVCpu->CTX_SUFF(pVM);
186 Assert(GIMIsEnabled(pVM));
187
188 switch (pVM->gim.s.enmProviderId)
189 {
190 case GIMPROVIDERID_KVM:
191 return gimKvmXcptUD(pVCpu, pCtx, pDis);
192
193 case GIMPROVIDERID_HYPERV:
194 return gimHvXcptUD(pVCpu, pCtx, pDis);
195
196 default:
197 return VERR_GIM_OPERATION_FAILED;
198 }
199}
200
201
202/**
203 * Invokes the read-MSR handler for the GIM provider configured for the VM.
204 *
205 * @returns Strict VBox status code like CPUMQueryGuestMsr.
206 * @retval VINF_CPUM_R3_MSR_READ
207 * @retval VERR_CPUM_RAISE_GP_0
208 *
209 * @param pVCpu The cross context virtual CPU structure.
210 * @param idMsr The MSR to read.
211 * @param pRange The range this MSR belongs to.
212 * @param puValue Where to store the MSR value read.
213 */
214VMM_INT_DECL(VBOXSTRICTRC) GIMReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue)
215{
216 Assert(pVCpu);
217 PVM pVM = pVCpu->CTX_SUFF(pVM);
218 Assert(GIMIsEnabled(pVM));
219 VMCPU_ASSERT_EMT(pVCpu);
220
221 switch (pVM->gim.s.enmProviderId)
222 {
223 case GIMPROVIDERID_HYPERV:
224 return gimHvReadMsr(pVCpu, idMsr, pRange, puValue);
225
226 case GIMPROVIDERID_KVM:
227 return gimKvmReadMsr(pVCpu, idMsr, pRange, puValue);
228
229 default:
230 AssertMsgFailed(("GIMReadMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
231 return VERR_CPUM_RAISE_GP_0;
232 }
233}
234
235
236/**
237 * Invokes the write-MSR handler for the GIM provider configured for the VM.
238 *
239 * @returns Strict VBox status code like CPUMSetGuestMsr.
240 * @retval VINF_CPUM_R3_MSR_WRITE
241 * @retval VERR_CPUM_RAISE_GP_0
242 *
243 * @param pVCpu The cross context virtual CPU structure.
244 * @param idMsr The MSR to write.
245 * @param pRange The range this MSR belongs to.
246 * @param uValue The value to set, ignored bits masked.
247 * @param uRawValue The raw value with the ignored bits not masked.
248 */
249VMM_INT_DECL(VBOXSTRICTRC) GIMWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uValue, uint64_t uRawValue)
250{
251 AssertPtr(pVCpu);
252 NOREF(uValue);
253
254 PVM pVM = pVCpu->CTX_SUFF(pVM);
255 Assert(GIMIsEnabled(pVM));
256 VMCPU_ASSERT_EMT(pVCpu);
257
258 switch (pVM->gim.s.enmProviderId)
259 {
260 case GIMPROVIDERID_HYPERV:
261 return gimHvWriteMsr(pVCpu, idMsr, pRange, uRawValue);
262
263 case GIMPROVIDERID_KVM:
264 return gimKvmWriteMsr(pVCpu, idMsr, pRange, uRawValue);
265
266 default:
267 AssertMsgFailed(("GIMWriteMsr: for unknown provider %u idMsr=%#RX32 -> #GP(0)", pVM->gim.s.enmProviderId, idMsr));
268 return VERR_CPUM_RAISE_GP_0;
269 }
270}
271
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