From 13b97736c876919b9786055829caaa4fa46984b7 Mon Sep 17 00:00:00 2001 From: Zhiguang Liu Date: Wed, 4 Jan 2023 11:42:43 +0800 Subject: [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging 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 Cc: Rahul Kumar Reviewed-by: Star Zeng Reviewed-by: Wu, Jiaxin Reviewed-by: Ray Ni Acked-by: Gerd Hoffmann Signed-off-by: Eric Dong Signed-off-by: Zhiguang Liu --- UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c index c1efda7126..1b0b6673e1 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.
+Copyright (c) 2012 - 2023, Intel Corporation. All rights reserved.
Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -587,13 +587,18 @@ 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) { - NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48); - SizeOfMemorySpace = 48; + if (Enable5LevelPaging) { + NumberOfPml5Entries = (UINTN)LShiftU64 (1, SizeOfMemorySpace - 48); + } + + SizeOfMemorySpace = 48; } NumberOfPml4Entries = 1; -- 2.39.2