Re: [edk2-devel][PATCH v2 2/2] IntelFsp2Pkg: Update SEC_IDT_TABLE struct

2022-07-12 Thread Chiu, Chasel


Thanks for updating!
Reviewed-by: Chasel Chiu 


> -Original Message-
> From: Kuo, Ted 
> Sent: Tuesday, July 12, 2022 2:31 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel ; Desimone, Nathaniel L
> ; Zeng, Star ; S, Ashraf
> Ali 
> Subject: [edk2-devel][PATCH v2 2/2] IntelFsp2Pkg: Update SEC_IDT_TABLE
> struct
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3957
> The reserved IDT table size in SecCore is too small for X64. Changed the type 
> of
> IdtTable in SEC_IDT_TABLE from UINT64 to IA32_IDT_GATE_DESCRIPTOR to
> have sufficient size reserved in IdtTable for X64.
> 
> Cc: Chasel Chiu 
> Cc: Nate DeSimone 
> Cc: Star Zeng 
> Cc: Ashraf Ali S 
> Signed-off-by: Ted Kuo 
> ---
>  IntelFsp2Pkg/FspSecCore/SecFsp.c  |  9 +
> IntelFsp2Pkg/FspSecCore/SecFsp.h  |  2 +-  IntelFsp2Pkg/FspSecCore/SecMain.c
> | 16   IntelFsp2Pkg/FspSecCore/SecMain.h |  4 ++--
>  4 files changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> index 7fde6e7f41..e9b4091b20 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> @@ -16,19 +16,20 @@
>@return FSP specific IDT gate descriptor.  **/-
> UINT64+IA32_IDT_GATE_DESCRIPTOR FspGetExceptionHandler (   IN  UINT64
> IdtEntryTemplate   ) {   UINT32Entry;-  UINT64
> ExceptionHandler;+  IA32_IDT_GATE_DESCRIPTOR  ExceptionHandler;
> IA32_IDT_GATE_DESCRIPTOR  *IdtGateDescriptor;   FSP_INFO_HEADER
> *FspInfoHeader; +  ZeroMem ((VOID *), sizeof
> (IA32_IDT_GATE_DESCRIPTOR));   FspInfoHeader  =
> (FSP_INFO_HEADER *)(UINTN)AsmGetFspInfoHeader ();-  ExceptionHandler
> = IdtEntryTemplate;-  IdtGateDescriptor  =
> (IA32_IDT_GATE_DESCRIPTOR *)+  *(UINT64
> *)   = IdtEntryTemplate;+  IdtGateDescriptor 
>  =
>Entry  = (IdtGateDescriptor-
> >Bits.OffsetHigh << 16) | IdtGateDescriptor->Bits.OffsetLow;   Entry
> = FspInfoHeader->ImageBase + FspInfoHeader->ImageSize - (~Entry + 1);
> IdtGateDescriptor->Bits.OffsetHigh = (UINT16)(Entry >> 16);diff --git
> a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> index 41931a33dd..e84528b378 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> @@ -30,7 +30,7 @@
>@return FSP specific IDT gate descriptor.  **/-
> UINT64+IA32_IDT_GATE_DESCRIPTOR FspGetExceptionHandler (   IN  UINT64
> IdtEntryTemplate   );diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c
> b/IntelFsp2Pkg/FspSecCore/SecMain.c
> index 8effe2225c..94ea3865b4 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecMain.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c
> @@ -58,13 +58,13 @@ SecStartup (
>IN UINT32  ApiIdx   ) {-  EFI_SEC_PEI_HAND_OFF  SecCoreData;-
> IA32_DESCRIPTOR   IdtDescriptor;-  SEC_IDT_TABLE IdtTableInStack;-
> UINT32Index;-  FSP_GLOBAL_DATA   PeiFspData;-  UINT64
> ExceptionHandler;-  UINTN IdtSize;+  EFI_SEC_PEI_HAND_OFF
> SecCoreData;+  IA32_DESCRIPTOR   IdtDescriptor;+  SEC_IDT_TABLE
> IdtTableInStack;+  UINT32Index;+  FSP_GLOBAL_DATA
> PeiFspData;+  IA32_IDT_GATE_DESCRIPTOR  ExceptionHandler;+  UINTN
> IdtSize;//   // Process all libraries constructor function linked to 
> SecCore.@@ -
> 119,7 +119,7 @@ SecStartup (
>if (IdtDescriptor.Base == 0) { ExceptionHandler = 
> FspGetExceptionHandler
> (mIdtEntryTemplate); for (Index = 0; Index < FixedPcdGet8
> (PcdFspMaxInterruptSupported); Index++) {-  CopyMem ((VOID
> *)[Index], (VOID *), sizeof
> (UINT64));+  CopyMem ((VOID *)[Index], (VOID
> *), sizeof (IA32_IDT_GATE_DESCRIPTOR)); }  IdtSize =
> sizeof (IdtTableInStack.IdtTable);diff --git 
> a/IntelFsp2Pkg/FspSecCore/SecMain.h
> b/IntelFsp2Pkg/FspSecCore/SecMain.h
> index 7c2642ad48..1fe7c15aeb 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecMain.h
> +++ b/IntelFsp2Pkg/FspSecCore/SecMain.h
> @@ -38,8 +38,8 @@ typedef struct _SEC_IDT_TABLE {
>// Note: For IA32, only the 4 bytes immediately preceding IDT is used to 
> store
> // EFI_PEI_SERVICES**   //-  UINT64PeiService;-  UINT64
> IdtTable[FixedPcdGet8 (PcdFspMaxInterruptSupported)];+  UINT64
> PeiService;+  IA32_IDT_GATE_DESCRIPTOR  IdtTable[FixedPcdGet8
> (PcdFspMaxInterruptSupported)]; } SEC_IDT_TABLE;  /**--
> 2.35.3.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#91287): https://edk2.groups.io/g/devel/message/91287
Mute This Topic: https://groups.io/mt/92329473/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel][PATCH v2 2/2] IntelFsp2Pkg: Update SEC_IDT_TABLE struct

2022-07-12 Thread Kuo, Ted
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3957
The reserved IDT table size in SecCore is too small for X64. Changed the type
of IdtTable in SEC_IDT_TABLE from UINT64 to IA32_IDT_GATE_DESCRIPTOR to have
sufficient size reserved in IdtTable for X64.

Cc: Chasel Chiu 
Cc: Nate DeSimone 
Cc: Star Zeng 
Cc: Ashraf Ali S 
Signed-off-by: Ted Kuo 
---
 IntelFsp2Pkg/FspSecCore/SecFsp.c  |  9 +
 IntelFsp2Pkg/FspSecCore/SecFsp.h  |  2 +-
 IntelFsp2Pkg/FspSecCore/SecMain.c | 16 
 IntelFsp2Pkg/FspSecCore/SecMain.h |  4 ++--
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c b/IntelFsp2Pkg/FspSecCore/SecFsp.c
index 7fde6e7f41..e9b4091b20 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
@@ -16,19 +16,20 @@
   @return FSP specific IDT gate descriptor.
 
 **/
-UINT64
+IA32_IDT_GATE_DESCRIPTOR
 FspGetExceptionHandler (
   IN  UINT64  IdtEntryTemplate
   )
 {
   UINT32Entry;
-  UINT64ExceptionHandler;
+  IA32_IDT_GATE_DESCRIPTOR  ExceptionHandler;
   IA32_IDT_GATE_DESCRIPTOR  *IdtGateDescriptor;
   FSP_INFO_HEADER   *FspInfoHeader;
 
+  ZeroMem ((VOID *), sizeof (IA32_IDT_GATE_DESCRIPTOR));
   FspInfoHeader  = (FSP_INFO_HEADER 
*)(UINTN)AsmGetFspInfoHeader ();
-  ExceptionHandler   = IdtEntryTemplate;
-  IdtGateDescriptor  = (IA32_IDT_GATE_DESCRIPTOR 
*)
+  *(UINT64 *)   = IdtEntryTemplate;
+  IdtGateDescriptor  = 
   Entry  = (IdtGateDescriptor->Bits.OffsetHigh << 
16) | IdtGateDescriptor->Bits.OffsetLow;
   Entry  = FspInfoHeader->ImageBase + 
FspInfoHeader->ImageSize - (~Entry + 1);
   IdtGateDescriptor->Bits.OffsetHigh = (UINT16)(Entry >> 16);
diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h
index 41931a33dd..e84528b378 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
@@ -30,7 +30,7 @@
   @return FSP specific IDT gate descriptor.
 
 **/
-UINT64
+IA32_IDT_GATE_DESCRIPTOR
 FspGetExceptionHandler (
   IN  UINT64  IdtEntryTemplate
   );
diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c 
b/IntelFsp2Pkg/FspSecCore/SecMain.c
index 8effe2225c..94ea3865b4 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.c
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.c
@@ -58,13 +58,13 @@ SecStartup (
   IN UINT32  ApiIdx
   )
 {
-  EFI_SEC_PEI_HAND_OFF  SecCoreData;
-  IA32_DESCRIPTOR   IdtDescriptor;
-  SEC_IDT_TABLE IdtTableInStack;
-  UINT32Index;
-  FSP_GLOBAL_DATA   PeiFspData;
-  UINT64ExceptionHandler;
-  UINTN IdtSize;
+  EFI_SEC_PEI_HAND_OFF  SecCoreData;
+  IA32_DESCRIPTOR   IdtDescriptor;
+  SEC_IDT_TABLE IdtTableInStack;
+  UINT32Index;
+  FSP_GLOBAL_DATA   PeiFspData;
+  IA32_IDT_GATE_DESCRIPTOR  ExceptionHandler;
+  UINTN IdtSize;
 
   //
   // Process all libraries constructor function linked to SecCore.
@@ -119,7 +119,7 @@ SecStartup (
   if (IdtDescriptor.Base == 0) {
 ExceptionHandler = FspGetExceptionHandler (mIdtEntryTemplate);
 for (Index = 0; Index < FixedPcdGet8 (PcdFspMaxInterruptSupported); 
Index++) {
-  CopyMem ((VOID *)[Index], (VOID 
*), sizeof (UINT64));
+  CopyMem ((VOID *)[Index], (VOID 
*), sizeof (IA32_IDT_GATE_DESCRIPTOR));
 }
 
 IdtSize = sizeof (IdtTableInStack.IdtTable);
diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.h 
b/IntelFsp2Pkg/FspSecCore/SecMain.h
index 7c2642ad48..1fe7c15aeb 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.h
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.h
@@ -38,8 +38,8 @@ typedef struct _SEC_IDT_TABLE {
   // Note: For IA32, only the 4 bytes immediately preceding IDT is used to 
store
   // EFI_PEI_SERVICES**
   //
-  UINT64PeiService;
-  UINT64IdtTable[FixedPcdGet8 (PcdFspMaxInterruptSupported)];
+  UINT64PeiService;
+  IA32_IDT_GATE_DESCRIPTOR  IdtTable[FixedPcdGet8 
(PcdFspMaxInterruptSupported)];
 } SEC_IDT_TABLE;
 
 /**
-- 
2.35.3.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#91235): https://edk2.groups.io/g/devel/message/91235
Mute This Topic: https://groups.io/mt/92329473/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-