summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/PiSmmCpuDxeSmm
diff options
context:
space:
mode:
authorDun Tan <dun.tan@intel.com>2023-05-15 18:03:48 +0800
committerRay Ni <ray.ni@intel.com>2023-06-30 11:07:40 +0530
commitb4394cca2dbe41f6adca06d600b330b3a8d7e0fc (patch)
tree2743b2d54125e4f70ed6a9a03586bba3744ec12f /UefiCpuPkg/PiSmmCpuDxeSmm
parent7132df94aca29caf62b88beb049cd9c169c45c09 (diff)
downloadedk2-b4394cca2dbe41f6adca06d600b330b3a8d7e0fc.tar.gz
edk2-b4394cca2dbe41f6adca06d600b330b3a8d7e0fc.tar.bz2
edk2-b4394cca2dbe41f6adca06d600b330b3a8d7e0fc.zip
UefiCpuPkg: Sort mProtectionMemRange when ReadyToLock
Sort mProtectionMemRange in InitProtectedMemRange() when ReadyToLock. Signed-off-by: Dun Tan <dun.tan@intel.com> Cc: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'UefiCpuPkg/PiSmmCpuDxeSmm')
-rw-r--r--UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
index 8736b5251c..eb3876978d 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
@@ -376,6 +376,32 @@ IsAddressSplit (
}
/**
+ Function to compare 2 MEMORY_PROTECTION_RANGE based on range base.
+
+ @param[in] Buffer1 pointer to Device Path poiner to compare
+ @param[in] Buffer2 pointer to second DevicePath pointer to compare
+
+ @retval 0 Buffer1 equal to Buffer2
+ @retval <0 Buffer1 is less than Buffer2
+ @retval >0 Buffer1 is greater than Buffer2
+**/
+INTN
+EFIAPI
+ProtectionRangeCompare (
+ IN CONST VOID *Buffer1,
+ IN CONST VOID *Buffer2
+ )
+{
+ if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base > ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) {
+ return 1;
+ } else if (((MEMORY_PROTECTION_RANGE *)Buffer1)->Range.Base < ((MEMORY_PROTECTION_RANGE *)Buffer2)->Range.Base) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
Initialize the protected memory ranges and the 4KB-page mapped memory ranges.
**/
@@ -397,6 +423,7 @@ InitProtectedMemRange (
EFI_PHYSICAL_ADDRESS Base2MBAlignedAddress;
UINT64 High4KBPageSize;
UINT64 Low4KBPageSize;
+ MEMORY_PROTECTION_RANGE MemProtectionRange;
NumberOfDescriptors = 0;
NumberOfAddedDescriptors = mSmmCpuSmramRangeCount;
@@ -533,6 +560,11 @@ InitProtectedMemRange (
mSplitMemRangeCount = NumberOfSpliteRange;
+ //
+ // Sort the mProtectionMemRange
+ //
+ QuickSort (mProtectionMemRange, mProtectionMemRangeCount, sizeof (MEMORY_PROTECTION_RANGE), (BASE_SORT_COMPARE)ProtectionRangeCompare, &MemProtectionRange);
+
DEBUG ((DEBUG_INFO, "SMM Profile Memory Ranges:\n"));
for (Index = 0; Index < mProtectionMemRangeCount; Index++) {
DEBUG ((DEBUG_INFO, "mProtectionMemRange[%d].Base = %lx\n", Index, mProtectionMemRange[Index].Range.Base));