Skip to content

Commit 4ae2f33

Browse files
committed
Update comments, cosmetic changes
1 parent 6a5006b commit 4ae2f33

File tree

4 files changed

+40
-35
lines changed

4 files changed

+40
-35
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
root = true
44

55
# All C++ files
6-
[*.{cpp,hpp}]
6+
[*.{cpp,hpp,asm}]
77
charset = utf-8
88
indent_style = space
99
indent_size = 4

SimpleSvmHook/HookCommon.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ OperateOnNestedPageTables (
219219
}
220220
}
221221
pageDirectoryPointerTable = reinterpret_cast<PPDP_ENTRY_4KB>(GetVaFromPfn(
222-
pml4Entry->Fields.PageFrameNumber));
222+
pml4Entry->Fields.PageFrameNumber));
223223

224224
//
225225
// PDPT (1 GB)
@@ -239,7 +239,7 @@ OperateOnNestedPageTables (
239239
}
240240
}
241241
pageDirectoryTable = reinterpret_cast<PPD_ENTRY_4KB>(GetVaFromPfn(
242-
pdptEntry->Fields.PageFrameNumber));
242+
pdptEntry->Fields.PageFrameNumber));
243243

244244
//
245245
// PDT (2 MB)
@@ -259,7 +259,7 @@ OperateOnNestedPageTables (
259259
}
260260
}
261261
pageTable = reinterpret_cast<PPT_ENTRY_4KB>(GetVaFromPfn(
262-
pdtEntry->Fields.PageFrameNumber));
262+
pdtEntry->Fields.PageFrameNumber));
263263

264264
//
265265
// PT (4 KB)
@@ -279,29 +279,34 @@ OperateOnNestedPageTables (
279279
(VOID)BuildNestedPageTableEntry(ptEntry, PhysicalAddress, HookData);
280280

281281
//
282-
// FIXME: Set the correct memory type. Do not make it WB unconditionally.
282+
// We do not explicitly configure PAT in the NPT entry. The consequences
283+
// of this are: 1) pages whose PAT (Page Attribute Table) type is the
284+
// Write-Combining (WC) memory type could be treated as the
285+
// Write-Combining Plus (WC+) while it should be WC when the MTRR type is
286+
// either Write Protect (WP), Writethrough (WT) or Writeback (WB), and
287+
// 2) pages whose PAT type is Uncacheable Minus (UC-) could be treated
288+
// as Cache Disabled (CD) while it should be WC, when MTRR type is WC.
283289
//
284-
// The host PAT type is set to WB because all PAT, PCD, and PWT bits in
285-
// the NPT entries are cleared. See "PAT-Register PA-Field Indexing" for
286-
// this determination.
290+
// While those are not desirable, this is acceptable given that 1) only
291+
// introduces additional cache snooping and associated performance
292+
// penalty, which would not be significant since WC+ still lets
293+
// processors combine multiple writes into one and avoid large
294+
// performance penalty due to frequent writes to memory without caching.
295+
// 2) might be worse but I have not seen MTRR ranges configured as WC
296+
// on testing, hence the unintentional UC- will just results in the same
297+
// effective memory type as what would be with UC.
287298
//
288-
// This introduces the following changes in the combined PAT type when
289-
// the guest PAT type is:
290-
// UC-, it will be UC
291-
// WC, it will be WC+
292-
// See "Combining Guest and Host PAT Types" for this determination.
299+
// See "Memory Types" (7.4), for details of memory types,
300+
// "PAT-Register PA-Field Indexing", "Combining Guest and Host PAT Types",
301+
// and "Combining PAT and MTRR Types" for how the effective memory type
302+
// is determined based on Guest PAT type, Host PAT type, and the MTRR
303+
// type.
293304
//
294-
// This introduces the following changes in the effective PAT type when
295-
// the MTRR type is:
296-
// WC, it will be WC while it could have been CD
297-
// WP,WT,WB, it will be WC+ while it could have been WC
298-
// See "Combining Memory Types, MTRRs" for this determination.
299-
//
300-
// This will be unwanted to change, especially for MMIO regions where the
301-
// guest PAT type can be one of those affected types (UC- or WC). The
302-
// correct fix is probably to look up the guest PTE and copy the caching
303-
// related bits (PAT, PCD, and PWT) when constructing NTP entries, so
304-
// the combined PAT will always be the same as the guest PAT type.
305+
// The correct approach may be to look up the guest PTE and copy the
306+
// caching related bits (PAT, PCD, and PWT) when constructing NTP
307+
// entries for non RAM regions, so the combined PAT will always be the
308+
// same as the guest PAT type. This may be done when any issue manifests
309+
// with the current implementation.
305310
//
306311
}
307312
else

