From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.5094.1674005045441451725 for ; Tue, 17 Jan 2023 17:24:05 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CX/+Ei1E; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: zhiguang.liu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674005045; x=1705541045; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pHF7sTiLbaJeMc3BTz1Cnke5IORWY9nwYfibtRQLoxM=; b=CX/+Ei1EYN7iTjXYuZinySRFhfA9AGOnt8af2tnQIP3jlHF0+nS7k1DY EJJ3EQcksnQcSzeeheGOBsMqsCXGT+dLkBFp6o1IxoJjyqQqOQj0ahJHP 8/zSiOnFVUpmOktlVTsbzZilEeY5oTkGKvoDIibuw+0JQyAI7kJ/HJCC6 h9wt/dv5zgBE1gRmMSdtEh4NgAiB2U/jFqQLjSKRe939YK1pIqX5rcGe3 Kx46kSCpvD81Jv4yT3zLwlMrJ33uwPvP2OIdRE/FpFalQSnbtQSON/WCd GQoyzUDxK1sn7Rw2wZ4uUQH7a2bletQjaqJYOxjx4zZZ8ItS8WV3Lgnzf A==; X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="326143333" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="326143333" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 17:24:04 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="748253143" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="748253143" Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 17:24:02 -0800 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Gerd Hoffmann , Rahul Kumar , Star Zeng , Wu, Jiaxin , Ray Ni , Eric Dong Subject: [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging Date: Wed, 18 Jan 2023 09:23:48 +0800 Message-Id: <20230118012348.1195-1-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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.31.1.windows.1