public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging
@ 2023-01-18  1:23 Zhiguang Liu
  2023-01-18  9:05 ` Gerd Hoffmann
  0 siblings, 1 reply; 4+ messages in thread
From: Zhiguang Liu @ 2023-01-18  1:23 UTC (permalink / raw)
  To: devel
  Cc: Zhiguang Liu, Gerd Hoffmann, Rahul Kumar, Star Zeng, Wu, Jiaxin,
	Ray Ni, 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: 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>
Signed-off-by: Eric Dong <eric.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 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.<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,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


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

* Re: [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging
  2023-01-18  1:23 [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging Zhiguang Liu
@ 2023-01-18  9:05 ` Gerd Hoffmann
  2023-02-01  5:25   ` Ni, Ray
  0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2023-01-18  9:05 UTC (permalink / raw)
  To: Zhiguang Liu; +Cc: devel, Rahul Kumar, Star Zeng, Wu, Jiaxin, Ray Ni, Eric Dong

On Wed, Jan 18, 2023 at 09:23:48AM +0800, Zhiguang Liu wrote:
> 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.

... if 5-level paging is not used.

Hardware which does not support 5-level paging is limited to 48 anyway.

This still does not explain why this fixes code hangs.

take care,
  Gerd


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

* Re: [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging
  2023-01-18  9:05 ` Gerd Hoffmann
@ 2023-02-01  5:25   ` Ni, Ray
  2023-02-01 13:51     ` Gerd Hoffmann
  0 siblings, 1 reply; 4+ messages in thread
From: Ni, Ray @ 2023-02-01  5:25 UTC (permalink / raw)
  To: Gerd Hoffmann, Liu, Zhiguang
  Cc: devel@edk2.groups.io, Kumar, Rahul R, Zeng, Star,
	Wu@sirius.home.kraxel.org, Wu, Jiaxin, Dong, Eric

Gerd,
I saw Zhiguang and you had some conversation in V1 mail thread.
Was below question answered in that conversation?

Any concern if I merge the patch?

Thanks,
Ray

> -----Original Message-----
> From: Gerd Hoffmann <kraxel@redhat.com>
> Sent: Wednesday, January 18, 2023 5:05 PM
> To: Liu, Zhiguang <zhiguang.liu@intel.com>
> Cc: devel@edk2.groups.io; Kumar, Rahul R <rahul.r.kumar@intel.com>; Zeng,
> Star <star.zeng@intel.com>; Wu@sirius.home.kraxel.org; Wu, Jiaxin
> <jiaxin.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Dong, Eric
> <eric.dong@intel.com>
> Subject: Re: [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging
> 
> On Wed, Jan 18, 2023 at 09:23:48AM +0800, Zhiguang Liu wrote:
> > 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.
> 
> ... if 5-level paging is not used.
> 
> Hardware which does not support 5-level paging is limited to 48 anyway.
> 
> This still does not explain why this fixes code hangs.
> 
> take care,
>   Gerd


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

* Re: [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging
  2023-02-01  5:25   ` Ni, Ray
@ 2023-02-01 13:51     ` Gerd Hoffmann
  0 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2023-02-01 13:51 UTC (permalink / raw)
  To: Ni, Ray
  Cc: Liu, Zhiguang, devel@edk2.groups.io, Kumar, Rahul R, Zeng, Star,
	Wu, Jiaxin, Dong, Eric

On Wed, Feb 01, 2023 at 05:25:18AM +0000, Ni, Ray wrote:
> Gerd,
> I saw Zhiguang and you had some conversation in V1 mail thread.
> Was below question answered in that conversation?

Yes (I missed the little detail the 5-level entry wasn't part of a page
table but just a single entry allocated at the stack, so without the fix
the stack gets corrupted).

> Any concern if I merge the patch?

No, v2 is fine.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

take care,
  Gerd


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

end of thread, other threads:[~2023-02-01 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-18  1:23 [PATCH v2] UefiCpuPkg: Fix SMM code hangs when InitPaging Zhiguang Liu
2023-01-18  9:05 ` Gerd Hoffmann
2023-02-01  5:25   ` Ni, Ray
2023-02-01 13:51     ` Gerd Hoffmann

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