]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: Update saved SMM ranges check in SmmProfile
authorJeff Fan <jeff.fan@intel.com>
Tue, 28 Mar 2017 06:01:24 +0000 (14:01 +0800)
committerJeff Fan <jeff.fan@intel.com>
Sat, 1 Apr 2017 03:45:00 +0000 (11:45 +0800)
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>
UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c

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