]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
StandaloneMmPkg/MmIpl: Correct unblocked memory regions attribute
authorHongbin1 Zhang <hongbin1.zhang@intel.com>
Thu, 29 Aug 2024 01:52:05 +0000 (09:52 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 11 Sep 2024 08:29:46 +0000 (08:29 +0000)
When CPU smm profile feature was enabled, unblocked memory should
not set logging attribute when building resource HOB.

Signed-off-by: Hongbin1 Zhang <hongbin1.zhang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
StandaloneMmPkg/Drivers/StandaloneMmIplPei/MmFoundationHob.c

index b13d4f688f007eaeac627f0652485a19ecc0b365..a0f8d1f14f7d0031dd6a0a45064f9f4d02a6a605 100644 (file)
@@ -450,6 +450,44 @@ MmIplBuildResourceHobForUnblockedRegion (
   *HobBufferSize = UsedSize;\r
 }\r
 \r
+/**\r
+  Collect unblock memory regions.\r
+\r
+  @param[in, out]  MemoryRegion       Pointer to unblock memory regions.\r
+  @param[in, out]  MemoryRegionCount  Count of unblock memory regions.\r
+**/\r
+VOID\r
+CollectUnblockMemoryRegions (\r
+  IN OUT MM_IPL_MEMORY_REGION  *MemoryRegion,\r
+  IN OUT UINTN                 *MemoryRegionCount\r
+  )\r
+{\r
+  UINTN                   Index;\r
+  EFI_HOB_GENERIC_HEADER  *GuidHob;\r
+  MM_UNBLOCK_REGION       *UnblockRegion;\r
+\r
+  ASSERT (MemoryRegionCount != NULL);\r
+  ASSERT (*MemoryRegionCount == 0 || MemoryRegion != NULL);\r
+\r
+  Index = 0;\r
+  //\r
+  // Collect unblock memory ranges\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gMmUnblockRegionHobGuid);\r
+  while (GuidHob != NULL) {\r
+    if (Index < *MemoryRegionCount) {\r
+      UnblockRegion              = GET_GUID_HOB_DATA (GuidHob);\r
+      MemoryRegion[Index].Base   = UnblockRegion->PhysicalStart;\r
+      MemoryRegion[Index].Length = EFI_PAGES_TO_SIZE (UnblockRegion->NumberOfPages);\r
+    }\r
+\r
+    Index++;\r
+    GuidHob = GetNextGuidHob (&gMmUnblockRegionHobGuid, GET_NEXT_HOB (GuidHob));\r
+  }\r
+\r
+  *MemoryRegionCount = Index;\r
+}\r
+\r
 /**\r
   Create MMIO memory map according to platform HOB.\r
 \r
@@ -564,16 +602,15 @@ MmIplCalculateMaximumSupportAddress (
 \r
 /**\r
   Build resource HOB to cover [0, PhysicalAddressBits length] by excluding\r
-  all Mmram ranges, MM Profile data and MMIO ranges.\r
-\r
-  @param[in]       HobBuffer         The pointer of new HOB buffer.\r
-  @param[in, out]  HobBufferSize     The available size of the HOB buffer when as input.\r
-                                     The used size of when as output.\r
-  @param[in]       PlatformHobList   Platform HOB list.\r
-  @param[in]       PlatformHobSize   Platform HOB size.\r
-  @param[in]       Block             Pointer of MMRAM descriptor block.\r
-  @param[in]       MmProfileDataHob  Pointer to MM profile data HOB.\r
-\r
+  all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges.\r
+\r
+  @param[in]       HobBuffer           The pointer of new HOB buffer.\r
+  @param[in, out]  HobBufferSize       The available size of the HOB buffer when as input.\r
+                                       The used size of when as output.\r
+  @param[in]       PlatformHobList     Platform HOB list.\r
+  @param[in]       PlatformHobSize     Platform HOB size.\r
+  @param[in]       Block               Pointer of MMRAM descriptor block.\r
+  @param[in]       MmProfileDataHob    Pointer to MM profile data HOB.\r
 **/\r
 VOID\r
 MmIplBuildResourceHobForAllSystemMemory (\r
@@ -593,6 +630,7 @@ MmIplBuildResourceHobForAllSystemMemory (
   UINT64                MaxAddress;\r
   MM_IPL_MEMORY_REGION  *MemoryRegions;\r
   MM_IPL_MEMORY_REGION  SortBuffer;\r
+  UINTN                 UnblockRegionCount;\r
 \r
   MaxAddress = LShiftU64 (1, MmIplCalculateMaximumSupportAddress ());\r
 \r
@@ -605,9 +643,16 @@ MmIplBuildResourceHobForAllSystemMemory (
   }\r
 \r
   //\r
-  // Allocate buffer for platform memory regions, MM Profile data, MMRam ranges, an extra terminator.\r
+  // Get the count of platform memory regions\r
+  //\r
+  UnblockRegionCount = 0;\r
+  CollectUnblockMemoryRegions (NULL, &UnblockRegionCount);\r
+\r
+  //\r
+  // Allocate buffer for platform memory regions, unblock memory regions,\r
+  // MM Profile data, MMRam ranges, an extra terminator.\r
   //\r
-  Count         = PlatformRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;\r
+  Count         = PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;\r
   MemoryRegions = AllocatePages (EFI_SIZE_TO_PAGES (Count * sizeof (*MemoryRegions)));\r
   ASSERT (MemoryRegions != NULL);\r
   if (MemoryRegions == NULL) {\r
@@ -629,24 +674,31 @@ MmIplBuildResourceHobForAllSystemMemory (
     CollectPlatformMemoryRegions (PlatformHobList, PlatformHobSize, MemoryRegions, &PlatformRegionCount);\r
   }\r
 \r
+  //\r
+  // Collect unblock memory regions\r
+  //\r
+  if (UnblockRegionCount != 0) {\r
+    CollectUnblockMemoryRegions (&MemoryRegions[PlatformRegionCount], &UnblockRegionCount);\r
+  }\r
+\r
   //\r
   // Collect SMRAM regions\r
   //\r
   for (Index = 0; Index < Block->NumberOfMmReservedRegions; Index++) {\r
-    MemoryRegions[PlatformRegionCount + Index].Base   = Block->Descriptor[Index].CpuStart;\r
-    MemoryRegions[PlatformRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;\r
+    MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Base   = Block->Descriptor[Index].CpuStart;\r
+    MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;\r
   }\r
 \r
   //\r
   // Collect MM profile database region\r
   //\r
   if (MmProfileDataHob != NULL) {\r
-    MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Base   = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;\r
-    MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;\r
+    MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Base   = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;\r
+    MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;\r
   }\r
 \r
   //\r
-  // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database.\r
+  // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database, Unblocked memory regions.\r
   //\r
   QuickSort (MemoryRegions, Count, sizeof (*MemoryRegions), MemoryRegionBaseAddressCompare, &SortBuffer);\r
   UsedSize        = 0;\r
@@ -843,24 +895,32 @@ CreateMmFoundationHobList (
     UsedSize += HobLength;\r
   }\r
 \r
+  //\r
+  // Build resource HOB for unblocked region\r
+  //\r
   HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);\r
-  if (PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {\r
-    //\r
-    // Only unblocked memory regions are accessible\r
-    //\r
-    MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);\r
-  } else {\r
+  MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);\r
+  UsedSize += HobLength;\r
+\r
+  if (!PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {\r
     //\r
     // All system memory (DRAM) is accessible.\r
     // When SMM Profile is enabled:\r
-    //   * Access to regions reported from MmPlatformHobProducerLib do not require logging.\r
+    //   * Access to regions included all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges do not require logging.\r
     //   * Access to other system memory requires logging.\r
     //\r
-    MmIplBuildResourceHobForAllSystemMemory (FoundationHobList + UsedSize, &HobLength, PlatformHobList, PlatformHobSize, Block, MmProfileDataHob);\r
+    HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);\r
+    MmIplBuildResourceHobForAllSystemMemory (\r
+      FoundationHobList + UsedSize,\r
+      &HobLength,\r
+      PlatformHobList,\r
+      PlatformHobSize,\r
+      Block,\r
+      MmProfileDataHob\r
+      );\r
+    UsedSize += HobLength;\r
   }\r
 \r
-  UsedSize += HobLength;\r
-\r
   if (*FoundationHobSize < UsedSize) {\r
     Status = RETURN_BUFFER_TOO_SMALL;\r
   } else {\r