public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] DxeMain: Fix the bug that StackGuard is not enabled
@ 2022-06-13  3:39 Ni, Ray
  2022-06-13  3:39 ` [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs Ni, Ray
  2022-06-13  3:39 ` [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
  0 siblings, 2 replies; 5+ messages in thread
From: Ni, Ray @ 2022-06-13  3:39 UTC (permalink / raw)
  To: devel

Ray Ni (2):
  ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs
  DxeMain: Fix the bug that StackGuard is not enabled

 .../Library/ArmExceptionLib/ArmExceptionLib.c | 58 ++++---------------
 MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c       |  8 +++
 2 files changed, 19 insertions(+), 47 deletions(-)

-- 
2.35.1.windows.2


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

* [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs
  2022-06-13  3:39 [PATCH 0/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
@ 2022-06-13  3:39 ` Ni, Ray
  2022-06-13 11:26   ` Sami Mujawar
  2022-06-13  3:39 ` [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
  1 sibling, 1 reply; 5+ messages in thread
From: Ni, Ray @ 2022-06-13  3:39 UTC (permalink / raw)
  To: devel; +Cc: Leif Lindholm, Ard Biesheuvel, Sami Mujawar

CpuExceptionHandlerLib has been refactored with following changes:
1. Removed InitializeCpuInterruptHandlers in 2a09527ebcb459b40
2. Removed InitializeCpuExceptionHandlersEx and
   added InitializeSeparateExceptionStacks in e7abb94d1fb8a0e7

The patch updates ARM version of CpuExceptionHandlerLib to follow
the API changes.

The functionality to ARM platforms should be none.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
---
 .../Library/ArmExceptionLib/ArmExceptionLib.c | 58 ++++---------------
 1 file changed, 11 insertions(+), 47 deletions(-)

diff --git a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
index 1904816c16..2c7bc66aa7 100644
--- a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
+++ b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
@@ -4,6 +4,7 @@
 *  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 *  Copyright (c) 2011-2021, Arm Limited. All rights reserved.<BR>
 *  Copyright (c) 2016 HP Development Company, L.P.
+*  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -194,32 +195,6 @@ CopyExceptionHandlers (
   return RETURN_SUCCESS;
 }
 
-/**
-Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
-
-Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
-persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
-If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
-If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
-
-@param[in]  VectorInfo    Pointer to reserved vector list.
-
-@retval EFI_SUCCESS           All CPU interrupt/exception entries have been successfully initialized
-with default interrupt/exception handlers.
-@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
-@retval EFI_UNSUPPORTED       This function is not supported.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeCpuInterruptHandlers (
-  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
-  )
-{
-  // not needed, this is what the CPU driver is for
-  return EFI_UNSUPPORTED;
-}
-
 /**
 Registers a function to be called from the processor exception handler. (On ARM/AArch64 this only
 provides exception handlers, not interrupt handling which is provided through the Hardware Interrupt
@@ -229,8 +204,8 @@ This function registers and enables the handler specified by ExceptionHandler fo
 interrupt or exception type specified by ExceptionType. If ExceptionHandler is NULL, then the
 handler for the processor interrupt or exception type specified by ExceptionType is uninstalled.
 The installed handler is called once for each processor interrupt or exception.
-NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
-InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
+NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,
+otherwise EFI_UNSUPPORTED returned.
 
 @param[in]  ExceptionType     Defines which interrupt or exception to hook.
 @param[in]  ExceptionHandler  A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
@@ -312,33 +287,22 @@ CommonCExceptionHandler (
 }
 
 /**
-  Initializes all CPU exceptions entries with optional extra initializations.
-
-  By default, this method should include all functionalities implemented by
-  InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
-  This could be done by calling InitializeCpuExceptionHandlers() directly
-  in this method besides the extra works.
+  Setup separate stacks for certain exception handlers.
 
-  InitData is optional and its use and content are processor arch dependent.
-  The typical usage of it is to convey resources which have to be reserved
-  elsewhere and are necessary for the extra initializations of exception.
+  InitData is optional and processor arch dependent.
 
-  @param[in]  VectorInfo    Pointer to reserved vector list.
-  @param[in]  InitData      Pointer to data optional for extra initializations
-                            of exception.
+  @param[in]  InitData      Pointer to data optional for information about how
+                            to assign stacks for certain exception handlers.
 
-  @retval EFI_SUCCESS             The exceptions have been successfully
-                                  initialized.
-  @retval EFI_INVALID_PARAMETER   VectorInfo or InitData contains invalid
-                                  content.
+  @retval EFI_SUCCESS             The stacks are assigned successfully.
+  @retval EFI_UNSUPPORTED         This function is not supported.
 
 **/
 EFI_STATUS
 EFIAPI
-InitializeCpuExceptionHandlersEx (
-  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL,
+InitializeSeparateExceptionStacks (
   IN CPU_EXCEPTION_INIT_DATA  *InitData OPTIONAL
   )
 {
-  return InitializeCpuExceptionHandlers (VectorInfo);
+  return EFI_SUCCESS;
 }
-- 
2.35.1.windows.2


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

* [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled
  2022-06-13  3:39 [PATCH 0/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
  2022-06-13  3:39 ` [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs Ni, Ray
@ 2022-06-13  3:39 ` Ni, Ray
  2022-06-13 11:28   ` [edk2-devel] " Sami Mujawar
  1 sibling, 1 reply; 5+ messages in thread
From: Ni, Ray @ 2022-06-13  3:39 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Liming Gao

Commit e7abb94d1 removed InitializeCpuExceptionHandlersEx
and updated DxeMain to call InitializeCpuExceptionHandlers
for exception setup. But the old behavior that calls *Ex() sets
up the stack guard as well. To match the old behavior,
the patch calls InitializeSeparateExceptionStacks.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
 MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
index 83f49d7c00..0a1f3d79e2 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
+++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
@@ -256,6 +256,14 @@ DxeMain (
   Status = InitializeCpuExceptionHandlers (VectorInfoList);
   ASSERT_EFI_ERROR (Status);
 
+  //
+  // Setup Stack Guard
+  //
+  if (PcdGetBool (PcdCpuStackGuard)) {
+    Status = InitializeSeparateExceptionStacks (NULL);
+    ASSERT_EFI_ERROR (Status);
+  }
+
   //
   // Initialize Debug Agent to support source level debug in DXE phase
   //
-- 
2.35.1.windows.2


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

* Re: [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs
  2022-06-13  3:39 ` [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs Ni, Ray
@ 2022-06-13 11:26   ` Sami Mujawar
  0 siblings, 0 replies; 5+ messages in thread
From: Sami Mujawar @ 2022-06-13 11:26 UTC (permalink / raw)
  To: Ray Ni, devel; +Cc: Leif Lindholm, Ard Biesheuvel, nd

[-- Attachment #1: Type: text/plain, Size: 6432 bytes --]

Hi Ray,

Thank you for this patch.

I have one minor suggestion marked inline as [SAMI], otherwise this 
patch looks good to me.

With that updated.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

On 13/06/2022 04:39 am, Ray Ni wrote:
> CpuExceptionHandlerLib has been refactored with following changes:
> 1. Removed InitializeCpuInterruptHandlers in 2a09527ebcb459b40
> 2. Removed InitializeCpuExceptionHandlersEx and
>     added InitializeSeparateExceptionStacks in e7abb94d1fb8a0e7
>
> The patch updates ARM version of CpuExceptionHandlerLib to follow
> the API changes.
>
> The functionality to ARM platforms should be none.
>
> Signed-off-by: Ray Ni<ray.ni@intel.com>
> Cc: Leif Lindholm<quic_llindhol@quicinc.com>
> Cc: Ard Biesheuvel<ardb+tianocore@kernel.org>
> Cc: Sami Mujawar<sami.mujawar@arm.com>
> ---
>   .../Library/ArmExceptionLib/ArmExceptionLib.c | 58 ++++---------------
>   1 file changed, 11 insertions(+), 47 deletions(-)
>
> diff --git a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
> index 1904816c16..2c7bc66aa7 100644
> --- a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
> +++ b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
> @@ -4,6 +4,7 @@
>   *  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
>
>   *  Copyright (c) 2011-2021, Arm Limited. All rights reserved.<BR>
>
>   *  Copyright (c) 2016 HP Development Company, L.P.
>
> +*  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
>   *
>
>   *  SPDX-License-Identifier: BSD-2-Clause-Patent
>
>   *
>
> @@ -194,32 +195,6 @@ CopyExceptionHandlers (
>     return RETURN_SUCCESS;
>
>   }
>
>   
>
> -/**
>
> -Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
>
> -
>
> -Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
>
> -persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
>
> -If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
>
> -If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
>
> -
>
> -@param[in]  VectorInfo    Pointer to reserved vector list.
>
> -
>
> -@retval EFI_SUCCESS           All CPU interrupt/exception entries have been successfully initialized
>
> -with default interrupt/exception handlers.
>
> -@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
>
> -@retval EFI_UNSUPPORTED       This function is not supported.
>
> -
>
> -**/
>
> -EFI_STATUS
>
> -EFIAPI
>
> -InitializeCpuInterruptHandlers (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL
>
> -  )
>
> -{
>
> -  // not needed, this is what the CPU driver is for
>
> -  return EFI_UNSUPPORTED;
>
> -}
>
> -
>
>   /**
>
>   Registers a function to be called from the processor exception handler. (On ARM/AArch64 this only
>
>   provides exception handlers, not interrupt handling which is provided through the Hardware Interrupt
>
> @@ -229,8 +204,8 @@ This function registers and enables the handler specified by ExceptionHandler fo
>   interrupt or exception type specified by ExceptionType. If ExceptionHandler is NULL, then the
>
>   handler for the processor interrupt or exception type specified by ExceptionType is uninstalled.
>
>   The installed handler is called once for each processor interrupt or exception.
>
> -NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
>
> -InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
>
> +NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,
>
> +otherwise EFI_UNSUPPORTED returned.
>
>   
>
>   @param[in]  ExceptionType     Defines which interrupt or exception to hook.
>
>   @param[in]  ExceptionHandler  A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
>
> @@ -312,33 +287,22 @@ CommonCExceptionHandler (
>   }
>
>   
>
>   /**
>
> -  Initializes all CPU exceptions entries with optional extra initializations.
>
> -
>
> -  By default, this method should include all functionalities implemented by
>
> -  InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
>
> -  This could be done by calling InitializeCpuExceptionHandlers() directly
>
> -  in this method besides the extra works.
>
> +  Setup separate stacks for certain exception handlers.
>
>   
>
> -  InitData is optional and its use and content are processor arch dependent.
>
> -  The typical usage of it is to convey resources which have to be reserved
>
> -  elsewhere and are necessary for the extra initializations of exception.
>
> +  InitData is optional and processor arch dependent.
>
>   
>
> -  @param[in]  VectorInfo    Pointer to reserved vector list.
>
> -  @param[in]  InitData      Pointer to data optional for extra initializations
>
> -                            of exception.
>
> +  @param[in]  InitData      Pointer to data optional for information about how
>
> +                            to assign stacks for certain exception handlers.
>
>   
>
> -  @retval EFI_SUCCESS             The exceptions have been successfully
>
> -                                  initialized.
>
> -  @retval EFI_INVALID_PARAMETER   VectorInfo or InitData contains invalid
>
> -                                  content.
>
> +  @retval EFI_SUCCESS             The stacks are assigned successfully.
>
> +  @retval EFI_UNSUPPORTED         This function is not supported.
>
>   
>
>   **/
>
>   EFI_STATUS
>
>   EFIAPI
>
> -InitializeCpuExceptionHandlersEx (
>
> -  IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL,
>
> +InitializeSeparateExceptionStacks (
>
>     IN CPU_EXCEPTION_INIT_DATA  *InitData OPTIONAL
>
>     )
>
>   {
>
> -  return InitializeCpuExceptionHandlers (VectorInfo);
>
> +  return EFI_SUCCESS;

[SAMI] I think this function should return EFI_UNSUPPORTED. Doing this 
should not impact the functionality as PcdCpuStackGuard is not enabled 
on Arm.

So, your patch [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not 
enabled 
<https://edk2.groups.io/g/devel/topic/patch_2_2_dxemain_fix_the/91719888?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,91719888,previd%3D1655113540627857877,nextid%3D1655040814392344888&previd=1655113540627857877&nextid=1655040814392344888> 
() does take care of this.

[/SAMI]

>
>   }
>

[-- Attachment #2: Type: text/html, Size: 7179 bytes --]

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

* Re: [edk2-devel] [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled
  2022-06-13  3:39 ` [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
@ 2022-06-13 11:28   ` Sami Mujawar
  0 siblings, 0 replies; 5+ messages in thread
From: Sami Mujawar @ 2022-06-13 11:28 UTC (permalink / raw)
  To: devel, ray.ni; +Cc: Jian J Wang, Liming Gao, Leif Lindholm, Ard Biesheuvel, nd

Hi Ray,

Thank you for this patch.

This change looks good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

On 13/06/2022 04:39 am, Ni, Ray via groups.io wrote:
> Commit e7abb94d1 removed InitializeCpuExceptionHandlersEx
> and updated DxeMain to call InitializeCpuExceptionHandlers
> for exception setup. But the old behavior that calls *Ex() sets
> up the stack guard as well. To match the old behavior,
> the patch calls InitializeSeparateExceptionStacks.
>
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> ---
>   MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
> index 83f49d7c00..0a1f3d79e2 100644
> --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
> +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
> @@ -256,6 +256,14 @@ DxeMain (
>     Status = InitializeCpuExceptionHandlers (VectorInfoList);
>
>     ASSERT_EFI_ERROR (Status);
>
>   
>
> +  //
>
> +  // Setup Stack Guard
>
> +  //
>
> +  if (PcdGetBool (PcdCpuStackGuard)) {
>
> +    Status = InitializeSeparateExceptionStacks (NULL);
>
> +    ASSERT_EFI_ERROR (Status);
>
> +  }
>
> +
>
>     //
>
>     // Initialize Debug Agent to support source level debug in DXE phase
>
>     //
>

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

end of thread, other threads:[~2022-06-13 11:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-13  3:39 [PATCH 0/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
2022-06-13  3:39 ` [PATCH 1/2] ArmPkg/ArmExceptionLib: Follow new CpuExceptionHandlerLib APIs Ni, Ray
2022-06-13 11:26   ` Sami Mujawar
2022-06-13  3:39 ` [PATCH 2/2] DxeMain: Fix the bug that StackGuard is not enabled Ni, Ray
2022-06-13 11:28   ` [edk2-devel] " Sami Mujawar

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