]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg: Fix SMM code hangs when InitPaging
authorZhiguang Liu <zhiguang.liu@intel.com>
Wed, 4 Jan 2023 03:42:43 +0000 (11:42 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 3 Feb 2023 08:24:55 +0000 (08:24 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4246

In function InitPaging, NumberOfPml5Entries is calculated by below code
NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48);
If the SizeOfMemorySpace is larger than 48, NumberOfPml5Entries will be
larger than 1. However, this doesn't make sense if the hardware doesn't
support 5 level page table.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Wu, Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Eric Dong <eric.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c

index c1efda7126054686df242199a45b6aafac65db20..1b0b6673e181ab4e663021e9c6c62340326d0760 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Enable SMM profile.\r
 \r
-Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2023, Intel Corporation. All rights reserved.<BR>\r
 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>\r
 \r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
@@ -587,13 +587,18 @@ InitPaging (
     }\r
 \r
     SizeOfMemorySpace = HighBitSet64 (gPhyMask) + 1;\r
+    ASSERT (SizeOfMemorySpace <= 52);\r
+\r
     //\r
-    // Calculate the table entries of PML4E and PDPTE.\r
+    // Calculate the table entries of PML5E, PML4E and PDPTE.\r
     //\r
     NumberOfPml5Entries = 1;\r
     if (SizeOfMemorySpace > 48) {\r
-      NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48);\r
-      SizeOfMemorySpace   = 48;\r
+      if (Enable5LevelPaging) {\r
+        NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48);\r
+      }\r
+\r
+      SizeOfMemorySpace = 48;\r
     }\r
 \r
     NumberOfPml4Entries = 1;\r