1 | /* $Id: GIM.cpp 51367 2014-05-23 07:45:35Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * GIM - Guest Interface Manager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014 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 | /** @page pg_gim GIM - The Guest Interface Manager
|
---|
19 | *
|
---|
20 | * The Guest Interface Manager abstracts an interface provider through which
|
---|
21 | * guests may interact with the hypervisor.
|
---|
22 | *
|
---|
23 | * @see grp_gim
|
---|
24 | *
|
---|
25 | *
|
---|
26 | * @section sec_gim_provider Providers
|
---|
27 | *
|
---|
28 | * A GIM provider implements a particular hypervisor interface such as Microsoft
|
---|
29 | * Hyper-V, Linux KVM and so on. It hooks into various components in the VMM to
|
---|
30 | * ease the guest in running under a recognized, virtualized environment. This
|
---|
31 | * is also referred to as paravirtualization interfaces.
|
---|
32 | *
|
---|
33 | * The idea behind this is primarily for making guests more accurate and
|
---|
34 | * efficient when operating in a virtualized environment.
|
---|
35 | *
|
---|
36 | * For instance, a guest when interfaced to VirtualBox through a GIM provider
|
---|
37 | * may rely on the provider (and VirtualBox ultimately) for providing the
|
---|
38 | * correct TSC frequency and may therefore not have to caliberate the TSC
|
---|
39 | * itself, resulting in higher accuracy and saving several CPU cycles.
|
---|
40 | *
|
---|
41 | * At most, only one GIM provider can be active for a running VM and cannot be
|
---|
42 | * changed during the lifetime of the VM.
|
---|
43 | */
|
---|
44 |
|
---|
45 | /*******************************************************************************
|
---|
46 | * Header Files *
|
---|
47 | *******************************************************************************/
|
---|
48 | #define LOG_GROUP LOG_GROUP_GIM
|
---|
49 | #include <VBox/log.h>
|
---|
50 | #include "GIMInternal.h"
|
---|
51 | #include <VBox/vmm/vm.h>
|
---|
52 | #include <VBox/vmm/hm.h>
|
---|
53 | #include <VBox/vmm/ssm.h>
|
---|
54 |
|
---|
55 | #include <iprt/err.h>
|
---|
56 | #include <iprt/string.h>
|
---|
57 |
|
---|
58 | /* Include all GIM providers. */
|
---|
59 | #include "GIMMinimalInternal.h"
|
---|
60 | #include "GIMHvInternal.h"
|
---|
61 |
|
---|
62 | /*******************************************************************************
|
---|
63 | * Internal Functions *
|
---|
64 | *******************************************************************************/
|
---|
65 | static DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM);
|
---|
66 | static DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
|
---|
67 |
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Initializes the GIM.
|
---|
71 | *
|
---|
72 | * @returns VBox status code.
|
---|
73 | * @param pVM Pointer to the VM.
|
---|
74 | */
|
---|
75 | VMMR3_INT_DECL(int) GIMR3Init(PVM pVM)
|
---|
76 | {
|
---|
77 | LogFlow(("GIMR3Init\n"));
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * Assert alignment and sizes.
|
---|
81 | */
|
---|
82 | AssertCompile(sizeof(pVM->gim.s) <= sizeof(pVM->gim.padding));
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Register the saved state data unit.
|
---|
86 | */
|
---|
87 | int rc;
|
---|
88 | #if 0
|
---|
89 | rc = SSMR3RegisterInternal(pVM, "GIM", 0, GIM_SSM_VERSION, sizeof(GIM),
|
---|
90 | NULL, NULL, NULL,
|
---|
91 | NULL, gimR3Save, NULL,
|
---|
92 | NULL, gimR3Load, NULL);
|
---|
93 | if (RT_FAILURE(rc))
|
---|
94 | return rc;
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Read configuration.
|
---|
99 | */
|
---|
100 | PCFGMNODE pCfgNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "GIM/");
|
---|
101 |
|
---|
102 | /** @cfgm{GIM/Provider, string}
|
---|
103 | * The name of the GIM provider. The default is "none". */
|
---|
104 | char szProvider[64];
|
---|
105 | rc = CFGMR3QueryStringDef(pCfgNode, "Provider", szProvider, sizeof(szProvider), "None");
|
---|
106 | AssertLogRelRCReturn(rc, rc);
|
---|
107 |
|
---|
108 | /** @cfgm{GIM/Version, uint32_t}
|
---|
109 | * The interface version. The default is 0, which means "provide the most
|
---|
110 | * up-to-date implementation". */
|
---|
111 | uint32_t uVersion;
|
---|
112 | rc = CFGMR3QueryU32Def(pCfgNode, "Version", &uVersion, 0 /* default */);
|
---|
113 | AssertLogRelRCReturn(rc, rc);
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Setup the GIM provider for this VM.
|
---|
117 | */
|
---|
118 | LogRel(("GIM: Using provider \"%s\" (Implementation version: %u)\n", szProvider, uVersion));
|
---|
119 | if (!RTStrCmp(szProvider, "None"))
|
---|
120 | {
|
---|
121 | Assert(!pVM->gim.s.fEnabled);
|
---|
122 | pVM->gim.s.enmProviderId = GIMPROVIDERID_NONE;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | pVM->gim.s.fEnabled = true;
|
---|
127 | pVM->gim.s.u32Version = uVersion;
|
---|
128 | if (!RTStrCmp(szProvider, "Minimal"))
|
---|
129 | {
|
---|
130 | pVM->gim.s.enmProviderId = GIMPROVIDERID_MINIMAL;
|
---|
131 | rc = GIMR3MinimalInit(pVM);
|
---|
132 | }
|
---|
133 | else if (!RTStrCmp(szProvider, "HyperV"))
|
---|
134 | {
|
---|
135 | pVM->gim.s.enmProviderId = GIMPROVIDERID_HYPERV;
|
---|
136 | rc = GIMR3HvInit(pVM);
|
---|
137 | }
|
---|
138 | /** @todo KVM and others. */
|
---|
139 | else
|
---|
140 | {
|
---|
141 | LogRel(("GIM: Provider \"%s\" unknown.\n", szProvider));
|
---|
142 | rc = VERR_NOT_SUPPORTED;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | return rc;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Applies relocations to data and code managed by this component. This function
|
---|
151 | * will be called at init and whenever the VMM need to relocate itself inside
|
---|
152 | * the GC.
|
---|
153 | *
|
---|
154 | * @param pVM Pointer to the VM.
|
---|
155 | * @param offDelta Relocation delta relative to old location.
|
---|
156 | */
|
---|
157 | VMM_INT_DECL(void) GIMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
|
---|
158 | {
|
---|
159 | LogFlow(("GIMR3Relocate\n"));
|
---|
160 |
|
---|
161 | if ( !pVM->gim.s.fEnabled
|
---|
162 | || HMIsEnabled(pVM))
|
---|
163 | {
|
---|
164 | return;
|
---|
165 | }
|
---|
166 |
|
---|
167 | switch (pVM->gim.s.enmProviderId)
|
---|
168 | {
|
---|
169 | case GIMPROVIDERID_MINIMAL:
|
---|
170 | {
|
---|
171 | GIMR3MinimalRelocate(pVM, offDelta);
|
---|
172 | break;
|
---|
173 | }
|
---|
174 |
|
---|
175 | case GIMPROVIDERID_HYPERV:
|
---|
176 | {
|
---|
177 | GIMR3HvRelocate(pVM, offDelta);
|
---|
178 | break;
|
---|
179 | }
|
---|
180 |
|
---|
181 | case GIMPROVIDERID_KVM: /** @todo KVM. */
|
---|
182 | default:
|
---|
183 | {
|
---|
184 | AssertMsgFailed(("Invalid provider Id %#x\n", pVM->gim.s.enmProviderId));
|
---|
185 | break;
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Execute state save operation.
|
---|
193 | *
|
---|
194 | * @returns VBox status code.
|
---|
195 | * @param pVM Pointer to the VM.
|
---|
196 | * @param pSSM SSM operation handle.
|
---|
197 | */
|
---|
198 | DECLCALLBACK(int) gimR3Save(PVM pVM, PSSMHANDLE pSSM)
|
---|
199 | {
|
---|
200 | /** @todo save state. */
|
---|
201 | return VINF_SUCCESS;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Execute state load operation.
|
---|
207 | *
|
---|
208 | * @returns VBox status code.
|
---|
209 | * @param pVM Pointer to the VM.
|
---|
210 | * @param pSSM SSM operation handle.
|
---|
211 | * @param uVersion Data layout version.
|
---|
212 | * @param uPass The data pass.
|
---|
213 | */
|
---|
214 | DECLCALLBACK(int) gimR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
215 | {
|
---|
216 | /** @todo load state. */
|
---|
217 | return VINF_SUCCESS;
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Terminates the GIM.
|
---|
223 | *
|
---|
224 | * Termination means cleaning up and freeing all resources,
|
---|
225 | * the VM itself is, at this point, powered off or suspended.
|
---|
226 | *
|
---|
227 | * @returns VBox status code.
|
---|
228 | * @param pVM Pointer to the VM.
|
---|
229 | */
|
---|
230 | VMMR3_INT_DECL(int) GIMR3Term(PVM pVM)
|
---|
231 | {
|
---|
232 | return VINF_SUCCESS;
|
---|
233 | }
|
---|
234 |
|
---|