VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/REMAll.cpp@ 80268

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

VMM: Refactoring VMMAll/* to use VMCC & VMMCPUCC. bugref:9217

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.4 KB
 
1/* $Id: REMAll.cpp 80268 2019-08-14 11:25:13Z vboxsync $ */
2/** @file
3 * REM - Recompiled Execution Monitor, all Contexts part.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define VBOX_BUGREF_9217_PART_I
23#define LOG_GROUP LOG_GROUP_REM
24#ifdef VBOX_WITH_REM
25# include <VBox/vmm/rem.h>
26#endif
27#include <VBox/vmm/em.h>
28#include <VBox/vmm/vmm.h>
29#include "REMInternal.h"
30#include <VBox/vmm/vmcc.h>
31#include <iprt/errcore.h>
32#include <VBox/log.h>
33
34#include <iprt/asm.h>
35#include <iprt/assert.h>
36
37
38#ifndef IN_RING3
39
40/**
41 * Records a invlpg instruction for replaying upon REM entry.
42 *
43 * @param pVM The cross context VM structure.
44 * @param GCPtrPage The
45 */
46VMMDECL(void) REMNotifyInvalidatePage(PVM pVM, RTGCPTR GCPtrPage)
47{
48 /*
49 * Try take the REM lock and push the address onto the array.
50 */
51 if ( pVM->rem.s.cInvalidatedPages < RT_ELEMENTS(pVM->rem.s.aGCPtrInvalidatedPages)
52 && EMRemTryLock(pVM) == VINF_SUCCESS)
53 {
54 uint32_t iPage = pVM->rem.s.cInvalidatedPages;
55 if (iPage < RT_ELEMENTS(pVM->rem.s.aGCPtrInvalidatedPages))
56 {
57 ASMAtomicWriteU32(&pVM->rem.s.cInvalidatedPages, iPage + 1);
58 pVM->rem.s.aGCPtrInvalidatedPages[iPage] = GCPtrPage;
59
60 EMRemUnlock(pVM);
61 return;
62 }
63
64 CPUMSetChangedFlags(VMMGetCpu(pVM), CPUM_CHANGED_GLOBAL_TLB_FLUSH); /** @todo this array should be per-cpu technically speaking. */
65 ASMAtomicWriteU32(&pVM->rem.s.cInvalidatedPages, 0); /** @todo leave this alone? Optimize this code? */
66
67 EMRemUnlock(pVM);
68 }
69 else
70 {
71 /* Fallback: Simply tell the recompiler to flush its TLB. */
72 CPUMSetChangedFlags(VMMGetCpu(pVM), CPUM_CHANGED_GLOBAL_TLB_FLUSH);
73 ASMAtomicWriteU32(&pVM->rem.s.cInvalidatedPages, 0); /** @todo leave this alone?! Optimize this code? */
74 }
75
76 return;
77}
78
79
80/**
81 * Insert pending notification
82 *
83 * @param pVM The cross context VM structure.
84 * @param pRec Notification record to insert
85 */
86static void remNotifyHandlerInsert(PVM pVM, PREMHANDLERNOTIFICATION pRec)
87{
88 /*
89 * Fetch a free record.
90 */
91 uint32_t cFlushes = 0;
92 uint32_t idxFree;
93 PREMHANDLERNOTIFICATION pFree;
94 do
95 {
96 idxFree = ASMAtomicUoReadU32(&pVM->rem.s.idxFreeList);
97 if (idxFree == UINT32_MAX)
98 {
99 do
100 {
101 cFlushes++;
102 Assert(cFlushes != 128);
103 AssertFatal(cFlushes < _1M);
104 VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS, 0);
105 idxFree = ASMAtomicUoReadU32(&pVM->rem.s.idxFreeList);
106 } while (idxFree == UINT32_MAX);
107 }
108 pFree = &pVM->rem.s.aHandlerNotifications[idxFree];
109 } while (!ASMAtomicCmpXchgU32(&pVM->rem.s.idxFreeList, pFree->idxNext, idxFree));
110
111 /*
112 * Copy the record.
113 */
114 pFree->enmKind = pRec->enmKind;
115 pFree->u = pRec->u;
116
117 /*
118 * Insert it into the pending list.
119 */
120 uint32_t idxNext;
121 do
122 {
123 idxNext = ASMAtomicUoReadU32(&pVM->rem.s.idxPendingList);
124 ASMAtomicWriteU32(&pFree->idxNext, idxNext);
125 ASMCompilerBarrier();
126 } while (!ASMAtomicCmpXchgU32(&pVM->rem.s.idxPendingList, idxFree, idxNext));
127
128 VM_FF_SET(pVM, VM_FF_REM_HANDLER_NOTIFY);
129}
130
131
132/**
133 * Notification about a successful PGMR3HandlerPhysicalRegister() call.
134 *
135 * @param pVM The cross context VM structure.
136 * @param enmKind Kind of access handler.
137 * @param GCPhys Handler range address.
138 * @param cb Size of the handler range.
139 * @param fHasHCHandler Set if the handler have a HC callback function.
140 */
141VMMDECL(void) REMNotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler)
142{
143 REMHANDLERNOTIFICATION Rec;
144 Rec.enmKind = REMHANDLERNOTIFICATIONKIND_PHYSICAL_REGISTER;
145 Rec.u.PhysicalRegister.enmKind = enmKind;
146 Rec.u.PhysicalRegister.GCPhys = GCPhys;
147 Rec.u.PhysicalRegister.cb = cb;
148 Rec.u.PhysicalRegister.fHasHCHandler = fHasHCHandler;
149 remNotifyHandlerInsert(pVM, &Rec);
150}
151
152
153/**
154 * Notification about a successful PGMR3HandlerPhysicalDeregister() operation.
155 *
156 * @param pVM The cross context VM structure.
157 * @param enmKind Kind of access handler.
158 * @param GCPhys Handler range address.
159 * @param cb Size of the handler range.
160 * @param fHasHCHandler Set if the handler have a HC callback function.
161 * @param fRestoreAsRAM Whether the to restore it as normal RAM or as unassigned memory.
162 */
163VMMDECL(void) REMNotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler, bool fRestoreAsRAM)
164{
165 REMHANDLERNOTIFICATION Rec;
166 Rec.enmKind = REMHANDLERNOTIFICATIONKIND_PHYSICAL_DEREGISTER;
167 Rec.u.PhysicalDeregister.enmKind = enmKind;
168 Rec.u.PhysicalDeregister.GCPhys = GCPhys;
169 Rec.u.PhysicalDeregister.cb = cb;
170 Rec.u.PhysicalDeregister.fHasHCHandler = fHasHCHandler;
171 Rec.u.PhysicalDeregister.fRestoreAsRAM = fRestoreAsRAM;
172 remNotifyHandlerInsert(pVM, &Rec);
173}
174
175
176/**
177 * Notification about a successful PGMR3HandlerPhysicalModify() call.
178 *
179 * @param pVM The cross context VM structure.
180 * @param enmKind Kind of access handler.
181 * @param GCPhysOld Old handler range address.
182 * @param GCPhysNew New handler range address.
183 * @param cb Size of the handler range.
184 * @param fHasHCHandler Set if the handler have a HC callback function.
185 * @param fRestoreAsRAM Whether the to restore it as normal RAM or as unassigned memory.
186 */
187VMMDECL(void) REMNotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fHasHCHandler, bool fRestoreAsRAM)
188{
189 REMHANDLERNOTIFICATION Rec;
190 Rec.enmKind = REMHANDLERNOTIFICATIONKIND_PHYSICAL_MODIFY;
191 Rec.u.PhysicalModify.enmKind = enmKind;
192 Rec.u.PhysicalModify.GCPhysOld = GCPhysOld;
193 Rec.u.PhysicalModify.GCPhysNew = GCPhysNew;
194 Rec.u.PhysicalModify.cb = cb;
195 Rec.u.PhysicalModify.fHasHCHandler = fHasHCHandler;
196 Rec.u.PhysicalModify.fRestoreAsRAM = fRestoreAsRAM;
197 remNotifyHandlerInsert(pVM, &Rec);
198}
199
200#endif /* !IN_RING3 */
201
202
203/**
204 * Make REM flush all translation block upon the next call to REMR3State().
205 *
206 * @param pVM The cross context VM structure.
207 */
208VMMDECL(void) REMFlushTBs(PVM pVM)
209{
210 LogFlow(("REMFlushTBs: fFlushTBs=%RTbool fInREM=%RTbool fInStateSync=%RTbool\n",
211 pVM->rem.s.fFlushTBs, pVM->rem.s.fInREM, pVM->rem.s.fInStateSync));
212 pVM->rem.s.fFlushTBs = true;
213}
214
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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