VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/HWACCMAll.cpp@ 23167

最後變更 在這個檔案從23167是 23167,由 vboxsync 提交於 16 年 前

Nothing to do if a TLB flush is already pending; the VCPU should have already been poked if it were active

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.8 KB
 
1/* $Id: HWACCMAll.cpp 23167 2009-09-21 08:35:19Z vboxsync $ */
2/** @file
3 * HWACCM - All contexts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_HWACCM
27#include <VBox/hwaccm.h>
28#include "HWACCMInternal.h"
29#include <VBox/vm.h>
30#include <VBox/x86.h>
31#include <VBox/hwacc_vmx.h>
32#include <VBox/hwacc_svm.h>
33#include <VBox/pgm.h>
34#include <VBox/pdm.h>
35#include <VBox/err.h>
36#include <VBox/log.h>
37#include <VBox/selm.h>
38#include <VBox/iom.h>
39#include <iprt/param.h>
40#include <iprt/assert.h>
41#include <iprt/asm.h>
42#include <iprt/string.h>
43#include <iprt/memobj.h>
44#include <iprt/cpuset.h>
45
46/**
47 * Queues a page for invalidation
48 *
49 * @returns VBox status code.
50 * @param pVCpu The VMCPU to operate on.
51 * @param GCVirt Page to invalidate
52 */
53void hwaccmQueueInvlPage(PVMCPU pVCpu, RTGCPTR GCVirt)
54{
55 /* Nothing to do if a TLB flush is already pending */
56 if (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_TLB_FLUSH))
57 return;
58#if 1
59 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
60#else
61 if (iPage == RT_ELEMENTS(pVCpu->hwaccm.s.TlbShootdown.aPages))
62 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
63 else
64 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_SHOOTDOWN);
65#endif
66}
67
68/**
69 * Invalidates a guest page
70 *
71 * @returns VBox status code.
72 * @param pVCpu The VMCPU to operate on.
73 * @param GCVirt Page to invalidate
74 */
75VMMDECL(int) HWACCMInvalidatePage(PVMCPU pVCpu, RTGCPTR GCVirt)
76{
77 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatFlushPageManual);
78#ifdef IN_RING0
79 PVM pVM = pVCpu->CTX_SUFF(pVM);
80 if (pVM->hwaccm.s.vmx.fSupported)
81 return VMXR0InvalidatePage(pVM, pVCpu, GCVirt);
82
83 Assert(pVM->hwaccm.s.svm.fSupported);
84 return SVMR0InvalidatePage(pVM, pVCpu, GCVirt);
85#endif
86
87 hwaccmQueueInvlPage(pVCpu, GCVirt);
88 return VINF_SUCCESS;
89}
90
91/**
92 * Flushes the guest TLB
93 *
94 * @returns VBox status code.
95 * @param pVCpu The VMCPU to operate on.
96 */
97VMMDECL(int) HWACCMFlushTLB(PVMCPU pVCpu)
98{
99 LogFlow(("HWACCMFlushTLB\n"));
100
101 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
102 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatFlushTLBManual);
103 return VINF_SUCCESS;
104}
105
106#ifndef IN_RC
107/**
108 * Invalidates a guest page on all VCPUs.
109 *
110 * @returns VBox status code.
111 * @param pVM The VM to operate on.
112 * @param GCVirt Page to invalidate
113 */
114VMMDECL(int) HWACCMInvalidatePageOnAllVCpus(PVM pVM, RTGCPTR GCPtr)
115{
116 VMCPUID idCurCpu = VMMGetCpuId(pVM);
117
118 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
119 {
120 PVMCPU pVCpu = &pVM->aCpus[idCpu];
121
122 if (pVCpu->idCpu == idCurCpu)
123 {
124 HWACCMInvalidatePage(pVCpu, GCPtr);
125 }
126 else
127 {
128 hwaccmQueueInvlPage(pVCpu, GCPtr);
129 if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
130 {
131 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdown);
132#ifdef IN_RING0
133 RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
134 if (idHostCpu != NIL_RTCPUID)
135 RTMpPokeCpu(idHostCpu);
136#else
137 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
138#endif
139 }
140 else
141 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatFlushPageManual);
142 }
143 }
144
145 return VINF_SUCCESS;
146}
147
148/**
149 * Flush the TLBs of all VCPUs
150 *
151 * @returns VBox status code.
152 * @param pVM The VM to operate on.
153 */
154VMMDECL(int) HWACCMFlushTLBOnAllVCpus(PVM pVM)
155{
156 if (pVM->cCpus == 1)
157 return HWACCMFlushTLB(&pVM->aCpus[0]);
158
159 VMCPUID idThisCpu = VMMGetCpuId(pVM);
160
161 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
162 {
163 PVMCPU pVCpu = &pVM->aCpus[idCpu];
164
165 /* Nothing to do if a TLB flush is already pending; the VCPU should have already been poked if it were active */
166 if (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_TLB_FLUSH))
167 continue;
168
169 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
170 if (idThisCpu == idCpu)
171 continue;
172
173 if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
174 {
175 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdownFlush);
176#ifdef IN_RING0
177 RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
178 if (idHostCpu != NIL_RTCPUID)
179 RTMpPokeCpu(idHostCpu);
180#else
181 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
182#endif
183 }
184 else
185 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatFlushTLBManual);
186 }
187 return VINF_SUCCESS;
188}
189#endif
190
191/**
192 * Checks if nested paging is enabled
193 *
194 * @returns boolean
195 * @param pVM The VM to operate on.
196 */
197VMMDECL(bool) HWACCMIsNestedPagingActive(PVM pVM)
198{
199 return HWACCMIsEnabled(pVM) && pVM->hwaccm.s.fNestedPaging;
200}
201
202/**
203 * Return the shadow paging mode for nested paging/ept
204 *
205 * @returns shadow paging mode
206 * @param pVM The VM to operate on.
207 */
208VMMDECL(PGMMODE) HWACCMGetShwPagingMode(PVM pVM)
209{
210 Assert(HWACCMIsNestedPagingActive(pVM));
211 if (pVM->hwaccm.s.svm.fSupported)
212 return PGMMODE_NESTED;
213
214 Assert(pVM->hwaccm.s.vmx.fSupported);
215 return PGMMODE_EPT;
216}
217
218/**
219 * Invalidates a guest page by physical address
220 *
221 * NOTE: Assumes the current instruction references this physical page though a virtual address!!
222 *
223 * @returns VBox status code.
224 * @param pVM The VM to operate on.
225 * @param GCPhys Page to invalidate
226 */
227VMMDECL(int) HWACCMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys)
228{
229 if (!HWACCMIsNestedPagingActive(pVM))
230 return VINF_SUCCESS;
231
232#ifdef IN_RING0
233 if (pVM->hwaccm.s.vmx.fSupported)
234 {
235 VMCPUID idThisCpu = VMMGetCpuId(pVM);
236
237 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
238 {
239 PVMCPU pVCpu = &pVM->aCpus[idCpu];
240
241 if (idThisCpu == idCpu)
242 {
243 VMXR0InvalidatePhysPage(pVM, pVCpu, GCPhys);
244 continue;
245 }
246
247 VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
248 if (VMCPU_GET_STATE(pVCpu) == VMCPUSTATE_STARTED_EXEC)
249 {
250 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTlbShootdownFlush);
251 #ifdef IN_RING0
252 RTCPUID idHostCpu = pVCpu->hwaccm.s.idEnteredCpu;
253 if (idHostCpu != NIL_RTCPUID)
254 RTMpPokeCpu(idHostCpu);
255 #else
256 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_POKE);
257 #endif
258 }
259 else
260 STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatFlushTLBManual);
261 }
262 return VINF_SUCCESS;
263 }
264
265 Assert(pVM->hwaccm.s.svm.fSupported);
266 /* AMD-V doesn't support invalidation with guest physical addresses; see comment in SVMR0InvalidatePhysPage. */
267 HWACCMFlushTLBOnAllVCpus(pVM);
268#else
269 HWACCMFlushTLBOnAllVCpus(pVM);
270#endif
271 return VINF_SUCCESS;
272}
273
274/**
275 * Checks if an interrupt event is currently pending.
276 *
277 * @returns Interrupt event pending state.
278 * @param pVM The VM to operate on.
279 */
280VMMDECL(bool) HWACCMHasPendingIrq(PVM pVM)
281{
282 PVMCPU pVCpu = VMMGetCpu(pVM);
283 return !!pVCpu->hwaccm.s.Event.fPending;
284}
285
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette