public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging
@ 2023-01-04  5:41 Zhiguang Liu
  2023-01-12 12:11 ` [edk2-devel] " Zeng, Star
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Zhiguang Liu @ 2023-01-04  5:41 UTC (permalink / raw)
  To: devel; +Cc: Zhiguang Liu, Ray Ni, Rahul Kumar, Eric Dong

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: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Eric Dong <eric.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
index c1efda7126..c597b39b8c 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
@@ -1,7 +1,7 @@
 /** @file
 Enable SMM profile.
 
-Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2012 - 2023, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -587,15 +587,17 @@ InitPaging (
     }
 
     SizeOfMemorySpace = HighBitSet64 (gPhyMask) + 1;
+    ASSERT (SizeOfMemorySpace <= 52);
+
     //
-    // Calculate the table entries of PML4E and PDPTE.
+    // Calculate the table entries of PML5E, PML4E and PDPTE.
     //
     NumberOfPml5Entries = 1;
-    if (SizeOfMemorySpace > 48) {
+    if (Enable5LevelPaging && (SizeOfMemorySpace > 48)) {
       NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48);
-      SizeOfMemorySpace   = 48;
     }
 
+    SizeOfMemorySpace   = SizeOfMemorySpace > 48 ? 48 : SizeOfMemorySpace;
     NumberOfPml4Entries = 1;
     if (SizeOfMemorySpace > 39) {
       NumberOfPml4Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 39);
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-01-18 15:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-04  5:41 [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging Zhiguang Liu
2023-01-12 12:11 ` [edk2-devel] " Zeng, Star
2023-01-17  8:44   ` Wu, Jiaxin
2023-01-17  9:01 ` Ni, Ray
2023-01-17  9:02 ` Ni, Ray
2023-01-17 12:13   ` Gerd Hoffmann
2023-01-17 12:48     ` [edk2-devel] " Ni, Ray
2023-01-18  1:13       ` Zhiguang Liu
2023-01-18  8:53         ` Gerd Hoffmann
2023-01-18  9:12           ` Zhiguang Liu
2023-01-18 10:10             ` Gerd Hoffmann
2023-01-18 15:27               ` Ni, Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox