UefiCpuPkg/PiSmmCpuDxeSmm: Update saved SMM ranges check in SmmProfile

SmmProfile feature required to protect all SMM ranges by structure
mProtectionMemRangeTemplate. This update is to add additonal save SMM ranges
into mProtectionMemRangeTemplate besides the range specified by
mCpuHotPlugData.SmrrBase/mCpuHotPlugData.SmrrSiz.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Jeff Fan 2017-03-28 14:01:24 +08:00
parent 97f1061e8b
commit ee58438970
1 changed files with 36 additions and 6 deletions

View File

@ -82,6 +82,12 @@ MEMORY_PROTECTION_RANGE mProtectionMemRangeTemplate[] = {
// //
{{0x00000000, 0x00000000},TRUE,TRUE}, {{0x00000000, 0x00000000},TRUE,TRUE},
//
// SMRAM ranges not covered by mCpuHotPlugData.SmrrBase/mCpuHotPlugData.SmrrSiz (to be fixed in runtime).
// It is always present and instruction fetches are allowed.
// {{0x00000000, 0x00000000},TRUE,FALSE},
//
// //
// Future extended range could be added here. // Future extended range could be added here.
// //
@ -360,7 +366,7 @@ InitProtectedMemRange (
{ {
UINTN Index; UINTN Index;
UINTN NumberOfDescriptors; UINTN NumberOfDescriptors;
UINTN NumberOfMmioDescriptors; UINTN NumberOfAddedDescriptors;
UINTN NumberOfProtectRange; UINTN NumberOfProtectRange;
UINTN NumberOfSpliteRange; UINTN NumberOfSpliteRange;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
@ -373,7 +379,7 @@ InitProtectedMemRange (
UINT64 Low4KBPageSize; UINT64 Low4KBPageSize;
NumberOfDescriptors = 0; NumberOfDescriptors = 0;
NumberOfMmioDescriptors = 0; NumberOfAddedDescriptors = mSmmCpuSmramRangeCount;
NumberOfSpliteRange = 0; NumberOfSpliteRange = 0;
MemorySpaceMap = NULL; MemorySpaceMap = NULL;
@ -386,12 +392,12 @@ InitProtectedMemRange (
); );
for (Index = 0; Index < NumberOfDescriptors; Index++) { for (Index = 0; Index < NumberOfDescriptors; Index++) {
if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) { if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
NumberOfMmioDescriptors++; NumberOfAddedDescriptors++;
} }
} }
if (NumberOfMmioDescriptors != 0) { if (NumberOfAddedDescriptors != 0) {
TotalSize = NumberOfMmioDescriptors * sizeof (MEMORY_PROTECTION_RANGE) + sizeof (mProtectionMemRangeTemplate); TotalSize = NumberOfAddedDescriptors * sizeof (MEMORY_PROTECTION_RANGE) + sizeof (mProtectionMemRangeTemplate);
mProtectionMemRange = (MEMORY_PROTECTION_RANGE *) AllocateZeroPool (TotalSize); mProtectionMemRange = (MEMORY_PROTECTION_RANGE *) AllocateZeroPool (TotalSize);
ASSERT (mProtectionMemRange != NULL); ASSERT (mProtectionMemRange != NULL);
mProtectionMemRangeCount = TotalSize / sizeof (MEMORY_PROTECTION_RANGE); mProtectionMemRangeCount = TotalSize / sizeof (MEMORY_PROTECTION_RANGE);
@ -409,9 +415,27 @@ InitProtectedMemRange (
ASSERT (mSplitMemRange != NULL); ASSERT (mSplitMemRange != NULL);
// //
// Create MMIO ranges which are set to present and execution-disable. // Create SMM ranges which are set to present and execution-enable.
// //
NumberOfProtectRange = sizeof (mProtectionMemRangeTemplate) / sizeof (MEMORY_PROTECTION_RANGE); NumberOfProtectRange = sizeof (mProtectionMemRangeTemplate) / sizeof (MEMORY_PROTECTION_RANGE);
for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) {
if (mSmmCpuSmramRanges[Index].CpuStart >= mProtectionMemRange[0].Range.Base &&
mSmmCpuSmramRanges[Index].CpuStart + mSmmCpuSmramRanges[Index].PhysicalSize < mProtectionMemRange[0].Range.Top) {
//
// If the address have been already covered by mCpuHotPlugData.SmrrBase/mCpuHotPlugData.SmrrSiz
//
break;
}
mProtectionMemRange[NumberOfProtectRange].Range.Base = mSmmCpuSmramRanges[Index].CpuStart;
mProtectionMemRange[NumberOfProtectRange].Range.Top = mSmmCpuSmramRanges[Index].CpuStart + mSmmCpuSmramRanges[Index].PhysicalSize;
mProtectionMemRange[NumberOfProtectRange].Present = TRUE;
mProtectionMemRange[NumberOfProtectRange].Nx = FALSE;
NumberOfProtectRange++;
}
//
// Create MMIO ranges which are set to present and execution-disable.
//
for (Index = 0; Index < NumberOfDescriptors; Index++) { for (Index = 0; Index < NumberOfDescriptors; Index++) {
if (MemorySpaceMap[Index].GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) { if (MemorySpaceMap[Index].GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {
continue; continue;
@ -422,6 +446,12 @@ InitProtectedMemRange (
mProtectionMemRange[NumberOfProtectRange].Nx = TRUE; mProtectionMemRange[NumberOfProtectRange].Nx = TRUE;
NumberOfProtectRange++; NumberOfProtectRange++;
} }
//
// Check and updated actual protected memory ranges count
//
ASSERT (NumberOfProtectRange <= mProtectionMemRangeCount);
mProtectionMemRangeCount = NumberOfProtectRange;
} }
// //