* [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
@ 2024-01-11 2:11 duntan
2024-01-11 3:36 ` Ni, Ray
2024-01-11 8:48 ` Laszlo Ersek
0 siblings, 2 replies; 4+ messages in thread
From: duntan @ 2024-01-11 2:11 UTC (permalink / raw)
To: devel; +Cc: Ray Ni, Laszlo Ersek, Rahul Kumar, Gerd Hoffmann
When creating smm page table, limit maximum
supported physical address bits returned by
CalculateMaximumSupportAddress() to 47 if
5-Level Paging is disabled.
When 5-Level Paging is disabled and the
PhysicalAddressBits retrived from CPU HOB or
CpuId is bigger than 47, and since virtual
addresses are sign-extended, only [0, 2^47-1]
range in 52-bit physical address is mapped
in page table.
Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
index ddd9be66b5..35c282a771 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
@@ -137,11 +137,13 @@ GetSubEntriesNum (
/**
Calculate the maximum support address.
+ @param[in] Is5LevelPagingNeeded If 5-level paging enabling is needed.
+
@return the maximum support address.
**/
UINT8
CalculateMaximumSupportAddress (
- VOID
+ BOOLEAN Is5LevelPagingNeeded
)
{
UINT32 RegEax;
@@ -164,6 +166,15 @@ CalculateMaximumSupportAddress (
}
}
+ //
+ // Only [0, 2^47 -1] in 52-bit physical addresses is mapped in page table
+ // when 5-Level Paging is disabled.
+ //
+ ASSERT (PhysicalAddressBits <= 52);
+ if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 47)) {
+ PhysicalAddressBits = 47;
+ }
+
return PhysicalAddressBits;
}
@@ -197,7 +208,7 @@ SmmInitPageTable (
mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess);
m1GPageTableSupport = Is1GPageSupport ();
m5LevelPagingNeeded = Is5LevelPagingNeeded ();
- mPhysicalAddressBits = CalculateMaximumSupportAddress ();
+ mPhysicalAddressBits = CalculateMaximumSupportAddress (m5LevelPagingNeeded);
PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1);
if (m5LevelPagingNeeded) {
mPagingMode = m1GPageTableSupport ? Paging5Level1GB : Paging5Level;
--
2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113570): https://edk2.groups.io/g/devel/message/113570
Mute This Topic: https://groups.io/mt/103655312/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
2024-01-11 2:11 [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case duntan
@ 2024-01-11 3:36 ` Ni, Ray
2024-01-11 8:48 ` Laszlo Ersek
1 sibling, 0 replies; 4+ messages in thread
From: Ni, Ray @ 2024-01-11 3:36 UTC (permalink / raw)
To: Tan, Dun, devel@edk2.groups.io
Cc: Laszlo Ersek, Kumar, Rahul R, Gerd Hoffmann
Reviewed-by: Ray Ni <ray.ni@intel.com>
Thanks,
Ray
> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Thursday, January 11, 2024 10:11 AM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar,
> Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>
> Subject: [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
>
> When creating smm page table, limit maximum
> supported physical address bits returned by
> CalculateMaximumSupportAddress() to 47 if
> 5-Level Paging is disabled.
> When 5-Level Paging is disabled and the
> PhysicalAddressBits retrived from CPU HOB or
> CpuId is bigger than 47, and since virtual
> addresses are sign-extended, only [0, 2^47-1]
> range in 52-bit physical address is mapped
> in page table.
>
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> index ddd9be66b5..35c282a771 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> @@ -137,11 +137,13 @@ GetSubEntriesNum (
> /**
> Calculate the maximum support address.
>
> + @param[in] Is5LevelPagingNeeded If 5-level paging enabling is
> needed.
> +
> @return the maximum support address.
> **/
> UINT8
> CalculateMaximumSupportAddress (
> - VOID
> + BOOLEAN Is5LevelPagingNeeded
> )
> {
> UINT32 RegEax;
> @@ -164,6 +166,15 @@ CalculateMaximumSupportAddress (
> }
> }
>
> + //
> + // Only [0, 2^47 -1] in 52-bit physical addresses is mapped in page table
> + // when 5-Level Paging is disabled.
> + //
> + ASSERT (PhysicalAddressBits <= 52);
> + if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 47)) {
> + PhysicalAddressBits = 47;
> + }
> +
> return PhysicalAddressBits;
> }
>
> @@ -197,7 +208,7 @@ SmmInitPageTable (
> mCpuSmmRestrictedMemoryAccess = PcdGetBool
> (PcdCpuSmmRestrictedMemoryAccess);
> m1GPageTableSupport = Is1GPageSupport ();
> m5LevelPagingNeeded = Is5LevelPagingNeeded ();
> - mPhysicalAddressBits = CalculateMaximumSupportAddress ();
> + mPhysicalAddressBits = CalculateMaximumSupportAddress
> (m5LevelPagingNeeded);
> PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded,
> 1);
> if (m5LevelPagingNeeded) {
> mPagingMode = m1GPageTableSupport ? Paging5Level1GB :
> Paging5Level;
> --
> 2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113575): https://edk2.groups.io/g/devel/message/113575
Mute This Topic: https://groups.io/mt/103655312/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
2024-01-11 2:11 [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case duntan
2024-01-11 3:36 ` Ni, Ray
@ 2024-01-11 8:48 ` Laszlo Ersek
2024-01-11 8:57 ` duntan
1 sibling, 1 reply; 4+ messages in thread
From: Laszlo Ersek @ 2024-01-11 8:48 UTC (permalink / raw)
To: Dun Tan, devel; +Cc: Ray Ni, Rahul Kumar, Gerd Hoffmann
On 1/11/24 03:11, Dun Tan wrote:
> When creating smm page table, limit maximum
> supported physical address bits returned by
> CalculateMaximumSupportAddress() to 47 if
> 5-Level Paging is disabled.
> When 5-Level Paging is disabled and the
> PhysicalAddressBits retrived from CPU HOB or
> CpuId is bigger than 47, and since virtual
> addresses are sign-extended, only [0, 2^47-1]
> range in 52-bit physical address is mapped
> in page table.
>
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
I'll let Gerd review this (thanks!), I just want to point out a typo in
the subject: "speicial" should be "special".
Thanks
Laszlo
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> index ddd9be66b5..35c282a771 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> @@ -137,11 +137,13 @@ GetSubEntriesNum (
> /**
> Calculate the maximum support address.
>
> + @param[in] Is5LevelPagingNeeded If 5-level paging enabling is needed.
> +
> @return the maximum support address.
> **/
> UINT8
> CalculateMaximumSupportAddress (
> - VOID
> + BOOLEAN Is5LevelPagingNeeded
> )
> {
> UINT32 RegEax;
> @@ -164,6 +166,15 @@ CalculateMaximumSupportAddress (
> }
> }
>
> + //
> + // Only [0, 2^47 -1] in 52-bit physical addresses is mapped in page table
> + // when 5-Level Paging is disabled.
> + //
> + ASSERT (PhysicalAddressBits <= 52);
> + if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 47)) {
> + PhysicalAddressBits = 47;
> + }
> +
> return PhysicalAddressBits;
> }
>
> @@ -197,7 +208,7 @@ SmmInitPageTable (
> mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess);
> m1GPageTableSupport = Is1GPageSupport ();
> m5LevelPagingNeeded = Is5LevelPagingNeeded ();
> - mPhysicalAddressBits = CalculateMaximumSupportAddress ();
> + mPhysicalAddressBits = CalculateMaximumSupportAddress (m5LevelPagingNeeded);
> PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1);
> if (m5LevelPagingNeeded) {
> mPagingMode = m1GPageTableSupport ? Paging5Level1GB : Paging5Level;
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113596): https://edk2.groups.io/g/devel/message/113596
Mute This Topic: https://groups.io/mt/103655312/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
2024-01-11 8:48 ` Laszlo Ersek
@ 2024-01-11 8:57 ` duntan
0 siblings, 0 replies; 4+ messages in thread
From: duntan @ 2024-01-11 8:57 UTC (permalink / raw)
To: Laszlo Ersek, devel@edk2.groups.io; +Cc: Ni, Ray, Kumar, Rahul R, Gerd Hoffmann
Oh, thanks for your comments! Will correct it in next version patch.
Thanks,
Dun
-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com>
Sent: Thursday, January 11, 2024 4:48 PM
To: Tan, Dun <dun.tan@intel.com>; devel@edk2.groups.io
Cc: Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case
On 1/11/24 03:11, Dun Tan wrote:
> When creating smm page table, limit maximum supported physical address
> bits returned by
> CalculateMaximumSupportAddress() to 47 if 5-Level Paging is disabled.
> When 5-Level Paging is disabled and the PhysicalAddressBits retrived
> from CPU HOB or CpuId is bigger than 47, and since virtual addresses
> are sign-extended, only [0, 2^47-1] range in 52-bit physical address
> is mapped in page table.
>
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
I'll let Gerd review this (thanks!), I just want to point out a typo in the subject: "speicial" should be "special".
Thanks
Laszlo
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> index ddd9be66b5..35c282a771 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> @@ -137,11 +137,13 @@ GetSubEntriesNum (
> /**
> Calculate the maximum support address.
>
> + @param[in] Is5LevelPagingNeeded If 5-level paging enabling is needed.
> +
> @return the maximum support address.
> **/
> UINT8
> CalculateMaximumSupportAddress (
> - VOID
> + BOOLEAN Is5LevelPagingNeeded
> )
> {
> UINT32 RegEax;
> @@ -164,6 +166,15 @@ CalculateMaximumSupportAddress (
> }
> }
>
> + //
> + // Only [0, 2^47 -1] in 52-bit physical addresses is mapped in page
> + table // when 5-Level Paging is disabled.
> + //
> + ASSERT (PhysicalAddressBits <= 52); if (!Is5LevelPagingNeeded &&
> + (PhysicalAddressBits > 47)) {
> + PhysicalAddressBits = 47;
> + }
> +
> return PhysicalAddressBits;
> }
>
> @@ -197,7 +208,7 @@ SmmInitPageTable (
> mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess);
> m1GPageTableSupport = Is1GPageSupport ();
> m5LevelPagingNeeded = Is5LevelPagingNeeded ();
> - mPhysicalAddressBits = CalculateMaximumSupportAddress ();
> + mPhysicalAddressBits = CalculateMaximumSupportAddress (m5LevelPagingNeeded);
> PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1);
> if (m5LevelPagingNeeded) {
> mPagingMode = m1GPageTableSupport ? Paging5Level1GB :
> Paging5Level;
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113599): https://edk2.groups.io/g/devel/message/113599
Mute This Topic: https://groups.io/mt/103655312/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-11 8:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-11 2:11 [edk2-devel] [Patch V2] UefiCpuPkg:Limit PhysicalAddressBits in speicial case duntan
2024-01-11 3:36 ` Ni, Ray
2024-01-11 8:48 ` Laszlo Ersek
2024-01-11 8:57 ` duntan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox