[edk2-devel] [PATCH 9/9] UefiCpuPkg/MpInitLib: For SEV-ES guest set stack based on processor number

Lendacky, Thomas posted 9 patches 5 years, 3 months ago
There is a newer version of this series
[edk2-devel] [PATCH 9/9] UefiCpuPkg/MpInitLib: For SEV-ES guest set stack based on processor number
Posted by Lendacky, Thomas 5 years, 3 months ago
From: Tom Lendacky <thomas.lendacky@amd.com>

Set the SEV-ES reset stack address for an AP based on the processor number
instead of the APIC ID in case the APIC IDs are not zero-based and densely
packed/enumerated. This will ensure an AP reset stack address does not get
set outside of the AP reset stack memory allocation.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 07426274f639..71922141b70b 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -680,11 +680,16 @@ MpInitLibSevEsAPReset (
   IN CPU_MP_DATA                  *CpuMpData
   )
 {
+  EFI_STATUS       Status;
+  UINTN            ProcessorNumber;
   UINT16           Code16, Code32;
   AP_RESET         *APResetFn;
   UINTN            BufferStart;
   UINTN            StackStart;
 
+  Status = GetProcessorNumber (CpuMpData, &ProcessorNumber);
+  ASSERT_EFI_ERROR (Status);
+
   Code16 = GetProtectedMode16CS ();
   Code32 = GetProtectedMode32CS ();
 
@@ -696,7 +701,7 @@ MpInitLibSevEsAPReset (
 
   BufferStart = CpuMpData->MpCpuExchangeInfo->BufferStart;
   StackStart = CpuMpData->SevEsAPResetStackStart -
-                 (AP_RESET_STACK_SIZE * GetApicId ());
+                 (AP_RESET_STACK_SIZE * ProcessorNumber);
 
   //
   // This call never returns.
-- 
2.28.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#66108): https://edk2.groups.io/g/devel/message/66108
Mute This Topic: https://groups.io/mt/77425927/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH 9/9] UefiCpuPkg/MpInitLib: For SEV-ES guest set stack based on processor number
Posted by Ni, Ray 5 years, 3 months ago
Acked-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Sunday, October 11, 2020 12:07 AM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh <brijesh.singh@amd.com>; Dong, Eric <eric.dong@intel.com>;
> Ni, Ray <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1
> <rahul1.kumar@intel.com>
> Subject: [PATCH 9/9] UefiCpuPkg/MpInitLib: For SEV-ES guest set stack based
> on processor number
> 
> From: Tom Lendacky <thomas.lendacky@amd.com>
> 
> Set the SEV-ES reset stack address for an AP based on the processor number
> instead of the APIC ID in case the APIC IDs are not zero-based and densely
> packed/enumerated. This will ensure an AP reset stack address does not get
> set outside of the AP reset stack memory allocation.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 07426274f639..71922141b70b 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -680,11 +680,16 @@ MpInitLibSevEsAPReset (
>    IN CPU_MP_DATA                  *CpuMpData
>    )
>  {
> +  EFI_STATUS       Status;
> +  UINTN            ProcessorNumber;
>    UINT16           Code16, Code32;
>    AP_RESET         *APResetFn;
>    UINTN            BufferStart;
>    UINTN            StackStart;
> 
> +  Status = GetProcessorNumber (CpuMpData, &ProcessorNumber);
> +  ASSERT_EFI_ERROR (Status);
> +
>    Code16 = GetProtectedMode16CS ();
>    Code32 = GetProtectedMode32CS ();
> 
> @@ -696,7 +701,7 @@ MpInitLibSevEsAPReset (
> 
>    BufferStart = CpuMpData->MpCpuExchangeInfo->BufferStart;
>    StackStart = CpuMpData->SevEsAPResetStackStart -
> -                 (AP_RESET_STACK_SIZE * GetApicId ());
> +                 (AP_RESET_STACK_SIZE * ProcessorNumber);
> 
>    //
>    // This call never returns.
> --
> 2.28.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#66118): https://edk2.groups.io/g/devel/message/66118
Mute This Topic: https://groups.io/mt/77425927/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH 9/9] UefiCpuPkg/MpInitLib: For SEV-ES guest set stack based on processor number
Posted by Laszlo Ersek 5 years, 3 months ago
On 10/10/20 18:07, Tom Lendacky wrote:
> From: Tom Lendacky <thomas.lendacky@amd.com>
> 
> Set the SEV-ES reset stack address for an AP based on the processor number
> instead of the APIC ID in case the APIC IDs are not zero-based and densely
> packed/enumerated. This will ensure an AP reset stack address does not get
> set outside of the AP reset stack memory allocation.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 07426274f639..71922141b70b 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -680,11 +680,16 @@ MpInitLibSevEsAPReset (
>    IN CPU_MP_DATA                  *CpuMpData
>    )
>  {
> +  EFI_STATUS       Status;
> +  UINTN            ProcessorNumber;
>    UINT16           Code16, Code32;
>    AP_RESET         *APResetFn;
>    UINTN            BufferStart;
>    UINTN            StackStart;
>  
> +  Status = GetProcessorNumber (CpuMpData, &ProcessorNumber);
> +  ASSERT_EFI_ERROR (Status);
> +
>    Code16 = GetProtectedMode16CS ();
>    Code32 = GetProtectedMode32CS ();
>  
> @@ -696,7 +701,7 @@ MpInitLibSevEsAPReset (
>  
>    BufferStart = CpuMpData->MpCpuExchangeInfo->BufferStart;
>    StackStart = CpuMpData->SevEsAPResetStackStart -
> -                 (AP_RESET_STACK_SIZE * GetApicId ());
> +                 (AP_RESET_STACK_SIZE * ProcessorNumber);
>  
>    //
>    // This call never returns.
> 

trivial request: please insert a comma in the subject line, after "For
SEV-ES guest". (The new subject length should still be accepted by
"PatchCheck.py".)

Thanks
Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#66248): https://edk2.groups.io/g/devel/message/66248
Mute This Topic: https://groups.io/mt/77425927/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-