SimpleSvmHook/Virtualization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ VirtualizeProcessor (
758758
locates an offset for IA32_MSR_EFER and sets the MSB bit. For details
759759
of logic, see "MSR Intercepts".
760760
761-
@param[inout] MsrPermissionsMap - The MSRPM to set up.
761+
@param[in,out] MsrPermissionsMap - The MSRPM to set up.
762762
*/
763763
static
764764
VOID

SimpleSvmHook/VmmMain.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/*!
1717
@brief Injects #GP with 0 of error code into the guest.
1818
19-
@param[inout] VpData - The address of per processor data.
19+
@param[in,out] VpData - The address of per processor data.
2020
*/
2121
static
2222
VOID
@@ -52,9 +52,9 @@ InjectGeneralProtectionException (
5252
https://msdn.microsoft.com/en-us/library/windows/hardware/Dn613994(v=vs.85).aspx
5353
for details of the interface.
5454
55-
@param[inout] VpData - The address of per processor data.
55+
@param[in,out] VpData - The address of per processor data.
5656
57-
@param[inout] GuestContext - The address of the guest GPRs.
57+
@param[in,out] GuestContext - The address of the guest GPRs.
5858
*/
5959
static
6060
VOID
@@ -155,9 +155,9 @@ HandleCpuid (
155155
@details This protects EFER.SVME from being cleared by the guest by
156156
injecting #GP when it is about to be cleared.
157157
158-
@param[inout] VpData - The address of per processor data.
158+
@param[in,out] VpData - The address of per processor data.
159159
160-
@param[inout] GuestContext - The address of the guest GPRs.
160+
@param[in,out] GuestContext - The address of the guest GPRs.
161161
*/
162162
static
163163
VOID
@@ -211,9 +211,9 @@ HandleMsrAccess (
211211
212212
@details This function always injects #GP to the guest.
213213
214-
@param[inout] VpData - The address of per processor data.
214+
@param[in,out] VpData - The address of per processor data.
215215
216-
@param[inout] GuestContext - The address of the guest GPRs.
216+
@param[in,out] GuestContext - The address of the guest GPRs.
217217
*/
218218
static
219219
VOID
@@ -242,9 +242,9 @@ HandleVmrun (
242242
this function loads guest state, disables SVM and returns to execution
243243
flow where the #VMEXIT triggered.
244244
245-
@param[inout] VpData - The address of per processor data.
245+
@param[in,out] VpData - The address of per processor data.
246246
247-
@param[inout] GuestRegisters - The address of the guest GPRs.
247+
@param[in,out] GuestRegisters - The address of the guest GPRs.
248248
249249
@return TRUE when virtualization is terminated; otherwise FALSE.
250250
*/
@@ -275,7 +275,7 @@ HandleVmExit (
275275
// Verifier. This protects developers from accidentally writing such #VMEXIT
276276
// handling code. This should actually raise IRQL to HIGH_LEVEL to represent
277277
// this running context better, but our Logger code is not designed to run at
278-
// that level unfortunatelly. Finally, note that this API is a thin wrapper
278+
// that level unfortunately. Finally, note that this API is a thin wrapper
279279
// of mov-to-CR8 on x64 and safe to call on this context.
280280
//
281281
oldIrql = KeGetCurrentIrql();

0 commit comments

Comments
 (0)