Re: [edk2-devel] [PATCH v4] UefiCpuPkg/PiSmmCpuDxeSmm: Fix CP Exception when CET enable

2023-11-08 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Wu, Jiaxin  
Sent: Tuesday, November 7, 2023 9:25 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Zeng, Star 
; Gerd Hoffmann ; Kumar, Rahul R 
; Laszlo Ersek 
Subject: [PATCH v4] UefiCpuPkg/PiSmmCpuDxeSmm: Fix CP Exception when CET enable

Root cause:
1. Before DisableReadonlyPageWriteProtect() is called, the return address (#1) 
is pushed in shadow stack.
2. CET is disabled.
3. DisableReadonlyPageWriteProtect() returns to #1.
4. Page table is modified.
5. EnableReadonlyPageWriteProtect() is called, but the return address (#2) is 
not pushed in shadow stack.
6. CET is enabled.
7. EnableReadonlyPageWriteProtect() returns to #2.
#CP exception happens because the actual return address (#2) doesn't match the 
return address stored in shadow stack (#1).

Analysis:
Shadow stack will stop update after CET disable (DisableCet() in 
DisableReadOnlyPageWriteProtect), but normal smi stack will be continue updated 
with the function called and return (DisableReadOnlyPageWriteProtect & 
EnableReadOnlyPageWriteProtect), thus leading stack mismatch after CET 
re-enabled (EnableCet() in EnableReadOnlyPageWriteProtect).

According SDM Vol 3, 6.15-Control Protection Exception:
Normal smi stack and shadow stack must be matched when CET enable, otherwise CP 
Exception will happen, which is caused by a near RET instruction.

CET is disabled in DisableCet(), while can be enabled in EnableCet(). This way 
won't cause the problem because they are implemented in a way that return 
address of DisableCet() is poped out from shadow stack (Incsspq performs a pop 
to increases the shadow stack) and EnableCet() doesn't use "RET" but "JMP" to 
return to caller. So calling EnableCet() and DisableCet() doesn't have the same 
issue as calling DisableReadonlyPageWriteProtect() and 
EnableReadonlyPageWriteProtect().

With above root cause & analysis, define below 2 macros instead of functions 
for WP & CET operation:
WRITE_UNPROTECT_RO_PAGES (Wp, Cet)
WRITE_PROTECT_RO_PAGES (Wp, Cet)
Because DisableCet() & EnableCet() must be in the same function to avoid shadow 
stack and normal SMI stack mismatch.

Note: WRITE_UNPROTECT_RO_PAGES () must be called pair with 
WRITE_PROTECT_RO_PAGES () in same function.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Zeng Star 
Cc: Gerd Hoffmann 
Cc: Rahul Kumar 
Cc: Laszlo Ersek 
Signed-off-by: Jiaxin Wu 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 59 +
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 73 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c |  7 ++-
 3 files changed, 81 insertions(+), 58 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h 
b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
index 654935dc76..20ada465c2 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
@@ -1551,29 +1551,64 @@ VOID
 SmmWaitForApArrival (
   VOID
   );
 
 /**
-  Disable Write Protect on pages marked as read-only if Cr0.Bits.WP is 1.
+  Write unprotect read-only pages if Cr0.Bits.WP is 1.
+
+  @param[out]  WriteProtect  If Cr0.Bits.WP is enabled.
 
-  @param[out]  WpEnabled  If Cr0.WP is enabled.
-  @param[out]  CetEnabled If CET is enabled.
 **/
 VOID
-DisableReadOnlyPageWriteProtect (
-  OUT BOOLEAN  *WpEnabled,
-  OUT BOOLEAN  *CetEnabled
+SmmWriteUnprotectReadOnlyPage (
+  OUT BOOLEAN  *WriteProtect
   );
 
 /**
-  Enable Write Protect on pages marked as read-only.
+  Write protect read-only pages.
+
+  @param[in]  WriteProtect  If Cr0.Bits.WP should be enabled.
 
-  @param[out]  WpEnabled  If Cr0.WP should be enabled.
-  @param[out]  CetEnabled If CET should be enabled.
 **/
 VOID
-EnableReadOnlyPageWriteProtect (
-  BOOLEAN  WpEnabled,
-  BOOLEAN  CetEnabled
+SmmWriteProtectReadOnlyPage (
+  IN  BOOLEAN  WriteProtect
   );
 
+///
+/// Define macros to encapsulate the write unprotect/protect /// 
+read-only pages.
+/// Below pieces of logic are defined as macros and not functions /// 
+because "CET" feature disable & enable must be in the same /// function 
+to avoid shadow stack and normal SMI stack mismatch, /// thus 
+WRITE_UNPROTECT_RO_PAGES () must be called pair with /// 
+WRITE_PROTECT_RO_PAGES () in same function.
+///
+/// @param[in,out] Wp   A BOOLEAN variable local to the containing
+/// function, carrying write protection status from
+/// WRITE_UNPROTECT_RO_PAGES() to
+/// WRITE_PROTECT_RO_PAGES().
+///
+/// @param[in,out] Cet  A BOOLEAN variable local to the containing
+/// function, carrying control flow integrity
+/// enforcement status from
+/// WRITE_UNPROTECT_RO_PAGES() to
+/// WRITE_PROTECT_RO_PAGES().
+///
+#define WRITE_UNPROTECT_RO_PAGES(Wp, Cet) \
+  do { \
+Cet = ((AsmReadCr4 () & CR4_CE

Re: [edk2-devel] [PATCH] UefiCpuPkg: Correct file description for MpHandOff header file

2023-10-30 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Xie, Yuanhao  
Sent: Saturday, October 7, 2023 2:32 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul R ; 
Tom Lendacky ; Xie, Yuanhao 
Subject: [PATCH] UefiCpuPkg: Correct file description for MpHandOff header file

Cc: Eric Dong 
Cc: Rahul Kumar 
Cc: Tom Lendacky 
Signed-off-by: Yuanhao Xie 
---
 UefiCpuPkg/Library/MpInitLib/MpHandOff.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpHandOff.h 
b/UefiCpuPkg/Library/MpInitLib/MpHandOff.h
index 83e4055ec9..77854d6a81 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpHandOff.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpHandOff.h
@@ -1,6 +1,9 @@
 /** @file
-  Defines the HOB GUID used to describe the MSEG memory region allocated in 
PEI.
+  Defines the HOB GUID, which is utilized for transferring essential  
+ information from the PEI to the DXE phase.
+
   Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.
+
   SPDX-License-Identifier: BSD-2-Clause-Patent  **/
 
--
2.36.1.windows.1



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




Re: [edk2-devel] [PATCH] Remove memory cache setting for memory under 1MB

2023-10-24 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Xie, Yuanhao  
Sent: Thursday, October 19, 2023 11:20 AM
To: devel@edk2.groups.io
Cc: Chiu, Chasel ; Desimone, Nathaniel L 
; Isaac Oram ; Gao, 
Liming ; Dong, Eric ; Xie, 
Yuanhao 
Subject: [PATCH] Remove memory cache setting for memory under 1MB

With the fact that CSM is not supported, the request is to remove the cache 
setting for memory under 1MB.
This can be treated as the missing part of legacy CSM deprecation.

This patch only set the 0 to 9 and C to F as Write Back.
A-B range is still uncacheable for VGA.

Cc: Chasel Chiu 
Cc: Nate DeSimone 
Cc: Isaac Oram 
Cc: Liming Gao 
Cc: Eric Dong 
Signed-off-by: Yuanhao Xie 
---
 Platform/Intel/MinPlatformPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/Platform/Intel/MinPlatformPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c 
b/Platform/Intel/MinPlatformPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c
index 05728275a5..38a8db6b3f 100644
--- a/Platform/Intel/MinPlatformPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c
+++ b/Platform/Intel/MinPlatformPkg/Library/SetCacheMtrrLib/SetCacheMtrr
+++ Lib.c
@@ -245,7 +245,7 @@ SetCacheMtrrAfterEndOfPei (
  ,
  0xC,
  0x4,
- CacheWriteProtected
+ CacheWriteBack
  );
   ASSERT_EFI_ERROR ( Status);
 
--
2.36.1.windows.1



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




Re: [edk2-devel] [PATCH 00/16] MtrrLib modules and Unit test Enhancement

2023-10-09 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Yuanhao Xie
Sent: Wednesday, September 13, 2023 12:26 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH 00/16] MtrrLib modules and Unit test Enhancement

Update MtrrLib modules to handle the absense of Fixed MTRRs Update unit test of 
Update for the absense of Fixed MTRRs

Ray Ni (6):
  UefiCpuPkg/MtrrLib: Add internal function MtrrLibIsMtrrSupported.
  UefiCpuPkg/MtrrUnitTest: Update test to cover no-fixed-mtrr cases.
  UefiCpuPkg/MtrrLib: Fix MtrrGetAllMtrrs to return correct MTRR
setting.
  UefiCpuPkg/MtrrLib: Fix MtrrSetAllMtrrs to handle absent fixed MTRRs.
  UefiCpuPkg/MtrrLib: Update APIs related to set memory attributes.
  UefiCpuPkg/CpuDxe: Update RefreshMemoryAttributesFromMtrr.

YuanhaoXie (10):
  UefiCpuPkg/MtrrUnitTest: Update the Unit Test for IsMtrrSupported().
  UefiCpuPkg/MtrrUnitTest: Update UnitTestGetFirmwareVariableMtrrCount.
  UefiCpuPkg/MtrrUnitTest: Update UnitTestMtrrGetDefaultMemoryType.
  UefiCpuPkg/MtrrUnitTest: Update UnitTestMtrrGetAllMtrrs().
  UefiCpuPkg/MtrrLib: Update MtrrGetFixedMtrr().
  UefiCpuPkg/MtrrUnitTest: Update UnitTestMtrrGetFixedMtrr().
  UefiCpuPkg/MtrrUnitTest: Update UnitTestMtrrSetAllMtrrs().
  UefiCpuPkg/MtrrLib: Add API MtrrGetMemoryAttributesInMtrrSettings.
  UefiCpuPkg/MtrrLib: Improve MtrrDebugPrintAllMtrrsWorker.
  UefiCpuPkg/MtrrUnitTest: Add Unit test of setting/getting memory
attributes

 UefiCpuPkg/CpuDxe/CpuDxe.c| 309 
-
 UefiCpuPkg/Include/Library/MtrrLib.h  |  32 
+---
 UefiCpuPkg/Library/MtrrLib/MtrrLib.c  | 391 
++-
 UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c | 244 
++--
 UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c |  24 
+++-
 5 files changed, 532 insertions(+), 468 deletions(-)

--
2.36.1.windows.1








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




Re: [edk2-devel] [PATCH v2] MdeModulePkg/SetupBrowser: Load storage via GetVariable for EfiVarStore

2023-07-30 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Bi, Dandan  
Sent: Monday, July 31, 2023 8:46 AM
To: devel@edk2.groups.io
Cc: Gao, Liming ; Dong, Eric 
Subject: [PATCH v2] MdeModulePkg/SetupBrowser: Load storage via GetVariable for 
EfiVarStore

For EfiVarStore (EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER), it will call 
ExtractConfig-GetVariable-HiiBlockToConfig-ConfigToBlock when load storage 
value in LoadStorage function. It's not necessary and costs lots of time to do 
the conversion between config and block.
So now enhance it to call GetVariable directly.

Cc: Liming Gao 
Cc: Eric Dong 
Signed-off-by: Dandan Bi 
---
v2: Fix coding style issue.

 .../Universal/SetupBrowserDxe/Setup.c | 54 +++
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c 
b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
index 5158baf5bd..2f7b11b1aa 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
@@ -5634,32 +5634,42 @@ LoadStorage (
 ConfigRequest = Storage->ConfigRequest;
   }
 
-  //
-  // Request current settings from Configuration Driver
-  //
-  Status = mHiiConfigRouting->ExtractConfig (
-mHiiConfigRouting,
-ConfigRequest,
-,
-
-);
-
-  //
-  // If get value fail, extract default from IFR binary
-  //
-  if (EFI_ERROR (Status)) {
-ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, 
FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, TRUE);
-  } else {
+  if (Storage->BrowserStorage->Type == 
+ EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {
 //
-// Convert Result from  to 
+// Call GetVariable directly for EfiVarStore
 //
-StrPtr = StrStr (Result, L"=");
-if (StrPtr != NULL) {
-  *StrPtr = L'\0';
+Status = gRT->GetVariable (Storage->BrowserStorage->Name, 
&(Storage->BrowserStorage->Guid), NULL, (UINTN 
*)(&(Storage->BrowserStorage->Size)), Storage->BrowserStorage->EditBuffer);
+if (EFI_ERROR (Status)) {
+  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, 
+ FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, 
+ TRUE);
 }
+  } else {
+//
+// Request current settings from Configuration Driver
+//
+Status = mHiiConfigRouting->ExtractConfig (
+  mHiiConfigRouting,
+  ConfigRequest,
+  ,
+  
+  );
 
-Status = ConfigRespToStorage (Storage->BrowserStorage, Result);
-FreePool (Result);
+//
+// If get value fail, extract default from IFR binary
+//
+if (EFI_ERROR (Status)) {
+  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, 
FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE, TRUE);
+} else {
+  //
+  // Convert Result from  to 
+  //
+  StrPtr = StrStr (Result, L"=");
+  if (StrPtr != NULL) {
+*StrPtr = L'\0';
+  }
+
+  Status = ConfigRespToStorage (Storage->BrowserStorage, Result);
+  FreePool (Result);
+}
   }
 
   Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize 
(Storage->ConfigRequest), Storage->ConfigRequest);
--
2.39.1.windows.1



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




Re: [edk2-devel] [PATCH v2 0/3] UefiCpuPkg/ResetVector: Remove pre-built binaries

2023-06-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Wednesday, June 21, 2023 2:01 PM
To: Liu, Zhiguang ; Dong, Eric 
Cc: devel@edk2.groups.io; Ni, Ray 
Subject: RE: [edk2-devel] [PATCH v2 0/3] UefiCpuPkg/ResetVector: Remove 
pre-built binaries

I updated the patch per Zhiguang's comments to remove ALIGN 16 requirement.
Can you please review again?

Only the 2nd patch is updated.

Thanks,
Ray

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ni, Ray
> Sent: Wednesday, June 21, 2023 10:55 AM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] [PATCH v2 0/3] UefiCpuPkg/ResetVector: Remove 
> pre- built binaries
> 
> Ray Ni (3):
>   UefiCpuPkg: Include ResetVector in DSC
>   UefiCpuPkg/ResetVector: Add guidance of FDF ffs rule
>   UefiCpuPkg/ResetVector: Remove pre-built binaries
> 
>  .../Vtf0/Bin/IA32/ResetVector.ia32.port80.raw | Bin 532 -> 0 bytes
>  .../Vtf0/Bin/IA32/ResetVector.ia32.raw| Bin 500 -> 0 bytes
>  .../Vtf0/Bin/IA32/ResetVector.ia32.serial.raw | Bin 900 -> 0 bytes
>  .../ResetVector/Vtf0/Bin/ResetVector.inf  |  31 --
>  .../ResetVector/Vtf0/Bin/ResetVector.uni  |  16 
>  .../ResetVector/Vtf0/Bin/ResetVector1G.inf|  31 --
>  .../ResetVector/Vtf0/Bin/ResetVectorExtra.uni |  12 ---
>  .../PageTable1G/ResetVector.x64.port80.raw| Bin 12292 -> 0 bytes
>  .../Bin/X64/PageTable1G/ResetVector.x64.raw   | Bin 12292 -> 0 bytes
>  .../PageTable1G/ResetVector.x64.serial.raw| Bin 12292 -> 0 bytes
>  .../PageTable2M/ResetVector.x64.port80.raw| Bin 28676 -> 0 bytes
>  .../Bin/X64/PageTable2M/ResetVector.x64.raw   | Bin 28676 -> 0 bytes
>  .../PageTable2M/ResetVector.x64.serial.raw| Bin 28676 -> 0 bytes
>  UefiCpuPkg/ResetVector/Vtf0/Build.py  |  89 --
>  UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt|  27 ++
>  .../Vtf0/Tools/FixupForRawSection.py  |  20 
>  UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf  |  28 +-
>  UefiCpuPkg/UefiCpuPkg.dsc |   4 +-
>  18 files changed, 36 insertions(+), 222 deletions(-)  delete mode 
> 100644 
> UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.port80.raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.serial.raw
>  delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf
>  delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.uni
>  delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector1G.inf
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVectorExtra.uni
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.port80
> .raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.serial
> .r
> aw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.port8
> 0.raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.raw
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.serial
> .r
> aw
>  delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Build.py
>  delete mode 100644
> UefiCpuPkg/ResetVector/Vtf0/Tools/FixupForRawSection.py
> 
> --
> 2.39.1.windows.1
> 
> 
> 
> 
> 



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




Re: [edk2-devel] [PATCH 2/3] UefiCpuPkg/ResetVector: Add guidance of how to guarantee 16B align

2023-06-18 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Thursday, June 15, 2023 6:51 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul R ; 
Gerd Hoffmann 
Subject: [PATCH 2/3] UefiCpuPkg/ResetVector: Add guidance of how to guarantee 
16B align

ResetVector assembly implementation puts "ALIGN 16" in the end to guarantee the 
final executable file size is multiple of 16 bytes.
Because the module uses a special GUID which guarantees it's put in the very 
end of a FV, which should be also the end of the FD.
Then to make sure the reset vector "JMP" code is at _FFF0h, the ResetVector 
has to be aligned at 16-byte boundary.

The patch updates INF file and ReadMe.txt to add guidance how to make sure the 
module is aligned on 16-byte boundary.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Rahul Kumar 
Cc: Gerd Hoffmann 
---
 UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt | 27 +++---
 UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf   | 19 +-
 2 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt 
b/UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt
index 97f4600968..edeb2d6d3e 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt
+++ b/UefiCpuPkg/ResetVector/Vtf0/ReadMe.txt
@@ -1,15 +1,16 @@
  === HOW TO USE VTF0 ===+Add this line to your DSC [Components.IA32] or 
[Components.X64] section:+  UefiCpuPkg/ResetVector/Vtf0/ResetVector.inf  Add 
this line to your FDF FV section:-INF  RuleOverride=RESET_VECTOR USE = IA32 
UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf-(For X64 SEC/PEI change IA32 to 
X64 => 'USE = X64')+  INF  RuleOverride=RESET_VECTOR 
UefiCpuPkg/ResetVector/Vtf0/ResetVector.inf  In your FDF FFS file rules 
sections add:-[Rule.Common.SEC.RESET_VECTOR]-  FILE RAW = $(NAMED_GUID) {-
RAW RAW|.raw-  }+  [Rule.Common.SEC.RESET_VECTOR]+FILE RAW 
= $(NAMED_GUID) {+  RAW BIN   Align = 16   |.bin+}  === VTF0 Boot Flow 
=== @@ -25,17 +26,3 @@ All inputs to SEC image are register based:
 EAX/RAX - Initial value of the EAX register (BIST: Built-in Self Test) DI  
- 'BP': boot-strap processor, or 'AP': application processor EBP/RBP - Pointer 
to the start of the Boot Firmware Volume--=== HOW TO BUILD VTF0 
===--Dependencies:-* Python 3 or newer-* Nasm 2.03 or newer--To rebuild the 
VTF0 binaries:-1. Change to VTF0 source dir: UefiCpuPkg/ResetVector/Vtf0-2. 
nasm and python should be in executable path-3. Run this command:-   python 
Build.py-4. Binaries output will be in UefiCpuPkg/ResetVector/Vtf0/Bin-diff 
--git a/UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf 
b/UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf
index 9922cb2755..28185a6e60 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf
+++ b/UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf
@@ -1,7 +1,24 @@
 ## @file #  Reset Vector #-#  Copyright (c) 2006 - 2014, Intel Corporation. 
All rights reserved.+#  Note:+#The platform FDF file MUST guarantee the 
ResetVector is aligned+#on 16-byte boundary. Otherwise, the CPU reset 
vector will NOT be+#at _FFF0h.+#+#A sample FDF build rule could be 
as follows:+#+#  [Rule.Common.SEC.RESET_VECTOR]+#FILE RAW = 
$(NAMED_GUID) {+#  RAW BIN   Align = 16   |.bin+#}+#+#  
  Following line in FDF forces to use the above build rule for the 
ResetVector:+#+#  INF  RuleOverride=RESET_VECTOR 
UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf+#+#+#  Copyright (c) 2006 - 2023, Intel 
Corporation. All rights reserved. # #  SPDX-License-Identifier: 
BSD-2-Clause-Patent #-- 
2.39.1.windows.1



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




Re: [edk2-devel] [PATCH 1/3] UefiCpuPkg: Include ResetVector in DSC

2023-06-18 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Thursday, June 15, 2023 6:51 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul R ; 
Gerd Hoffmann 
Subject: [PATCH 1/3] UefiCpuPkg: Include ResetVector in DSC

Since ResetVector source module shares the same GUID as the binary module, the 
binary INF file is just removed from DSC.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Rahul Kumar 
Cc: Gerd Hoffmann 
---
 UefiCpuPkg/UefiCpuPkg.dsc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 
593c11cc74..7af1c83424 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -1,7 +1,7 @@
 ## @file #  UefiCpuPkg Package #-#  Copyright (c) 2007 - 2022, Intel 
Corporation. All rights reserved.+#  Copyright (c) 2007 - 2023, Intel 
Corporation. All rights reserved. # #  SPDX-License-Identifier: 
BSD-2-Clause-Patent #@@ -168,7 +168,7 @@
   
SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf 
  }   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf-  
UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf+  
UefiCpuPkg/ResetVector/Vtf0/ResetVector.inf   
UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf   
UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf   
UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/PeiCpuExceptionHandlerLibUnitTest.inf--
 
2.39.1.windows.1



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




Re: [edk2-devel] [PATCH 3/3] UefiCpuPkg/ResetVector: Remove pre-built binaries

2023-06-15 Thread Dong, Eric
Reviewed-by: Eric Dong 

Thanks,
Eric
-Original Message-
From: Ni, Ray  
Sent: Thursday, June 15, 2023 6:51 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul R ; 
Gerd Hoffmann 
Subject: [PATCH 3/3] UefiCpuPkg/ResetVector: Remove pre-built binaries

Because it's simpler for a platform to include the ResetVector source and 
having pre-built binaries add burdens of updating the pre-built binaries. This 
patch removes the pre-built binaries and the script that buids the pre-built 
binaries.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Rahul Kumar 
Cc: Gerd Hoffmann 
---
 .../Vtf0/Bin/IA32/ResetVector.ia32.port80.raw | Bin 532 -> 0 bytes
 .../Vtf0/Bin/IA32/ResetVector.ia32.raw| Bin 500 -> 0 bytes
 .../Vtf0/Bin/IA32/ResetVector.ia32.serial.raw | Bin 900 -> 0 bytes
 .../ResetVector/Vtf0/Bin/ResetVector.inf  |  31 --
 .../ResetVector/Vtf0/Bin/ResetVector.uni  |  16 
 .../ResetVector/Vtf0/Bin/ResetVector1G.inf|  31 --
 .../ResetVector/Vtf0/Bin/ResetVectorExtra.uni |  12 ---
 .../PageTable1G/ResetVector.x64.port80.raw| Bin 12292 -> 0 bytes
 .../Bin/X64/PageTable1G/ResetVector.x64.raw   | Bin 12292 -> 0 bytes
 .../PageTable1G/ResetVector.x64.serial.raw| Bin 12292 -> 0 bytes
 .../PageTable2M/ResetVector.x64.port80.raw| Bin 28676 -> 0 bytes
 .../Bin/X64/PageTable2M/ResetVector.x64.raw   | Bin 28676 -> 0 bytes
 .../PageTable2M/ResetVector.x64.serial.raw| Bin 28676 -> 0 bytes
 UefiCpuPkg/ResetVector/Vtf0/Build.py  |  89 --
 .../Vtf0/Tools/FixupForRawSection.py  |  20 
 UefiCpuPkg/ResetVector/Vtf0/Vtf0.inf  |   9 ++
 16 files changed, 9 insertions(+), 199 deletions(-)  delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.port80.raw
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.serial.raw
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.uni
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector1G.inf
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVectorExtra.uni
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.port80.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable1G/ResetVector.x64.serial.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.port80.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.raw
 delete mode 100644 
UefiCpuPkg/ResetVector/Vtf0/Bin/X64/PageTable2M/ResetVector.x64.serial.raw
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Build.py
 delete mode 100644 UefiCpuPkg/ResetVector/Vtf0/Tools/FixupForRawSection.py

diff --git a/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.port80.raw 
b/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.port80.raw
deleted file mode 100644
index 
a3601274c25dde665872ff375f1deadf1c838476..
GIT binary patch
literal 0
HcmV?d1

literal 532
zcmYk3L1+^}6hQxG?OGMxP=XCuO{oFvA!34x5(Ckq=%JWHDKR3&%U*@;4lLqfmnDa3
z%DNy3Djoz+o>n|`p_PoRky;N5Js1c|L|nU_OT82o$@oJN@(=(2nR!+4(O*Tp(W`R7TpTmFm4ifa-;zC*vz4XttW
zq}0}nTrTTp>dYuOY`31v{#vMxZinN>X5{wjokJ@1Uq(rY83f3nOGnJ7F{XGEc^
zd@axD+xj+9{H@3`dj3!J3w#sG<{Xwjw>n?7OgU*B!aQOW8fp7m--koX4wLm__Al=^
zY?o%Aovx9bx>P+cg?6!W34mnesY#x}LmFy!akfSd$Wy}(n^c!>D977;D8Mlg8>sUS
zM%JHY*m66|cf|=!l}5GTC_q`AVA|#!0!awU3V=G%^$U@u1;gOBUFLS(4fi9z>Se$~
z2tQ>Y`tp9@WdZJg*r|{I*L%>sSmAq{7b<*6qi=YE|Bg)|JbKgC45A{vlk%hz|-
Oedp}VWx$=4LE;}o$@(e)

diff --git a/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.raw 
b/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.raw
deleted file mode 100644
index 
6124f3f9a40e4e58cc672b54cbf5cc33360b3858..
GIT binary patch
literal 0
HcmV?d1

literal 500
zcmbO*VZsE%1G)?X3=Fmm3=IE^A{#3Nsty!~l*%?%h@7@P`lJPIy15`EBv@@}EGf-9QVcpB6tC}lR7)qCP9%hbE
zD4qM7bH{!l=sf!RU+2-6j*JWphPONKb-qaJjx}JsQDps^*`dg+^+1VH^8xlEU6mhQ
z5#rwtE0nzI_7G`&`2YWZ2F{ZucNq_sFcn>Is1RZ#o8d#>?cFW^_0sqm#nW~uGcY*tD;-FCl?{{>VA$cn#=yX@^dM~q2SeYD
zz5{&^`d;*1c8TLB`yyn{P81R}kt@Frh
trq@4TcfR!a_y7OPT|lDq!T)CvW8mcL%Md2W%&-tQh6xj1?}1AK82|{?Cv

diff --git a/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.serial.raw 
b/UefiCpuPkg/ResetVector/Vtf0/Bin/IA32/ResetVector.ia32.serial.raw
deleted file mode 100644
index 
48b46e3473e77a1179bf818a1f1deafb7e46cf3e..
GIT binary patch
literal 0
HcmV?d1

literal 900
zcmbO*VZwx6znM3*zuWbbc>}|{T|byNFuntcu)lk$%4~Q*mqCDm!Ipu6;eSzNV}(G~
zf#Q%-*~SWy)3$hB=+XZO)KSYtdQw^ZZfNs>9q<_RmIbup3
zs%DyYCYEjns%kx~d%1K~bA<{+>5|UF%n=Hub6y9;GyisKLn%SYqvh_fT
zY4ZX0A_J8lT@m8n4l9(r>h=(6e

Re: [edk2-devel] [PATCH] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP perf-logging

2023-06-08 Thread Dong, Eric
Looks good to me.

Thanks,
Eric

-Original Message-
From: Ni, Ray  
Sent: Wednesday, June 7, 2023 4:38 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul R ; 
Gerd Hoffmann 
Subject: [PATCH] UefiCpuPkg/SmmCpu: Add PcdSmmApPerfLogEnable control AP 
perf-logging

When a platform has lots of CPU cores/threads, perf-logging on every
AP produces lots of records. When this multiplies with number of SMIs
during post, the records are even more.

So, this patch adds a new PCD PcdSmmApPerfLogEnable (default TRUE)
to allow platform to turn off perf-logging on APs.

Cc: Eric Dong 
Cc: Rahul Kumar 
Cc: Gerd Hoffmann 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c|  2 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf |  1 +
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c| 11 ++-
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h|  4 +++-
 UefiCpuPkg/UefiCpuPkg.dec|  6 ++
 5 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index bcd90f0671..8364b73242 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -784,7 +784,7 @@ BSPHandler (
   // Any SMM MP performance logging after this point will be migrated in next 
SMI.

   //

   PERF_CODE (

-MigrateMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus);

+MigrateMpPerf (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus, CpuIndex);

 );

 

   //

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf 
b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
index 4864532c35..d864ae9101 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -128,6 +128,7 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmProfileRingBuffer ## CONSUMES

   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmFeatureControlMsrLock ## CONSUMES

   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES

+  gUefiCpuPkgTokenSpaceGuid.PcdSmmApPerfLogEnable  ## CONSUMES

 

 [Pcd]

   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber## 
SOMETIMES_CONSUMES

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
index c13556af46..92c67f31bf 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
@@ -39,16 +39,25 @@ InitializeMpPerf (
   Migrate MP performance data to standardized performance database.

 

   @param NumberofCpusNumber of processors in the platform.

+  @param BspIndexThe index of the BSP.

 **/

 VOID

 MigrateMpPerf (

-  UINTN  NumberofCpus

+  UINTN  NumberofCpus,

+  UINTN  BspIndex

   )

 {

   UINTN  CpuIndex;

   UINTN  MpProcecureId;

 

   for (CpuIndex = 0; CpuIndex < NumberofCpus; CpuIndex++) {

+if ((CpuIndex != BspIndex) && !FeaturePcdGet (PcdSmmApPerfLogEnable)) {

+  //

+  // Skip migrating AP performance data if AP perf-logging is disabled.

+  //

+  continue;

+}

+

 for (MpProcecureId = 0; MpProcecureId < SMM_MP_PERF_PROCEDURE_ID 
(SmmMpProcedureMax); MpProcecureId++) {

   if (mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId] != 0) {

 PERF_START (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, 
mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId]);

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h 
b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
index b148a99e86..5ad1734cc8 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h
@@ -44,10 +44,12 @@ InitializeMpPerf (
   Migrate MP performance data to standardized performance database.

 

   @param NumberofCpusNumber of processors in the platform.

+  @param BspIndexThe index of the BSP.

 **/

 VOID

 MigrateMpPerf (

-  UINTN  NumberofCpus

+  UINTN  NumberofCpus,

+  UINTN  BspIndex

   );

 

 /**

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index d31c3b127c..5b0ac64e33 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -175,6 +175,12 @@
   # @Prompt Support SmmFeatureControl.

   gUefiCpuPkgTokenSpaceGuid.PcdSmmFeatureControlEnable|TRUE|BOOLEAN|0x32132110

 

+  ## Indicates if SMM perf logging in APs will be enabled.

+  #   TRUE  - SMM perf logging in APs will be enabled.

+  #   FALSE - SMM perf logging in APs will not be enabled.

+  # @Prompt Enable SMM perf logging in APs.

+  gUefiCpuPkgTokenSpaceGuid.PcdSmmApPerfLogEnable|TRUE|BOOLEAN|0x32132114

+

 [PcdsFixedAtBuild]

   ## List of exception vectors which need switching stack.

   #  This PCD will only take into effect if PcdCpuStackGuard is enabled.

-- 
2.39.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105965): https://edk2.groups.io/g/devel/message/105965
Mute This Topic: https://groups.io/mt/99380509/21656
Group Owner: devel+

Re: [edk2-devel] [PATCH V2 0/6] Enable perf-logging in SMM environment

2023-06-08 Thread Dong, Eric
This patch serial looks good to me.

Thanks,
Eric

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Ni, Ray
Sent: Wednesday, May 31, 2023 7:35 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH V2 0/6] Enable perf-logging in SMM environment


Ray Ni (6):
  UefiCpuPkg/CpuSmm: Add perf-logging for time-consuming BSP procedures
  UefiCpuPkg/CpuSmm: Add perf-logging for MP procedures
  MdeModulePkg/SmmCore: Add perf-logging for time-consuming procedures
  MdeModulePkg/SmmCore: Add perf-logging for SmmDriverDispatchHandler
  MdeModulePkg/SmmPerformanceLib: Disable perf-logging after ExitBS
  MdeModulePkg/SmmCorePerformanceLib: Disable perf-logging at runtime

 MdeModulePkg/Core/PiSmmCore/Dispatcher.c  |  5 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c   | 14 ++-
 MdeModulePkg/Core/PiSmmCore/Smi.c |  6 ++
 .../SmmCorePerformanceLib.c   | 48 +-
 .../SmmCorePerformanceLib.inf |  3 +-
 .../SmmPerformanceLib/SmmPerformanceLib.c | 63 -
 .../SmmPerformanceLib/SmmPerformanceLib.inf   |  4 +
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 42 -
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c| 38 
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h|  2 +
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf  |  3 +
 .../PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c   | 13 ++-
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c | 91 +++
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h | 77 
 UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c|  4 +-
 15 files changed, 402 insertions(+), 11 deletions(-)  create mode 100644 
UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.c
 create mode 100644 UefiCpuPkg/PiSmmCpuDxeSmm/SmmMpPerf.h

--
2.39.1.windows.1








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




Re: [edk2-devel] [PATCH] UefiCpuPkg/MicrocodeMeasurementDxe: Fix exception

2023-03-09 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Darbin Reyes
Sent: Wednesday, March 8, 2023 7:04 AM
To: devel@edk2.groups.io
Cc: Reyes, Darbin ; Narey, Jacob 
Subject: [edk2-devel] [PATCH] UefiCpuPkg/MicrocodeMeasurementDxe: Fix exception

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4360

An incorrect format specifier is being used in a DEBUG print, specifically, a 
variable of type EFI_STATUS was being printed with the %a format specifier 
(pointer to an ASCII string), thus the value of the Status variable was being 
treated as the address of a string, leading to a CPU exception, when 
encountered this bug manifests itself as a hang near "Ready to Boot Event", 
with the last DEBUG print being
"INFO: Got MicrocodePatchHob with microcode patches starting address"
followed by a CPU Exception dump.

Signed-off-by: Darbin Reyes 
Reviewed-by: Jacob Narey 
---
 UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.c 
b/UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.c
index 762ca159ff..5fd3b3365c 100644
--- a/UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.c
+++ b/UefiCpuPkg/MicrocodeMeasurementDxe/MicrocodeMeasurementDxe.c
@@ -238,7 +238,7 @@ MeasureMicrocodePatches (
TotalMicrocodeSize)   );   } else {-DEBUG ((DEBUG_ERROR, 
"ERROR: TpmMeasureAndLogData failed with status %a!\n", Status));+DEBUG 
((DEBUG_ERROR, "ERROR: TpmMeasureAndLogData failed with status %r!\n", 
Status));   }FreePool (Offsets);-- 
2.38.1.windows.1



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#100818): https://edk2.groups.io/g/devel/message/100818
Mute This Topic: https://groups.io/mt/97461560/1768733
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [eric.d...@intel.com] 
-=-=-=-=-=-=




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




Re: [edk2-devel] [PATCH v1] Maintainers.txt: Update NetworkPkg & MM modules Reviewer

2022-12-15 Thread Dong, Eric
Thanks Jiaxin.

Reviewed-by: Eric Dong 

-Original Message-
From: Wu, Jiaxin  
Sent: Thursday, December 15, 2022 5:41 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Maciej Rabeda 

Subject: [PATCH v1] Maintainers.txt: Update NetworkPkg & MM modules Reviewer

This is to change NetworkPkg & MM modules Reviewer.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Maciej Rabeda 
Signed-off-by: Jiaxin Wu 
---
 Maintainers.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Maintainers.txt b/Maintainers.txt index 6a92922258..e2beafbaa6 
100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -374,11 +374,11 @@ R: Eric Dong  [ydong10]
 MdeModulePkg: Management Mode (MM, SMM) modules
 F: MdeModulePkg/*Smi*/
 F: MdeModulePkg/*Smm*/
 F: MdeModulePkg/Include/*Smi*.h
 F: MdeModulePkg/Include/*Smm*.h
-R: Eric Dong  [ydong10]
+R: Jiaxin Wu  [jiaxinwu]
 R: Ray Ni  [niruiyu]
 
 MdeModulePkg: Pei Core
 F: MdeModulePkg/Core/Pei/
 R: Dandan Bi  [dandanbi] @@ -430,11 +430,10 @@ R: 
Zhiguang Liu  [LiuZhiguang001]
 
 NetworkPkg
 F: NetworkPkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/NetworkPkg
 M: Maciej Rabeda  [mrabeda]
-R: Jiaxin Wu  [jiaxinwu]
 R: Siyuan Fu  [sfu5]
 
 OvmfPkg
 F: OvmfPkg/
 W: http://www.tianocore.org/ovmf/
--
2.16.2.windows.1



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




Re: [edk2-devel] [PATCH 00/10] UefiCpuPkg: Create CpuPageTableLib for manipulating X86 paging structs

2022-08-08 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Ni, Ray
Sent: Monday, July 18, 2022 9:18 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH 00/10] UefiCpuPkg: Create CpuPageTableLib for 
manipulating X86 paging structs

Ray Ni (10):
  UefiCpuPkg: Create CpuPageTableLib for manipulating X86 paging structs
  UefiCpuPkg/CpuPageTableLib: Return error on invalid parameters
  CpuPageTableLib: Fix a bug when a bit is 1 in Attribute, 0 in Mask
  CpuPageTableLib: Refactor the logic
  CpuPageTableLib: Split the page entry when LA is aligned but PA is not
  CpuPageTableLib: Avoid treating non-leaf entry as leaf one
  CpuPageTableLib: Fix parent attributes are not inherited properly
  CpuPageTableLib: Fix a bug to avoid unnecessary changing to page table
  CpuPageTableLib: Fix bug that wrongly requires extra size for mapping
  CpuPageTableLib: define IA32_PAGE_LEVEL enum type internally

 UefiCpuPkg/Include/Library/CpuPageTableLib.h  | 129 
 .../Library/CpuPageTableLib/CpuPageTable.h| 230 ++
 .../CpuPageTableLib/CpuPageTableLib.inf   |  35 +
 .../Library/CpuPageTableLib/CpuPageTableMap.c | 690 ++
 .../CpuPageTableLib/CpuPageTableParse.c   | 330 +
 UefiCpuPkg/UefiCpuPkg.dec |   3 +
 UefiCpuPkg/UefiCpuPkg.dsc |   4 +-
 7 files changed, 1420 insertions(+), 1 deletion(-)  create mode 100644 
UefiCpuPkg/Include/Library/CpuPageTableLib.h
 create mode 100644 UefiCpuPkg/Library/CpuPageTableLib/CpuPageTable.h
 create mode 100644 UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf
 create mode 100644 UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
 create mode 100644 UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableParse.c

--
2.35.1.windows.2








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




Re: [edk2-devel][PATCH V1 1/1] UefiCpuPkg/SecCore: Add debug messages to illuminate data flow

2022-07-07 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Oram, Isaac W  
Sent: Tuesday, June 28, 2022 6:49 AM
To: devel@edk2.groups.io
Cc: Oram, Isaac W ; Dong, Eric ; 
Ni, Ray ; Kumar, Rahul1 ; De, 
Debkumar ; Han, Harry ; West, 
Catharine 
Subject: [edk2-devel][PATCH V1 1/1] UefiCpuPkg/SecCore: Add debug messages to 
illuminate data flow

Add debug messages to make it easier to verify PlatformSecLib is passing the 
data properly.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Debkumar De 
Cc: Harry Han 
Cc: Catharine West 
Signed-off-by: Isaac Oram 
---
 UefiCpuPkg/SecCore/SecMain.c | 37 
 1 file changed, 37 insertions(+)

diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c index 
a7526be9dd..4edf0ce972 100644
--- a/UefiCpuPkg/SecCore/SecMain.c
+++ b/UefiCpuPkg/SecCore/SecMain.c
@@ -167,6 +167,15 @@ SecStartup (
 EFI_SOFTWARE_SEC | EFI_SW_SEC_PC_ENTRY_POINT
 );
 
+  DEBUG ((
+DEBUG_INFO,
+"%a() TempRAM Base: 0x%x, TempRAM Size: 0x%x, BootFirmwareVolume 0x%x\n",
+__FUNCTION__,
+TempRamBase,
+SizeOfRam,
+BootFirmwareVolume
+));
+
   PeiStackSize = PcdGet32 (PcdPeiTemporaryRamStackSize);
   if (PeiStackSize == 0) {
 PeiStackSize = (SizeOfRam >> 1);
@@ -229,6 +238,20 @@ SecStartup (
   SecCoreData.StackBase  = (VOID *)(UINTN)(TempRamBase + 
SecCoreData.PeiTemporaryRamSize);
   SecCoreData.StackSize  = PeiStackSize;
 
+  DEBUG ((
+DEBUG_INFO,
+"%a() BFV Base: 0x%x, BFV Size: 0x%x, TempRAM Base: 0x%x, TempRAM Size: 
0x%x, PeiTempRamBase: 0x%x, PeiTempRamSize: 0x%x, StackBase: 0x%x, StackSize: 
0x%x\n",
+__FUNCTION__,
+SecCoreData.BootFirmwareVolumeBase,
+SecCoreData.BootFirmwareVolumeSize,
+SecCoreData.TemporaryRamBase,
+SecCoreData.TemporaryRamSize,
+SecCoreData.PeiTemporaryRamBase,
+SecCoreData.PeiTemporaryRamSize,
+SecCoreData.StackBase,
+SecCoreData.StackSize
+));
+
   //
   // Initialize Debug Agent to support source level debug in SEC/PEI phases 
before memory ready.
   //
@@ -318,6 +341,13 @@ SecStartupPhase2 (
 }
   }
 
+  DEBUG ((
+DEBUG_INFO,
+"%a() PeiCoreEntryPoint: 0x%x\n",
+__FUNCTION__,
+PeiCoreEntryPoint
+));
+
   if (PpiList != NULL) {
 AllSecPpiList = (EFI_PEI_PPI_DESCRIPTOR *)SecCoreData->PeiTemporaryRamBase;
 
@@ -360,6 +390,13 @@ SecStartupPhase2 (
 //
 SecCoreData->PeiTemporaryRamBase  = (VOID 
*)(((UINTN)SecCoreData->PeiTemporaryRamBase + 7) & ~0x07);
 SecCoreData->PeiTemporaryRamSize &= ~(UINTN)0x07;
+DEBUG ((
+  DEBUG_INFO,
+  "%a() PeiTemporaryRamBase: 0x%x, PeiTemporaryRamSize: 0x%x\n",
+  __FUNCTION__,
+  SecCoreData->PeiTemporaryRamBase,
+  SecCoreData->PeiTemporaryRamSize
+  ));
   } else {
 //
 // No addition PPI, PpiList directly point to the common PPI list.
--
2.36.1.windows.1



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




Re: [edk2-devel] [PATCH v3 0/5] MpInitLib code refactoring

2022-06-10 Thread Dong, Eric
Reviewed-by: Eric Dong   for this serial.

Thanks,
Eric

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Ni, Ray
Sent: Monday, May 16, 2022 3:14 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH v3 0/5] MpInitLib code refactoring

v2:
  Updated 3/5: "Put SEV logic in separate file" patch.
  Added 5/5: "Move the Above1Mb vector allocation to MpInitLibInitialize" patch.

v3:
  v2 was sent to wrong mailing list "edk2-de...@lists.01.org".
  v3 is created to send to correct mailing list.
  All code changes are in https://github.com/niruiyu/edk2/tree/refactormp3.

Ray Ni (5):
  MpInitLib: Allocate code buffer for PEI phase
  MpInitLib: remove unneeded global ASM_PFX
  MpInitLib: Put SEV logic in separate file
  MpInitLib: Only allocate below 1MB memory for 16bit code
  MpInitLib: Move the Above1Mb vector allocation to MpInitLibInitialize

 UefiCpuPkg/Library/MpInitLib/AmdSev.c |   6 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |   2 +-
 .../Library/MpInitLib/Ia32/MpFuncs.nasm   |  13 +-
 UefiCpuPkg/Library/MpInitLib/MpEqu.inc|   6 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c  | 124 ++---
 UefiCpuPkg/Library/MpInitLib/MpLib.h  |   6 +-
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c   |  15 +-
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm  | 148 +++  
UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 169 +-
 9 files changed, 233 insertions(+), 256 deletions(-)

--
2.35.1.windows.2








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




Re: [edk2-devel] [PATCH 5/5] CpuException: Add InitializeSeparateExceptionStacks

2022-06-06 Thread Dong, Eric
Acked-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Wang, Jian J 
Subject: [PATCH 5/5] CpuException: Add InitializeSeparateExceptionStacks

Today InitializeCpuExceptionHandlersEx is called from three modules:
1. DxeCore (links to DxeCpuExceptionHandlerLib)
DxeCore expects it initializes the IDT entries as well as
assigning separate stacks for #DF and #PF.
2. CpuMpPei (links to PeiCpuExceptionHandlerLib)
   and CpuDxe (links to DxeCpuExceptionHandlerLib)
It's called for each thread for only assigning separate stacks for
#DF and #PF. The IDT entries initialization is skipped because
caller sets InitData->X64.InitDefaultHandlers to FALSE.

Additionally, SecPeiCpuExceptionHandlerLib, SmmCpuExceptionHandlerLib also 
implement such API and the behavior of the API is simply to initialize IDT 
entries only.

Because it mixes the IDT entries initialization and separate stacks assignment 
for certain exception handlers together, in order to know whether the function 
call only initializes IDT entries, or assigns stacks, we need to check:
1. value of InitData->X64.InitDefaultHandlers 2. library instance

This patch cleans up the code to separate the stack assignment to a new API:
InitializeSeparateExceptionStacks().

Only when caller calls the new API, the separate stacks are assigned.
With this change, the SecPei and Smm instance can return unsupported which 
gives caller a very clear status.

The old API InitializeCpuExceptionHandlersEx() is removed in this patch.
Because no platform module is consuming the old API, the impact is none.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Jian J Wang 
---
 MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c   |  2 +-
 .../Include/Library/CpuExceptionHandlerLib.h  | 24 ++---
 .../CpuExceptionHandlerLibNull.c  | 26 ++
 UefiCpuPkg/CpuDxe/CpuMp.c |  6 +-
 UefiCpuPkg/CpuMpPei/CpuMpPei.c|  4 +-
 .../CpuExceptionHandlerLib/DxeException.c | 91 ++-
 .../CpuExceptionHandlerLib/PeiCpuException.c  | 51 ++-
 .../SecPeiCpuException.c  | 27 ++
 .../CpuExceptionHandlerLib/SmmException.c | 27 ++
 9 files changed, 74 insertions(+), 184 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c 
b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
index 2c27fc0695..83f49d7c00 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
+++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
@@ -253,7 +253,7 @@ DxeMain (
 VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob)); 
  } -  Status = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);+  
Status = InitializeCpuExceptionHandlers (VectorInfoList);   ASSERT_EFI_ERROR 
(Status);//diff --git 
a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h 
b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
index d4649bebe1..9a495081f7 100644
--- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
+++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
@@ -103,32 +103,20 @@ InitializeCpuExceptionHandlers (
   );  /**-  Initializes all CPU exceptions entries with optional extra 
initializations.+  Setup separate stacks for certain exception handlers. -  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.+  InitData is optional and processor arch 
dependent. -  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.+  @param[in]  InitData  Pointer to data optional for information 
about how+to assign stacks for certain exception 
handlers. -  @param[in]  VectorInfoPointer to reserved vector list.-  
@param[in]  InitData  Pointer to data optional for extra initializations-   
 of exception.--  @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   ); diff --git 
a/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.c 
b/MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.c
index 54f38788fe..8aeedcb4d1 

Re: [edk2-devel] [PATCH 4/5] CpuException: Remove InitializeCpuInterruptHandlers

2022-06-06 Thread Dong, Eric
Acked-by: Eric Dong eric.d...@intel.com<mailto:eric.d...@intel.com>

From: Ni, Ray 
Sent: Tuesday, May 24, 2022 4:04 PM
To: Wang, Jian J ; devel@edk2.groups.io
Cc: Dong, Eric 
Subject: Re: [edk2-devel] [PATCH 4/5] CpuException: Remove 
InitializeCpuInterruptHandlers

Jian,
I think we need discussion on where to put the common CPU_INTERRUPT_NUM 
definition.

Do you agree that we can leave that to another patch?


From: Wang, Jian J mailto:jian.j.w...@intel.com>>
Sent: Monday, May 23, 2022 0:27
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 4/5] CpuException: Remove 
InitializeCpuInterruptHandlers

Hi Ray,

Both CpuDxe.c and CpuExceptionCommon.h have CPU_INTERRUPT_NUM defined.
I'd suggest to move it to a common place, such as BaseLib.h. I don't see any 
issue
if they are defined to different value. It just gives me a feeling that it 
might cause
potential problems sometimes in the future.


Regards,
Jian

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Ni, Ray
> Sent: Friday, May 20, 2022 10:16 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Dong, Eric mailto:eric.d...@intel.com>>
> Subject: [edk2-devel] [PATCH 4/5] CpuException: Remove
> InitializeCpuInterruptHandlers
>
> InitializeCpuExceptionHandlers() expects caller allocates IDT while
> InitializeCpuInterruptHandlers() allocates 256 IDT entries itself.
>
> InitializeCpuExceptionHandlers() fills max 32 IDT entries allocated
> by caller. If caller allocates 10 entries, the API just fills 10 IDT
> entries.
>
> The inconsistency between the two APIs makes code hard to
> unerstand and hard to share.
>
> Because there is only one caller (CpuDxe) for
> InitializeCpuInterruptHandler(), this patch updates CpuDxe driver
> to allocates 256 IDT entries then call
> InitializeCpuExceptionHandlers().
>
> With this change, InitializeCpuInterruptHandlers() is removed
> completely.
>
> And InitializeCpuExceptionHandlers() fills max 32 entries for PEI
> and SMM instance, max 256 entries for DXE instance.
> Such behavior matches to the original one.
>
> Signed-off-by: Ray Ni mailto:ray...@intel.com>>
> Cc: Eric Dong mailto:eric.d...@intel.com>>
> ---
>  .../Include/Library/CpuExceptionHandlerLib.h  | 28 +--
>  .../CpuExceptionHandlerLibNull.c  | 31 +--
>  UefiCpuPkg/CpuDxe/CpuDxe.c| 33 ++--
>  .../CpuExceptionHandlerLib/DxeException.c | 80 ++-
>  .../CpuExceptionHandlerLib/PeiCpuException.c  | 61 +-
>  .../PeiDxeSmmCpuException.c   | 19 ++---
>  .../SecPeiCpuException.c  | 31 +--
>  .../CpuExceptionHandlerLib/SmmException.c | 35 ++--
>  8 files changed, 56 insertions(+), 262 deletions(-)
>
> diff --git a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> index 22a4408f9f..d4649bebe1 100644
> --- a/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> +++ b/MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
> @@ -2,7 +2,7 @@
>CPU Exception library provides the default CPU interrupt/exception handler.
>
>It also provides capability to register user interrupt/exception handler.
>
>
>
> -  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
>
> +  Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.
>
>SPDX-License-Identifier: BSD-2-Clause-Patent
>
>
>
>  **/
>
> @@ -132,28 +132,6 @@ InitializeCpuExceptionHandlersEx (
>IN CPU_EXCEPTION_INIT_DATA  *InitData OPTIONAL
>
>);
>
>
>
> -/**
>
> -  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]  VectorInfoPointer 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

Re: [edk2-devel] [PATCH 3/5] CpuException: Avoid allocating page but using global variables

2022-06-06 Thread Dong, Eric
Acked-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric 
Subject: [PATCH 3/5] CpuException: Avoid allocating page but using global 
variables

Signed-off-by: Ray Ni 
Cc: Eric Dong 
---
 .../CpuExceptionHandlerLib/DxeException.c | 24 ---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index da5b96d6c6..f139131a7c 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -14,8 +14,8 @@
 

 CONST UINTN  mDoFarReturnFlag = 0;

 

-RESERVED_VECTORS_DATA  mReservedVectorsData[CPU_EXCEPTION_NUM];

-EFI_CPU_INTERRUPT_HANDLER  mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];

+RESERVED_VECTORS_DATA  mReservedVectorsData[CPU_INTERRUPT_NUM];

+EFI_CPU_INTERRUPT_HANDLER  mExternalInterruptHandlerTable[CPU_INTERRUPT_NUM];

 EXCEPTION_HANDLER_DATA mExceptionHandlerData = {

   0,   // To be fixed

   0,   // To be fixed

@@ -96,27 +96,15 @@ InitializeCpuInterruptHandlers (
   IA32_DESCRIPTOR IdtDescriptor;

   UINTN   IdtEntryCount;

   EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;

-  RESERVED_VECTORS_DATA   *ReservedVectors;

-  EFI_CPU_INTERRUPT_HANDLER   *ExternalInterruptHandler;

-

-  Status = gBS->AllocatePool (

-  EfiBootServicesCode,

-  sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM,

-  (VOID **)

-  );

-  ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);

-  SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * 
CPU_INTERRUPT_NUM, 0xff);

+

+  SetMem ((VOID *)mReservedVectorsData, sizeof (RESERVED_VECTORS_DATA) * 
CPU_INTERRUPT_NUM, 0xff);

   if (VectorInfo != NULL) {

-Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, 
CPU_INTERRUPT_NUM);

+Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectorsData, 
CPU_INTERRUPT_NUM);

 if (EFI_ERROR (Status)) {

-  FreePool (ReservedVectors);

   return EFI_INVALID_PARAMETER;

 }

   }

 

-  ExternalInterruptHandler = AllocateZeroPool (sizeof 
(EFI_CPU_INTERRUPT_HANDLER) * CPU_INTERRUPT_NUM);

-  ASSERT (ExternalInterruptHandler != NULL);

-

   //

   // Read IDT descriptor and calculate IDT size

   //

@@ -137,8 +125,6 @@ InitializeCpuInterruptHandlers (
   ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);

 

   mExceptionHandlerData.IdtEntryCount= CPU_INTERRUPT_NUM;

-  mExceptionHandlerData.ReservedVectors  = ReservedVectors;

-  mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;

   InitializeSpinLock ();

 

   UpdateIdtTable (IdtTable, , );

-- 
2.35.1.windows.2



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




Re: [edk2-devel] [PATCH 2/5] CpuException: Init global variables in-place

2022-06-06 Thread Dong, Eric
Acked-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, May 20, 2022 10:16 PM
To: devel@edk2.groups.io
Cc: Dong, Eric 
Subject: [PATCH 2/5] CpuException: Init global variables in-place

Additionally removed two useless global variables:
"SPIN_LOCK  mDisplayMessageSpinLock" from SMM instance.
"UINTN mEnabledInterruptNum" from DXE instance.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
---
 .../Library/CpuExceptionHandlerLib/DxeException.c  | 11 ++-  
.../Library/CpuExceptionHandlerLib/SmmException.c  | 14 ++
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index 5083c4b8e8..da5b96d6c6 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -16,9 +16,12 @@ CONST UINTN  mDoFarReturnFlag = 0;
  RESERVED_VECTORS_DATA  mReservedVectorsData[CPU_EXCEPTION_NUM]; 
EFI_CPU_INTERRUPT_HANDLER  
mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];-UINTN  
mEnabledInterruptNum = 0;--EXCEPTION_HANDLER_DATA  
mExceptionHandlerData;+EXCEPTION_HANDLER_DATA mExceptionHandlerData = {+  
0,   // To be fixed+  0,   // To be fixed+  mReservedVectorsData,+  
mExternalInterruptHandlerTable+};  UINT8  
mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *  
CPU_KNOWN_GOOD_STACK_SIZE];@@ -62,8 +65,6 @@ InitializeCpuExceptionHandlers (
   IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL   ) {-  
mExceptionHandlerData.ReservedVectors  = mReservedVectorsData;-  
mExceptionHandlerData.ExternalInterruptHandler = 
mExternalInterruptHandlerTable;   InitializeSpinLock 
();   return 
InitializeCpuExceptionHandlersWorker (VectorInfo, ); 
}diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
index 77ee74579f..9f0af4120a 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
@@ -11,14 +11,14 @@
  CONST UINTN  mDoFarReturnFlag = 1; -//-// Spin lock for CPU information 
display-//-SPIN_LOCK  mDisplayMessageSpinLock;- RESERVED_VECTORS_DATA  
mReservedVectorsData[CPU_EXCEPTION_NUM]; EFI_CPU_INTERRUPT_HANDLER  
mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];-EXCEPTION_HANDLER_DATA 
mExceptionHandlerData;+EXCEPTION_HANDLER_DATA mExceptionHandlerData = {+  
0,   // To be fixed+  0,   // To be fixed+  mReservedVectorsData,+  
mExternalInterruptHandlerTable+};  /**   Common exception handler.@@ -58,8 
+58,6 @@ InitializeCpuExceptionHandlers (
   IN EFI_VECTOR_HANDOFF_INFO  *VectorInfo OPTIONAL   ) {-  
mExceptionHandlerData.ReservedVectors  = mReservedVectorsData;-  
mExceptionHandlerData.ExternalInterruptHandler = 
mExternalInterruptHandlerTable;   InitializeSpinLock 
();   return 
InitializeCpuExceptionHandlersWorker (VectorInfo, ); }-- 
2.35.1.windows.2



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




Re: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages for DXE instance

2022-06-06 Thread Dong, Eric
Acked-by: Eric Dong 

From: Ni, Ray 
Sent: Tuesday, May 24, 2022 4:02 PM
To: Wang, Jian J ; devel@edk2.groups.io
Cc: Dong, Eric 
Subject: Re: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages 
for DXE instance

Jian,
Ia32/ExceptionHandlerAsm.nasm is used by 32bit DxeCpuExceptionHandlerLib 
instance.

I agree the commit message is not correct. The commit message says
SEC still creates 32 entries but 32bit SEC creates 256 entries.

I will update the commit message to align to code behavior.

Thanks,
Ray


From: Wang, Jian J mailto:jian.j.w...@intel.com>>
Sent: Monday, May 23, 2022 0:40
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Ni, Ray
Cc: Dong, Eric
Subject: RE: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages 
for DXE instance

Ray,

You changed "%rep 32" to "%rep 256" in Ia32/ExceptionHandlerAsm.nasm.
According to my understanding and your comments, this should be done
only to X64 code, right?

Regards,
Jian

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Ni, Ray
> Sent: Friday, May 20, 2022 10:16 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Dong, Eric mailto:eric.d...@intel.com>>
> Subject: [edk2-devel] [PATCH 1/5] CpuException: Avoid allocating code pages
> for DXE instance
>
> Today the DXE instance allocates code page and then copies the IDT
> vectors to the allocated code page. Then it fixes up the vector number
> in the IDT vector.
>
> But if we update the NASM file to generate 256 IDT vectors, there is
> no need to do the copy and fix-up.
>
> A side effect is up to 4096 bytes (HOOKAFTER_STUB_SIZE * 256) is
> used for 256 IDT vectors. While 32 IDT vectors only require 512 bytes.
>
> But considering the code logic simplification, 3.5K space is not a big
> deal. SEC instance still generates 32 IDT vectors so no impact to SEC.
> If 3.5K is too much a waste in PEI phase, we can enhance the code
> further to generate 32 vectors for PEI.
>
> Signed-off-by: Ray Ni mailto:ray...@intel.com>>
> Cc: Eric Dong mailto:eric.d...@intel.com>>
> ---
>  .../CpuExceptionHandlerLib/DxeException.c | 22 ---
>  .../Ia32/ExceptionHandlerAsm.nasm |  4 ++--
>  .../X64/ExceptionHandlerAsm.nasm  |  2 ++
>  .../X64/Xcode5ExceptionHandlerAsm.nasm|  9 
>  4 files changed, 9 insertions(+), 28 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> index 61f11e98f8..5083c4b8e8 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
> @@ -95,9 +95,6 @@ InitializeCpuInterruptHandlers (
>IA32_DESCRIPTOR IdtDescriptor;
>
>UINTN   IdtEntryCount;
>
>EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;
>
> -  UINTN   Index;
>
> -  UINTN   InterruptEntry;
>
> -  UINT8   *InterruptEntryCode;
>
>RESERVED_VECTORS_DATA   *ReservedVectors;
>
>EFI_CPU_INTERRUPT_HANDLER   *ExternalInterruptHandler;
>
>
>
> @@ -138,25 +135,6 @@ InitializeCpuInterruptHandlers (
>AsmGetTemplateAddressMap ();
>
>ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
>
>
>
> -  Status = gBS->AllocatePool (
>
> -  EfiBootServicesCode,
>
> -  TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,
>
> -  (VOID **)
>
> -  );
>
> -  ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);
>
> -
>
> -  InterruptEntry = (UINTN)InterruptEntryCode;
>
> -  for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {
>
> -CopyMem (
>
> -  (VOID *)InterruptEntry,
>
> -  (VOID *)TemplateMap.ExceptionStart,
>
> -  TemplateMap.ExceptionStubHeaderSize
>
> -  );
>
> -AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID
> *)TemplateMap.ExceptionStart);
>
> -InterruptEntry += TemplateMap.ExceptionStubHeaderSize;
>
> -  }
>
> -
>
> -  TemplateMap.ExceptionStart = (UINTN)InterruptEntryCode;
>
>mExceptionHandlerData.IdtEntryCount= CPU_INTERRUPT_NUM;
>
>mExceptionHandlerData.ReservedVectors  = ReservedVectors;
>
>mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;
>
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/E

Re: [edk2-devel] [edk2-platforms: PATCH] MinPlatformPkg/SaveMemoryConfig: Fix GCC build failure.

2022-02-17 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Chiu, Chasel  
Sent: Friday, February 18, 2022 10:52 AM
To: devel@edk2.groups.io
Cc: Chiu, Chasel ; Desimone, Nathaniel L 
; Gao, Liming ; Dong, 
Eric 
Subject: [edk2-platforms: PATCH] MinPlatformPkg/SaveMemoryConfig: Fix GCC build 
failure.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3829

Commit cbc8e420ac4505e9c51aa0d4f049026691024ca5 caused GCC build failure which 
should be fixed.

Cc: Nate DeSimone 
Cc: Liming Gao 
Cc: Eric Dong 
Signed-off-by: Chasel Chiu 
---
 
Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c
 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c
 
b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c
index 3a9869ff9c..de23ae6160 100644
--- 
a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWriteLib.c
+++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVa
+++ riableWriteLib.c
@@ -485,7 +485,7 @@ LockLargeVariable (
   ) {   CHAR16TempVariableName[MAX_VARIABLE_NAME_SIZE];-  UINT64   
 VariableSize;+  UINTN VariableSize;   EFI_STATUSStatus;   UINTN
 Index; -- 
2.28.0.windows.1



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




Re: [edk2-devel] [Patch V2] MinPlatformPkg: Check if Acpi table is already installed.

2021-12-06 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Sravanthi, K KavyaX  
Sent: Monday, December 6, 2021 2:16 PM
To: devel@edk2.groups.io
Cc: Sravanthi, K KavyaX ; Chiu, Chasel 
; Desimone, Nathaniel L 
; Liming Gao ; Dong, 
Eric 
Subject: [Patch V2] MinPlatformPkg: Check if Acpi table is already installed.

Check if Acpi table is already installed by locating the first ACPI table in 
XSDT/RSDT based on Signature

Cc: Chasel Chiu 
Cc: Nate DeSimone 
Cc: Liming Gao 
Cc: Eric Dong 
Signed-off-by: kavya 
Reviewed-by: Zhiguang Liu 
---
 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 18 
++
 1 file changed, 18 insertions(+)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c 
b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 785cf4c2f9..dcbb8b7c7f 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -1048,12 +1048,21 @@ InstallMcfgFromScratch (  {
   EFI_STATUS   
 Status;
   EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER   
 *McfgTable;
+  EFI_ACPI_COMMON_HEADER   
 *Mcfg;
   
EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE
 *Segment;
   UINTN
 Index;
   UINTN
 SegmentCount;
   PCI_SEGMENT_INFO 
 *PciSegmentInfo;
   UINTN
 TableHandle;
 
+  Mcfg = (EFI_ACPI_COMMON_HEADER *) EfiLocateFirstAcpiTable (
+  
EFI_ACPI_3_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
+  );  if (Mcfg != NULL) {
+DEBUG ((DEBUG_INFO, "MCFG table already installed\n"));
+return EFI_SUCCESS;
+  }
+
   PciSegmentInfo = GetPciSegmentInfo ();
 
   McfgTable = AllocateZeroPool (
@@ -1365,6 +1374,7 @@ UpdateLocalTable (  {
   EFI_STATUSStatus;
   EFI_ACPI_COMMON_HEADER*CurrentTable;
+  EFI_ACPI_COMMON_HEADER*Table;
   EFI_ACPI_TABLE_VERSIONVersion;
   UINTN TableHandle;
   UINTN Index;
@@ -1372,6 +1382,14 @@ UpdateLocalTable (
   for (Index = 0; Index < sizeof(mLocalTable)/sizeof(mLocalTable[0]); Index++) 
{
 CurrentTable = mLocalTable[Index];
 
+Table = (EFI_ACPI_COMMON_HEADER *) EfiLocateFirstAcpiTable 
(CurrentTable->Signature);
+if (Table != NULL) {
+  DEBUG ((DEBUG_INFO, "Acpi table with signature=%c%c%c%c already 
installed\n",
+((CHAR8*)>Signature)[0], 
((CHAR8*)>Signature)[1],
+((CHAR8*)>Signature)[2], 
((CHAR8*)>Signature)[3]));
+  continue;
+}
+
 PlatformUpdateTables (CurrentTable, );
 
 TableHandle = 0;
--
2.16.2.windows.1



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




[edk2-devel] [PATCH][Edk2 Platform] UserAuthFeaturePkg: Add boot menu return status code to trigger function.

2021-12-06 Thread Dong, Eric
From: Bo Chang Ke 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3764

BIOS password is not required when overriding boot device via F7 hotkey.
Add boot menu return status code in callback function
for ReportStatusCode() notification.

Signed-off-by: Bo Chang Ke 
Cc: Sai Chaganty 
Cc: Liming Gao 
Cc: Dandan Bi 
---
 .../UserAuthenticationDxeSmm/UserAuthenticationDxe.c   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationDxe.c
 
b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationDxe.c
index bba2057a96..4433fb1a20 100644
--- 
a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationDxe.c
+++ 
b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationDxe.c
@@ -355,7 +355,8 @@ CheckForPassword (
   BOOLEAN   PasswordSet;
 
   if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) &&
-  (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP))) {
+ ((Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)) ||
+ ((Value == (EFI_SOFTWARE_DXE_BS_DRIVER | 
EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT) {
 //
 // Check whether enter setup page.
 //
-- 
2.26.2.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and GetCpuSteppingId

2021-11-09 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, October 19, 2021 2:42 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Kumar, Rahul1 
Subject: [PATCH] UefiCpuPkg/UefiCpuLib: Add GetCpuFamilyModel and 
GetCpuSteppingId

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3698

Lots of code relies on CPU Family/Model/Stepping for different logics.

The change adds two APIs for such needs.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Include/Library/UefiCpuLib.h   | 23 +-
 .../Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 43 +++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Include/Library/UefiCpuLib.h 
b/UefiCpuPkg/Include/Library/UefiCpuLib.h
index 5326e72463..092c1d2116 100644
--- a/UefiCpuPkg/Include/Library/UefiCpuLib.h
+++ b/UefiCpuPkg/Include/Library/UefiCpuLib.h
@@ -4,7 +4,7 @@
   This library class defines some routines that are generic for IA32 family CPU

   to be UEFI specification compliant.

 

-  Copyright (c) 2009, Intel Corporation. All rights reserved.

+  Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.

   Copyright (c) 2020, AMD Inc. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

@@ -43,4 +43,25 @@ StandardSignatureIsAuthenticAMD (
   VOID

   );

 

+/**

+  Return the 32bit CPU family and model value.

+

+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.

+**/

+UINT32

+EFIAPI

+GetCpuFamilyModel (

+  VOID

+  );

+

+/**

+  Return the CPU stepping ID.

+  @return CPU stepping ID value in CPUID[01h].EAX.

+**/

+UINT8

+EFIAPI

+GetCpuSteppingId (

+  VOID

+  );

+

 #endif

diff --git a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c 
b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
index c2cc3ff9a7..50891618c4 100644
--- a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
+++ b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
@@ -4,6 +4,7 @@
   The library routines are UEFI specification compliant.

 

   Copyright (c) 2020, AMD Inc. All rights reserved.

+  Copyright (c) 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -36,3 +37,45 @@ StandardSignatureIsAuthenticAMD (
   RegEcx == CPUID_SIGNATURE_AUTHENTIC_AMD_ECX &&

   RegEdx == CPUID_SIGNATURE_AUTHENTIC_AMD_EDX);

 }

+

+/**

+  Return the 32bit CPU family and model value.

+

+  @return CPUID[01h].EAX with Processor Type and Stepping ID cleared.

+**/

+UINT32

+EFIAPI

+GetCpuFamilyModel (

+  VOID

+  )

+{

+  CPUID_VERSION_INFO_EAX  Eax;

+

+  AsmCpuid (CPUID_VERSION_INFO, , NULL, NULL, NULL);

+

+  //

+  // Mask other fields than Family and Model.

+  //

+  Eax.Bits.SteppingId= 0;

+  Eax.Bits.ProcessorType = 0;

+  Eax.Bits.Reserved1 = 0;

+  Eax.Bits.Reserved2 = 0;

+  return Eax.Uint32;

+}

+

+/**

+  Return the CPU stepping ID.

+  @return CPU stepping ID value in CPUID[01h].EAX.

+**/

+UINT8

+EFIAPI

+GetCpuSteppingId (

+  VOID

+  )

+{

+  CPUID_VERSION_INFO_EAX  Eax;

+

+  AsmCpuid (CPUID_VERSION_INFO, , NULL, NULL, NULL);

+

+  return (UINT8) Eax.Bits.SteppingId;

+}

-- 
2.32.0.windows.1



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




Re: [edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated

2021-09-29 Thread Dong, Eric
Hi,

Can you help to explain more why PeiAllocatePages does not have the problem 
while PeiAllocatePool has?

Thanks,
Eric

-Original Message-
From: Lou, Yun  
Sent: Wednesday, September 29, 2021 7:53 PM
To: devel@edk2.groups.io
Cc: Lou, Yun ; Ni, Ray ; Dong, Eric 
; Laszlo Ersek ; Kumar, Rahul1 

Subject: [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be 
migrated

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3634

The memory allocated through "PeiAllocatePool" is located in HOB, and
in DXE phase, the HOB will be migrated to a different location.
After the migration, the data stored in the HOB stays the same, but the
address of pointer to the memory(such as the pointers in ACPI_CPU_DATA
structure) changes, which may cause "PiSmmCpuDxeSmm" driver can't find
the memory(the pointers in ACPI_CPU_DATA structure) that allocated in
"PeiRegisterCpuFeaturesLib", so use "PeiAllocatePages" to allocate
memory instead.

Signed-off-by: Jason Lou 
Cc: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c 
b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 6e2ab79518..e9eba64914 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
@@ -153,7 +153,7 @@ CpuInitDataInitialize (
   CpuFeaturesData->AcpiCpuData= AcpiCpuData;

 

   CpuStatus = >CpuFeatureInitData.CpuStatus;

-  Location = AllocateZeroPool (sizeof (EFI_CPU_PHYSICAL_LOCATION) * 
NumberOfCpus);

+  Location = AllocatePages (EFI_SIZE_TO_PAGES (sizeof 
(EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));

   ASSERT (Location != NULL);

   AcpiCpuData->CpuFeatureInitData.ApLocation = 
(EFI_PHYSICAL_ADDRESS)(UINTN)Location;

 

@@ -205,11 +205,11 @@ CpuInitDataInitialize (
   //

   // Collect valid core count in each package because not all cores are valid.

   //

-  ThreadCountPerPackage = AllocateZeroPool (sizeof (UINT32) * 
CpuStatus->PackageCount);

+  ThreadCountPerPackage = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT32) * 
CpuStatus->PackageCount));

   ASSERT (ThreadCountPerPackage != NULL);

   CpuStatus->ThreadCountPerPackage = 
(EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerPackage;

 

-  ThreadCountPerCore = AllocateZeroPool (sizeof (UINT8) * 
CpuStatus->PackageCount * CpuStatus->MaxCoreCount);

+  ThreadCountPerCore = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT8) * 
CpuStatus->PackageCount * CpuStatus->MaxCoreCount));

   ASSERT (ThreadCountPerCore != NULL);

   CpuStatus->ThreadCountPerCore = 
(EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;

 

-- 
2.28.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/ExceptionLib: Conditionally clear shadow stack token busy bit

2021-07-05 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Sheng, W  
Sent: Friday, July 2, 2021 1:29 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Laszlo Ersek 
; Kumar, Rahul1 ; Yao, Jiewen 
; Zhuang, Qihua ; Dong, Daquan 
; Tong, Justin ; Xu, Tom 

Subject: [PATCH] UefiCpuPkg/ExceptionLib: Conditionally clear shadow stack 
token busy bit

When enter SMM exception, there will be a stack switch only if the IST field of 
the interrupt gate is set. When CET shadow stack feature is enabled, if there 
is a stack switch between SMM exception and SMM, the shadow stack token busy 
bit needs to be cleared when return from SMM exception to SMM. In UEFI BIOS, 
only page fault exception does the stack swith when SMM shack guard feature is 
enabled. The condition of clear shadow stack token busy bit should be SMM stack 
guard enabled, CET shadows stack feature enabled and page fault exception.
The shadow stack token should be initialized by UINT64.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3462

Signed-off-by: Sheng Wei 
Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
Cc: Jiewen Yao 
Cc: Qihua Zhuang 
Cc: Daquan Dong 
Cc: Justin Tong 
Cc: Tom Xu 
---
 .../X64/Xcode5ExceptionHandlerAsm.nasm | 83 +++---
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c   |  2 +-
 2 files changed, 43 insertions(+), 42 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
index ebe0eec874..4881a02848 100644
--- 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandl
+++ erAsm.nasm
@@ -20,6 +20,7 @@
 ;
 
 %define VC_EXCEPTION 29
+%define PF_EXCEPTION 14
 
 extern ASM_PFX(mErrorCodeFlag); Error code flags for exceptions
 extern ASM_PFX(mDoFarReturnFlag)  ; Do far return flag @@ -279,6 +280,46 @@ 
DrFinish:
 callASM_PFX(CommonExceptionHandler)
 add rsp, 4 * 8 + 8
 
+; The follow algorithm is used for clear shadow stack token busy bit.
+; The comment is based on the sample shadow stack.
+; The sample shadow stack layout :
+; Address | Context
+; +-+
+;  0xFD0  |   FREE  | it is 0xFD8|0x02|(LMA & CS.L), after 
SAVEPREVSSP.
+; +-+
+;  0xFD8  |  Prev SSP   |
+; +-+
+;  0xFE0  |   RIP   |
+; +-+
+;  0xFE8  |   CS|
+; +-+
+;  0xFF0  |  0xFF0 | BUSY   | BUSY flag cleared after CLRSSBSY
+; +-+
+;  0xFF8  | 0xFD8|0x02|(LMA & CS.L) |
+; +-+
+; Instructions for Intel Control Flow Enforcement Technology (CET) are 
supported since NASM version 2.15.01.
+cmp qword [ASM_PFX(mDoFarReturnFlag)], 0
+jz  CetDone
+cmp qword [rbp + 8], PF_EXCEPTION   ; check if it is a Page Fault
+jnz CetDone
+cmp byte [dword ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))], 0
+jz  CetDone
+mov rax, cr4
+and rax, 0x80   ; check if CET is enabled
+jz  CetDone
+; SSP should be 0xFD8 at this point
+mov rax, 0x04   ; advance past cs:lip:prevssp;supervisor 
shadow stack token
+INCSSP_RAX  ; After this SSP should be 0xFF8
+SAVEPREVSSP ; now the shadow stack restore token will be 
created at 0xFD0
+READSSP_RAX ; Read new SSP, SSP should be 0x1000
+sub rax, 0x10
+CLRSSBSY_RAX; Clear token at 0xFF0, SSP should be 0 after 
this
+sub rax, 0x20
+RSTORSSP_RAX; Restore to token at 0xFD0, new SSP will be 
0xFD0
+mov rax, 0x01   ; Pop off the new save token created
+INCSSP_RAX  ; SSP should be 0xFD8 now
+CetDone:
+
 cli
 ;; UINT64  ExceptionData;
 add rsp, 8
@@ -373,47 +414,7 @@ DoReturn:
 pushqword [rax + 0x18]   ; save EFLAGS in new location
 mov rax, [rax]; restore rax
 popfq ; restore EFLAGS
-
-; The follow algorithm is used for clear shadow stack token busy bit.
-; The comment is based on the sample shadow stack.
-; The sample shadow stack layout :
-; Address | Context
-; +-+
-;  0xFD0  |   FREE  | it is 0xFD8|0x02|(LMA & CS.L), after 
SAVEPREVSSP.
-; +-+
-;  0xFD8  |  Prev SSP   |
-; +-+
-;  0xFE0  |   RIP   |
-; +-+
-;  0

Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpu: Remove hardcode 48 address size limitation

2021-05-12 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Wednesday, May 12, 2021 12:53 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH] UefiCpuPkg/PiSmmCpu: Remove hardcode 48 address size limitation

5-level paging can be enabled on CPU which supports up to 52 physical
address size. But when the feature was enabled, the 48 address size
limit was not removed and the 5-level paging testing didn't access
address >= 2^48. So the issue wasn't detected until recently an
address >= 2^48 is accessed.

Change-Id: Iaedc73be318d4b4122071efc3ba6e967a4b58fc3
Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index fd6583f9d1..89143810b6 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1887,11 +1887,13 @@ InitializeMpServiceData (
   IN UINTN   ShadowStackSize

   )

 {

-  UINT32Cr3;

-  UINTN Index;

-  UINT8 *GdtTssTables;

-  UINTN GdtTableStepSize;

-  CPUID_VERSION_INFO_EDXRegEdx;

+  UINT32  Cr3;

+  UINTN   Index;

+  UINT8   *GdtTssTables;

+  UINTN   GdtTableStepSize;

+  CPUID_VERSION_INFO_EDX  RegEdx;

+  UINT32  MaxExtendedFunction;

+  CPUID_VIR_PHY_ADDRESS_SIZE_EAX  VirPhyAddressSize;

 

   //

   // Determine if this CPU supports machine check

@@ -1918,9 +1920,17 @@ InitializeMpServiceData (
   // Initialize physical address mask

   // NOTE: Physical memory above virtual address limit is not supported !!!

   //

-  AsmCpuid (0x8008, (UINT32*), NULL, NULL, NULL);

-  gPhyMask = LShiftU64 (1, (UINT8)Index) - 1;

-  gPhyMask &= (1ull << 48) - EFI_PAGE_SIZE;

+  AsmCpuid (CPUID_EXTENDED_FUNCTION, , NULL, NULL, NULL);

+  if (MaxExtendedFunction >= CPUID_VIR_PHY_ADDRESS_SIZE) {

+AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, , NULL, 
NULL, NULL);

+  } else {

+VirPhyAddressSize.Bits.PhysicalAddressBits = 36;

+  }

+  gPhyMask  = LShiftU64 (1, VirPhyAddressSize.Bits.PhysicalAddressBits) - 1;

+  //

+  // Clear the low 12 bits

+  //

+  gPhyMask &= 0xf000ULL;

 

   //

   // Create page tables

-- 
2.31.1.windows.1



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




Re: [edk2-devel] [PATCH 4/4] UefiCpuPkg/MpInitLib: Consume MicrocodeLib to remove duplicated code

2021-04-08 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, April 2, 2021 1:58 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH 4/4] UefiCpuPkg/MpInitLib: Consume MicrocodeLib to remove 
duplicated code

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   1 +
 UefiCpuPkg/Library/MpInitLib/Microcode.c  | 484 --
 UefiCpuPkg/Library/MpInitLib/MpLib.h  |   1 +
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   1 +
 4 files changed, 96 insertions(+), 391 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 860a9750e2..d34419c2a5 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -52,6 +52,7 @@ [LibraryClasses]
   SynchronizationLib

   PcdLib

   VmgExitLib

+  MicrocodeLib

 

 [Protocols]

   gEfiTimerArchProtocolGuid ## SOMETIMES_CONSUMES

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 297c2abcd1..105a9f84bf 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -1,70 +1,16 @@
 /** @file

   Implementation of loading microcode on processors.

 

-  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.

+  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

 

 #include "MpLib.h"

 

-/**

-  Get microcode update signature of currently loaded microcode update.

-

-  @return  Microcode signature.

-**/

-UINT32

-GetCurrentMicrocodeSignature (

-  VOID

-  )

-{

-  MSR_IA32_BIOS_SIGN_ID_REGISTER   BiosSignIdMsr;

-

-  AsmWriteMsr64 (MSR_IA32_BIOS_SIGN_ID, 0);

-  AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, NULL);

-  BiosSignIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_BIOS_SIGN_ID);

-  return BiosSignIdMsr.Bits.MicrocodeUpdateSignature;

-}

-

 /**

   Detect whether specified processor can find matching microcode patch and 
load it.

 

-  Microcode Payload as the following format:

-  ++--+

-  |  CPU_MICROCODE_HEADER  |  |

-  ++  CheckSum Part1  |

-  |Microcode Binary|  |

-  ++--+

-  |  CPU_MICROCODE_EXTENDED_TABLE_HEADER   |  |

-  ++  CheckSum Part2  |

-  |  CPU_MICROCODE_EXTENDED_TABLE  |  |

-  |   ...  |  |

-  ++--+

-

-  There may by multiple CPU_MICROCODE_EXTENDED_TABLE in this format.

-  The count of CPU_MICROCODE_EXTENDED_TABLE is indicated by 
ExtendedSignatureCount

-  of CPU_MICROCODE_EXTENDED_TABLE_HEADER structure.

-

-  When we are trying to verify the CheckSum32 with extended table.

-  We should use the fields of exnteded table to replace the corresponding

-  fields in CPU_MICROCODE_HEADER structure, and recalculate the

-  CheckSum32 with CPU_MICROCODE_HEADER + Microcode Binary. We named

-  it as CheckSum Part3.

-

-  The CheckSum Part2 is used to verify the CPU_MICROCODE_EXTENDED_TABLE_HEADER

-  and CPU_MICROCODE_EXTENDED_TABLE parts. We should make sure CheckSum Part2

-  is correct before we are going to verify each CPU_MICROCODE_EXTENDED_TABLE.

-

-  Only ProcessorSignature, ProcessorFlag and CheckSum are different between

-  CheckSum Part1 and CheckSum Part3. To avoid multiple computing CheckSum 
Part3.

-  Save an in-complete CheckSum32 from CheckSum Part1 for common parts.

-  When we are going to calculate CheckSum32, just should use the corresponding 
part

-  of the ProcessorSignature, ProcessorFlag and CheckSum with in-complete 
CheckSum32.

-

-  Notes: CheckSum32 is not a strong verification.

- It does not guarantee that the data has not been modified.

- CPU has its own mechanism to verify Microcode Binary part.

-

   @param[in]  CpuMpDataThe pointer to CPU MP Data structure.

   @param[in]  ProcessorNumber  The handle number of the processor. The range is

from 0 to the total number of logical processors

@@ -76,26 +22,13 @@ MicrocodeDetect (
   IN UINTN   ProcessorNumber

   )

 {

-  UINT32  ExtendedTableLength;

-  UINT32  ExtendedTableCount;

-  CPU_MICROCODE_EXTENDED_TABLE*ExtendedTable;

-  CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader;

-  CPU_MICROCODE_HEADER*MicrocodeEntryPoint;

+  CPU_MICROCODE_HEADER*Microcode;

Re: [edk2-devel] [PATCH 1/4] UefiCpuPkg: Add MicrocodeLib for loading microcode

2021-04-07 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, April 2, 2021 1:58 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH 1/4] UefiCpuPkg: Add MicrocodeLib for loading microcode

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Include/Library/MicrocodeLib.h | 120 +++
 .../Library/MicrocodeLib/MicrocodeLib.c   | 322 ++
 .../Library/MicrocodeLib/MicrocodeLib.inf |  32 ++
 UefiCpuPkg/UefiCpuPkg.dec |   5 +-
 UefiCpuPkg/UefiCpuPkg.dsc |   1 +
 5 files changed, 479 insertions(+), 1 deletion(-)
 create mode 100644 UefiCpuPkg/Include/Library/MicrocodeLib.h
 create mode 100644 UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.c
 create mode 100644 UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf

diff --git a/UefiCpuPkg/Include/Library/MicrocodeLib.h 
b/UefiCpuPkg/Include/Library/MicrocodeLib.h
new file mode 100644
index 00..2570c43cce
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/MicrocodeLib.h
@@ -0,0 +1,120 @@
+/** @file

+  Public include file for Microcode library.

+

+  Copyright (c) 2021, Intel Corporation. All rights reserved.

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef __MICROCODE_LIB_H__

+#define __MICROCODE_LIB_H__

+

+#include 

+#include 

+

+/**

+  Get microcode update signature of currently loaded microcode update.

+

+  @return  Microcode signature.

+**/

+UINT32

+EFIAPI

+GetProcessorMicrocodeSignature (

+  VOID

+  );

+

+/**

+  Get the processor signature and platform ID for current processor.

+

+  @param MicrocodeCpuId  Return the processor signature and platform ID.

+**/

+VOID

+EFIAPI

+GetProcessorMicrocodeCpuId (

+  EDKII_PEI_MICROCODE_CPU_ID  *MicrocodeCpuId

+  );

+

+/**

+  Return the total size of the microcode entry.

+

+  Logic follows pseudo code in SDM as below:

+

+ N = 512

+ If (Update.DataSize != H)

+   N = Update.TotalSize / 4

+

+  If Microcode is NULL, then ASSERT.

+

+  @param Microcode  Pointer to the microcode entry.

+

+  @return The microcode total size.

+**/

+UINT32

+EFIAPI

+GetMicrocodeLength (

+  IN CPU_MICROCODE_HEADER *Microcode

+  );

+

+/**

+  Load the microcode to the processor.

+

+  If Microcode is NULL, then ASSERT.

+

+  @param Microcode  Pointer to the microcode entry.

+**/

+VOID

+EFIAPI

+LoadMicrocode (

+  IN CPU_MICROCODE_HEADER *Microcode

+  );

+

+/**

+  Detect whether specified processor can find matching microcode patch and 
load it.

+

+  Microcode format is as below:

+  
++-+

+  |  CPU_MICROCODE_HEADER  |   
  |

+  ++   
  V

+  |  Update Data   |   
CPU_MICROCODE_HEADER.Checksum

+  ++---+   
  ^

+  |  CPU_MICROCODE_EXTENDED_TABLE_HEADER   |   |   
  |

+  ++   V   
  |

+  |  CPU_MICROCODE_EXTENDED_TABLE[0]   |  
CPU_MICROCODE_EXTENDED_TABLE_HEADER.Checksum   |

+  |  CPU_MICROCODE_EXTENDED_TABLE[1]   |   ^   
  |

+  |   ...  |   |   
  |

+  
++---+-+

+

+  There may by multiple CPU_MICROCODE_EXTENDED_TABLE in this format.

+  The count of CPU_MICROCODE_EXTENDED_TABLE is indicated by 
ExtendedSignatureCount

+  of CPU_MICROCODE_EXTENDED_TABLE_HEADER structure.

+

+  If Microcode is NULL, then ASSERT.

+

+  @param MicrocodePointer to a microcode entry.

+  @param MicrocodeLength  The total length of the microcode entry.

+  @param MinimumRevision  The microcode whose revision <= MinimumRevision 
is treated as invalid.

+  Caller can supply value get from 
GetProcessorMicrocodeSignature() to check

+  whether the microcode is newer than loaded one.

+  Caller can supply 0 to treat any revision 
(except 0) microcode as valid.

+  @param MicrocodeCpuIds  Pointer to an array of processor signature and 
platform ID that represents

+  a set of processors.

+  Caller can supply zero-element array to skip the 
processor signature and

+  platform ID check.

+  @param MicrocodeCpuIdCount  The number of elements in MicrocodeCpuIds.

+  @param VerifyChecksum   FALSE to skip all the check

Re: [edk2-devel] [patch V2 25/29] UefiCpuPkg: Consume MdeLibs.dsc.inc for RegisterFilterLib

2021-03-25 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Bi, Dandan  
Sent: Monday, March 22, 2021 4:10 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Laszlo Ersek 
; Kumar, Rahul1 
Subject: [patch V2 25/29] UefiCpuPkg: Consume MdeLibs.dsc.inc for 
RegisterFilterLib

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3246

MdeLibs.dsc.inc was added for some basic/default library instances provided by 
MdePkg and RegisterFilterLibNull Library was also added into it as the first 
version of MdeLibs.dsc.inc.

So update platform dsc to consume MdeLibs.dsc.inc for RegisterFilterLibNull 
which will be consumed by IoLib and BaseLib.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
Signed-off-by: Dandan Bi 
---
 UefiCpuPkg/UefiCpuPkg.dsc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 
7db419471d..6c7cc6b273 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -1,9 +1,9 @@
 ## @file
 #  UefiCpuPkg Package
 #
-#  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
+#  Copyright (c) 2007 - 2021, Intel Corporation. All rights 
+reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ##
 
@@ -20,10 +20,12 @@ [Defines]
 #
 # External libraries to build package
 #
 
 [LibraryClasses]
+  !include MdePkg/MdeLibs.dsc.inc
+
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
   SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
--
2.18.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/SmmCommunication: Remove out-dated comments

2021-03-23 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, March 23, 2021 9:15 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH] UefiCpuPkg/SmmCommunication: Remove out-dated comments

The comments in PiSmmCommunicationPei.c describe the whole memory
layout of the SMRAM regarding the SMM communication.

But SHA-1: 8b1d14939053b63d80355465649c50f9f391a64a
PiSmmCommunicationSmm: Deprecate SMM Communication ACPI Table
removed the code that produces the ACPI Table.

This change updates the accordingly comments.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 .../PiSmmCommunication/PiSmmCommunicationPei.c   | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.c 
b/UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.c
index 68e5003ad4..110165b20b 100644
--- a/UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.c
+++ b/UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.c
@@ -1,7 +1,7 @@
 /** @file

 PiSmmCommunication PEI Driver.

 

-Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.

+Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.

 SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -47,16 +47,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
   +--+<--

   | EFI_SMM_COMMUNICATION_CONTEXT|

   |   SwSmiNumber| <- SMRAM

-  |   BufferPtrAddress   |

-  +--+|

-  |

-  +--+|

-  | EFI_SMM_COMMUNICATION_ACPI_TABLE ||

-  |   SwSmiNumber| <- AcpiTable   |

-  |   BufferPtrAddress   |--- |

-  +--+   ||

- ||

-  +--+<---

+  |   BufferPtrAddress   |---

+  +--+   |

+ |

+  +--+<--

   | Communication Buffer Pointer | <- AcpiNvs

   +--+---

  |

-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH v2 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII coding standard

2021-03-17 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Wednesday, March 17, 2021 7:07 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v2 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII 
coding standard

The change doesn't impact any functionality.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/CpuDxe/CpuGdt.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c index 
a1ab543f2d..8847bc4819 100644
--- a/UefiCpuPkg/CpuDxe/CpuGdt.c
+++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
@@ -2,7 +2,7 @@
   C based implementation of IA32 interrupt handling only   requiring a minimal 
assembly interrupt entry point. -  Copyright (c) 2006 - 2015, Intel 
Corporation. All rights reserved.+  Copyright (c) 2006 - 2021, Intel 
Corporation. All rights reserved.   SPDX-License-Identifier: 
BSD-2-Clause-Patent  **/@@ -13,7 +13,7 @@
 // // Global descriptor table (GDT) Template //-STATIC GDT_ENTRIES GdtTemplate 
= {+STATIC GDT_ENTRIES mGdtTemplate = {   //   // NULL_SEL   //@@ -124,27 
+124,27 @@ InitGlobalDescriptorTable (
   VOID   ) {-  GDT_ENTRIES *gdt;-  IA32_DESCRIPTOR gdtPtr;+  GDT_ENTRIES   
*Gdt;+  IA32_DESCRIPTOR   Gdtr;//   // Allocate Runtime Data for 
the GDT   //-  gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);-  ASSERT 
(gdt != NULL);-  gdt = ALIGN_POINTER (gdt, 8);+  Gdt = AllocateRuntimePool 
(sizeof (mGdtTemplate) + 8);+  ASSERT (Gdt != NULL);+  Gdt = ALIGN_POINTER 
(Gdt, 8);//   // Initialize all GDT entries   //-  CopyMem (gdt, 
, sizeof (GdtTemplate));+  CopyMem (Gdt, , sizeof 
(mGdtTemplate));//   // Write GDT register   //-  gdtPtr.Base = 
(UINT32)(UINTN)(VOID*) gdt;-  gdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 
1);-  AsmWriteGdtr ();+  Gdtr.Base  = (UINT32) (UINTN) Gdt;+  Gdtr.Limit 
= (UINT16) (sizeof (mGdtTemplate) - 1);+  AsmWriteGdtr ();//   // 
Update selector (segment) registers base on new GDT@@ -152,4 +152,3 @@ 
InitGlobalDescriptorTable (
   SetCodeSelector ((UINT16)CPU_CODE_SEL);   SetDataSelectors 
((UINT16)CPU_DATA_SEL); }--- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP

2021-03-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, March 16, 2021 9:52 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v2] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP

MpInitLib contains a function MicrocodeDetect() which is called by
all threads as an AP procedure.
Today this function contains below code:

if (CurrentRevision != LatestRevision) {
  AcquireSpinLock(>MpLock);
  DEBUG ((
EFI_D_ERROR,
"Updated microcode signature [0x%08x] does not match \
loaded microcode signature [0x%08x]\n",
CurrentRevision, LatestRevision
));
  ReleaseSpinLock(>MpLock);
}

When the if-check is passed, the code may call into PEI services:
1. AcquireSpinLock
   When the PcdSpinTimeout is not 0, TimerLib
   GetPerformanceCounterProperties() is called. And some of the
   TimerLib implementations would get the information cached in
   HOB. But AP procedure cannot call PEI services to retrieve the
   HOB list.

2. DEBUG
   Certain DebugLib relies on ReportStatusCode services and the
   ReportStatusCode PPI is retrieved through the PEI services.
   DebugLibSerialPort should be used.
   But when SerialPortLib is implemented to depend on PEI services,
   even using DebugLibSerialPort can still cause AP calls PEI
   services resulting hang.

It causes a lot of debugging effort on the platform side.

There are 2 options to fix the problem:
1. make sure platform DSC chooses the proper DebugLib and set the
   PcdSpinTimeout to 0. So that AcquireSpinLock and DEBUG don't call
   PEI services.
2. remove the AcquireSpinLock and DEBUG call from the procedure.

Option #2 is preferred because it's not practical to ask every
platform DSC to be written properly.

Following option #2, there are two sub-options:
2.A. Just remove the if-check.
2.B. Capture the CurrentRevision and ExpectedRevision in the memory
 for each AP and print them together from BSP.

The patch follows option 2.B.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 11 +--
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 25 
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  1 +
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 15629591e2..297c2abcd1 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -315,17 +315,8 @@ Done:
 MSR_IA32_BIOS_UPDT_TRIG,

 (UINT64) (UINTN) MicrocodeData

 );

-//

-// Get and check new microcode signature

-//

-CurrentRevision = GetCurrentMicrocodeSignature ();

-if (CurrentRevision != LatestRevision) {

-  AcquireSpinLock(>MpLock);

-  DEBUG ((EFI_D_ERROR, "Updated microcode signature [0x%08x] does not 
match \

-loaded microcode signature [0x%08x]\n", CurrentRevision, 
LatestRevision));

-  ReleaseSpinLock(>MpLock);

-}

   }

+  CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision = 
GetCurrentMicrocodeSignature ();

 }

 

 /**

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 5040053dad..3d945972a0 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -2135,6 +2135,31 @@ MpInitLibInitialize (
 }

   }

 

+  //

+  // Dump the microcode revision for each core.

+  //

+  DEBUG_CODE (

+UINT32 ThreadId;

+UINT32 ExpectedMicrocodeRevision;

+CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;

+for (Index = 0; Index < CpuMpData->CpuCount; Index++) {

+  GetProcessorLocationByApicId (CpuInfoInHob[Index].InitialApicId, NULL, 
NULL, );

+  if (ThreadId == 0) {

+//

+// MicrocodeDetect() loads microcode in first thread of each core, so,

+// CpuMpData->CpuData[Index].MicrocodeEntryAddr is initialized only 
for first thread of each core.

+//

+ExpectedMicrocodeRevision = 0;

+if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {

+  ExpectedMicrocodeRevision = ((CPU_MICROCODE_HEADER 
*)(UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision;

+}

+DEBUG ((

+  DEBUG_INFO, "CPU[%04d]: Microcode revision = %08x, expected = 
%08x\n",

+  Index, CpuMpData->CpuData[Index].MicrocodeRevision, 
ExpectedMicrocodeRevision

+  ));

+  }

+}

+  );

   //

   // Initialize global data for MP support

   //

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 0bd60388b1..66f9eb2304 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -144,6 +144,7 @@ typedef str

Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/CpuCacheInfoLib: Collect cache associative type

2021-03-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Lou, Yun  
Sent: Monday, March 15, 2021 9:49 PM
To: devel@edk2.groups.io
Cc: Lou, Yun ; Ni, Ray ; Dong, Eric 
; Laszlo Ersek ; Kumar, Rahul1 

Subject: [PATCH v2 1/1] UefiCpuPkg/CpuCacheInfoLib: Collect cache associative 
type

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3265

Support collecting cache associative type in CpuCacheInfoLib.
This prevents the user from using additional code to obtain the
same information.

Signed-off-by: Jason Lou 
Cc: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c | 49 
+++-
 UefiCpuPkg/Include/Library/CpuCacheInfoLib.h | 15 +-
 UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h | 15 +-
 3 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c 
b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c
index d46fb0425851..126ee0da86fc 100644
--- a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c
+++ b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c
@@ -1,7 +1,7 @@
 /** @file

   Provides cache info for each package, core type, cache level and cache type.

 

-  Copyright (c) 2020 Intel Corporation. All rights reserved.

+  Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -23,18 +23,18 @@ CpuCacheInfoPrintCpuCacheInfoTable (
 {

   UINTN Index;

 

-  DEBUG ((DEBUG_INFO, 
"+---+---+\n"));

-  DEBUG ((DEBUG_INFO, "| Index | Packge  CoreType  CacheLevel  CacheType  
CacheWays  CacheSizeinKB  CacheCount |\n"));

-  DEBUG ((DEBUG_INFO, 
"+---+---+\n"));

+  DEBUG ((DEBUG_INFO, 
"+---+--+\n"));

+  DEBUG ((DEBUG_INFO, "| Index | Packge  CoreType  CacheLevel  CacheType  
CacheWays (FA|DM) CacheSizeinKB  CacheCount |\n"));

+  DEBUG ((DEBUG_INFO, 
"+---+--+\n"));

 

   for (Index = 0; Index < CpuCacheInfoCount; Index++) {

-DEBUG ((DEBUG_INFO, "| %4x  | %4x   %2x%2x  %2x   
%4x  %8x %4x |\n", Index,

-CpuCacheInfo[Index].Package, CpuCacheInfo[Index].CoreType, 
CpuCacheInfo[Index].CacheLevel,

-CpuCacheInfo[Index].CacheType, CpuCacheInfo[Index].CacheWays, 
CpuCacheInfo[Index].CacheSizeinKB,

-CpuCacheInfo[Index].CacheCount));

+DEBUG ((DEBUG_INFO, "| %4x  | %4x   %2x%2x  %2x   
%4x ( %x| %x) %8x %4x |\n",

+Index, CpuCacheInfo[Index].Package, CpuCacheInfo[Index].CoreType, 
CpuCacheInfo[Index].CacheLevel,

+CpuCacheInfo[Index].CacheType, CpuCacheInfo[Index].CacheWays, 
CpuCacheInfo[Index].FullyAssociativeCache,

+CpuCacheInfo[Index].DirectMappedCache, 
CpuCacheInfo[Index].CacheSizeinKB, CpuCacheInfo[Index].CacheCount));

   }

 

-  DEBUG ((DEBUG_INFO, 
"+---+---+\n"));

+  DEBUG ((DEBUG_INFO, 
"+---+--+\n"));

 }

 

 /**

@@ -160,6 +160,7 @@ CpuCacheInfoCollectCoreAndCacheData (
   CPUID_CACHE_PARAMS_EAXCacheParamEax;

   CPUID_CACHE_PARAMS_EBXCacheParamEbx;

   UINT32CacheParamEcx;

+  CPUID_CACHE_PARAMS_EDXCacheParamEdx;

   CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX   NativeModelIdAndCoreTypeEax;

   COLLECT_CPUID_CACHE_DATA_CONTEXT  *Context;

   CPUID_CACHE_DATA  *CacheData;

@@ -185,17 +186,19 @@ CpuCacheInfoCollectCoreAndCacheData (
   CacheParamLeafIndex = 0;

 

   while (CacheParamLeafIndex < MAX_NUM_OF_CACHE_PARAMS_LEAF) {

-AsmCpuidEx (CPUID_CACHE_PARAMS, CacheParamLeafIndex, 
, , , NULL);

+AsmCpuidEx (CPUID_CACHE_PARAMS, CacheParamLeafIndex, 
, , , 
);

 

 if (CacheParamEax.Bits.CacheType == 0) {

   break;

 }

 

-CacheData[CacheParamLeafIndex].CacheLevel = 
(UINT8)CacheParamEax.Bits.CacheLevel;

-CacheData[CacheParamLeafIndex].CacheType  = 
(UINT8)CacheParamEax.Bits.CacheType;

-CacheData[CacheParamLeafIndex].CacheWays  = 
(UINT16)CacheParamEbx.Bits.Ways;

-CacheData[CacheParamLeafIndex].CacheShareBits = 
(UINT16)CacheParamEax.Bits.MaximumAddressableIdsForLogicalProcessors;

-CacheData[CacheParamLeafIndex].CacheSizeinKB  = (CacheParamEbx.Bits.Ways + 
1) *

+CacheData[CacheParamLeafIndex].CacheLevel= 
(UINT8)CacheParamEax.Bits.CacheLevel;

+CacheData[CacheParamLeafIndex].Ca

Re: [edk2-devel] [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB

2021-03-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, March 16, 2021 11:34 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3233

GDT needs to be allocated below 4GB in 64bit environment
because AP needs it for entering to protected mode.
CPU running in big real mode cannot access above 4GB GDT.

But CpuDxe driver contains below code:
  gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
  .
  gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;

The AllocateRuntimePool() may allocate memory above 4GB.
Thus, we cannot use AllocateRuntimePool (), instead,
we should use AllocatePages() to make sure GDT is below 4GB space.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/CpuDxe/CpuGdt.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c
index 322ce87142..98d5551702 100644
--- a/UefiCpuPkg/CpuDxe/CpuGdt.c
+++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
@@ -124,15 +124,26 @@ InitGlobalDescriptorTable (
   VOID

   )

 {

+  EFI_STATUSStatus;

   GDT_ENTRIES   *Gdt;

   IA32_DESCRIPTOR   Gdtr;

+  EFI_PHYSICAL_ADDRESS  Memory;

 

   //

-  // Allocate Runtime Data for the GDT

-  //

-  Gdt = AllocateRuntimePool (sizeof (gGdtTemplate) + 8);

-  ASSERT (Gdt != NULL);

-  Gdt = ALIGN_POINTER (Gdt, 8);

+  // Allocate Runtime Data below 4GB for the GDT

+  // AP uses the same GDT when it's waken up from real mode so

+  // the GDT needs to be below 4GB.

+  //

+  Memory = SIZE_4GB - 1;

+  Status = gBS->AllocatePages (

+  AllocateMaxAddress,

+  EfiRuntimeServicesData,

+  EFI_SIZE_TO_PAGES (sizeof (gGdtTemplate)),

+  

+  );

+  ASSERT_EFI_ERROR (Status);

+  ASSERT ((Memory != 0) && (Memory < SIZE_4GB));

+  Gdt = (GDT_ENTRIES *) (UINTN) Memory;

 

   //

   // Initialize all GDT entries

-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII coding standard

2021-03-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, March 16, 2021 11:34 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII coding 
standard

The change doesn't impact any functionality.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/CpuDxe/CpuGdt.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c
index a1ab543f2d..322ce87142 100644
--- a/UefiCpuPkg/CpuDxe/CpuGdt.c
+++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
@@ -2,7 +2,7 @@
   C based implementation of IA32 interrupt handling only

   requiring a minimal assembly interrupt entry point.

 

-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.

+  Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -13,7 +13,7 @@
 //

 // Global descriptor table (GDT) Template

 //

-STATIC GDT_ENTRIES GdtTemplate = {

+STATIC GDT_ENTRIES gGdtTemplate = {

   //

   // NULL_SEL

   //

@@ -124,32 +124,31 @@ InitGlobalDescriptorTable (
   VOID

   )

 {

-  GDT_ENTRIES *gdt;

-  IA32_DESCRIPTOR gdtPtr;

+  GDT_ENTRIES   *Gdt;

+  IA32_DESCRIPTOR   Gdtr;

 

   //

   // Allocate Runtime Data for the GDT

   //

-  gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);

-  ASSERT (gdt != NULL);

-  gdt = ALIGN_POINTER (gdt, 8);

+  Gdt = AllocateRuntimePool (sizeof (gGdtTemplate) + 8);

+  ASSERT (Gdt != NULL);

+  Gdt = ALIGN_POINTER (Gdt, 8);

 

   //

   // Initialize all GDT entries

   //

-  CopyMem (gdt, , sizeof (GdtTemplate));

+  CopyMem (Gdt, , sizeof (gGdtTemplate));

 

   //

   // Write GDT register

   //

-  gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;

-  gdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 1);

-  AsmWriteGdtr ();

+  Gdtr.Base  = (UINT32) (UINTN) Gdt;

+  Gdtr.Limit = (UINT16) (sizeof (gGdtTemplate) - 1);

+  AsmWriteGdtr ();

 

   //

   // Update selector (segment) registers base on new GDT

   //

-  SetCodeSelector ((UINT16)CPU_CODE_SEL);

-  SetDataSelectors ((UINT16)CPU_DATA_SEL);

+  SetCodeSelector  ((UINT16) CPU_CODE_SEL);

+  SetDataSelectors ((UINT16) CPU_DATA_SEL);

 }

-

-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP

2021-03-12 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Friday, March 12, 2021 7:48 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH] UefiCpuPkg/MpInitLib: avoid printing debug messages in AP

MpInitLib contains a function MicrocodeDetect() which is called by
all threads as an AP procedure.
Today this function contains below code:

if (CurrentRevision != LatestRevision) {
  AcquireSpinLock(>MpLock);
  DEBUG ((
EFI_D_ERROR,
"Updated microcode signature [0x%08x] does not match \
loaded microcode signature [0x%08x]\n",
CurrentRevision, LatestRevision
));
  ReleaseSpinLock(>MpLock);
}

When the if-check is passed, the code may call into PEI services:
1. AcquireSpinLock
   When the PcdSpinTimeout is not 0, TimerLib
   GetPerformanceCounterProperties() is called. And some of the
   TimerLib implementations would get the information cached in
   HOB. But AP procedure cannot call PEI services to retrieve the
   HOB list.

2. DEBUG
   Certain DebugLib relies on ReportStatusCode services and the
   ReportStatusCode PPI is retrieved through the PEI services.
   DebugLibSerialPort should be used.
   But when SerialPortLib is implemented to depend on PEI services,
   even using DebugLibSerialPort can still cause AP calls PEI
   services resulting hang.

It causes a lot of debugging effort on the platform side.

There are 2 options to fix the problem:
1. make sure platform DSC chooses the proper DebugLib and set the
   PcdSpinTimeout to 0. So that AcquireSpinLock and DEBUG don't call
   PEI services.
2. remove the AcquireSpinLock and DEBUG call from the procedure.

Option #2 is preferred because it's not practical to ask every
platform DSC to be written properly.

Following option #2, there are two sub-options:
2.A. Just remove the if-check.
2.B. Capture the CurrentRevision and ExpectedRevision in the memory
 for each AP and print them together from BSP.

The patch follows option 2.B.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 11 +--
 UefiCpuPkg/Library/MpInitLib/MpLib.c |  9 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  1 +
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c 
b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 15629591e2..297c2abcd1 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -315,17 +315,8 @@ Done:
 MSR_IA32_BIOS_UPDT_TRIG,

 (UINT64) (UINTN) MicrocodeData

 );

-//

-// Get and check new microcode signature

-//

-CurrentRevision = GetCurrentMicrocodeSignature ();

-if (CurrentRevision != LatestRevision) {

-  AcquireSpinLock(>MpLock);

-  DEBUG ((EFI_D_ERROR, "Updated microcode signature [0x%08x] does not 
match \

-loaded microcode signature [0x%08x]\n", CurrentRevision, 
LatestRevision));

-  ReleaseSpinLock(>MpLock);

-}

   }

+  CpuMpData->CpuData[ProcessorNumber].MicrocodeRevision = 
GetCurrentMicrocodeSignature ();

 }

 

 /**

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 5040053dad..e4baeff894 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1947,6 +1947,7 @@ MpInitLibInitialize (
   UINTNApResetVectorSize;

   UINTNBackupBufferAddr;

   UINTNApIdtBase;

+  UINT32   ExpectedMicrocodeRevision;

 

   OldCpuMpData = GetCpuMpDataFromGuidedHob ();

   if (OldCpuMpData == NULL) {

@@ -2131,6 +2132,14 @@ MpInitLibInitialize (
   CpuMpData->InitFlag = ApInitDone;

 }

 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {

+  ExpectedMicrocodeRevision = 0;

+  if (CpuMpData->CpuData[Index].MicrocodeEntryAddr != 0) {

+ExpectedMicrocodeRevision = ((CPU_MICROCODE_HEADER 
*)(UINTN)CpuMpData->CpuData[Index].MicrocodeEntryAddr)->UpdateRevision;

+  }

+  DEBUG ((

+DEBUG_INFO, "CPU[%04d]: Microcode revision = %08x, expected = %08x\n",

+Index, CpuMpData->CpuData[Index].MicrocodeRevision, 
ExpectedMicrocodeRevision

+));

   SetApState (>CpuData[Index], CpuStateIdle);

 }

   }

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 0bd60388b1..66f9eb2304 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -144,6 +144,7 @@ typedef struct {
   UINT32 ProcessorSignature;

   UINT8  PlatformId;

   UINT64 MicrocodeEntryAddr;

+  UINT32 MicrocodeRevision;

 } CPU_AP_DATA;

 

 //

-- 
2.27.0.windows.1



-

Re: [edk2-devel] [Patch edk2-platforms V3] Intel/BoardModulePkg: sort load option in the first boot

2021-03-10 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Liu, Zhiguang  
Sent: Thursday, March 11, 2021 9:22 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Liming Gao ; 
Desimone, Nathaniel L ; Agyeman, Prince 
; Ni, Ray ; Gao, Zhichao 

Subject: [Patch edk2-platforms V3] Intel/BoardModulePkg: sort load option in 
the first boot

Currently, load option is only sorted when setup is the first priority in boot 
option. However, Below change in UefiBootManagerLib puts setup in the end, 
which causes the sort function won't be called.
  MdeModulePkg/UefiBootManagerLib: Put BootMenu at the end of BootOrder
  SHA-1: 7f34681c488aee2563eaa2afcc6a2c8aa7c5b912

This patch will set a NV variable in the first boot, and sort the boot option 
in first boot.

Cc: Eric Dong 
Cc: Liming Gao 
Cc: Nate DeSimone 
Cc: Prince Agyeman 
Cc: Ray Ni 
Cc: Zhichao Gao 

Signed-off-by: Zhiguang Liu 
---
 Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c | 72 
+---
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git 
a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c 
b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
index d7612fb80a..a37139a007 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHook
+++ Lib.c
@@ -20,6 +20,8 @@
  #include "BoardBdsHook.h" +#define IS_FIRST_BOOT_VAR_NAME L"IsFirstBoot"+ 
GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODEgBootMode; BOOLEAN   
 gPPRequireUIConfirm; extern UINTN  
 mBootMenuOptionNumber;@@ -992,37 +994,6 @@ ConnectSequence (
   EfiBootManagerConnectAll (); } --/**-  The function is to consider the boot 
order which is not in our expectation.-  In the case that we need to re-sort 
the boot option.--  @retval  TRUE Need to sort Boot Option.-  @retval  
FALSEDon't need to sort Boot Option.-**/-BOOLEAN-IsNeedSortBootOption 
(-  VOID-  )-{-  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOptions;-  UINTN
 BootOptionCount;--  BootOptions = EfiBootManagerGetLoadOptions 
(, LoadOptionTypeBoot);--  //-  // If setup is the first 
priority in boot option, we need to sort boot option.-  //-  if 
((BootOptionCount > 1) &&-(((StrnCmp (BootOptions->Description, L"Enter 
Setup", StrLen (L"Enter Setup"))) == 0) ||-((StrnCmp 
(BootOptions->Description, L"BootManagerMenuApp", StrLen 
(L"BootManagerMenuApp"))) == 0))) {-return TRUE;-  }--  return FALSE;-}-- 
/**   Connects Root Bridge  **/@@ -1332,6 +1303,9 @@ 
BdsAfterConsoleReadyBeforeBootOptionCallback (
   ) {   EFI_BOOT_MODE LocalBootMode;+  EFI_STATUS  
  Status;+  BOOLEAN   IsFirstBoot;+  UINTN  
   DataSize;DEBUG ((DEBUG_INFO, "Event 
gBdsAfterConsoleReadyBeforeBootOptionEvent callback starts\n"));   //@@ 
-1376,14 +1350,42 @@ BdsAfterConsoleReadyBeforeBootOptionCallback (
   //   // PXE boot option may appear after boot option enumeration 
  //++  EfiBootManagerRefreshAllBootOption ();+  DataSize = sizeof 
(BOOLEAN);+  Status = gRT->GetVariable (+  
IS_FIRST_BOOT_VAR_NAME,+  ,+   
   NULL,+  ,+  
+  );+  if (EFI_ERROR (Status)) {+
//+// If can't find the variable, see it as the first boot+//+  
  IsFirstBoot = TRUE;+  }++  if (IsFirstBoot) {+//+
// In the first boot, sort the boot option+//+
EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);+  
  IsFirstBoot = FALSE;+Status = gRT->SetVariable (+ 
   IS_FIRST_BOOT_VAR_NAME,+,+  
  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,+ 
   sizeof (BOOLEAN),++  
  );+  }+   break;   }Print (L"Press F7 for 
BootMenu!\n"); -  EfiBootManagerRefreshAllBootOption (); -  if 
(IsNeedSortBootOption()) {-EfiBootManagerSortLoadOptionVariable 
(LoadOptionTypeBoot, CompareBootOption);-  } }-- 
2.30.0.windows.2



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




Re: [edk2-devel] [PATCH v3] UefiCpuPkg/PiSmmCpu: Don't allocate Token for SmmStartupThisAp

2021-03-09 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, March 9, 2021 5:09 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v3] UefiCpuPkg/PiSmmCpu: Don't allocate Token for 
SmmStartupThisAp

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3199

When Token points to mSmmStartupThisApToken, this routine is called
from SmmStartupThisAp() in non-blocking mode due to
PcdCpuSmmBlockStartupThisAp == FALSE.

In this case, caller wants to startup AP procedure in non-blocking
mode and cannot get the completion status from the Token because there
is no way to return the Token to caller from SmmStartupThisAp().
Caller needs to use its specific way to query the completion status.

There is no need to allocate a token for such case so the 3 overheads
can be avoided:
1. Call AllocateTokenBuffer() when there is no free token.
2. Get a free token from the token buffer.
3. Call ReleaseToken() in APHandler().

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Reviewed-by: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 30 ---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 6227b2428a..4f3c5f60a1 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1,7 +1,7 @@
 /** @file

 SMM MP service implementation

 

-Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.

+Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.

 Copyright (c) 2017, AMD Incorporated. All rights reserved.

 

 SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -22,6 +22,7 @@ UINTN   mSemaphoreSize;
 SPIN_LOCK   *mPFLock = NULL;

 SMM_CPU_SYNC_MODE   mCpuSmmSyncMode;

 BOOLEAN mMachineCheckSupported = FALSE;

+MM_COMPLETION   mSmmStartupThisApToken;

 

 extern UINTN mSmmShadowStackSize;

 

@@ -1240,9 +1241,26 @@ InternalSmmStartupThisAp (
   mSmmMpSyncData->CpuData[CpuIndex].Procedure = Procedure;

   mSmmMpSyncData->CpuData[CpuIndex].Parameter = ProcArguments;

   if (Token != NULL) {

-ProcToken= GetFreeToken (1);

-mSmmMpSyncData->CpuData[CpuIndex].Token = ProcToken;

-*Token = (MM_COMPLETION)ProcToken->SpinLock;

+if (Token != ) {

+  //

+  // When Token points to mSmmStartupThisApToken, this routine is called

+  // from SmmStartupThisAp() in non-blocking mode 
(PcdCpuSmmBlockStartupThisAp == FALSE).

+  //

+  // In this case, caller wants to startup AP procedure in non-blocking

+  // mode and cannot get the completion status from the Token because there

+  // is no way to return the Token to caller from SmmStartupThisAp().

+  // Caller needs to use its implementation specific way to query the 
completion status.

+  //

+  // There is no need to allocate a token for such case so the 3 overheads

+  // can be avoided:

+  // 1. Call AllocateTokenBuffer() when there is no free token.

+  // 2. Get a free token from the token buffer.

+  // 3. Call ReleaseToken() in APHandler().

+  //

+  ProcToken= GetFreeToken (1);

+  mSmmMpSyncData->CpuData[CpuIndex].Token = ProcToken;

+  *Token = (MM_COMPLETION)ProcToken->SpinLock;

+}

   }

   mSmmMpSyncData->CpuData[CpuIndex].Status= CpuStatus;

   if (mSmmMpSyncData->CpuData[CpuIndex].Status != NULL) {

@@ -1474,8 +1492,6 @@ SmmStartupThisAp (
   IN OUT  VOID  *ProcArguments OPTIONAL

   )

 {

-  MM_COMPLETION   Token;

-

   gSmmCpuPrivate->ApWrapperFunc[CpuIndex].Procedure = Procedure;

   gSmmCpuPrivate->ApWrapperFunc[CpuIndex].ProcedureArgument = ProcArguments;

 

@@ -1486,7 +1502,7 @@ SmmStartupThisAp (
 ProcedureWrapper,

 CpuIndex,

 >ApWrapperFunc[CpuIndex],

-FeaturePcdGet (PcdCpuSmmBlockStartupThisAp) ? NULL : ,

+FeaturePcdGet (PcdCpuSmmBlockStartupThisAp) ? NULL : 
,

 0,

 NULL

 );

-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH v3 0/5] UefiCpuPkg/StandaloneMmCpuFeaturesLib: Add Standalone MM support

2021-03-07 Thread Dong, Eric
Reviewed-by: Eric Dong   for this serial.

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Michael Kubacki
Sent: Thursday, February 18, 2021 5:32 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Laszlo Ersek 
; Kumar, Rahul1 
Subject: [edk2-devel] [PATCH v3 0/5] UefiCpuPkg/StandaloneMmCpuFeaturesLib: Add 
Standalone MM support

From: Michael Kubacki 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3218

The present SmmCpuFeaturesLib implementation in UefiCpuPkg can be useful for 
IA32/X64 platforms that need a library instance for a Standalone MM 
environment. Much of the logic can be reused and a new INF can isolate the 
differences unique to Standalone MM.

This patch series contains an initial set of changes for cleaning up 
pre-existing design issues in the library. The final two patches contain 
changes needed for Standalone MM support.

Here's an overview of how the three library instances are organized that may be 
a useful reference (provided by Laszlo):

Traditional,  Traditional,  Standalone,
no STMSTM   no STM

Entry point type   DXE   DXE   MM

Lib inst. init.basic STM   basic

Processor init.basic STM   basic

PCD access any   any   fixed

* Traditional no STM = SmmCpuFeaturesLib.inf
* Traditional STM = SmmCpuFeaturesLibStm.inf
* Standalone no STM = StandaloneMmCpuFeaturesLib.inf

V3 changes:

  PATCH v3 2/5 is a new patch in the series that renames the file
  SmmCpuFeaturesLib.c to SmmCpuFeaturesLibCommon.c to more clearly
  identify implementation in the file as shared between all library
  instances.

  PATCH v3 3/5 adds a new source file SmmCpuFeaturesLib.c that
  contains the constructor specific to the Traditional MM no
  STM library instance. This was previously implemented in a
  file built by the Standalone MM instance and while not
  harmful, it was not clean.

  PATCH v3 4/5 updates "@retval" to "@return" in the documentation
  for GetCpuMaxLogicalProcessorNumber() since it is not a constant
  return value.

  PATCH v3 5/5 contains a commit message update to note that all
  instances of "PiSmm.h" in the library source files have been
  updated to "PiMm.h" for consistency throughout the library.

V2 changes:

  Due to some pre-existing design issues in the library that
  affected a single v1 patch that add Standalone MM support,
  it was suggested to first address those issues and then add the
  new INF StandaloneMmCpuFeaturesLib.inf.

  To address these concerns, the following v1 patch was converted
  into a v2 patch series:
  https://edk2.groups.io/g/devel/message/71626

  The first two patches in v2 primarily addressed those concerns.

  PATCH v2 1/4 and PATCH v2 2/4 focused on fixing pre-existing
  design issues.

  PATCH v2 3/4 and PATCH v2 4/4 focused on the changes needed to add
  Standalone MM support.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
Signed-off-by: Michael Kubacki 

Michael Kubacki (5):
  UefiCpuPkg/SmmCpuFeaturesLib: Move multi-instance function decl to
header
  UefiCpuPkg/SmmCpuFeaturesLib: Rename SmmCpuFeaturesLib.c
  UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors
  UefiCpuPkg/SmmCpuFeaturesLib: Abstract PcdCpuMaxLogicalProcessorNumber
  UefiCpuPkg/SmmCpuFeaturesLib: Add Standalone MM support

 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmmStmSupport.c  
|   2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c   
| 608 +---
 UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLib.c => 
SmmCpuFeaturesLibCommon.c}|  36 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c  
|   3 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c  
|  26 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c  
|  50 ++
 UefiCpuPkg/Library/SmmCpuFeaturesLib/TraditionalMmCpuFeaturesLib.c 
|  28 +
 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmmStmSupport.c   
|   2 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/CpuFeaturesLib.h  
|  48 ++
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf 
|   3 +
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf  
|   4 +-
 UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLib.inf => 
StandaloneMmCpuFeaturesLib.inf} |  22 +-
 UefiCpuPkg/UefiCpuPkg.dsc  
|   1 +
 13 files changed, 172 insertions(+), 661 deletions(-)  copy 
UefiCpuPkg/Library/SmmCpuFeaturesLib/{SmmCpuFeaturesLib.c => 
SmmCpuFeaturesLibCommon

Re: [edk2-devel] [PATCH v3 4/4] UefiCpuPkg/MpInitLib: Remove unused Lock from MP_CPU_EXCHANGE_INFO

2021-02-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, February 9, 2021 10:17 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v3 4/4] UefiCpuPkg/MpInitLib: Remove unused Lock from 
MP_CPU_EXCHANGE_INFO

The Lock is no longer needed since "LOCK XADD" was used in MpFuncs.nasm for 
ApIndex atomic increment.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 4 
 UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 4 
 UefiCpuPkg/Library/MpInitLib/MpLib.c   | 1 -
 UefiCpuPkg/Library/MpInitLib/MpLib.h   | 3 +--
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm  | 4 
 5 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 4363ad9a18..7bd2415670 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -121,10 +121,6 @@ SkipEnableExecuteDisable:
 lock inc   dword [edi]  ; AP init-movedi, esi-add  
  edi, MP_CPU_EXCHANGE_INFO_FIELD (Lock)-moveax, NotVacantFlag- 
movedi, esi addedi, MP_CPU_EXCHANGE_INFO_FIELD (ApIndex)
 movebx, 1diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
index 46c2b5c116..2e9368a374 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
+++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc
@@ -13,9 +13,6 @@
 
;---
 %include "Nasm.inc" -VacantFlagequ
00h-NotVacantFlag equ0ffh- CPU_SWITCH_STATE_IDLE
 equ0 CPU_SWITCH_STATE_STORED   equ1 
CPU_SWITCH_STATE_LOADED   equ2@@ -72,7 +69,6 @@ endstruc
 ; Equivalent NASM structure of MP_CPU_EXCHANGE_INFO ; struc 
MP_CPU_EXCHANGE_INFO-  .Lock: CTYPE_UINTN 1   
.StackStart:   CTYPE_UINTN 1   .StackSize:
CTYPE_UINTN 1   .CFunction:CTYPE_UINTN 1diff --git 
a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 2568986d8c..5040053dad 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1006,7 +1006,6 @@ FillExchangeInfoData (
   IA32_CR4 Cr4;ExchangeInfo  = 
CpuMpData->MpCpuExchangeInfo;-  ExchangeInfo->Lock= 0;   
ExchangeInfo->StackStart  = CpuMpData->Buffer;   ExchangeInfo->StackSize
   = CpuMpData->CpuApStackSize;   ExchangeInfo->BufferStart = 
CpuMpData->WakeupBuffer;diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 02652eaae1..0bd60388b1 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -1,7 +1,7 @@
 /** @file   Common header file for MP Initialize Library. -  Copyright (c) 
2016 - 2020, Intel Corporation. All rights reserved.+  Copyright (c) 2016 - 
2021, Intel Corporation. All rights reserved.   Copyright (c) 2020, AMD 
Inc. All rights reserved.SPDX-License-Identifier: BSD-2-Clause-Patent@@ 
-190,7 +190,6 @@ typedef struct _CPU_MP_DATA  CPU_MP_DATA;
 // into this structure are used in assembly code in this module // typedef 
struct {-  UINTN Lock;   UINTN StackStart;   
UINTN StackSize;   UINTN CFunction;diff --git 
a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index db297f5cca..50df802d1f 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -157,10 +157,6 @@ LongModeStart:
 lock inc   dword [edi]  ; AP init-movedi, esi-add  
  edi, MP_CPU_EXCHANGE_INFO_FIELD (Lock)-movrax, NotVacantFlag- 
movedi, esi addedi, MP_CPU_EXCHANGE_INFO_FIELD (ApIndex)
 movebx, 1-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH v3 3/4] UefiCpuPkg/MpInitLib: Use NASM struc to avoid hardcode offset

2021-02-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, February 9, 2021 10:17 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v3 3/4] UefiCpuPkg/MpInitLib: Use NASM struc to avoid hardcode 
offset

In Windows environment, "dumpbin /disasm" is used to verify the disassembly 
before and after using NASM struc doesn't change.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   5 +-
 UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc   |  43 
 .../Library/MpInitLib/Ia32/MpFuncs.nasm   |  80 +++---
 UefiCpuPkg/Library/MpInitLib/MpEqu.inc| 103 ++
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   5 +-
 UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc|  45 
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm |  92 
 7 files changed, 193 insertions(+), 180 deletions(-)  delete mode 100644 
UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
 create mode 100644 UefiCpuPkg/Library/MpInitLib/MpEqu.inc
 delete mode 100644 UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 1771575c69..860a9750e2 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -1,7 +1,7 @@
 ## @file #  MP Initialize Library instance for DXE driver. #-#  Copyright (c) 
2016 - 2020, Intel Corporation. All rights reserved.+#  Copyright (c) 2016 
- 2021, Intel Corporation. All rights reserved. #  SPDX-License-Identifier: 
BSD-2-Clause-Patent # ##@@ -22,14 +22,13 @@ [Defines]
 #  [Sources.IA32]-  Ia32/MpEqu.inc   Ia32/MpFuncs.nasm  [Sources.X64]-  
X64/MpEqu.inc   X64/MpFuncs.nasm  [Sources.common]+  MpEqu.inc   DxeMpLib.c   
MpLib.c   MpLib.hdiff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
deleted file mode 100644
index 4f5a7c859a..00
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc
+++ /dev/null
@@ -1,43 +0,0 @@
-;--
 ;-; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.-; 
SPDX-License-Identifier: BSD-2-Clause-Patent-;-; Module Name:-;-;   
MpEqu.inc-;-; Abstract:-;-;   This is the equates file for Multiple Processor 
support-;-;-VacantFlag
equ00h-NotVacantFlag equ
0ffh--CPU_SWITCH_STATE_IDLE equ0-CPU_SWITCH_STATE_STORED   
equ1-CPU_SWITCH_STATE_LOADED   equ2--LockLocation   
   equ(SwitchToRealProcEnd - 
RendezvousFunnelProcStart)-StackStartAddressLocation equ
LockLocation + 04h-StackSizeLocation equLockLocation + 
08h-ApProcedureLocation   equLockLocation + 0Ch-GdtrLocation
  equLockLocation + 10h-IdtrLocation  equ   
 LockLocation + 16h-BufferStartLocation   equLockLocation + 
1Ch-ModeOffsetLocationequLockLocation + 20h-ApIndexLocation 
  equLockLocation + 24h-CodeSegmentLocation   equ   
 LockLocation + 28h-DataSegmentLocation   equLockLocation + 
2Ch-EnableExecuteDisableLocation  equLockLocation + 30h-Cr3Location 
  equLockLocation + 34h-InitFlagLocation  equ   
 LockLocation + 38h-CpuInfoLocation   equLockLocation + 
3Ch-NumApsExecutingLocation   equLockLocation + 
40h-InitializeFloatingPointUnitsAddress equ  LockLocation + 
48h-ModeTransitionMemoryLocationequ  LockLocation + 
4Ch-ModeTransitionSegmentLocation   equ  LockLocation + 
50h-ModeHighMemoryLocation  equ  LockLocation + 
52h-ModeHighSegmentLocation equ  LockLocation + 56h-diff --git 
a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 2eaddc93bc..4363ad9a18 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -39,21 +39,21 @@ BITS 16
 movfs, ax movgs, ax -movsi,  
BufferStartLocation+movsi,  MP_CPU_EXCHANGE_INFO_FIELD 
(BufferStart) movebx, [si] -movsi,  
DataSegmentLocation+movsi,  MP_CPU_EXCHANGE_INFO_FIELD 
(DataSegment) movedx, [si]  ; ; Get start address of 32-bit 
code in low memory (<1MB) ;-movedi, 
ModeTransitionMemoryLocation+movedi, MP_CPU_EXCHANGE_INFO_FIELD 
(ModeTransitionMemory) -movsi, GdtrLocation+movsi, 
MP_CPU_EXCHANGE_INFO_FIELD (GdtrProfile) o32 lgdt   [cs:si] -mov
si, IdtrLoc

Re: [edk2-devel] [PATCH v3 1/4] UefiCpuPkg/MpInitLib: Use XADD to avoid lock acquire/release

2021-02-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Tuesday, February 9, 2021 10:17 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH v3 1/4] UefiCpuPkg/MpInitLib: Use XADD to avoid lock 
acquire/release

When AP firstly wakes up, MpFuncs.nasm contains below logic to assign an unique 
ApIndex to each AP according to who comes first:
---ASM---
TestLock:
xchg   [edi], eax
cmpeax, NotVacantFlag
jz TestLock

movecx, esi
addecx, ApIndexLocation
incdword [ecx]
movebx, [ecx]

Releaselock:
moveax, VacantFlag
xchg   [edi], eax
---ASM END---

"lock inc" cannot be used to increase ApIndex because not only the global 
ApIndex should be increased, but also the result should be stored to a local 
general purpose register EBX.

This patch learns from the NASM implementation of
InternalSyncIncrement() to use "XADD" instruction which can increase the global 
ApIndex and store the original ApIndex to EBX in one instruction.

With this patch, OVMF when running in a 255 threads QEMU spends about one 
second to wakeup all APs. Original implementation needs more than
10 seconds.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 .../Library/MpInitLib/Ia32/MpFuncs.nasm   | 20 ++-
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 18 ++---
 2 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
index 7e81d24aa6..2eaddc93bc 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
@@ -1,5 +1,5 @@
 
;-- 
;-; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.+; 
Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved. ; 
SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name:@@ -125,19 +125,11 
@@ SkipEnableExecuteDisable:
 addedi, LockLocation moveax, NotVacantFlag -TestLock:- 
   xchg   [edi], eax-cmpeax, NotVacantFlag-jz 
TestLock--movecx, esi-addecx, ApIndexLocation-inc   
 dword [ecx]-movebx, [ecx]--Releaselock:-moveax, 
VacantFlag-xchg   [edi], eax+movedi, esi+add
edi, ApIndexLocation+movebx, 1+lock xadd  dword [edi], ebx  
   ; EBX = ApIndex+++incebx  ; 
EBX is CpuNumber  movedi, esi addedi, 
StackSizeLocationdiff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm 
b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
index aecfd07bc0..5b588f2dcb 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
@@ -1,5 +1,5 @@
 
;-- 
;-; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.+; 
Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved. ; 
SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name:@@ -161,18 +161,12 
@@ LongModeStart:
 addedi, LockLocation movrax, NotVacantFlag -TestLock:- 
   xchg   qword [edi], rax-cmprax, NotVacantFlag-jz 
TestLock--leaecx, [esi + ApIndexLocation]-incdword 
[ecx]-movebx, [ecx]+movedi, esi+addedi, 
ApIndexLocation+movebx, 1+lock xadd  dword [edi], ebx   
  ; EBX = ApIndex+++incebx  ; EBX 
is CpuNumber -Releaselock:-movrax, VacantFlag-xchg   qword 
[edi], rax ; program stack movedi, esi addedi, 
StackSizeLocation-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase CpuCount in ApWakeupFunction

2021-01-27 Thread Dong, Eric
Reviewed-by: Eric Dong 

From: Ni, Ray 
Sent: Thursday, January 28, 2021 11:27 AM
To: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Cc: devel@edk2.groups.io; Ni, Ray 
Subject: RE: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase CpuCount 
in ApWakeupFunction

Somehow I forgot to add "Cc" tag in the patch resulting the package maintainers 
are not CCed.
Add them back.

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Ni, Ray
> Sent: Tuesday, January 26, 2021 1:50 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Don't increase
> CpuCount in ApWakeupFunction
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3179
>
> When BSP first time wakes all APs, each AP atomically increases
> CpuMpData->CpuCount and CpuMpData->FinishedCount.
> Each AP atomically increases CpuMpData->NumApsExecuting
> in early assembly code and decreases it before it enters to HLT or
> MWAIT state.
>
> Putting them together, the 3 variables are changed in the following order:
> 1. NumApsExecuting++ // in assembly
> 2. CpuCpunt++
> 4. FinishedCount++
> 3. NumApsExecuting-- // in C
>
> BSP waits for a certain timeout and then polls NumApsExecuting
> until it drops to zero. It assumes all APs are waken up concurrently
> and NumApsExecuting only drops to zero when all APs have checked in.
>
> Then it additionally waits for FinishedCount == CpuCount - 1.
> (FinishedCount doesn't include BSP while CpuCount includes BSP.)
>
> There is no need to additionally wait for
> FinishedCount == CpuCount - 1 because when NumApsExecuting == 0,
> the number of increments of FinishedCount and CpuCount should equal.
>
> This patch simplifies the code to remove "CpuCount++" in
> ApWakeupFunction() and assigns FinishedCount + 1 to CpuCount after
> WakeUpAP().
>
> Signed-off-by: Ray Ni mailto:ray...@intel.com>>
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 16 +---
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 8b1f7f84ba..2568986d8c 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>
>CPU MP Initialize Library common functions.
>
>
>
> -  Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.
>
> +  Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.
>
>Copyright (c) 2020, AMD Inc. All rights reserved.
>
>
>
>SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -485,14 +485,12 @@ CollectProcessorCount (
>CpuMpData->InitFlag = ApInitConfig;
>
>WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
>
>CpuMpData->InitFlag = ApInitDone;
>
> -  ASSERT (CpuMpData->CpuCount <= PcdGet32
> (PcdCpuMaxLogicalProcessorNumber));
>
>//
>
> -  // Wait for all APs finished the initialization
>
> +  // When InitFlag == ApInitConfig, WakeUpAP () guarantees all APs are
> checked in.
>
> +  // FinishedCount is the number of check-in APs.
>
>//
>
> -  while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) {
>
> -CpuPause ();
>
> -  }
>
> -
>
> +  CpuMpData->CpuCount = CpuMpData->FinishedCount + 1;
>
> +  ASSERT (CpuMpData->CpuCount <= PcdGet32
> (PcdCpuMaxLogicalProcessorNumber));
>
>
>
>//
>
>// Enable x2APIC mode if
>
> @@ -751,10 +749,6 @@ ApWakeupFunction (
>CurrentApicMode = GetApicMode ();
>
>while (TRUE) {
>
>  if (CpuMpData->InitFlag == ApInitConfig) {
>
> -  //
>
> -  // Add CPU number
>
> -  //
>
> -  InterlockedIncrement ((UINT32 *) >CpuCount);
>
>ProcessorNumber = ApIndex;
>
>//
>
>// This is first time AP wakeup, get BIST information from AP stack
>
> --
> 2.27.0.windows.1
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#70757): https://edk2.groups.io/g/devel/message/70757
> Mute This Topic: https://groups.io/mt/80124850/1712937
> Group Owner: devel+ow...@edk2.groups.io<mailto:devel+ow...@edk2.groups.io>
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray...@intel.com]
> -=-=-=-=-=-=
>


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




Re: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition

2021-01-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Michael D Kinney  
Sent: Saturday, January 23, 2021 1:10 AM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Laszlo Ersek 
; Kumar, Rahul1 
Subject: [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters 
race condition

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3182

Fix the order of operations in ApWakeupFunction() when PcdCpuApLoopMode
is set to HLT mode that uses INIT-SIPI-SIPI to wake APs.  In this mode,
volatile state is restored and saved each time a INIT-SIPI-SIPI is sent
to an AP to request a function to be executed on the AP.  When the
function is completed the volatile state of the AP is saved.  However,
the counters NumApsExecuting and FinishedCount are updated before
the volatile state is saved.  This allows for a race condition window
for the BSP that is waiting on these counters to request a new
INIT-SIPI-SIPI before all the APs have completely saved their volatile
state.  The fix is to save the AP volatile state before updating the
NumApsExecuting and FinishedCount counters.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
Signed-off-by: Michael D Kinney 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 31 
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 681fa79b4cff..8b1f7f84bad6 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -769,15 +769,6 @@ ApWakeupFunction (
   RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);
   InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);
   ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
-
-  //
-  // Delay decrementing the APs executing count when SEV-ES is enabled
-  // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly
-  // performs another INIT-SIPI-SIPI sequence.
-  //
-  if (!CpuMpData->SevEsIsEnabled) {
-InterlockedDecrement ((UINT32 *) 
>MpCpuExchangeInfo->NumApsExecuting);
-  }
 } else {
   //
   // Execute AP function if AP is ready
@@ -866,19 +857,33 @@ ApWakeupFunction (
   }
 }
 
+if (CpuMpData->ApLoopMode == ApInHltLoop) {
+  //
+  // Save AP volatile registers
+  //
+  SaveVolatileRegisters 
(>CpuData[ProcessorNumber].VolatileRegisters);
+}
+
 //
 // AP finished executing C code
 //
 InterlockedIncrement ((UINT32 *) >FinishedCount);
 
+if (CpuMpData->InitFlag == ApInitConfig) {
+  //
+  // Delay decrementing the APs executing count when SEV-ES is enabled
+  // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly
+  // performs another INIT-SIPI-SIPI sequence.
+  //
+  if (!CpuMpData->SevEsIsEnabled) {
+InterlockedDecrement ((UINT32 *) 
>MpCpuExchangeInfo->NumApsExecuting);
+  }
+}
+
 //
 // Place AP is specified loop mode
 //
 if (CpuMpData->ApLoopMode == ApInHltLoop) {
-  //
-  // Save AP volatile registers
-  //
-  SaveVolatileRegisters 
(>CpuData[ProcessorNumber].VolatileRegisters);
   //
   // Place AP in HLT-loop
   //
-- 
2.29.2.windows.2



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/CpuMp: Fix hang when StackGuard is enabled in 16-core cpu

2021-01-19 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Ni, Ray  
Sent: Thursday, January 14, 2021 9:12 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek ; Kumar, 
Rahul1 
Subject: [PATCH] UefiCpuPkg/CpuMp: Fix hang when StackGuard is enabled in 
16-core cpu

When StackGuard is enabled, the CpuMp driver allocates
known good stacks for all CPUs for DF# and PF# exceptions.
It uses AllocatePool to do so.

The size needed equals to 64KB
= StackSize (2K) * ExceptionNumber (2) * NumberOfProcessors (16)

However, AllocatePool max allocation size is less than 64K.
To fix the issue, AllocatePages() is used.

Signed-off-by: Ray Ni 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
---
 UefiCpuPkg/CpuMpPei/CpuMpPei.c   | 10 +++---
 UefiCpuPkg/CpuMpPei/CpuMpPei.h   |  3 ++-
 UefiCpuPkg/CpuMpPei/CpuMpPei.inf |  3 ++-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index d07540cf74..40729a09b9 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -1,7 +1,7 @@
 /** @file

   CPU PEI Module installs CPU Multiple Processor PPI.

 

-  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.

+  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -532,13 +532,9 @@ InitializeMpExceptionStackSwitchHandlers (
   ExceptionNumber = FixedPcdGetSize (PcdCpuStackSwitchExceptionList);

   NewStackSize = FixedPcdGet32 (PcdCpuKnownGoodStackSize) * ExceptionNumber;

 

-  Status = PeiServicesAllocatePool (

- NewStackSize * NumberOfProcessors,

- (VOID **)

- );

+  StackTop = AllocatePages (EFI_SIZE_TO_PAGES (NewStackSize * 
NumberOfProcessors));

   ASSERT(StackTop != NULL);

-  if (EFI_ERROR (Status)) {

-ASSERT_EFI_ERROR (Status);

+  if (StackTop == NULL) {

 return;

   }

   StackTop += NewStackSize  * NumberOfProcessors;

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
index 6a481a84dc..c6870656ca 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
@@ -1,7 +1,7 @@
 /** @file

   Definitions to install Multiple Processor PPI.

 

-  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.

+  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.

   SPDX-License-Identifier: BSD-2-Clause-Patent

 

 **/

@@ -27,6 +27,7 @@
 #include 

 #include 

 #include 

+#include 

 

 extern EFI_PEI_PPI_DESCRIPTOR   mPeiCpuMpPpiDesc;

 

diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
index 7e511325d8..ba829d816e 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
@@ -1,7 +1,7 @@
 ## @file

 #  CPU driver installs CPU PI Multi-processor PPI.

 #

-#  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.

+#  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.

 #  SPDX-License-Identifier: BSD-2-Clause-Patent

 #

 ##

@@ -45,6 +45,7 @@ [LibraryClasses]
   MpInitLib

   BaseMemoryLib

   CpuLib

+  MemoryAllocationLib

 

 [Guids]

   gEdkiiMigratedFvInfoGuid ## 
SOMETIMES_CONSUMES ## HOB

-- 
2.27.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiCpuPkg/RegisterCpuFeaturesLib: Support MpServices2 only case.

2020-09-10 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Chasel Chiu  
Sent: Thursday, September 10, 2020 5:03 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel ; Dong, Eric ; Ni, 
Ray ; Laszlo Ersek ; Kumar, Rahul1 
; Desimone, Nathaniel L 
Subject: [PATCH] UefiCpuPkg/RegisterCpuFeaturesLib: Support MpServices2 only 
case.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2883

MpServices Ppi can be replaced by MpServices2 Ppi and MpServices2 Ppi is 
mandatory for RegisterCpuFeaturesLib functionality, basing on this we can drop 
MpServices Ppi usage from the library and the constraint that both Ppis must be 
installed.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Cc: Rahul Kumar 
Cc: Nate DeSimone 
Signed-off-by: Chasel Chiu 
---
 UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c | 61 
+++--
 UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h   |  6 
+++---
 2 files changed, 26 insertions(+), 41 deletions(-)

diff --git 
a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c 
b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c
index 64768f7a74..4e558e9fee 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLi
+++ b.c
@@ -1,7 +1,7 @@
 /** @file
   CPU Register Table Library functions.
 
-  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
+  Copyright (c) 2016 - 2020, Intel Corporation. All rights 
+ reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "RegisterCpuFeatures.h"
@@ -75,10 +74,10 @@ GetMpService (
   MP_SERVICESMpService;
 
   //
-  // Get MP Services Protocol
+  // Get MP Services2 Ppi
   //
   Status = PeiServicesLocatePpi (
- ,
+ ,
  0,
  NULL,
  (VOID **)
@@ -100,17 +99,17 @@ GetProcessorIndex (
   )
 {
   EFI_STATUS Status;
-  EFI_PEI_MP_SERVICES_PPI*CpuMpPpi;
+  EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
   UINTN  ProcessorIndex;
 
-  CpuMpPpi = CpuFeaturesData->MpService.Ppi;
+  CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
 
   //
   // For two reasons which use NULL for WhoAmI:
   // 1. This function will be called by APs and AP should not use PeiServices 
Table
   // 2. Check WhoAmI implementation, this parameter will not be used.
   //
-  Status = CpuMpPpi->WhoAmI(NULL, CpuMpPpi, );
+  Status = CpuMp2Ppi->WhoAmI (CpuMp2Ppi, );
   ASSERT_EFI_ERROR (Status);
   return ProcessorIndex;
 }
@@ -131,16 +130,15 @@ GetProcessorInformation (
   OUT EFI_PROCESSOR_INFORMATION*ProcessorInfoBuffer
   )
 {
-  EFI_PEI_MP_SERVICES_PPI*CpuMpPpi;
+  EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
   EFI_STATUS Status;
   CPU_FEATURES_DATA  *CpuFeaturesData;
 
   CpuFeaturesData = GetCpuFeaturesData ();
-  CpuMpPpi = CpuFeaturesData->MpService.Ppi;
+  CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
 
-  Status = CpuMpPpi->GetProcessorInfo (
-   GetPeiServicesTablePointer(),
-   CpuMpPpi,
+  Status = CpuMp2Ppi->GetProcessorInfo (
+   CpuMp2Ppi,
ProcessorNumber,
ProcessorInfoBuffer
);
@@ -162,18 +160,17 @@ StartupAllAPsWorker (
   )
 {
   EFI_STATUS   Status;
-  EFI_PEI_MP_SERVICES_PPI  *CpuMpPpi;
+  EDKII_PEI_MP_SERVICES2_PPI   *CpuMp2Ppi;
   CPU_FEATURES_DATA*CpuFeaturesData;
 
   CpuFeaturesData = GetCpuFeaturesData ();
-  CpuMpPpi = CpuFeaturesData->MpService.Ppi;
+  CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
 
   //
   // Wakeup all APs for data collection.
   //
-  Status = CpuMpPpi->StartupAllAPs (
- GetPeiServicesTablePointer (),
- CpuMpPpi,
+  Status = CpuMp2Ppi->StartupAllAPs (
+ CpuMp2Ppi,
  Procedure,
  FALSE,
  0,
@@ -203,17 +200,7 @@ StartupAllCPUsWorker (
   //
   // Get MP Services2 Ppi
   //
-  Status = PeiServicesLocatePpi (
- ,
- 0,
- NULL,
- (VOID **)
- );
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // Wakeup all APs for data collection.
-  //
+  CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
   Status = CpuMp2Ppi->StartupAllCPUs (
  CpuMp2Ppi,
  Procedure,
@@ -234,18 +221,17 @@ SwitchNewBsp (
   )
 {
   EFI_STATUS   Status;
-  EFI_PEI_MP_SERVICES_PPI  *CpuMpPpi;
+  EDKII_PEI_MP_SERVICES2_PPI   *CpuMp2Ppi;
   CPU_FEATURES_DATA*CpuFeaturesData;
 
   CpuFeaturesData = GetCpuFeaturesData ();
-  CpuMpPpi = CpuFeaturesData->MpService.Ppi;
+  CpuMp2Ppi = CpuFeaturesData->MpSer

Re: 回复: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-05 Thread Dong, Eric
yes, I will close that Bugzilla. Thanks all for your feedback.

Thanks,
Eric

From: Yao, Jiewen 
Sent: Saturday, September 5, 2020 8:31 PM
To: devel@edk2.groups.io; ler...@redhat.com; vanjeff_...@hotmail.com; Dong, 
Eric ; Ni, Ray 
Cc: Lou, Yun 
Subject: RE: 回复: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

Thank you Laszlo.

Eric and I communicated with internal team. They understand that CPU is the 
only owner of the CPU state (CR3/DGT/IDT) and MP_SERVICE_PROTOCOL. Then we 
agree that the original test is invalid.

As conclusion, we can withdraw this patch and close the Bugzilla with "not a 
defect". 

Thank you
Yao Jiewen

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Laszlo Ersek
> Sent: Friday, September 4, 2020 4:37 PM
> To: Yao, Jiewen mailto:jiewen@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>;
> vanjeff_...@hotmail.com<mailto:vanjeff_...@hotmail.com>; Dong, Eric 
> mailto:eric.d...@intel.com>>; Ni, Ray
> mailto:ray...@intel.com>>
> Cc: Lou, Yun mailto:yun@intel.com>>
> Subject: Re: 回复: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for
> CR3/GDT/IDT.
>
> On 09/04/20 10:06, Yao, Jiewen wrote:
> > When we say “validate”, we need get clear on what is the contract between
> caller and callee, and what is the expectation of the validation.
> >
> > For example, in this case, the validation is limited to 4G or not 4G. Why?
> > This function does not verify following, why?
> >
> >   1.  if the GDT table is valid.
> >   2.  if the IDT table is valid
> >   3.  if the exception handler is valid
> >   4.  if the timer handler still works
> >   5.  if the page table is valid
> >   6.  if the page table is 1:1 mapping
> >   7.  if the page table still enforce the expected protection, such as RO, 
> > NX
> >   8.  ……
>
> Yes, very good point; it has crossed my mind before too. The currently
> proposed checks verify the CR3 (but not the end of the root page
> directory). They also don't try to walk the whole forest of page tables
> and check every entry against 4GB (or, as you say, for 1:1 mapping). The
> check covers the GDT and the IDT, but not the GDT and IDT entries
> (segment granularity? direction of growth?)
>
> I'm OK with the proposed rudimentary checks because in my mind they are
> supposed to catch only one idiosyncratic UEFI application.
>
> > If an application creates a crazy state, CpuDxe may pass the validation with
> below 4G page table, but still fail to wake up APs.
>
> Yes, absolutely.
>
> >
> > If it is the app’s responsibility to ensure the system in good state, the
> validation is unnecessary.
> > If it is the CpuDxe’s responsibility to ensure the system in good state, the
> validation is insufficient.
>
> Agreed on both counts.
>
> I'm just under the impression that Eric has some internal use case that
> doesn't let him fix the application -- or maybe there's no time left for
> them for fixing the application.
>
> >
> > I think we should wait. I am working with Eric to collect the requirement on
> why test case is designed in this way.
>
> Sounds good, thanks!
>
> >
> > DebugAgentDxe is a good case. It is for debug purpose.
> > I believe there must be contract between CPU driver and DebugAgentDxe that
> which status DebugAgentDxe may modify and which state DebugAgentDxe may
> not.
> > It is DebugAgentDxe’s responsibility to ensure the new system state is 
> > correct
> and compatible with the CPU driver.
>
> Agreed 100%
>
> > With the contract, I don’t think CPU driver need validate the system state
> changed by DebugAgentDxe.
> > If DebugAgentDxe put system in a wrong state, CPUDriver has no chance to
> run.
>
> Agreed again.
>
> Thanks
> Laszlo
>
>
> 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#65064): https://edk2.groups.io/g/devel/message/65064
Mute This Topic: https://groups.io/mt/76625321/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-03 Thread Dong, Eric
Agree, current is too much PCDs for the driver.

Laszlo, what’s your comments?

Thanks,
Eric
From: Fan Jeff 
Sent: Friday, September 4, 2020 10:19 AM
To: devel@edk2.groups.io; Dong, Eric ; Ni, Ray 
; ler...@redhat.com
Cc: Lou, Yun 
Subject: 回复: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

Laszlo & Eric,

Introducing one new PCD to handle such rare test case is too heavy. I think We 
could do validating CR3/GDT/IDT space < 4GB address always in MpInitLib.

Jeff

发件人: Dong, Eric<mailto:eric.d...@intel.com>
发送时间: 2020年9月4日 10:01
收件人: Ni, Ray<mailto:ray...@intel.com>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>; 
ler...@redhat.com<mailto:ler...@redhat.com>
抄送: Lou, Yun<mailto:yun@intel.com>
主题: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

I guess Laszlo think this check is not always needed, just used for this 
special shell application case. He wants to use default FALSE to always ignore 
this check and make code logic clear.

Thanks,
Eric

From: Ni, Ray mailto:ray...@intel.com>>
Sent: Friday, September 4, 2020 9:34 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; 
ler...@redhat.com<mailto:ler...@redhat.com>; Dong, Eric 
mailto:eric.d...@intel.com>>
Cc: Lou, Yun mailto:yun@intel.com>>
Subject: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

Why do we need a new PCD to control such check? Under what circumstance the PCD 
is false?
We may need to move such check out of MpLib.c. Because when bps runs at 32bit 
mode, AP doesn’t need to switch to long mode, such check is not needed and also 
always passes.

We should not assume PEI runs at 32 bit mode.


发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>> 代表 Laszlo Ersek 
mailto:ler...@redhat.com>>
发送时间: Friday, September 4, 2020 3:55:47 AM
收件人: Dong, Eric mailto:eric.d...@intel.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>
抄送: Ni, Ray mailto:ray...@intel.com>>
主题: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

On 09/03/20 21:00, Laszlo Ersek wrote:

> (10) More importantly, ValidCR3GdtIdtCheck() should not be called in the
> Worker functions for StartupAllAPs, StartupThisAP, SwitchBSP, and
> EnableDisableAP, in "UefiCpuPkg/Library/MpInitLib/MpLib.c".
>
> Instead, the calls should be made in the DXE instance of the library
> ("UefiCpuPkg/Library/MpInitLib/DxeMpLib.c"), at the very top of the
> functions:
>
> - MpInitLibStartupAllAPs
> - MpInitLibStartupThisAP
> - MpInitLibSwitchBSP
> - MpInitLibEnableDisableAP
>
> Here's why:
>
> (a) The symptom does not affect the PEI phase -- by the time the UEFI
> application is executed, the PEI phase has ended; there's no need to
> modify the PEI instance of the library.
>
> (b) The currently proposed failure exits are too late. For example, in
> the SwitchBSPWorker() function, by the time we exit, we have called
> DisableApicTimerInterrupt(), SaveAndDisableInterrupts(), and
> DisableLvtInterrupts() -- and the error path does not restore the
> original environment.
>
> (c) According to the PI spec (v1.7), the StartupAllAPs(),
> StartupThisAP(), SwitchBSP(), EnableDisableAP() member functions of
> EFI_MP_SERVICES_PROTOCOL may only be called on the (current) BSP.
> Because of this, it is OK to call ValidCR3GdtIdtCheck() as the very
> first action in the above-listed DxeMpLib functions.
>
> (Assuming the protocol members are called from an AP, and consequently
> we check CR3 / GDTR / IDTR on the AP (and not on the BSP), that's the
> *caller's* fault, per spec!)

This means we can move the ValidCr3GdtIdtCheck() function to
"DxeMpLib.c", and it is not necessary to modify "MpLib.h".

Thanks
Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#65024): https://edk2.groups.io/g/devel/message/65024
Mute This Topic: https://groups.io/mt/76609049/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-03 Thread Dong, Eric
I guess Laszlo think this check is not always needed, just used for this 
special shell application case. He wants to use default FALSE to always ignore 
this check and make code logic clear.

Thanks,
Eric

From: Ni, Ray 
Sent: Friday, September 4, 2020 9:34 AM
To: devel@edk2.groups.io; ler...@redhat.com; Dong, Eric 
Cc: Lou, Yun 
Subject: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

Why do we need a new PCD to control such check? Under what circumstance the PCD 
is false?
We may need to move such check out of MpLib.c. Because when bps runs at 32bit 
mode, AP doesn’t need to switch to long mode, such check is not needed and also 
always passes.

We should not assume PEI runs at 32 bit mode.


发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>> 代表 Laszlo Ersek 
mailto:ler...@redhat.com>>
发送时间: Friday, September 4, 2020 3:55:47 AM
收件人: Dong, Eric mailto:eric.d...@intel.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>
抄送: Ni, Ray mailto:ray...@intel.com>>
主题: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

On 09/03/20 21:00, Laszlo Ersek wrote:

> (10) More importantly, ValidCR3GdtIdtCheck() should not be called in the
> Worker functions for StartupAllAPs, StartupThisAP, SwitchBSP, and
> EnableDisableAP, in "UefiCpuPkg/Library/MpInitLib/MpLib.c".
>
> Instead, the calls should be made in the DXE instance of the library
> ("UefiCpuPkg/Library/MpInitLib/DxeMpLib.c"), at the very top of the
> functions:
>
> - MpInitLibStartupAllAPs
> - MpInitLibStartupThisAP
> - MpInitLibSwitchBSP
> - MpInitLibEnableDisableAP
>
> Here's why:
>
> (a) The symptom does not affect the PEI phase -- by the time the UEFI
> application is executed, the PEI phase has ended; there's no need to
> modify the PEI instance of the library.
>
> (b) The currently proposed failure exits are too late. For example, in
> the SwitchBSPWorker() function, by the time we exit, we have called
> DisableApicTimerInterrupt(), SaveAndDisableInterrupts(), and
> DisableLvtInterrupts() -- and the error path does not restore the
> original environment.
>
> (c) According to the PI spec (v1.7), the StartupAllAPs(),
> StartupThisAP(), SwitchBSP(), EnableDisableAP() member functions of
> EFI_MP_SERVICES_PROTOCOL may only be called on the (current) BSP.
> Because of this, it is OK to call ValidCR3GdtIdtCheck() as the very
> first action in the above-listed DxeMpLib functions.
>
> (Assuming the protocol members are called from an AP, and consequently
> we check CR3 / GDTR / IDTR on the AP (and not on the BSP), that's the
> *caller's* fault, per spec!)

This means we can move the ValidCr3GdtIdtCheck() function to
"DxeMpLib.c", and it is not necessary to modify "MpLib.h".

Thanks
Laszlo




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#65023): https://edk2.groups.io/g/devel/message/65023
Mute This Topic: https://groups.io/mt/76609049/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-03 Thread Dong, Eric
Hi Laszlo,

Very appreciate your good and detail comments, you are very good coach!

I follow all your comments in this mail and updated V3 patch, please check it 
and provide feedback.

Thanks,
Eric
From: devel@edk2.groups.io  On Behalf Of Laszlo Ersek
Sent: Friday, September 4, 2020 3:00 AM
To: Dong, Eric ; devel@edk2.groups.io
Cc: Ni, Ray 
Subject: Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

On 09/03/20 17:11, Eric Dong wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2954
>
> AP needs to run from real mode to 32bit mode to LONG mode. Page table
> (pointed by CR3) and GDT are necessary to set up to correct value when
> CPU execution mode is switched to LONG mode.
> AP uses the same location page table (CR3) and GDT as what BSP uses.
> But when the page table or GDT is above 4GB, it's impossible for CPU
> to use because GDTR.base and CR3 are 32bits before switching to LONG
> mode.
> This patch adds check for the CR3, GDT.Base and IDT.Base to not above
> 32 bits restriction.
>
> Change-Id: I231180f45d9f542641082c57d001e38e3f6759d5

(1) Please drop the Change-Id line.


(2) We should document that the motivation for this patch is a special
UEFI shell application that changes the GDT / CR3 to above 4GB.
Currently, neither the bugzilla, nor the commit message, nor the PCD
documentation in the DEC file explains this. So one is left wondering if
and why they should change the PCD to TRUE on their platform.

Please append the following two paragraphs to the commit message:

"""
The check is avoided -- assumed successful -- if the new
PcdEnableCpuApCr3GdtIdtCheck is FALSE (which is the default). The reason
is that the 32-bit requirement is always ensured by edk2 itself; the
requirement is only possibly invalidated by a particular UEFI shell
application that manually moves the GDT/IDT/CR3 above 4GB. Platforms
that don't intend to be compatible with such UEFI applications need not
set the PCD to TRUE.

If the PCD is TRUE and the check fails, then the StartupAllAPs(),
StartupThisAP(), SwitchBSP() and EnableDisableAP() MP service APIs are
rejected at once. Reporting an error immediately is more graceful than
hanging when the APs attempt to switch to long mode.
"""

> Signed-off-by: Eric Dong mailto:eric.d...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> Cc: Laszlo Ersek mailto:ler...@redhat.com>>
> ---
>
> V2:
> Change the check point. Just in the different caller to make the logic
> clear. V1 patch add check just before the use of the code. It make the
> logic complicated.
>
>  UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  1 +
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  9 +++
>  UefiCpuPkg/Library/MpInitLib/MpLib.c  | 76 +++
>  UefiCpuPkg/Library/MpInitLib/MpLib.h  | 12 +++
>  UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |  1 +
>  UefiCpuPkg/UefiCpuPkg.dec |  4 +
>  6 files changed, 103 insertions(+)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
> b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> index 1771575c69..20851f251a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> @@ -76,3 +76,4 @@
>gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase   ## 
> SOMETIMES_CONSUMES
>gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard  ## 
> CONSUMES
>gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase   ## 
> CONSUMES
> +  gUefiCpuPkgTokenSpaceGuid.PcdEnableCpuApCr3GdtIdtCheck   ## 
> CONSUMES
> \ No newline at end of file

(3) Can you insert this new line just after
"gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase" please? In order to
keep the "gUefiCpuPkgTokenSpaceGuid" PCDs grouped together.


> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
> b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> index 2c00d72dde..f598372c4d 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> @@ -394,6 +394,15 @@ MpInitChangeApLoopCallback (
>  {
>CPU_MP_DATA   *CpuMpData;
>
> +  //
> +  // Check the CR3/GDT/IDT before waking up AP.
> +  // If the check return fail, it will block later
> +  // OS boot, so halt the system here.
> +  //
> +  if (!ValidCR3GdtIdtCheck()) {

(4) Missing space character after "ValidCR3GdtIdtCheck".

(Applies to all the other call sites as well.)


> +CpuDeadLoop ();
> +  }
> +
>CpuMpData = GetCpuMpData ();
>CpuMpData->PmCodeSegment = GetProtectedModeCS ();
>CpuMpData->Pm16CodeSegment = GetProtectedMode16CS ();
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
> b/Uef

[edk2-devel] [PATCH v3] UefiCpuPkg/MpInitLib: Add check for Cr3/GDT/IDT.

2020-09-03 Thread Dong, Eric
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2954

AP needs to run from real mode to 32bit mode to LONG mode. Page table
(pointed by Cr3) and GDT are necessary to set up to correct value when
CPU execution mode is switched to LONG mode.
AP uses the same location page table (Cr3) and GDT as what BSP uses.
But when the page table or GDT is above 4GB, it's impossible for CPU
to use because GDTR.base and Cr3 are 32bits before switching to LONG
mode.

This patch adds check for the Cr3, GDT and IDT to not above 4G limitation.

The check is avoided -- assumed successful -- if the new
PcdEnableCpuApCr3GdtIdtCheck is FALSE (which is the default). The reason
is that the 32-bit requirement is always ensured by edk2 itself; the
requirement is only possibly invalidated by a particular UEFI shell
application that manually moves the GDT/IDT/CR3 above 4GB. Platforms
that don't intend to be compatible with such UEFI applications need not
set the PCD to TRUE.

If the PCD is TRUE and the check fails, then the StartupAllAPs(),
StartupThisAP(), SwitchBSP() and EnableDisableAP() MP service APIs are
rejected at once. Reporting an error immediately is more graceful than
hanging when the APs attempt to switch to long mode.

Signed-off-by: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
---
V3:
only add check for the DxeMplib, no need for PeiMpLib.

V2:
Change the check point. Just in the different caller to make the logic
clear. V1 patch add check just before the use of the code. It make the
logic complicated.

 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   | 97 +++
 UefiCpuPkg/UefiCpuPkg.dec |  4 +
 UefiCpuPkg/UefiCpuPkg.uni |  2 +
 4 files changed, 104 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 1771575c69..7792df516e 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -74,5 +74,6 @@
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds  ## 
CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled  ## 
CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase   ## 
SOMETIMES_CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdEnableCpuApCr3GdtIdtCheck   ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard  ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase   ## 
CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 2c00d72dde..332b4447bb 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -29,6 +29,66 @@ VOID *mReservedApLoopFunc = NULL;
 UINTNmReservedTopOfApStack;
 volatile UINT32  mNumberToFinish = 0;
 
+/**
+  Check whether Cr3/GDT/IDT value valid for the APs.
+
+  @retval  TRUE  Pass the check.
+  @retval  FALSE Fail the check.
+
+**/
+BOOLEAN
+ValidCr3GdtIdtCheck (
+  VOID
+  )
+{
+  IA32_DESCRIPTOR   Gdtr;
+  IA32_DESCRIPTOR   Idtr;
+
+  if (!PcdGetBool (PcdEnableCpuApCr3GdtIdtCheck)) {
+return TRUE;
+  }
+
+  //
+  // AP needs to run from real mode to 32bit mode to LONG mode. Page table
+  // (pointed by Cr3) and GDT are necessary to set up to correct value when
+  // CPU execution mode is switched to LONG mode. IDT also necessary if the
+  // exception happened.
+  // AP uses the same location page table (Cr3) and GDT/IDT as what BSP uses.
+  // But when the page table or GDT is above 4GB, it's impossible for CPU
+  // to use because GDTR.base and Cr3 are 32bits before switching to LONG
+  // mode.
+  // Here add check for the Cr3, GDT.Base and range, IDT.Base and range are
+  // not above 32 bits limitation.
+  //
+  if (AsmReadCr3 () >= BASE_4GB) {
+return FALSE;
+  }
+
+  AsmReadGdtr ();
+  //
+  // Here code needs to check both Gdtr.Base and Gdtr.Base + Gdtr.Limit
+  // below BASE_4GB, but Gdtr.Base + Gdtr.Limit below BASE_4GB also means
+  // Gdtr.Base below BASE_4GB. so here just add Gdtr.Base + Gdtr.Limit
+  // check.
+  //
+  if (Gdtr.Base + Gdtr.Limit >= BASE_4GB) {
+return FALSE;
+  }
+
+  AsmReadIdtr ();
+  //
+  // Here code needs to check both Idtr.Base and Idtr.Base + Idtr.Limit
+  // below BASE_4GB, but Idtr.Base + Idtr.Limit below BASE_4GB also means
+  // Idtr.Base below BASE_4GB. so here just add Idtr.Base + Idtr.Limit
+  // check.
+  //
+  if (Idtr.Base + Idtr.Limit >= BASE_4GB) {
+return FALSE;
+  }
+
+  return TRUE;
+}
+
 /**
   Enable Debug Agent to support source debugging on AP function.
 
@@ -394,6 +454,15 @@ MpInitChangeApLoopCallback (
 {
   CPU_MP_DATA   *CpuMpData;
 
+  //
+  // Check the Cr3/GDT/IDT before waking up AP.
+  // If the check return fail, it will block later
+  // OS boot, so halt the system here.
+  //
+  if (!ValidCr3GdtIdtCheck 

Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-03 Thread Dong, Eric
Hi Laszlo,

Thanks for your comments, I send out v2 change.  I agree with you suggest 
adding PCD to control this check. Detail see v2 change.

Add other comments inline below.

From: Laszlo Ersek 
Sent: Thursday, September 3, 2020 3:59 PM
To: Dong, Eric ; devel@edk2.groups.io
Cc: Ni, Ray 
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

On 09/03/20 03:47, Dong, Eric wrote:
> Hi Laszlo,
>
> Thanks for your detail review and good comments, add my reply in
> below.
>
> This issue was reported by tester. They use a shell application to do
> the test. In the test, it first moves the page table to above 4G range
> then calls StartUpThisAp to let AP run the test procedure.  The system
> will hang during the test.
>
> Add more comments in below inline.

Thanks. Let me summarize my understanding:

(1) During normal boot, and normal MP services PPI usage, and normal MP
services protocol usage, there is no issue.
[Eric] Correct.

(2) Right now, we have not identified the exact edk2 core modules and
locations that are responsible for allocating the IDT / GDT / page
tables.
[Eric] I don’t check the IDT/GDT yet.
For page table, it created by DxeIpl driver and used for later boot phase.

Nonetheless, the allocations are all placed in the 32-bit
address space, and so there is no problem with AP startup, during
normal usage (see point (1)).
[Eric] Correct.


(3) There is a UEFI shell application that isn't more closely identified
in this discussion. It first moves at least one of the IDT / GDT /
page tables above 4GB, and then calls some member functions of the
MP services protocol. This causes a hang, experienced during the
execution of the UEFI shell application.
[Eric] Correct.


(4) The present patch recognizes the issue in FillExchangeInfoData(),
and returns an error. In the relevant use case (UEFI shell
application), this causes the called MP services protocol member
function to fail, synchronously. This means the application still
doesn't work, but there is no hang at least.
[Eric] Correct.

Is my understanding correct?

If it is, then I have the following comments:

- Please file a TianoCore BZ for this issue, and capture the use case in
  it (= UEFI shell application that changes the IDT / GDT / page tables
  base). Please feel free to copy parts of the above description, if you
  think that's useful.

- I'm quite doubtful that the use case is valid, in the first place. A
  UEFI application is supposed to consume the services described in the
  UEFI specification. Messing with the page tables is something that a
  UEFI application should *not* do, in my opinion. Such page table
  manipulation is expected to interfere with various DXE drivers in the
  platform firmware.

- Another comment on the UEFI shell application, and the present patch,
  is that their *combination* will still break ExitBootServices().
  Assume that the patch is applied, and the UEFI shell application is
  invoked. The application now fails gracefully, and exits. Then we
  attempt to boot an OS (this is a valid thing to do). Because the
  application moved the IDT / GDT / page tables "out of range",
  MpInitChangeApLoopCallback() will do the wrong thing.

- Most importantly: in MpInitLib, there is a *large* amount of call
  sites, and a large number of call paths that lead to WakeUpAP(), and
  ultimately to FillExchangeInfoData(). This means that changing the
  return type of FillExchangeInfoData() from VOID to EFI_STATUS has a
  "ripple effect" -- many call paths would have to deal with error
  checking, error propagation, and resource release (!!!) along those
  error paths.

  - For example, your current patch leaks resources in WakeUpAP(), when
FillExchangeInfoData() fails -- see AllocateResetVector() and
AllocateSevEsAPMemory().

  - For another example, your current patch does not handle several
WakeUpAP() call sites, such as the ones in
ResetProcessorToIdleState() and CheckAllAPs().

  Whereas in reality, from the applications point of view, we only need
  the MP services protocol member functions to fail cleanly. Therefore
  we should address this problem *early*; that is, *much less deep* in
  the call stack.


I suggest the following:

- introduce a feature PCD (default value FALSE)

- modify the following functions in MpInitLib:

  - MpInitLibStartupAllAPs
  - MpInitLibStartupThisAP
  - MpInitLibSwitchBSP
  - MpInitLibEnableDisableAP
[Eric] I found above 4 API need to wake up AP to do the task, so I add code to 
check the CR3/GDT/IDT.
Below 3 API does not need to wake up AP, so I don’t add the check.

  - MpInitLibGetNumberOfProcessors
  - MpInitLibGetProcessorInfo
  - MpInitLibWhoAmI


- each modified function should check the feature PCD *very early*. If
  the PCD is true, then the function should pre-emptively verify the IDT
  / GDT / root page table  location. If any on

[edk2-devel] [PATCH v2] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-03 Thread Dong, Eric
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2954

AP needs to run from real mode to 32bit mode to LONG mode. Page table
(pointed by CR3) and GDT are necessary to set up to correct value when
CPU execution mode is switched to LONG mode.
AP uses the same location page table (CR3) and GDT as what BSP uses.
But when the page table or GDT is above 4GB, it's impossible for CPU
to use because GDTR.base and CR3 are 32bits before switching to LONG
mode.
This patch adds check for the CR3, GDT.Base and IDT.Base to not above
32 bits restriction.

Change-Id: I231180f45d9f542641082c57d001e38e3f6759d5
Signed-off-by: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
---

V2:
Change the check point. Just in the different caller to make the logic
clear. V1 patch add check just before the use of the code. It make the
logic complicated.

 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  9 +++
 UefiCpuPkg/Library/MpInitLib/MpLib.c  | 76 +++
 UefiCpuPkg/Library/MpInitLib/MpLib.h  | 12 +++
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |  1 +
 UefiCpuPkg/UefiCpuPkg.dec |  4 +
 6 files changed, 103 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 1771575c69..20851f251a 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -76,3 +76,4 @@
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase   ## 
SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard  ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase   ## 
CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdEnableCpuApCr3GdtIdtCheck   ## 
CONSUMES
\ No newline at end of file
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 2c00d72dde..f598372c4d 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -394,6 +394,15 @@ MpInitChangeApLoopCallback (
 {
   CPU_MP_DATA   *CpuMpData;
 
+  //
+  // Check the CR3/GDT/IDT before waking up AP.
+  // If the check return fail, it will block later
+  // OS boot, so halt the system here.
+  //
+  if (!ValidCR3GdtIdtCheck()) {
+CpuDeadLoop ();
+  }
+
   CpuMpData = GetCpuMpData ();
   CpuMpData->PmCodeSegment = GetProtectedModeCS ();
   CpuMpData->Pm16CodeSegment = GetProtectedMode16CS ();
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 07426274f6..69a0372df7 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1909,6 +1909,54 @@ CheckAllAPs (
   return EFI_NOT_READY;
 }
 
+/**
+  Check whether CR3/GDT/IDT value valid for AP.
+
+  @retval  TRUE  Pass the check.
+  @retval  FALSE Fail the check.
+
+**/
+BOOLEAN
+ValidCR3GdtIdtCheck (
+  VOID
+  )
+{
+  IA32_DESCRIPTOR   Gdtr;
+  IA32_DESCRIPTOR   Idtr;
+
+  if (!PcdGetBool (PcdEnableCpuApCr3GdtIdtCheck)) {
+return TRUE;
+  }
+
+  //
+  // AP needs to run from real mode to 32bit mode to LONG mode. Page table
+  // (pointed by CR3) and GDT are necessary to set up to correct value when
+  // CPU execution mode is switched to LONG mode. IDT also necessary if the
+  // exception happened.
+  // AP uses the same location page table (CR3) and GDT/IDT as what BSP uses.
+  // But when the page table or GDT is above 4GB, it's impossible for CPU
+  // to use because GDTR.base and CR3 are 32bits before switching to LONG
+  // mode.
+  // Here add check for the CR3, GDT.Base and range, IDT.Base and range are
+  // not above 32 bits limitation.
+  //
+  if (AsmReadCr3 () >= BASE_4GB) {
+return FALSE;
+  }
+
+  AsmReadGdtr ((IA32_DESCRIPTOR *) );
+  if ((Gdtr.Base >= BASE_4GB) || (Gdtr.Base + Gdtr.Limit >= BASE_4GB)) {
+return FALSE;
+  }
+
+  AsmReadIdtr ((IA32_DESCRIPTOR *) );
+  if ((Idtr.Base >= BASE_4GB) || (Idtr.Base + Idtr.Limit >= BASE_4GB)) {
+return FALSE;
+  }
+
+  return TRUE;
+}
+
 /**
   MP Initialize Library initialization.
 
@@ -2318,6 +2366,13 @@ SwitchBSPWorker (
 return EFI_NOT_READY;
   }
 
+  //
+  // Check whether CR3/GDT/IDT valid for AP.
+  //
+  if (!ValidCR3GdtIdtCheck()) {
+return EFI_INVALID_PARAMETER;
+  }
+
   CpuMpData->BSPInfo.State = CPU_SWITCH_STATE_IDLE;
   CpuMpData->APInfo.State  = CPU_SWITCH_STATE_IDLE;
   CpuMpData->SwitchBspFlag = TRUE;
@@ -2420,6 +2475,13 @@ EnableDisableApWorker (
 return EFI_NOT_FOUND;
   }
 
+  //
+  // Check whether CR3/GDT/IDT valid for AP.
+  //
+  if (!ValidCR3GdtIdtCheck()) {
+return EFI_INVALID_PARAMETER;
+  }
+
   if (!EnableAP) {
 SetApState (>CpuData[ProcessorNumber], CpuStateDisabled);
   } else {
@@ -2607,6 +2669,13 @@ StartupAllCPUsWorker (
 return EFI_DEVICE_ERROR;
   }
 
+  //
+  // Check whether CR3/GDT/IDT valid for AP.
+  //
+  if 

Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-02 Thread Dong, Eric
Hi Laszlo,

Thanks for your detail review and good comments, add my reply in below.

This issue was reported by tester. They use a shell application to do the test. 
In the test, it first moves the page table to above 4G range then calls 
StartUpThisAp to let AP run the test procedure.  The system will hang during 
the test.

Add more comments in below inline.

From: Laszlo Ersek mailto:ler...@redhat.com>>
Sent: Wednesday, September 2, 2020 3:43 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Dong, Eric 
mailto:eric.d...@intel.com>>
Cc: Ni, Ray mailto:ray...@intel.com>>
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Add check for 
CR3/GDT/IDT.

Hi Eric,

On 09/02/20 02:43, Dong, Eric wrote:
> AP needs to run from real mode to 32bit mode to LONG mode. Page table
> (pointed by CR3) and GDT are necessary to set up to correct value when
> CPU execution mode is switched to LONG mode.
> AP uses the same location page table (CR3) and GDT as what BSP uses.
> But when the page table or GDT is above 4GB, it's impossible for CPU
> to use because GDTR.base and CR3 are 32bits before switching to LONG
> mode.
> This patch adds check for the CR3, GDT.Base and IDT.Base to not above
> 32 bits restriction.
>
> Signed-off-by: Eric Dong mailto:eric.d...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> Cc: Laszlo Ersek mailto:ler...@redhat.com>>
> ---
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |   8 +-
>  UefiCpuPkg/Library/MpInitLib/MpLib.c| 108 +++-
>  UefiCpuPkg/Library/MpInitLib/MpLib.h|   6 +-
>  3 files changed, 97 insertions(+), 25 deletions(-)

(1) This is not for edk2-stable202008, correct?
[Eric] Yes, just a bug fix for the issue I received recently.



(2) If I understand correctly, this patch does not solve the problem
when any one of the IDT, GDT, and CR3, are out of 32-bit address space.
Instead, the patch makes the failure symptoms more graceful.

Is that correct?
[Eric] yes, current result is the system hang, I just add error handling to 
avoid hang.


If so, can you explain in the commit message what happens without the
patch, versus with the patch, when the IDT / GDT / CR3 are out of 32-bit
address space?
[Eric] got it, will include it in next version patch.


Like, if we abandon MpInitChangeApLoopCallback() mid-way, then (AIUI)
the AP "pen" (HLT loop) will not be relocated to reserved memory at
ExitBootServces(). I don't think that simply giving up can end well for
the OS!
[Eric] agree. I don’t find a good way to handle it, so I add an error console 
log
In it. I will also add  “ASSERT (FALSE)” code to highlight the error.

(3) Can you remind us in the commit message where the IDT / GDT / page
tables are actually allocated? That is, can you please name the
component that is usually responsible for keeping the allocations in the
32-bit address space?

And once we know where the IDT / GDT / page tables come from --
shouldn't we rather modify those modules, to allocate IDT / GDT / page
tables in the 32-bit address space?
[Eric] This issue trigged by a shell application, so I can’t provide the module 
or driver that cause this failure.


More below:

> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
> b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> index 2c00d72dde..27f12a75a8 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> @@ -393,13 +393,19 @@ MpInitChangeApLoopCallback (
>)
>  {
>CPU_MP_DATA   *CpuMpData;
> +  EFI_STATUSStatus;
>
>CpuMpData = GetCpuMpData ();
>CpuMpData->PmCodeSegment = GetProtectedModeCS ();
>CpuMpData->Pm16CodeSegment = GetProtectedMode16CS ();
>CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
>mNumberToFinish = CpuMpData->CpuCount - 1;
> -  WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
> +  Status = WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "ERROR :: %a() Change Ap Loop Mode failed!\n", 
> __FUNCTION__));
> +return;
> +  }
> +
>while (mNumberToFinish > 0) {
>  CpuPause ();
>}
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 07426274f6..21b17a7b40 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -470,7 +470,7 @@ GetProcessorNumber (
>
>@return  CPU count detected
>  **/
> -UINTN
> +EFI_STATUS
>  CollectProcessorCount (
>IN CPU_MP_DATA *CpuMpData
>)
> @@ -478,12 +478,17 @@ CollectProcessorCount (
>UINTN  Index;
>CPU_INFO_IN_HOB*CpuInfoInHob;
>BOOLEANX2Apic;
> +  EFI_STATUS  

[edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Add check for CR3/GDT/IDT.

2020-09-01 Thread Dong, Eric
AP needs to run from real mode to 32bit mode to LONG mode. Page table
(pointed by CR3) and GDT are necessary to set up to correct value when
CPU execution mode is switched to LONG mode.
AP uses the same location page table (CR3) and GDT as what BSP uses.
But when the page table or GDT is above 4GB, it's impossible for CPU
to use because GDTR.base and CR3 are 32bits before switching to LONG
mode.
This patch adds check for the CR3, GDT.Base and IDT.Base to not above
32 bits restriction.

Signed-off-by: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c |   8 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 108 +++-
 UefiCpuPkg/Library/MpInitLib/MpLib.h|   6 +-
 3 files changed, 97 insertions(+), 25 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 2c00d72dde..27f12a75a8 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -393,13 +393,19 @@ MpInitChangeApLoopCallback (
   )
 {
   CPU_MP_DATA   *CpuMpData;
+  EFI_STATUSStatus;
 
   CpuMpData = GetCpuMpData ();
   CpuMpData->PmCodeSegment = GetProtectedModeCS ();
   CpuMpData->Pm16CodeSegment = GetProtectedMode16CS ();
   CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
   mNumberToFinish = CpuMpData->CpuCount - 1;
-  WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
+  Status = WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "ERROR :: %a() Change Ap Loop Mode failed!\n", 
__FUNCTION__));
+return;
+  }
+
   while (mNumberToFinish > 0) {
 CpuPause ();
   }
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 07426274f6..21b17a7b40 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -470,7 +470,7 @@ GetProcessorNumber (
 
   @return  CPU count detected
 **/
-UINTN
+EFI_STATUS
 CollectProcessorCount (
   IN CPU_MP_DATA *CpuMpData
   )
@@ -478,12 +478,17 @@ CollectProcessorCount (
   UINTN  Index;
   CPU_INFO_IN_HOB*CpuInfoInHob;
   BOOLEANX2Apic;
+  EFI_STATUS Status;
 
   //
   // Send 1st broadcast IPI to APs to wakeup APs
   //
   CpuMpData->InitFlag = ApInitConfig;
-  WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
+  Status = WakeUpAP (CpuMpData, TRUE, 0, NULL, NULL, TRUE);
+  if (EFI_ERROR (Status)) {
+return Status;
+  }
+
   CpuMpData->InitFlag = ApInitDone;
   ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber));
   //
@@ -520,7 +525,11 @@ CollectProcessorCount (
 //
 // Wakeup all APs to enable x2APIC mode
 //
-WakeUpAP (CpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL, TRUE);
+Status = WakeUpAP (CpuMpData, TRUE, 0, ApFuncEnableX2Apic, NULL, TRUE);
+if (EFI_ERROR (Status)) {
+  return Status;
+}
+
 //
 // Wait for all known APs finished
 //
@@ -546,7 +555,7 @@ CollectProcessorCount (
 
   DEBUG ((DEBUG_INFO, "MpInitLib: Find %d processors in system.\n", 
CpuMpData->CpuCount));
 
-  return CpuMpData->CpuCount;
+  return EFI_SUCCESS;
 }
 
 /**
@@ -990,7 +999,7 @@ WaitApWakeup (
   @param[in] CpuMpData  Pointer to CPU MP Data
 
 **/
-VOID
+EFI_STATUS
 FillExchangeInfoData (
   IN CPU_MP_DATA   *CpuMpData
   )
@@ -1001,6 +1010,35 @@ FillExchangeInfoData (
   IA32_CR4 Cr4;
 
   ExchangeInfo  = CpuMpData->MpCpuExchangeInfo;
+  ExchangeInfo->Cr3 = AsmReadCr3 ();
+  if (ExchangeInfo->Cr3 > 0x) {
+//
+// AP needs to run from real mode to 32bit mode to LONG mode. Page table
+// (pointed by CR3) and GDT are necessary to set up to correct value when
+// CPU execution mode is switched to LONG mode.
+// AP uses the same location page table (CR3) and GDT as what BSP uses.
+// But when the page table or GDT is above 4GB, it's impossible for CPU
+// to use because GDTR.base and CR3 are 32bits before switching to LONG
+// mode.
+// Here add check for the CR3, GDT.Base and IDT.Base to not above 32 bits
+// limitation.
+//
+return EFI_UNSUPPORTED;
+  }
+
+  //
+  // Get the BSP's data of GDT and IDT
+  //
+  AsmReadGdtr ((IA32_DESCRIPTOR *) >GdtrProfile);
+  if (ExchangeInfo->GdtrProfile.Base > 0x) {
+return EFI_UNSUPPORTED;
+  }
+
+  AsmReadIdtr ((IA32_DESCRIPTOR *) >IdtrProfile);
+  if (ExchangeInfo->IdtrProfile.Base > 0x) {
+return EFI_UNSUPPORTED;
+  }
+
   ExchangeInfo->Lock= 0;
   ExchangeInfo->StackStart  = CpuMpData->Buffer;
   ExchangeInfo->StackSize   = CpuMpData->CpuApStackSize;
@@ -1009,9 +1047,6 @@ FillExchangeInfoData (
 
   ExchangeInfo->CodeSegment = AsmReadCs ();
   ExchangeInfo->DataSegment = AsmReadDs ();
-
-  ExchangeInfo->Cr3 = AsmReadCr3 ();
-
   ExchangeInfo->CFunction

Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Always initialize the DoDecrement variable

2020-08-20 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Lendacky, Thomas
> Sent: Thursday, August 20, 2020 10:53 PM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Dong, Eric ;
> Ni, Ray ; Laszlo Ersek ; Kumar,
> Rahul1 
> Subject: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Always initialize
> the DoDecrement variable
> 
> From: Tom Lendacky 
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2901
> 
> The DoDecrement variable in ApWakeupFunction () wasn't always being
> initialized. Update the code to always fully initialize it.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Cc: Rahul Kumar 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index 90416c81b616..07426274f639 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -885,9 +885,7 @@ ApWakeupFunction (
>UINT64Status;
>BOOLEAN   DoDecrement;
> 
> -  if (CpuMpData->InitFlag == ApInitConfig) {
> -DoDecrement = TRUE;
> -  }
> +  DoDecrement = (BOOLEAN) (CpuMpData->InitFlag ==
> + ApInitConfig);
> 
>while (TRUE) {
>  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
> --
> 2.28.0
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64515): https://edk2.groups.io/g/devel/message/64515
Mute This Topic: https://groups.io/mt/76309738/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [Patch] UefiCpuPkg/CpuCommonFeaturesLib: Fix spelling mistake

2020-08-01 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Kinney, Michael D 
> Sent: Saturday, August 1, 2020 8:28 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek ; Kumar, Rahul1 
> Subject: [Patch] UefiCpuPkg/CpuCommonFeaturesLib: Fix spelling mistake
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2357
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Cc: Rahul Kumar 
> Signed-off-by: Michael D Kinney 
> ---
>  UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c
> b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c
> index 844052b9a5..822126d355 100644
> --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c
> +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c
> @@ -287,7 +287,7 @@ LmceSupport (
> 
>McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
>if (ProcessorNumber == 0) {
> -DEBUG ((EFI_D_INFO, "LMCE eanble = %x\n", (BOOLEAN)
> (McgCap.Bits.MCG_LMCE_P != 0)));
> +DEBUG ((EFI_D_INFO, "LMCE enable = %x\n", (BOOLEAN)
> (McgCap.Bits.MCG_LMCE_P != 0)));
>}
>return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);
>  }
> --
> 2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63617): https://edk2.groups.io/g/devel/message/63617
Mute This Topic: https://groups.io/mt/75918827/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: pause in WaitForSemaphore() before re-fetch

2020-07-30 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Laszlo Ersek 
> Sent: Thursday, July 30, 2020 2:52 AM
> To: edk2-devel-groups-io 
> Cc: Dong, Eric ; Philippe Mathieu-Daudé
> ; Kumar, Rahul1 ; Ni, Ray
> 
> Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: pause in
> WaitForSemaphore() before re-fetch
> 
> Most busy waits (spinlocks) in
> "UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c"
> already call CpuPause() in their loop bodies; see SmmWaitForApArrival(),
> APHandler(), and SmiRendezvous(). However, the "main wait" within
> APHandler():
> 
> > //
> > // Wait for something to happen
> > //
> > WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
> 
> doesn't do so, as WaitForSemaphore() keeps trying to acquire the
> semaphore without pausing.
> 
> The performance impact is especially notable in QEMU/KVM + OVMF
> virtualization with CPU overcommit (that is, when the guest has significantly
> more VCPUs than the host has physical CPUs). The guest BSP is working
> heavily in:
> 
>   BSPHandler()  [MpService.c]
> PerformRemainingTasks() [PiSmmCpuDxeSmm.c]
>   SetUefiMemMapAttributes() [SmmCpuMemoryManagement.c]
> 
> while the many guest APs are spinning in the "Wait for something to happen"
> semaphore acquisition, in APHandler(). The guest APs are generating useless
> memory traffic and saturating host CPUs, hindering the guest BSP's progress
> in SetUefiMemMapAttributes().
> 
> Rework the loop in WaitForSemaphore(): call CpuPause() in every iteration
> after the first check fails. Due to Pause Loop Exiting (known as Pause Filter 
> on
> AMD), the host scheduler can favor the guest BSP over the guest APs.
> 
> Running a 16 GB RAM + 512 VCPU guest on a 448 PCPU host, this patch
> reduces OVMF boot time (counted until reaching grub) from 20-30 minutes
> to less than 4 minutes.
> 
> The patch should benefit physical machines as well -- according to the Intel
> SDM, PAUSE "Improves the performance of spin-wait loops". Adding PAUSE
> to the generic WaitForSemaphore() function is considered a general
> improvement.
> 
> Cc: Eric Dong 
> Cc: Philippe Mathieu-Daudé 
> Cc: Rahul Kumar 
> Cc: Ray Ni 
> Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1861718
> Signed-off-by: Laszlo Ersek 
> ---
> 
> Notes:
> Repo:   https://pagure.io/lersek/edk2.git
> Branch: sem_wait_pause_rhbz1861718
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 18 +++---
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> index 57e788c01b1f..4bcd217917d7 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> @@ -40,14 +40,18 @@ WaitForSemaphore (
>  {
>UINT32Value;
> 
> -  do {
> +  for (;;) {
>  Value = *Sem;
> -  } while (Value == 0 ||
> -   InterlockedCompareExchange32 (
> - (UINT32*)Sem,
> - Value,
> - Value - 1
> - ) != Value);
> +if (Value != 0 &&
> +InterlockedCompareExchange32 (
> +  (UINT32*)Sem,
> +  Value,
> +  Value - 1
> +  ) == Value) {
> +  break;
> +}
> +CpuPause ();
> +  }
>return Value - 1;
>  }
> 
> --
> 2.19.1.3.g30247aa5d201

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63531): https://edk2.groups.io/g/devel/message/63531
Mute This Topic: https://groups.io/mt/75871294/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2] UefiCpuPkg/MtrrLib/UnitTest: Add host based unit test

2020-07-26 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Ni, Ray 
> Sent: Friday, July 24, 2020 2:42 PM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Shao, Ming
> ; Dong, Eric ; Laszlo Ersek
> ; Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: [PATCH v2] UefiCpuPkg/MtrrLib/UnitTest: Add host based unit test
> 
> Add host based unit tests for the MtrrLib services.
> The BaseLib services AsmCpuid(), AsmReadMsr64(), and
> AsmWriteMsr64() are hooked and provide simple emulation
> of the CPUID leafs and MSRs required by the MtrrLib to
> run as a host based unit test.
> 
> Test cases are developed for each of the API.
> 
> For the most important APIs MtrrSetMemoryAttributesInMtrrSettings()
> and MtrrSetMemoryAttributeInMtrrSettings(), random inputs are
> generated and fed to the APIs to make sure the implementation is
> good. The test application accepts an optional parameter which
> specifies how many iterations of feeding random inputs to the two
> APIs. The overall number of test cases increases when the iteration
> increases. Default iteration is 10 when no parameter is specified.
> 
> Signed-off-by: Ray Ni 
> Signed-off-by: Michael D Kinney 
> Signed-off-by: Ming Shao 
> Cc: Michael D Kinney 
> Cc: Ming Shao 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Jiewen Yao 
> ---
>  .../MtrrLib/UnitTest/MtrrLibUnitTest.c| 1140 +
>  .../MtrrLib/UnitTest/MtrrLibUnitTest.h|  171 +++
>  .../MtrrLib/UnitTest/MtrrLibUnitTestHost.inf  |   39 +
>  UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c |  913 +
>  UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc|   31 +
>  5 files changed, 2294 insertions(+)
>  create mode 100644 UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
>  create mode 100644
> UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.h
>  create mode 100644
> UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTestHost.inf
>  create mode 100644 UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c
>  create mode 100644 UefiCpuPkg/Test/UefiCpuPkgHostTest.dsc
> 
> diff --git a/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
> b/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
> new file mode 100644
> index 00..2eac41fc74
> --- /dev/null
> +++ b/UefiCpuPkg/Library/MtrrLib/UnitTest/MtrrLibUnitTest.c
> @@ -0,0 +1,1140 @@
> +/** @file
> 
> +  Unit tests of the MtrrLib instance of the MtrrLib class
> 
> +
> 
> +  Copyright (c) 2020, Intel Corporation. All rights reserved.
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include "MtrrLibUnitTest.h"
> 
> +
> 
> +STATIC CONST MTRR_LIB_SYSTEM_PARAMETER mDefaultSystemParameter
> = {
> 
> +  42, TRUE, TRUE, CacheUncacheable, 12
> 
> +};
> 
> +
> 
> +STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters[] = {
> 
> +  { 38, TRUE, TRUE, CacheUncacheable,12 },
> 
> +  { 38, TRUE, TRUE, CacheWriteBack,  12 },
> 
> +  { 38, TRUE, TRUE, CacheWriteThrough,   12 },
> 
> +  { 38, TRUE, TRUE, CacheWriteProtected, 12 },
> 
> +  { 38, TRUE, TRUE, CacheWriteCombining, 12 },
> 
> +
> 
> +  { 42, TRUE, TRUE, CacheUncacheable,12 },
> 
> +  { 42, TRUE, TRUE, CacheWriteBack,  12 },
> 
> +  { 42, TRUE, TRUE, CacheWriteThrough,   12 },
> 
> +  { 42, TRUE, TRUE, CacheWriteProtected, 12 },
> 
> +  { 42, TRUE, TRUE, CacheWriteCombining, 12 },
> 
> +
> 
> +  { 48, TRUE, TRUE, CacheUncacheable,12 },
> 
> +  { 48, TRUE, TRUE, CacheWriteBack,  12 },
> 
> +  { 48, TRUE, TRUE, CacheWriteThrough,   12 },
> 
> +  { 48, TRUE, TRUE, CacheWriteProtected, 12 },
> 
> +  { 48, TRUE, TRUE, CacheWriteCombining, 12 },
> 
> +};
> 
> +
> 
> +UINT32mFixedMtrrsIndex[] = {
> 
> +  MSR_IA32_MTRR_FIX64K_0,
> 
> +  MSR_IA32_MTRR_FIX16K_8,
> 
> +  MSR_IA32_MTRR_FIX16K_A,
> 
> +  MSR_IA32_MTRR_FIX4K_C,
> 
> +  MSR_IA32_MTRR_FIX4K_C8000,
> 
> +  MSR_IA32_MTRR_FIX4K_D,
> 
> +  MSR_IA32_MTRR_FIX4K_D8000,
> 
> +  MSR_IA32_MTRR_FIX4K_E,
> 
> +  MSR_IA32_MTRR_FIX4K_E8000,
> 
> +  MSR_IA32_MTRR_FIX4K_F,
> 
> +  MSR_IA32_MTRR_FIX4K_F8000
> 
> +};
> 
> +STATIC_ASSERT (
> 
> +  (ARRAY_SIZE (mFixedMtrrsIndex) == MTRR_NUMBER_OF_FIXED_MTRR),
> 
> +  "gFixedMtrrIndex does NOT contain all the fixed MTRRs!"
> 
> +  );
> 
> +
> 
> +//
> 
> +// Context structure to be used for most of the test cases.
> 
> +//
> 
> +typedef struct {
> 
> +  CONST MTRR_LIB_SYSTEM_PARAMETER *SystemPa

Re: [edk2-devel] [PATCH 14/15] UefiCpuPkg/UefiCpuPkg.ci.yaml: Add configuration for LicenseCheck

2020-07-20 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Zhang, Shenglei 
> Sent: Monday, July 20, 2020 4:37 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [PATCH 14/15] UefiCpuPkg/UefiCpuPkg.ci.yaml: Add configuration
> for LicenseCheck
> 
> Add configuration IgnoreFiles for package config files.
> So users can rely on this to skip license conflict for some generated files.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Shenglei Zhang 
> ---
>  UefiCpuPkg/UefiCpuPkg.ci.yaml | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml
> b/UefiCpuPkg/UefiCpuPkg.ci.yaml index 99e460a8b090..d54651d43800
> 100644
> --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml
> +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml
> @@ -5,6 +5,9 @@
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  ##  {
> +"LicenseCheck": {
> +"IgnoreFiles": []
> +},
>  "CompilerPlugin": {
>  "DscPath": "UefiCpuPkg.dsc"
>  },
> --
> 2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62913): https://edk2.groups.io/g/devel/message/62913
Mute This Topic: https://groups.io/mt/75678225/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use

2020-07-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tom Lendacky 
> Sent: Tuesday, July 14, 2020 10:38 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs
> for OS use
> 
> From: Tom Lendacky 
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Before UEFI transfers control to the OS, it must park the AP. This is done
> using the AsmRelocateApLoop function to transition into 32-bit non-paging
> mode. For an SEV-ES guest, a few additional things must be
> done:
>   - AsmRelocateApLoop must be updated to support SEV-ES. This means
> performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop.
>   - Since the AP must transition to real mode, a small routine is copied
> to the WakeupBuffer area. Since the WakeupBuffer will be used by
> the AP during OS booting, it must be placed in reserved memory.
> Additionally, the AP stack must be located where it can be accessed
> in real mode.
>   - Once the AP is in real mode it will transfer control to the
> destination specified by the OS in the SEV-ES AP Jump Table. The
> SEV-ES AP Jump Table address is saved by the hypervisor for the OS
> using the GHCB VMGEXIT AP Jump Table exit code.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.h  |   8 +-
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  54 +++-
>  UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 131
> --
>  3 files changed, 175 insertions(+), 18 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index b1a9d99cb3eb..267aa5201c50 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -293,7 +293,8 @@ struct _CPU_MP_DATA {
>UINT64 GhcbBase;
>  };
> 
> -#define AP_RESET_STACK_SIZE 64
> +#define AP_SAFE_STACK_SIZE  128
> +#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
> 
>  #pragma pack(1)
> 
> @@ -349,8 +350,11 @@ VOID
>IN BOOLEAN MwaitSupport,
>IN UINTN   ApTargetCState,
>IN UINTN   PmCodeSegment,
> +  IN UINTN   Pm16CodeSegment,
>IN UINTN   TopOfApStack,
> -  IN UINTN   NumberToFinish
> +  IN UINTN   NumberToFinish,
> +  IN UINTN   SevEsAPJumpTable,
> +  IN UINTN   WakeupBuffer
>);
> 
>  /**
> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> index 9115ff9e3e30..7165bcf3124a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> @@ -12,6 +12,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
> 
> @@ -85,6 +86,13 @@ GetWakeupBuffer (
>  {
>EFI_STATUS  Status;
>EFI_PHYSICAL_ADDRESSStartAddress;
> +  EFI_MEMORY_TYPE MemoryType;
> +
> +  if (PcdGetBool (PcdSevEsIsEnabled)) {
> +MemoryType = EfiReservedMemoryType;  } else {
> +MemoryType = EfiBootServicesData;
> +  }
> 
>//
>// Try to allocate buffer below 1M for waking vector.
> @@ -97,7 +105,7 @@ GetWakeupBuffer (
>StartAddress = 0x88000;
>Status = gBS->AllocatePages (
>AllocateMaxAddress,
> -  EfiBootServicesData,
> +  MemoryType,
>EFI_SIZE_TO_PAGES (WakeupBufferSize),
>
>);
> @@ -159,8 +167,10 @@ GetSevEsAPMemory (
>VOID
>)
>  {
> -  EFI_STATUSStatus;
> -  EFI_PHYSICAL_ADDRESS  StartAddress;
> +  EFI_STATUSStatus;
> +  EFI_PHYSICAL_ADDRESS  StartAddress;
> +  MSR_SEV_ES_GHCB_REGISTER  Msr;
> +  GHCB  *Ghcb;
> 
>//
>// Allocate 1 page for AP jump table page @@ -176,6 +186,16 @@
> GetSevEsAPMemory (
> 
>DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN)
> StartAddress));
> 
> +  //
> +  // Save the SevEsAPMemory as the AP jump table.
> +  //
> +  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);  Ghcb
> =
> + Msr.Ghcb;
> +
> +  VmgInit (Ghcb);
> +  VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN)
> + StartAddress);  VmgDone (Ghcb);
> +
>return (UINTN) StartAddress;
>  }
> 
> @@ -330,17 +350

Re: [edk2-devel] [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES

2020-07-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tom Lendacky 
> Sent: Tuesday, July 14, 2020 10:38 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES
> 
> From: Tom Lendacky 
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This sequence is
> intercepted by the hypervisor, which sets the AP's registers to the values
> requested by the sequence. At that point, the hypervisor can start the AP,
> which will then begin execution at the appropriate location.
> 
> Under SEV-ES, AP booting presents some challenges since the hypervisor is
> not allowed to alter the AP's register state. In this situation, we have to
> distinguish between the AP's first boot and AP's subsequent boots.
> 
> First boot:
>  Once the AP's register state has been defined (which is before the guest  is
> first booted) it cannot be altered. Should the hypervisor attempt to  alter 
> the
> register state, the change would be detected by the hardware  and the
> VMRUN instruction would fail. Given this, the first boot for the  AP is
> required to begin execution with this initial register state, which  is 
> typically
> the reset vector. This prevents the BSP from directing the  AP startup
> location through the INIT-SIPI-SIPI sequence.
> 
>  To work around this, the firmware will provide a build time reserved area
> that can be used as the initial IP value. The hypervisor can extract this
> location value by checking for the SEV-ES reset block GUID that must be
> located 48-bytes from the end of the firmware. The format of the SEV-ES
> reset block area is:
> 
>0x00 - 0x01 - SEV-ES Reset IP
>0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16]
>0x04 - 0x05 - Size of the SEV-ES reset block
>0x06 - 0x15 - SEV-ES Reset Block GUID
>(00f771de-1a7e-4fcb-890e-68c77e2fb44e)
> 
>The total size is 22 bytes. Any expansion to this block must be done
>by adding new values before existing values.
> 
>  The hypervisor will use the IP and CS values obtained from the SEV-ES  reset
> block to set as the AP's initial values. The CS Segment Base  represents the
> upper 16 bits of the CS segment base and must be left  shifted by 16 bits to
> form the complete CS segment base value.
> 
>  Before booting the AP for the first time, the BSP must initialize the  SEV-ES
> reset area. This consists of programming a FAR JMP instruction  to the
> contents of a memory location that is also located in the SEV-ES  reset area.
> The BSP must program the IP and CS values for the FAR JMP  based on values
> drived from the INIT-SIPI-SIPI sequence.
> 
> Subsequent boots:
>  Again, the hypervisor cannot alter the AP register state, so a method is
> required to take the AP out of halt state and redirect it to the desired  IP
> location. If it is determined that the AP is running in an SEV-ES  guest, then
> instead of calling CpuSleep(), a VMGEXIT is issued with the  AP Reset Hold
> exit code (0x8004). The hypervisor will put the AP in  a halt state, 
> waiting
> for an INIT-SIPI-SIPI sequence. Once the sequence  is recognized, the
> hypervisor will resume the AP. At this point the AP  must transition from the
> current 64-bit long mode down to 16-bit real  mode and begin executing at
> the derived location from the INIT-SIPI-SIPI  sequence.
> 
>  Another change is around the area of obtaining the (x2)APIC ID during AP
> startup. During AP startup, the AP can't take a #VC exception before the  AP
> has established a stack. However, the AP stack is set by using the  (x2)APIC 
> ID,
> which is obtained through CPUID instructions. A CPUID  instruction will cause
> a #VC, so a different method must be used. The  GHCB protocol supports a
> method to obtain CPUID information from the  hypervisor through the GHCB
> MSR. This method does not require a stack,  so it is used to obtain the
> necessary CPUID information to determine the  (x2)APIC ID.
> 
> The new 16-bit protected mode GDT entry is used in order to transition from
> 64-bit long mode down to 16-bit real mode.
> 
> A new assembler routine is created that takes the AP from 64-bit long mode
> to 16-bit real mode.  This is located under 1MB in memory and transitions
> from 64-bit long mode to 32-bit compatibility mode to 16-bit protected mode
> and finally 16-bit real mode.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   3 +
&g

Re: [edk2-devel] [PATCH v2 1/3] UefiCpuPkg/MtrrLib: Remove unnecessary API MtrrGetVariableMtrr()

2020-07-13 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ni, Ray
> Sent: Monday, July 13, 2020 4:13 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Laszlo Ersek ;
> Kumar, Rahul1 
> Subject: [edk2-devel] [PATCH v2 1/3] UefiCpuPkg/MtrrLib: Remove
> unnecessary API MtrrGetVariableMtrr()
> 
> MtrrGetVariableMtrr() returns all the variable MTRR settings.
> But in fact MtrrGetAllMtrrs() and
> MtrrGetMemoryAttributeInVariableMtrr() are used by callers to get the
> MTRR settings. The former one returns both the fixed and variable
> MTRR settings.
> 
> The patch removes the necessary API MtrrGetVariableMtrr() to simplify
> the MtrrLib API.
> 
> There is no code in edk2 and edk2-platforms repo that calls
> MtrrGetVariableMtrr().
> 
> Signed-off-by: Ray Ni 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Cc: Rahul Kumar 
> ---
>  UefiCpuPkg/Include/Library/MtrrLib.h | 17 +
>  UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 27 +--
>  2 files changed, 2 insertions(+), 42 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/MtrrLib.h
> b/UefiCpuPkg/Include/Library/MtrrLib.h
> index 95ffbc8bf1..cfe3c0ab59 100644
> --- a/UefiCpuPkg/Include/Library/MtrrLib.h
> +++ b/UefiCpuPkg/Include/Library/MtrrLib.h
> @@ -1,7 +1,7 @@
>  /** @file
> 
>MTRR setting library
> 
> 
> 
> -  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
> 
> +  Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.
> 
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
>  **/
> 
> @@ -185,21 +185,6 @@ MtrrGetMemoryAttribute (
>);
> 
> 
> 
> 
> 
> -/**
> 
> -  This function will get the raw value in variable MTRRs
> 
> -
> 
> -  @param[out]  VariableSettings   A buffer to hold variable MTRRs content.
> 
> -
> 
> -  @return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the
> content of the variable MTRR
> 
> -
> 
> -**/
> 
> -MTRR_VARIABLE_SETTINGS*
> 
> -EFIAPI
> 
> -MtrrGetVariableMtrr (
> 
> -  OUT MTRR_VARIABLE_SETTINGS *VariableSettings
> 
> -  );
> 
> -
> 
> -
> 
>  /**
> 
>This function sets variable MTRRs
> 
> 
> 
> diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> index dfa848022b..f4a10edc87 100644
> --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> @@ -5,7 +5,7 @@
>  Most of services in this library instance are suggested to be invoked by 
> BSP
> only,
> 
>  except for MtrrSetAllMtrrs() which is used to sync BSP's MTRR setting to
> APs.
> 
> 
> 
> -  Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.
> 
> +  Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.
> 
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
>  **/
> 
> @@ -456,31 +456,6 @@ MtrrGetVariableMtrrWorker (
>return  VariableSettings;
> 
>  }
> 
> 
> 
> -/**
> 
> -  This function will get the raw value in variable MTRRs
> 
> -
> 
> -  @param[out]  VariableSettings   A buffer to hold variable MTRRs content.
> 
> -
> 
> -  @return The VariableSettings input pointer
> 
> -
> 
> -**/
> 
> -MTRR_VARIABLE_SETTINGS*
> 
> -EFIAPI
> 
> -MtrrGetVariableMtrr (
> 
> -  OUT MTRR_VARIABLE_SETTINGS *VariableSettings
> 
> -  )
> 
> -{
> 
> -  if (!IsMtrrSupported ()) {
> 
> -return VariableSettings;
> 
> -  }
> 
> -
> 
> -  return MtrrGetVariableMtrrWorker (
> 
> -   NULL,
> 
> -   GetVariableMtrrCountWorker (),
> 
> -   VariableSettings
> 
> -   );
> 
> -}
> 
> -
> 
>  /**
> 
>Programs fixed MTRRs registers.
> 
> 
> 
> --
> 2.27.0.windows.1
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#62404): https://edk2.groups.io/g/devel/message/62404
> Mute This Topic: https://groups.io/mt/75472802/1768733
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub  [eric.d...@intel.com]
> -=-=-=-=-=-=


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62469): https://edk2.groups.io/g/devel/message/62469
Mute This Topic: https://groups.io/mt/75472802/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 2/3] UefiCpuPkg/MtrrLib: Remove unnecessary API MtrrSetVariableMtrr()

2020-07-13 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ni, Ray
> Sent: Monday, July 13, 2020 4:13 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Laszlo Ersek ;
> Kumar, Rahul1 
> Subject: [edk2-devel] [PATCH v2 2/3] UefiCpuPkg/MtrrLib: Remove
> unnecessary API MtrrSetVariableMtrr()
> 
> MtrrSetVariableMtrr() sets all the variable MTRR settings.
> But in fact MtrrSetAllMtrrs() is always used by callers to set all
> MTRR settings including the fixed and variable ones.
> 
> The patch removes the necessary API MtrrSetVariableMtrr() to simplify
> the MtrrLib API.
> 
> There is no code in edk2 and edk2-platforms repo that calls
> MtrrGetVariableMtrr().
> 
> Signed-off-by: Ray Ni 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Cc: Rahul Kumar 
> ---
>  UefiCpuPkg/Include/Library/MtrrLib.h | 15 --
>  UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 29 
>  2 files changed, 44 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/MtrrLib.h
> b/UefiCpuPkg/Include/Library/MtrrLib.h
> index cfe3c0ab59..0bc69e235c 100644
> --- a/UefiCpuPkg/Include/Library/MtrrLib.h
> +++ b/UefiCpuPkg/Include/Library/MtrrLib.h
> @@ -185,21 +185,6 @@ MtrrGetMemoryAttribute (
>);
> 
> 
> 
> 
> 
> -/**
> 
> -  This function sets variable MTRRs
> 
> -
> 
> -  @param[in]  VariableSettings   A buffer to hold variable MTRRs content.
> 
> -
> 
> -  @return The pointer of VariableSettings
> 
> -
> 
> -**/
> 
> -MTRR_VARIABLE_SETTINGS*
> 
> -EFIAPI
> 
> -MtrrSetVariableMtrr (
> 
> -  IN MTRR_VARIABLE_SETTINGS *VariableSettings
> 
> -  );
> 
> -
> 
> -
> 
>  /**
> 
>This function gets the content in fixed MTRRs
> 
> 
> 
> diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> index f4a10edc87..8b54f2c03b 100644
> --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> @@ -2558,35 +2558,6 @@ MtrrSetVariableMtrrWorker (
>}
> 
>  }
> 
> 
> 
> -
> 
> -/**
> 
> -  This function sets variable MTRRs
> 
> -
> 
> -  @param[in]  VariableSettings   A buffer to hold variable MTRRs content.
> 
> -
> 
> -  @return The pointer of VariableSettings
> 
> -
> 
> -**/
> 
> -MTRR_VARIABLE_SETTINGS*
> 
> -EFIAPI
> 
> -MtrrSetVariableMtrr (
> 
> -  IN MTRR_VARIABLE_SETTINGS *VariableSettings
> 
> -  )
> 
> -{
> 
> -  MTRR_CONTEXT  MtrrContext;
> 
> -
> 
> -  if (!IsMtrrSupported ()) {
> 
> -return VariableSettings;
> 
> -  }
> 
> -
> 
> -  MtrrLibPreMtrrChange ();
> 
> -  MtrrSetVariableMtrrWorker (VariableSettings);
> 
> -  MtrrLibPostMtrrChange ();
> 
> -  MtrrDebugPrintAllMtrrs ();
> 
> -
> 
> -  return  VariableSettings;
> 
> -}
> 
> -
> 
>  /**
> 
>Worker function setting fixed MTRRs
> 
> 
> 
> --
> 2.27.0.windows.1
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#62405): https://edk2.groups.io/g/devel/message/62405
> Mute This Topic: https://groups.io/mt/75472803/1768733
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub  [eric.d...@intel.com]
> -=-=-=-=-=-=


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62468): https://edk2.groups.io/g/devel/message/62468
Mute This Topic: https://groups.io/mt/75472803/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 3/3] UefiCpuPkg/MtrrLib: Remove unnecessary API MtrrSetFixedMtrr()

2020-07-13 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ni, Ray
> Sent: Monday, July 13, 2020 4:13 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Laszlo Ersek ;
> Kumar, Rahul1 
> Subject: [edk2-devel] [PATCH v2 3/3] UefiCpuPkg/MtrrLib: Remove
> unnecessary API MtrrSetFixedMtrr()
> 
> MtrrSetFixedMtrr() sets all the fixed MTRR settings.
> But in fact MtrrSetAllMtrrs() is always used by callers to set all MTRR 
> settings
> including the fixed and variable ones.
> 
> The patch removes the necessary API MtrrSetFixedMtrr() to simplify the
> MtrrLib API.
> 
> There is no code in edk2 and edk2-platforms repo that calls
> MtrrGetVariableMtrr().
> 
> Signed-off-by: Ray Ni 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Cc: Rahul Kumar 
> ---
>  UefiCpuPkg/Include/Library/MtrrLib.h | 15 --
> UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 29 
>  2 files changed, 44 deletions(-)
> 
> diff --git a/UefiCpuPkg/Include/Library/MtrrLib.h
> b/UefiCpuPkg/Include/Library/MtrrLib.h
> index 0bc69e235c..9110787067 100644
> --- a/UefiCpuPkg/Include/Library/MtrrLib.h
> +++ b/UefiCpuPkg/Include/Library/MtrrLib.h
> @@ -200,21 +200,6 @@ MtrrGetFixedMtrr (
>);  -/**-  This function sets fixed MTRRs--  @param[in]   FixedSettings
>   A
> buffer holding fixed MTRRs content.--  @return  The pointer of
> FixedSettings--**/-MTRR_FIXED_SETTINGS*-EFIAPI-MtrrSetFixedMtrr (-  IN
> MTRR_FIXED_SETTINGS  *FixedSettings-  );-- /**   This function gets 
> the
> content in all MTRRs (variable and fixed) diff --git
> a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> index 8b54f2c03b..ceab7a065f 100644
> --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
> @@ -2580,35 +2580,6 @@ MtrrSetFixedMtrrWorker (
>  }  -/**-  This function sets fixed MTRRs--  @param[in]  FixedSettings  A
> buffer to hold fixed MTRRs content.--  @retval The pointer of FixedSettings--
> **/-MTRR_FIXED_SETTINGS*-EFIAPI-MtrrSetFixedMtrr (-  IN
> MTRR_FIXED_SETTINGS  *FixedSettings-  )-{-  MTRR_CONTEXT
> MtrrContext;--  if (!IsMtrrSupported ()) {-return FixedSettings;-  }--
> MtrrLibPreMtrrChange ();-  MtrrSetFixedMtrrWorker
> (FixedSettings);-  MtrrLibPostMtrrChange ();-
> MtrrDebugPrintAllMtrrs ();--  return FixedSettings;-}-- /**   This function 
> gets
> the content in all MTRRs (variable and fixed) --
> 2.27.0.windows.1
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#62406): https://edk2.groups.io/g/devel/message/62406
> Mute This Topic: https://groups.io/mt/75472804/1768733
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub  [eric.d...@intel.com] -
> =-=-=-=-=-=


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62467): https://edk2.groups.io/g/devel/message/62467
Mute This Topic: https://groups.io/mt/75472804/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH V3 4/4] UefiCpuPkg: Add New Memory Attributes

2020-07-13 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Oleksiy
> Yakovlev
> Sent: Friday, July 3, 2020 4:51 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Kinney, Michael D
> ; Bi, Dandan ; Ni, Ray
> ; ler...@redhat.com; Kumar, Rahul1
> ; fel...@ami.com; oleks...@ami.com
> Subject: [edk2-devel] [PATCH V3 4/4] UefiCpuPkg: Add New Memory
> Attributes
> 
> Add usage of EFI_MEMORY_SP and EFI_MEMORY_CPU_CRYPTO attributes
> introduced in UEFI 2.8.
> (UEFI 2.8, mantis 1919 and 1872).
> Use attributes bitmasks, defined in MdePkg.
> 
> Signed-off-by: Oleksiy Yakovlev 
> Reviewed-by: Laszlo Ersek 
> ---
>  UefiCpuPkg/CpuDxe/CpuDxe.c | 11 ---
>  UefiCpuPkg/CpuDxe/CpuDxe.h | 13 -
>  UefiCpuPkg/CpuDxe/CpuPageTable.c   |  6 +++---
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c |  2 +-
>  4 files changed, 8 insertions(+), 24 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c
> index a571fc3..52cc26e 100644
> --- a/UefiCpuPkg/CpuDxe/CpuDxe.c
> +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c
> @@ -10,9 +10,6 @@
>  #include "CpuMp.h"
>  #include "CpuPageTable.h"
> 
> -#define CACHE_ATTRIBUTE_MASK   (EFI_MEMORY_UC | EFI_MEMORY_WC
> | EFI_MEMORY_WT | EFI_MEMORY_WB | EFI_MEMORY_UCE |
> EFI_MEMORY_WP)
> -#define MEMORY_ATTRIBUTE_MASK  (EFI_MEMORY_RP |
> EFI_MEMORY_XP | EFI_MEMORY_RO)
> -
>  //
>  // Global Variables
>  //
> @@ -417,8 +414,8 @@ CpuSetMemoryAttributes (
>  return EFI_SUCCESS;
>}
> 
> -  CacheAttributes = Attributes & CACHE_ATTRIBUTE_MASK;
> -  MemoryAttributes = Attributes & MEMORY_ATTRIBUTE_MASK;
> +  CacheAttributes = Attributes & EFI_CACHE_ATTRIBUTE_MASK;
> + MemoryAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;
> 
>if (Attributes != (CacheAttributes | MemoryAttributes)) {
>  return EFI_INVALID_PARAMETER;
> @@ -677,7 +674,7 @@ SetGcdMemorySpaceAttributes (
>  gDS->SetMemorySpaceAttributes (
> RegionStart,
> RegionLength,
> -   (MemorySpaceMap[Index].Attributes &
> ~EFI_MEMORY_CACHETYPE_MASK) |
> (MemorySpaceMap[Index].Capabilities & Attributes)
> +   (MemorySpaceMap[Index].Attributes &
> + ~EFI_CACHE_ATTRIBUTE_MASK) | (MemorySpaceMap[Index].Capabilities
> &
> + Attributes)
> );
>}
> 
> @@ -754,7 +751,7 @@ RefreshMemoryAttributesFromMtrr (
>  gDS->SetMemorySpaceAttributes (
> MemorySpaceMap[Index].BaseAddress,
> MemorySpaceMap[Index].Length,
> -   (MemorySpaceMap[Index].Attributes &
> ~EFI_MEMORY_CACHETYPE_MASK) |
> +   (MemorySpaceMap[Index].Attributes &
> + ~EFI_CACHE_ATTRIBUTE_MASK) |
> (MemorySpaceMap[Index].Capabilities & DefaultAttributes)
> );
>}
> diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h
> index b30a896..9771ec8 100644
> --- a/UefiCpuPkg/CpuDxe/CpuDxe.h
> +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h
> @@ -39,19 +39,6 @@
>  #include 
>  #include 
> 
> -#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC  | \
> -   EFI_MEMORY_WC  | \
> -   EFI_MEMORY_WT  | \
> -   EFI_MEMORY_WB  | \
> -   EFI_MEMORY_UCE | \
> -   EFI_MEMORY_WP\
> -   )
> -
> -#define EFI_MEMORY_PAGETYPE_MASK  (EFI_MEMORY_RP  | \
> -   EFI_MEMORY_XP  | \
> -   EFI_MEMORY_RO\
> -   )
> -
>  #define HEAP_GUARD_NONSTOP_MODE   \
>  ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) >
> BIT6)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c
> b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> index 0a02cb3..06ee1b8 100644
> --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c
> +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> @@ -717,7 +717,7 @@ ConvertMemoryPageAttributes (
>  return RETURN_INVALID_PARAMETER;
>}
> 
> -  if ((Attributes & ~(EFI_MEMORY_RP | EFI_MEMORY_RO |
> EFI_MEMORY_XP)) != 0) {
> +  if ((Attributes & ~EFI_MEMORY_ATTRIBUTE_MASK) != 0) {
>  DEBUG ((DEBUG_ERROR, "Attributes(0x%lx) has unsupported bit\n",
> Attributes));
>  return EFI_UNSUPPORTED;
>}
> @@ -1018,9 +1018,9 @@ RefreshGcdMemoryAttributesFromPaging (
> 
>Length = MIN (PageLength, MemorySpaceLength);
>if (Attributes != (MemorySpaceMap[Index].Attributes &
> - EFI_MEMORY_PAGETYPE_MASK)) {
> + EFI_MEMORY_ATTRIBUTE_MASK)) {
>  NewAttributes = (MemorySpaceMap[Index].Attributes &
> - ~EFI_MEMORY_PAGETYPE_MASK) | Attributes;
> + ~EFI_MEMORY_ATTRIBUTE_MASK) | Attributes;
>  Status = gDS->SetMemorySpaceAttributes (
>  BaseAddress,
>  Length,
> 

Re: [edk2-devel] [PATCH V3 3/4] UefiCpuPkg: Update EFI_MEMORY_CACHETYPE_MASK definition

2020-07-13 Thread Dong, Eric
Sorry, I missed this patch serial.

Acked-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Oleksiy
> Yakovlev
> Sent: Friday, July 3, 2020 4:51 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Kinney, Michael D
> ; Bi, Dandan ; Ni, Ray
> ; ler...@redhat.com; Kumar, Rahul1
> ; fel...@ami.com; oleks...@ami.com
> Subject: [edk2-devel] [PATCH V3 3/4] UefiCpuPkg: Update
> EFI_MEMORY_CACHETYPE_MASK definition
> 
> Add EFI_MEMORY_WP attribute to
> EFI_MEMORY_CACHETYPE_MASK definition.
> 
> Signed-off-by: Oleksiy Yakovlev 
> ---
>  UefiCpuPkg/CpuDxe/CpuDxe.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h
> index 9299eaa..b30a896 100644
> --- a/UefiCpuPkg/CpuDxe/CpuDxe.h
> +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h
> @@ -43,7 +43,8 @@
> EFI_MEMORY_WC  | \
> EFI_MEMORY_WT  | \
> EFI_MEMORY_WB  | \
> -   EFI_MEMORY_UCE   \
> +   EFI_MEMORY_UCE | \
> +   EFI_MEMORY_WP\
> )
> 
>  #define EFI_MEMORY_PAGETYPE_MASK  (EFI_MEMORY_RP  | \
> --
> 2.9.0.windows.1
> 
> 
> Please consider the environment before printing this email.
> 
> The information contained in this message may be confidential and
> proprietary to American Megatrends (AMI).  This communication is intended
> to be read only by the individual or entity to whom it is addressed or by 
> their
> designee. If the reader of this message is not the intended recipient, you are
> on notice that any distribution of this message, in any form, is strictly
> prohibited.  Please promptly notify the sender by reply e-mail or by
> telephone at 770-246-8600, and then delete or destroy all copies of the
> transmission.
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62456): https://edk2.groups.io/g/devel/message/62456
Mute This Topic: https://groups.io/mt/75267366/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v6 3/4] UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib

2020-07-06 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Garrett Kirkendall 
> Sent: Monday, June 22, 2020 9:18 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [PATCH v6 3/4] UefiCpuPkg: Move
> StandardSignatureIsAuthenticAMD to BaseUefiCpuLib
> 
> Refactor StandardSignatureIsAuthenticAMD into BaseUefiCpuLib from
> separate copies in BaseXApicLib, BaseXApicX2ApicLib, and MpInitLib.
> This allows for future use of StandarSignatureIsAuthinticAMD without
> creating more instances in other modules.
> 
> This function allows IA32/X64 code to determine if it is running on an AMD
> brand processor.
> 
> UefiCpuLib is already included directly or indirectly in all modified modules.
> Complete move is made in this change.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Garrett Kirkendall 
> Reviewed-by: Laszlo Ersek 
> Reviewed-by: Eric Dong 
> ---
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf |  7 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf |  2 ++
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf |  2 ++
>  UefiCpuPkg/Include/Library/UefiCpuLib.h  | 14 
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 38
> 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c   | 25 
> ++---
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c   | 25 ++--
> -
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 
> 
>  8 files changed, 67 insertions(+), 69 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> index 006b7acbf14e..34d3a7bb4303 100644
> --- a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> +++ b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> @@ -4,6 +4,7 @@
>  #  The library routines are UEFI specification compliant.
>  #
>  #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -29,6 +30,12 @@
> [Sources.IA32]  [Sources.X64]
>X64/InitializeFpu.nasm
> 
> +[Sources]
> +  BaseUefiCpuLib.c
> +
>  [Packages]
>MdePkg/MdePkg.dec
>UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> index bdb2ff372677..561baa44b0e6 100644
> --- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> +++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> @@ -5,6 +5,7 @@
>  #  where local APIC is disabled.
>  #
>  #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -37,6 +38,7 @@
> [LibraryClasses]
>TimerLib
>IoLib
>PcdLib
> +  UefiCpuLib
> 
>  [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuInitIpiDelayInMicroSeconds  ##
> SOMETIMES_CONSUMES diff --git
> a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> index ac1e0a1c9896..1e2a4f8b790f 100644
> --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> @@ -5,6 +5,7 @@
>  #  where local APIC is disabled.
>  #
>  #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -37,6 +38,7 @@
> [LibraryClasses]
>TimerLib
>IoLib
>PcdLib
> +  UefiCpuLib
> 
>  [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuInitIpiDelayInMicroSeconds  ##
> SOMETIMES_CONSUMES diff --git
> a/UefiCpuPkg/Include/Library/UefiCpuLib.h
> b/UefiCpuPkg/Include/Library/UefiCpuLib.h
> index 82e53bab3a0f..5326e7246301 100644
> --- a/UefiCpuPkg/Include/Library/UefiCpuLib.h
> +++ b/UefiCpuPkg/Include/Library/UefiCpuLib.h
> @@ -5,6 +5,7 @@
>to be UEFI specification compliant.
> 
>Copyright (c) 2009, Intel Corporation. All rights reserved.
> +  Copyright (c) 2020, AMD Inc. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -29,4 +30,17 @@ InitializeFloatingPointUnits (
>VOID
>);
> 
> +/**
> +  Determine if the standard CPU signature is "AuthenticAMD".
> +
> +  @retval TRUE  The CPU signature matches.
> +  @retval FALSE The CPU signature does not match

Re: [edk2-devel] [PATCH v6 4/4] UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE manipulation on AMD

2020-07-06 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Garrett Kirkendall 
> Sent: Monday, June 22, 2020 9:18 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [PATCH v6 4/4] UefiCpuPkg: PiSmmCpuDxeSmm skip
> MSR_IA32_MISC_ENABLE manipulation on AMD
> 
> AMD does not support MSR_IA32_MISC_ENABLE.  Accessing that register
> causes and exception on AMD processors.  If Execution Disable is supported,
> but if the processor is an AMD processor, skip manipulating
> MSR_IA32_MISC_ENABLE[34] XD Disable bit.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Garrett Kirkendall 
> ---
> 
> Notes:
> Tested on Intel hardware with Laszlo Ersek's help
> 
> (1) downloaded two Linux images from provided links.
> (2) Test using a 32-bit guest on an Intel host (standing in your edk2 
> tree,
> with the patches applied):
> 
> $ build -a IA32 -b DEBUG -p OvmfPkg/OvmfPkgIa32.dsc -t GCC5 -D
> SMM_REQUIRE
> 
> $ qemu-system-i386 \
> -cpu coreduo,-nx \
> -machine q35,smm=on,accel=kvm \
> -m 4096 \
> -smp 4 \
> -global driver=cfi.pflash01,property=secure,value=on \
> -drive
> if=pflash,format=raw,unit=0,readonly=on,file=Build/OvmfIa32/DEBUG_GCC
> 5/FV/OVMF_CODE.fd \
> -drive
> if=pflash,format=raw,unit=1,snapshot=on,file=Build/OvmfIa32/DEBUG_GCC
> 5/FV/OVMF_VARS.fd \
> -drive id=hdd,if=none,format=qcow2,snapshot=on,file=fedora-30-efi-
> systemd-i686.qcow2 \
> -device virtio-scsi-pci,id=scsi0 \
> -device scsi-hd,drive=hdd,bus=scsi0.0,bootindex=1
> 
> (Once you get a login prompt, feel free to interrupt QEMU with Ctrl-C.)
> 
> (3) Test using a 64-bit guest on an Intel host:
> 
> $ build -a IA32 -a X64 -b DEBUG -p OvmfPkg/OvmfPkgIa32X64.dsc -t GCC5 -
> D SMM_REQUIRE
> 
> $ qemu-system-x86_64 \
> -cpu host \
> -machine q35,smm=on,accel=kvm \
> -m 4096 \
> -smp 4 \
> -global driver=cfi.pflash01,property=secure,value=on \
> -drive
> if=pflash,format=raw,unit=0,readonly=on,file=Build/Ovmf3264/DEBUG_GCC
> 5/FV/OVMF_CODE.fd \
> -drive
> if=pflash,format=raw,unit=1,snapshot=on,file=Build/Ovmf3264/DEBUG_GCC
> 5/FV/OVMF_VARS.fd \
> -drive id=hdd,if=none,format=qcow2,snapshot=on,file=fedora-31-efi-
> grub2-x86_64.qcow2 \
> -device virtio-scsi-pci,id=scsi0 \
> -device scsi-hd,drive=hdd,bus=scsi0.0,bootindex=1
> 
> Tested on real AMD Hardware
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h |  3 +++
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c |  9 -
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm   | 19
> +--
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm| 20
> ++--
>  4 files changed, 46 insertions(+), 5 deletions(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> index 43f6935cf9dc..993360a8a8c1 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> @@ -2,6 +2,7 @@
>  SMM profile internal header file.
> 
>  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2020, AMD Incorporated. All rights reserved.
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -13,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include
> 
>  #include   #include 
> +#include 
>  #include 
> 
>  #include "SmmProfileArch.h"
> @@ -99,6 +101,7 @@ extern SMM_S3_RESUME_STATE
> *mSmmS3ResumeState;
>  extern UINTN gSmiExceptionHandlers[];
>  extern BOOLEAN   mXdSupported;
>  X86_ASSEMBLY_PATCH_LABEL gPatchXdSupported;
> +X86_ASSEMBLY_PATCH_LABEL gPatchMsrIa32MiscEnableSupported;
>  extern UINTN *mPFEntryCount;
>  extern UINT64(*mLastPFEntryValue)[MAX_PF_ENTRY_COUNT];
>  extern UINT64*(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT];
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> index c47b5573e366..d7ed9ab7a770 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> @@ -2,7 +2,7 @@
>  Enable SMM profile.
> 
>  Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved. -
> Copyright (c) 2017, AMD Incorporated. All rights reserved.
> +Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -1015,6 +1015,13 @@ CheckFeatureSup

Re: [edk2-devel] [PATCH v6 0/4] AMD processor MSR_IA32_MISC_ENABLE

2020-07-06 Thread Dong, Eric
Hi Laszlo,

I have fixed the issue reported by Guomin in below change.

SHA-1: 0060e0a694f3f249c3ec081b0e61287c36f64ebb

* IntelFsp2Pkg/FspSecCore: Use UefiCpuLib.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2825

UefiCpuLib has API InitializeFloatingPointUnits.
Remove internal copy of InitializeFloatingPointUnits
in FspSecCoreM, use UefiCpuLib API.

This change also avoid later potential conflict when
use UefiCpuLib for FspSecCoreM module.

Signed-off-by: Eric Dong 
Reviewed-by: Chasel Chiu 
Cc: Nate DeSimone 
Cc: Star Zeng 

Thanks,
Eric
From: Laszlo Ersek 
Sent: Wednesday, June 24, 2020 4:54 PM
To: Kirkendall, Garrett ; devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Wu, Hao A 
; Jiang, Guomin 
Subject: Re: [edk2-devel] [PATCH v6 0/4] AMD processor MSR_IA32_MISC_ENABLE

On 06/24/20 03:04, Kirkendall, Garrett wrote:
> [AMD Public Use]
>
> Is there anything else needed from me for this patch at this time?

I think we still have an open question here:

  https://edk2.groups.io/g/devel/message/61583

To clarify: I'm not suggesting that we should fix that issue. I'm saying
that we should *understand* Guomin's report enough so we can decide
*whether* this series needs a further update, or not.

If there is no feedback (clarification) from Guomin in a few days, I
think Eric or Ray (the UefiCpuPkg maintainers) should merge v6 -- for
example, on Friday.

Thanks,
Laszlo

>
> GARRETT KIRKENDALL
> SMTS Firmware Engineer | CTE
> 7171 Southwest Parkway, Austin, TX 78735 USA
> AMD   facebook  |  amd.com
>
> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Kirkendall, 
> Garrett via groups.io
> Sent: Monday, June 22, 2020 8:18 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Eric Dong mailto:eric.d...@intel.com>>; Ray Ni 
> mailto:ray...@intel.com>>; Laszlo Ersek 
> mailto:ler...@redhat.com>>; Hao A Wu 
> mailto:hao.a...@intel.com>>
> Subject: [edk2-devel] [PATCH v6 0/4] AMD processor MSR_IA32_MISC_ENABLE
>
> [CAUTION: External Email]
>
> AMD processor does not support MSR_IA32_MISC_ENABLE register.  Accessing this 
> register on AMD causes an unhandled exception in SmmEntry.nasm and a 
> subsequent failure to boot since this is too early in SMM path for the 
> exception handler to be loaded.
>
> 1. Prepare PcAtChipsetPkg/PcAtChipsetPkg.dsc to move 
> StandardSignatureIsAuthenticAMD into UefiCpuLib LibraryClass BaseUefiCpuLib 
> in UefiCpuPkg.
>
> 2. To distinguish between AMD and other processors, refactor 
> StandardSignatureIsAuthenticAMD into BaseUefiCpuLib.  So there is only one 
> copy in the source.
>
> 3. Skip manipulation of MSR_IA32_MISC_ENABLE register if running on an AMD 
> processor.
>
> Tested on AMD X64 hardware.
> OvmfIa32 and OvmfIa32X64 on Intel hardware.
>
> v1: Move StandardSignatureIsAuthenticAMD. Handle MSR_IA32_MISC_ENABLE
> v2: Incorporate Laszlo's feedback
> v3: Typo, not sent
> v4: Patch in to add UefiCpuLib to PcAtChipsetPkg.dsc
> v5: Patch in to add UefiCpuLib to SourceLevelDebugPkg.dsc
> v6: Hopefully reformat patch when sending
>
> Garrett Kirkendall (4):
>   PcAtChipsetPkg: PcAtChipsetPkg.dsc add UefiCpuLib LibraryClass
>   SourceLevelDebugPkg: SourceLevelDebugPkg.dsc add UefiCpuLib
> LibraryClass
>   UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib
>   UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE manipulation on
> AMD
>
>  PcAtChipsetPkg/PcAtChipsetPkg.dsc|  2 ++
>  SourceLevelDebugPkg/SourceLevelDebugPkg.dsc  |  2 ++
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf |  7 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf |  2 ++
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf |  2 ++
>  UefiCpuPkg/Include/Library/UefiCpuLib.h  | 14 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h   |  3 ++
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 38 
> 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c   | 25 
> ++---
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c   | 25 
> ++---
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c   |  9 -
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm | 19 --
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm  | 20 +--
>  14 files changed, 117 insertions(+), 74 deletions(-)  create mode 100644 
> UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
>
> Changes at:
> https://nam11.s

Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-07-02 Thread Dong, Eric
Hi Tom,

We have root cause this Mac file format issue. The patch mail from your side 
include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is 
Mac file line ending format. So this issue been reported. We have updated our 
tool to handle this special case.

With that change, now I met below error when use VS2015 tool chain. Can you 
help to fix it?

Building ... 
g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf 
[X64]
PeCoffLoaderEx.c
g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): 
warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits 
(was 64-bit shift intended?)
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 
14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2'

Thanks,
Eric
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Lendacky, Thomas
> Sent: Tuesday, June 23, 2020 8:58 PM
> To: devel@edk2.groups.io; Dong, Eric ;
> ler...@redhat.com
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Justen, Jordan L ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
> 
> On 6/22/20 8:16 PM, Dong, Eric via groups.io wrote:
> >
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of
> Laszlo
> >> Ersek
> >> Sent: Friday, June 19, 2020 11:39 PM
> >> To: Tom Lendacky ; devel@edk2.groups.io;
> >> Dong, Eric 
> >> Cc: Brijesh Singh ; Ard Biesheuvel
> >> ; Justen, Jordan L
> >> ; Gao, Liming ;
> >> Kinney, Michael D ; Ni, Ray
> >> 
> >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement
> >> library support for VMGEXIT
> >>
> >> On 06/19/20 15:50, Tom Lendacky wrote:
> >>> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
> >>>>
> >>>>
> >>>>> -Original Message-
> >>>>> From: devel@edk2.groups.io  On Behalf Of
> >>>>> Lendacky, Thomas
> >>>>> Sent: Thursday, June 18, 2020 10:09 PM
> >>>>> To: Dong, Eric ; devel@edk2.groups.io
> >>>>> Cc: Brijesh Singh ; Ard Biesheuvel
> >>>>> ; Justen, Jordan L
> >> ;
> >>>>> Laszlo Ersek ; Gao, Liming
> >>>>> ; Kinney, Michael D
> >>>>> ; Ni, Ray 
> >>>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement
> >> library
> >>>>> support for VMGEXIT
> >>>>>
> >>>>> On 6/18/20 2:23 AM, Dong, Eric wrote:
> >>>>>> Hi Tom,
> >>>>>>
> >>>>>> When use VS2015 to build this code, it reports below error.
> >>>>>> Please help to
> >>>>> fix it.
> >>>>>>
> >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220:
> >> warning
> >>>>>> treated as error - no 'object' file generated
> >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335:
> >> Mac
> >>>>>> file format detected: please convert the source file to either
> >>>>>> DOS or UNIX format
> >>>>>
> >>>>> That is strange...  I didn't see this when I ran through the CI.
> >>>>> When I do a file command against the file it reports:
> >>>>>
> >>>>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text,
> >>>>> with
> >> CRLF
> >>>>> line terminators
> >>>>>
> >>>>> I'll investigate this and try and figure out what's going on, but
> >>>>> if anyone else has some ideas, please let me know.
> >>>>
> >>>> Hi Tom,
> >>>>
> >>>> I met this error again when I trig below patch from AMD again for
> >>>> CPU change.
> >>>> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to
> >> BaseUefiCpuLib"
> >>>
> >>> Hmmm... I think we could be running into issues with sending patches
> >>> through our mail servers. Let me send you the patch series directly
> >>> using some changes I made to my git config file to see if that helps.
> >>> Would that be ok?
> >>
> >> both sender and recipient git clones should have
> >>
> >> [core]
> >> whitespace = cr-at-eol

Re: [edk2-devel] [PATCH v6 15/16] UefiCpuPkg/UefiCpuPkg.ci.yaml: Add configuration for Ecc check

2020-07-01 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Zhang,
> Shenglei
> Sent: Wednesday, July 1, 2020 9:55 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [edk2-devel] [PATCH v6 15/16] UefiCpuPkg/UefiCpuPkg.ci.yaml:
> Add configuration for Ecc check
> 
> Add configuration ExceptionList and IgnoreFiles for package config files. So
> users can rely on this to ignore some Ecc issues.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Shenglei Zhang 
> Acked-by: Ray Ni 
> ---
>  UefiCpuPkg/UefiCpuPkg.ci.yaml | 11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml
> b/UefiCpuPkg/UefiCpuPkg.ci.yaml index 99e460a8b090..0e216344cd53
> 100644
> --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml
> +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml
> @@ -2,9 +2,20 @@
>  # CI configuration for UefiCpuPkg
>  #
>  # Copyright (c) Microsoft Corporation
> +# Copyright (c) 2020, Intel Corporation. All rights reserved.
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  ##  {
> +"EccCheck": {
> +## Exception sample looks like below:
> +## "ExceptionList": [
> +## "", ""
> +## ]
> +"ExceptionList": [
> +],
> +"IgnoreFiles": [
> +]
> +},
>  "CompilerPlugin": {
>  "DscPath": "UefiCpuPkg.dsc"
>  },
> --
> 2.18.0.windows.1
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61929): https://edk2.groups.io/g/devel/message/61929
Mute This Topic: https://groups.io/mt/75227246/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [patch V2] MdeModulePkg/DisplayEngine: Add Debug message to show mismatch menu info

2020-06-28 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Bi, Dandan 
> Sent: Sunday, June 28, 2020 10:17 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Dong, Eric ;
> Laszlo Ersek 
> Subject: [patch V2] MdeModulePkg/DisplayEngine: Add Debug message to
> show mismatch menu info
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2326
> 
> Currently when meet mismatch case for one-of and ordered-list menu, just
> show a popup window to indicate mismatch, no more info for debugging.
> This patch is to add more debug message about mismatch menu info which is
> helpful to debug.
> 
> Cc: Liming Gao 
> Cc: Eric Dong 
> Cc: Laszlo Ersek 
> Signed-off-by: Dandan Bi 
> ---
> v2:
> 1) Refine debug message info.
> 2) Use gEfiCallerBaseName.to replace hard code "DisplayEngine"
> 3) Handle question and option value based on value type.
> 
>  .../DisplayEngineDxe/ProcessOptions.c | 125 ++
>  1 file changed, 125 insertions(+)
> 
> diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> b/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> index e7306f6d04..c02e36a63a 100644
> --- a/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> +++ b/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> @@ -911,10 +911,120 @@ PasswordProcess (
>FreePool (StringPtr);
> 
>return Status;
>  }
> 
> +/**
> +  Print some debug message about mismatched menu info.
> +
> +  @param  MenuOption The MenuOption for this Question.
> +
> +**/
> +VOID
> +PrintMismatchMenuInfo (
> +  IN  UI_MENU_OPTION  *MenuOption
> +)
> +{
> +  CHAR16  *FormTitleStr;
> +  CHAR16  *FormSetTitleStr;
> +  CHAR16  *OneOfOptionStr;
> +  CHAR16  *QuestionName;
> +  LIST_ENTRY  *Link;
> +  FORM_DISPLAY_ENGINE_STATEMENT   *Question;
> +  EFI_IFR_ORDERED_LIST*OrderList;
> +  UINT8   Index;
> +  EFI_HII_VALUE   HiiValue;
> +  EFI_HII_VALUE   *QuestionValue;
> +  DISPLAY_QUESTION_OPTION *Option;
> +  UINT8   *ValueArray;
> +  UINT8   ValueType;
> +  EFI_IFR_FORM_SET*FormsetBuffer;
> +  UINTN   FormsetBufferSize;
> +
> +  Question = MenuOption->ThisTag;
> +  HiiGetFormSetFromHiiHandle (gFormData->HiiHandle, ,
> + );
> +
> +  FormSetTitleStr = GetToken (FormsetBuffer->FormSetTitle,
> + gFormData->HiiHandle);  FormTitleStr = GetToken (gFormData->FormTitle,
> + gFormData->HiiHandle);
> +
> +  DEBUG ((DEBUG_ERROR, "\n[%a]: Mismatch Formset: Formset Guid
> = %g,  FormSet title = %s\n", gEfiCallerBaseName, 
> >FormSetGuid, FormSetTitleStr));
> +  DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Form   : FormId = %d,  Form
> title = %s.\n", gEfiCallerBaseName, gFormData->FormId, FormTitleStr));
> +
> +  if (Question->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
> +QuestionName = GetToken (((EFI_IFR_ORDERED_LIST*)MenuOption-
> >ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
> +Link = GetFirstNode (>OptionListHead);
> +Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
> +ValueType = Option->OptionOpCode->Type;
> +DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Error  : OrderedList value in
> the array doesn't match with option value.\n", gEfiCallerBaseName));
> +DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OrderedList: Name = %s.\n",
> gEfiCallerBaseName, QuestionName));
> +DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OrderedList: OrderedList array
> + value :\n", gEfiCallerBaseName));
> +
> +OrderList = (EFI_IFR_ORDERED_LIST *) Question->OpCode;
> +for (Index = 0; Index < OrderList->MaxContainers; Index++) {
> +  ValueArray = Question->CurrentValue.Buffer;
> +  HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);
> +  DEBUG ((DEBUG_ERROR, "   Value[%d] 
> =%ld.\n", Index,
> HiiValue.Value.u64));
> +}
> +  } else if (Question->OpCode->OpCode == EFI_IFR_ONE_OF_OP) {
> +QuestionName = GetToken (((EFI_IFR_ONE_OF*)MenuOption->ThisTag-
> >OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
> +QuestionValue = >CurrentValue;
> +DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Error  : OneOf value doesn't
> match with option value.\n", gEfiCallerBaseName));
> +DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf 

Re: [edk2-devel] [PATCH v6 1/4] PcAtChipsetPkg: PcAtChipsetPkg.dsc add UefiCpuLib LibraryClass

2020-06-28 Thread Dong, Eric
Hi Guomin, Laszlo & Garrett,

Because both UefiCpuLib and FspSecCoreT / FspSecCoreM both define 
InitializeFloatingPointUnits API. So this build issue been reported.

I have submit a patch to remove InitializeFloatingPointUnits in FspSecCoreT / 
FspSecCoreM, https://edk2.groups.io/g/devel/message/61757.

Please wait that patch been merged before committing this change.

Thanks,
Eric
> -Original Message-
> From: Jiang, Guomin 
> Sent: Sunday, June 28, 2020 5:11 PM
> To: Laszlo Ersek ; devel@edk2.groups.io;
> garrett.kirkend...@amd.com
> Cc: Ni, Ray ; Dong, Eric 
> Subject: RE: [edk2-devel] [PATCH v6 1/4] PcAtChipsetPkg:
> PcAtChipsetPkg.dsc add UefiCpuLib LibraryClass
> 
> Hi Laszlo,
> 
> The step to reproduce as below:
> 1. add below change
> diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.dsc b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
> index 26cd3da43c3f..d43cb5be6472 100644
> --- a/IntelFsp2Pkg/IntelFsp2Pkg.dsc
> +++ b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
> @@ -62,7 +62,10 @@ [Components]
>IntelFsp2Pkg/Library/BaseDebugDeviceLibNull/BaseDebugDeviceLibNull.inf
> 
> IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.in
> f
> 
> -  IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
> +  IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf {
> +
> +NULL|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> +  }
>IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
>IntelFsp2Pkg/FspSecCore/FspSecCoreS.inf
>IntelFsp2Pkg/FspSecCore/Fsp22SecCoreS.inf
> 
> 2. build -p IntelFsp2Pkg\IntelFsp2Pkg.dsc -b DEBUG -a IA32 -t VS2019 and I
> can see BaseUefiCpuLib.lib(InitializeFpu.obj) : error LNK2005:
> _InitializeFloatingPointUnits already defined in
> FspSecCoreT.lib(InitializeFpu.obj)
> 
> I can't reproduce it with the original edk2 or edk2-platforms, but our project
> have the depend on ApicLib, so if the ApicLib depend on UefiCpuLib, it will
> break our project build.
> 
> Below
> Thanks.
> 
> > -Original Message-
> > From: Laszlo Ersek 
> > Sent: Tuesday, June 23, 2020 7:16 PM
> > To: devel@edk2.groups.io; Jiang, Guomin ;
> > garrett.kirkend...@amd.com
> > Cc: Ni, Ray ; Dong, Eric 
> > Subject: Re: [edk2-devel] [PATCH v6 1/4] PcAtChipsetPkg:
> > PcAtChipsetPkg.dsc add UefiCpuLib LibraryClass
> >
> > On 06/23/20 02:52, Guomin Jiang wrote:
> > > Hi Garrett,
> > >
> > > Thanks for report quickly and it work and the 'Mac format issue
> disappear'.
> > >
> > > But another build error occur 'error LNK2005:
> > > _InitializeFloatingPointUnits
> > already defined in FspSecCoreT.lib(InitializeFpu.obj)'
> > > It seem that result by ApicLib who depend UefiCpuLib now.
> >
> > Yes.
> >
> > > I want to know why you add this dependency,
> >
> > It was discussed on the list in advance.
> >
> > [edk2-devel] UefiCpuPkg: Discuss: Move
> StandardSignatureIsAuthenticAMD
> > function to BaseUefiCpuLib
> >
> >   https://edk2.groups.io/g/devel/message/61079
> >
> > In addition, we have investigated all the platforms in the open source
> > edk2 and edk2-platforms trees that could require an update due to the
> > new
> > dependency:
> >
> >   https://edk2.groups.io/g/devel/message/61525
> >
> > And this series is in fact addressing them all.
> >
> > > have any other way to do it, for example, add the dependency to the
> > > dsc
> > file.
> >
> > Please describe how you can reproduce the link error using edk2 and
> > edk2- platforms content *only* (= using open source components only).
> >
> > Thanks
> > Laszlo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61768): https://edk2.groups.io/g/devel/message/61768
Mute This Topic: https://groups.io/mt/75037835/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH] IntelFsp2Pkg/FspSecCore: Use UefiCpuLib.

2020-06-26 Thread Dong, Eric
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2825

UefiCpuLib has API InitializeFloatingPointUnits.
Remove internal copy of InitializeFloatingPointUnits
in FspSecCoreM, use UefiCpuLib API.

This change also avoid later potential conflict when
use UefiCpuLib for FspSecCoreM module.

Signed-off-by: Eric Dong 
Cc: Chasel Chiu 
Cc: Nate DeSimone 
Cc: Star Zeng 
---
 IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf   |  3 +-
 IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf   |  1 -
 .../FspSecCore/Ia32/InitializeFpu.nasm| 72 ---
 IntelFsp2Pkg/FspSecCore/SecMain.h | 15 +---
 IntelFsp2Pkg/IntelFsp2Pkg.dsc |  1 +
 5 files changed, 4 insertions(+), 88 deletions(-)
 delete mode 100644 IntelFsp2Pkg/FspSecCore/Ia32/InitializeFpu.nasm

diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf 
b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
index 25f2a109ab..61b7ddca4c 100644
--- a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
+++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
@@ -29,7 +29,6 @@
 
 [Sources.IA32]
   Ia32/Stack.nasm
-  Ia32/InitializeFpu.nasm
   Ia32/FspApiEntryM.nasm
   Ia32/FspApiEntryCommon.nasm
   Ia32/FspHelper.nasm
@@ -41,6 +40,7 @@
 [Packages]
   MdePkg/MdePkg.dec
   IntelFsp2Pkg/IntelFsp2Pkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
   BaseMemoryLib
@@ -51,6 +51,7 @@
   FspSwitchStackLib
   FspCommonLib
   FspSecPlatformLib
+  UefiCpuLib
 
 [Pcd]
   gIntelFsp2PkgTokenSpaceGuid.PcdTemporaryRamBase  ## CONSUMES
diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf 
b/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
index 971b311e42..664bde5678 100644
--- a/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
+++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
@@ -25,7 +25,6 @@
 
 [Sources.IA32]
   Ia32/Stack.nasm
-  Ia32/InitializeFpu.nasm
   Ia32/FspApiEntryT.nasm
   Ia32/FspHelper.nasm
 
diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/InitializeFpu.nasm 
b/IntelFsp2Pkg/FspSecCore/Ia32/InitializeFpu.nasm
deleted file mode 100644
index ebc91c41e4..00
--- a/IntelFsp2Pkg/FspSecCore/Ia32/InitializeFpu.nasm
+++ /dev/null
@@ -1,72 +0,0 @@
-;--
-;
-; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
-; SPDX-License-Identifier: BSD-2-Clause-Patent
-;
-; Abstract:
-;
-;--
-
-
-SECTION .data
-;
-; Float control word initial value:
-; all exceptions masked, double-precision, round-to-nearest
-;
-ASM_PFX(mFpuControlWord):
-dw0x027F
-;
-; Multimedia-extensions control word:
-; all exceptions masked, round-to-nearest, flush to zero for masked underflow
-;
-ASM_PFX(mMmxControlWord):
- dd 0x01F80
-
-SECTION .text
-
-;
-; Initializes floating point units for requirement of UEFI specification.
-;
-; This function initializes floating-point control word to 0x027F (all 
exceptions
-; masked,double-precision, round-to-nearest) and multimedia-extensions control 
word
-; (if supported) to 0x1F80 (all exceptions masked, round-to-nearest, flush to 
zero
-; for masked underflow).
-;
-
-global ASM_PFX(InitializeFloatingPointUnits)
-ASM_PFX(InitializeFloatingPointUnits):
-
-
-pushebx
-
-;
-; Initialize floating point units
-;
-finit
-fldcw[ASM_PFX(mFpuControlWord)]
-
-;
-; Use CpuId instruction (CPUID.01H:EDX.SSE[bit 25] = 1) to test
-; whether the processor supports SSE instruction.
-;
-mov eax, 1
-cpuid
-bt  edx, 25
-jnc Done
-
-;
-; Set OSFXSR bit 9 in CR4
-;
-mov eax, cr4
-or  eax, BIT9
-mov cr4, eax
-
-;
-; The processor should support SSE instruction and we can use
-; ldmxcsr instruction
-;
-ldmxcsr [ASM_PFX(mMmxControlWord)]
-Done:
-pop ebx
-
-ret
diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.h 
b/IntelFsp2Pkg/FspSecCore/SecMain.h
index af7f387960..f6333b0ffb 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.h
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 typedef VOID (*PEI_CORE_ENTRY) ( \
@@ -80,20 +81,6 @@ SecTemporaryRamSupport (
   IN UINTNCopySize
   );
 
-/**
-  Initializes floating point units for requirement of UEFI specification.
-
-  This function initializes floating-point control word to 0x027F (all 
exceptions
-  masked,double-precision, round-to-nearest) and multimedia-extensions control 
word
-  (if supported) to 0x1F80 (all exceptions masked, round-to-nearest, flush to 
zero
-  for masked underflow).
-
-**/
-VOID
-EFIAPI
-InitializeFloatingPointUnits (
-  VOID
-  );
 
 /**
 
diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.dsc b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
index 26cd3da43c..309411630d 100644
--- a/IntelFsp2Pkg/IntelFsp2Pkg.dsc
+++ b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
@@ -25,6 +25,7 @@
   PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
   

Re: [edk2-devel] [edk2-rfc] MdeModulePkg/StatusCodeHandler: Separate NULL class libraries for Memory and serial handlers from MdeModulePkg/Universal/StatusCodeHandler modules

2020-06-25 Thread Dong, Eric
Hi Brian,

In this new design, we still use register status code handler Protocol/Ppi to 
register the handler logic. We just want to change the StatusCodeHandler 
driver. We try to split the register logic to NULL library to make the code 
more modularity. We already created sample library in Edk2-Platforms repo  
https://github.com/tianocore/edk2-platforms/tree/master/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStatusCodeHandlerLib.
  You can check this code to understand more about what we want to do.

Thanks,
Eric
From: Brian J. Johnson 
Sent: Thursday, June 25, 2020 4:25 AM
To: Bi, Dandan ; Andrew Fish ; 
edk2-devel-groups-io 
Cc: r...@edk2.groups.io; Dong, Eric ; Ni, Ray 
; Wang, Jian J ; Wu, Hao A 
; Tan, Ming ; Laszlo Ersek 

Subject: Re: [edk2-devel] [edk2-rfc] MdeModulePkg/StatusCodeHandler: Separate 
NULL class libraries for Memory and serial handlers from 
MdeModulePkg/Universal/StatusCodeHandler modules

Dandan,

The Status Code Protocol/PPI is the high-level interface which is being 
implemented.  The ReportStatusCodeRouter module implements this in terms of the 
ReportStatusCodeHandler Protocol/PPI.  That allows multiple 
ReportStatusCodeHandler modules to be used at once, so they can each react to 
different types of status codes, or report them through multiple channels.  
That sort of multiplexing seems like a useful feature.

Now we're considering adding a mechanism which allows registering status code 
handlers via NULL libraries, rather than via the protocol/PPI.  That sounds 
like exactly what ReportStatusCodeRouter is intended for.  It wouldn't really 
change its scope, it would just make it more flexible.  Adding this feature via 
a StatusCodeHandler module wouldn't improve modularity, it would just add 
complexity.  As an OEM, adding a custom handler would look the same to me 
either way:  I would have to add the NULL class library to a MdeModulePkg 
driver's entry in my .dsc file.  It doesn't matter to me whether it's the 
ReportStatusCodeRouter or StatusCodeHandler module.  And if I can do it in 
ReportStatusCodeRouter, then I don't need to include any StatusCodeHandler 
modules in the build at all.  That saves code space and reduces the number of 
modules in the APRIORI list, which are both good things.

ReportStatusCodeRouterPei already has to track registered handlers in PEI when 
running from ROM (it uses a HOB.)  Tracking handlers from NULL libraries 
wouldn't be any harder.  In fact, it looks like it could just export the 
Register() function to the NULL libraries, and they could call it in their 
constructors.

I think using NULL libraries for status code handlers is a great idea.  I'd 
just like to take that opportunity to reduce the complexity of the overall 
status code stack while we're at it.

Thanks,

Brian J. Johnson
Enterprise X86 Lab

Hewlett Packard Enterprise


From: Bi, Dandan [mailto:dandan...@intel.com]
Sent: Monday, June 22, 2020, 2:27 AM
To: Andrew Fish <mailto:af...@apple.com>, edk2-devel-groups-io 
<mailto:devel@edk2.groups.io>, 
brian.john...@hpe.com<mailto:brian.john...@hpe.com> 
<mailto:brian.john...@hpe.com>
Cc: r...@edk2.groups.io<mailto:r...@edk2.groups.io> 
<mailto:r...@edk2.groups.io>, Dong, Eric 
<mailto:eric.d...@intel.com>, Ni, Ray 
<mailto:ray...@intel.com>, Wang, Jian J 
<mailto:jian.j.w...@intel.com>, Wu, Hao A 
<mailto:hao.a...@intel.com>, Tan, Ming 
<mailto:ming@intel.com>, Laszlo Ersek 
<mailto:ler...@redhat.com>, Bi, Dandan 
<mailto:dandan...@intel.com>
Subject: [edk2-devel] [edk2-rfc] MdeModulePkg/StatusCodeHandler: Separate NULL 
class libraries for Memory and serial handlers from 
MdeModulePkg/Universal/StatusCodeHandler modules

Hi Brian,

Personally, I prefer to add the NULL class Library to StatusCodeHandler modules.

  1.  I think we should make the functionality of each module clear and 
separated. It may also be why we added ReportStatusCodeRouter and 
StatusCodeHandler modules in edk2 repo before.

ReportStatusCodeRouter modules are responsible for producing Status Code 
Protocol/PPI and Report Status Code Handler Protocol/PPI, and StatusCodeHandler 
modules are responsible for producing handlers (Handlers can be provided by 
NULL class Libraries in this RFC).

 So, that’s why I don’t want to add the NULL class Library to 
ReportStatusCodeRouter modules directly, which change the functionality scope 
of existing modules.



  1.  I agree that we have a lot of layers of indirection now, but what we may 
gain is the good modularity. And you also mentioned that one or more 
StatusCodeHandler Modules may be used. We also want to achieve that only the 
StatusCodeHandler modules in MdeModulePkg can be used after this separation, 
platform can only add its own handler Libs to meet its requirement.



  1.  As Andrew mentioned below, if add the libraries to 
ReportStatusCodeRouter, there will be so

Re: [edk2-devel] [PATCH] UefiCpuPkg/SecCore: Add pre-memory AP vector

2020-06-22 Thread Dong, Eric
Reviewed-by: Eric Dong eric.d...@intel.com<mailto:eric.d...@intel.com>

Pushed:
SHA-1: 00b8bf7eda00fb6f0197d3968b6078cfdb4870fa

* UefiCpuPkg/SecCore: Add pre-memory AP vector

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2776


Thanks,
Eric
From: Ni, Ray 
Sent: Tuesday, June 23, 2020 8:57 AM
To: Cole, Deric ; devel@edk2.groups.io
Cc: Dong, Eric ; Laszlo Ersek 
Subject: RE: [PATCH] UefiCpuPkg/SecCore: Add pre-memory AP vector

Reviewed-by: Ray Ni mailto:ray...@intel.com>>


> -Original Message-
> From: Cole, Deric mailto:deric.c...@intel.com>>
> Sent: Wednesday, June 3, 2020 12:42 AM
> To: Ni, Ray mailto:ray...@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Dong, Eric mailto:eric.d...@intel.com>>; Laszlo 
> Ersek mailto:ler...@redhat.com>>
> Subject: RE: [PATCH] UefiCpuPkg/SecCore: Add pre-memory AP vector
>
> Ray,
>
> The NOP is not a functional change, it's just for ease of debug.
>
> Before, this file was padding with zeros in various places. When viewing this 
> memory using a disassembler, two
> subsequent zero-bytes show up as an ADD instruction, which I found confusing. 
> But worse, if the number of zero-bytes was
> odd, the disassembler might try to "consume" part of the next (real) 
> instruction as an operand to the last hypothetical
> ADD.
>
> Since NOP is a 1-byte instruction, I used that instead, so it is easier to 
> visually identify the real code versus the padding
> when viewing disassembly.
>
> -Deric
>
> -Original Message-
> From: Ni, Ray mailto:ray...@intel.com>>
> Sent: Monday, June 1, 2020 9:51 PM
> To: Cole, Deric mailto:deric.c...@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Dong, Eric mailto:eric.d...@intel.com>>; Laszlo 
> Ersek mailto:ler...@redhat.com>>
> Subject: RE: [PATCH] UefiCpuPkg/SecCore: Add pre-memory AP vector
>
> Deric,
> Can you explain why changing all padding 0x0 to 0x90 (nop) in your patch?
>
> Is it required to enable AP start up in pre-mem?
>
> Thanks,
> Ray
>
> > -Original Message-----
> > From: Cole, Deric mailto:deric.c...@intel.com>>
> > Sent: Tuesday, June 2, 2020 6:32 AM
> > To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> > Cc: Cole, Deric mailto:deric.c...@intel.com>>; Dong, 
> > Eric
> > mailto:eric.d...@intel.com>>; Ni, Ray 
> > mailto:ray...@intel.com>>; Laszlo Ersek
> > mailto:ler...@redhat.com>>
> > Subject: [PATCH] UefiCpuPkg/SecCore: Add pre-memory AP vector
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2776
> >
> > Add a vector at 0xFF000 (0xF000) that can be used by
> > Init-SIPI-SIPI to start an AP before memory is initialized. This
> > vector jumps into the same SEC entry point as the ordinary reset
> > vector, with a special value of "AP" in the DI register. The
> > platform-specific SEC code is expected to check for that value and
> > take a different path for APs, if this feature is supported by the platform.
> >
> > Cc: Eric Dong mailto:eric.d...@intel.com>>
> > Cc: Ray Ni mailto:ray...@intel.com>>
> > Cc: Laszlo Ersek mailto:ler...@redhat.com>>
> > Signed-off-by: Deric Cole 
> > mailto:deric.c...@intel.com>>
> > ---
> >  UefiCpuPkg/SecCore/Ia32/ResetVec.nasmb | 31
> > ---
> >  1 file changed, 24 insertions(+), 7 deletions(-)
> >
> > diff --git a/UefiCpuPkg/SecCore/Ia32/ResetVec.nasmb
> > b/UefiCpuPkg/SecCore/Ia32/ResetVec.nasmb
> > index f41b9669d0..1dfc4efe4c 100644
> > --- a/UefiCpuPkg/SecCore/Ia32/ResetVec.nasmb
> > +++ b/UefiCpuPkg/SecCore/Ia32/ResetVec.nasmb
> > @@ -10,7 +10,7 @@
> >  ; Abstract:
> >
> >  ;
> >
> >  ;  Reset Vector Data structure
> >
> > -;  This structure is located at 0xFFC0
> >
> > +;  This structure is located at 0xF000
> >
> >  ;
> >
> >
> > ;-
> > -
> >
> >
> >
> > @@ -23,19 +23,36 @@ USE16
> >  ;
> >
> >
> >
> >  ORG 0h
> >
> > +
> >
> > +;
> >
> > +; 0xF000
> >
> > +;
> >
> > +; We enter here with CS:IP = 0xFF00:0x. Do a far-jump to change
> > +CS to
> > 0xF000
> >
> > +; and IP to ApStartup.
> >
> > +;
> >
> > +ApVector:
> >
> > +mov di, "AP"
> >
> > +jmp 0xF000:0xF000+ApStartup

Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-06-22 Thread Dong, Eric


> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Laszlo
> Ersek
> Sent: Friday, June 19, 2020 11:39 PM
> To: Tom Lendacky ; devel@edk2.groups.io;
> Dong, Eric 
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Justen, Jordan L ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
> 
> On 06/19/20 15:50, Tom Lendacky wrote:
> > On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
> >>
> >>
> >>> -Original Message-
> >>> From: devel@edk2.groups.io  On Behalf Of
> >>> Lendacky, Thomas
> >>> Sent: Thursday, June 18, 2020 10:09 PM
> >>> To: Dong, Eric ; devel@edk2.groups.io
> >>> Cc: Brijesh Singh ; Ard Biesheuvel
> >>> ; Justen, Jordan L
> ;
> >>> Laszlo Ersek ; Gao, Liming ;
> >>> Kinney, Michael D ; Ni, Ray
> >>> 
> >>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement
> library
> >>> support for VMGEXIT
> >>>
> >>> On 6/18/20 2:23 AM, Dong, Eric wrote:
> >>>> Hi Tom,
> >>>>
> >>>> When use VS2015 to build this code, it reports below error. Please
> >>>> help to
> >>> fix it.
> >>>>
> >>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220:
> warning
> >>>> treated as error - no 'object' file generated
> >>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335:
> Mac
> >>>> file format detected: please convert the source file to either DOS or
> >>>> UNIX format
> >>>
> >>> That is strange...  I didn't see this when I ran through the CI. When
> >>> I do a file
> >>> command against the file it reports:
> >>>
> >>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with
> CRLF
> >>> line terminators
> >>>
> >>> I'll investigate this and try and figure out what's going on, but if
> >>> anyone else
> >>> has some ideas, please let me know.
> >>
> >> Hi Tom,
> >>
> >> I met this error again when I trig below patch from AMD again for CPU
> >> change.
> >> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to
> BaseUefiCpuLib"
> >
> > Hmmm... I think we could be running into issues with sending patches
> > through our mail servers. Let me send you the patch series directly
> > using some changes I made to my git config file to see if that helps.
> > Would that be ok?
> 
> both sender and recipient git clones should have
> 
> [core]
> whitespace = cr-at-eol
> 
> and the recipient clone should have
> 
> [am]
> keepcr = true
> 
> https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-
> guide-for-edk2-contributors-and-maintainers#contrib-05
> 
> These are also set by "BaseTools/Scripts/SetupGit.py".
> 

Hi Tom,

I see below context in another mail thread and base on the latest status, this 
solution works and that patch has fixed the issue. Can you follow below suggest 
fixing your issue?

Hi Garrett,

I encounter below error when build
UefiCpuPkg\Library\BaseUefiCpuLib\BaseUefiCpuLib.c: warning C4335: Mac 
file format detected: please convert the source file to either DOS or UNIX 
format'

I encounter the issue ever, it result by mail encoding.
To resolve this issue, you can run [BaseTools\ Scripts\SetupGit.py] 
first, and then send the patch again.

Could you try it and send the patch again?

Thanks,
Eric

> Thanks
> Laszlo
> 
> 
> 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61572): https://edk2.groups.io/g/devel/message/61572
Mute This Topic: https://groups.io/mt/74692413/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] Features/Intel/Debugging: Fix build error when use Xcode

2020-06-22 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Tan,
> Ming
> Sent: Monday, June 22, 2020 3:33 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Gao, Liming 
> Subject: [edk2-devel] [PATCH] Features/Intel/Debugging: Fix build error
> when use Xcode
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2822
> 
> When use Xcode, it will report following compile error:
>   duplicate symbol _mRscHandlerProtocol in:
> 
> So in the Features/Intel/Debugging/,
> change the global variable name in the following files
>   RuntimeDxeBeepStatusCodeHandlerLib.c
>   RuntimeDxePostCodeStatusCodeHandlerLib.c
> 
> Cc: Eric Dong 
> Cc: Liming Gao 
> Signed-off-by: Ming Tan 
> ---
>  .../RuntimeDxeBeepStatusCodeHandlerLib.c  | 20 +--
>  .../RuntimeDxePostCodeStatusCodeHandlerLib.c  | 20 +--
>  2 files changed, 20 insertions(+), 20 deletions(-)
> 
> diff --git
> a/Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCod
> eHandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.c
> b/Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCod
> eHandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.c
> index 631e2eecae..0bdc3f4575 100644
> ---
> a/Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCod
> eHandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.c
> +++
> b/Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCod
> eHandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.c
> @@ -17,9 +17,9 @@
>  #include 
> 
>  #include 
> 
> 
> 
> -EFI_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol   = NULL;
> 
> -EFI_EVENT mExitBootServicesEvent = NULL;
> 
> -BOOLEAN   mRegistered= FALSE;
> 
> +EFI_RSC_HANDLER_PROTOCOL  *mBeepRscHandlerProtocol   = NULL;
> 
> +EFI_EVENT mBeepExitBootServicesEvent = NULL;
> 
> +BOOLEAN   mBeepRegistered= FALSE;
> 
> 
> 
>  /**
> 
>Convert status code value to the times of beep.
> 
> @@ -79,8 +79,8 @@ UnregisterBeepBootTimeHandlers (
>IN VOID *Context
> 
>)
> 
>  {
> 
> -  if (mRegistered) {
> 
> -mRscHandlerProtocol->Unregister (BeepStatusCodeReportWorker);
> 
> +  if (mBeepRegistered) {
> 
> +mBeepRscHandlerProtocol->Unregister (BeepStatusCodeReportWorker);
> 
>}
> 
>  }
> 
> 
> 
> @@ -105,13 +105,13 @@ RegisterBeepBootTimeHandlers (
>Status = gBS->LocateProtocol (
> 
>,
> 
>NULL,
> 
> -  (VOID **) 
> 
> +  (VOID **) 
> 
>);
> 
>ASSERT_EFI_ERROR (Status);
> 
> 
> 
> -  mRscHandlerProtocol->Register (BeepStatusCodeReportWorker,
> TPL_HIGH_LEVEL);
> 
> +  mBeepRscHandlerProtocol->Register (BeepStatusCodeReportWorker,
> TPL_HIGH_LEVEL);
> 
>ASSERT_EFI_ERROR (Status);
> 
> -  mRegistered = TRUE;
> 
> +  mBeepRegistered = TRUE;
> 
> 
> 
>Status = gBS->CreateEventEx (
> 
>EVT_NOTIFY_SIGNAL,
> 
> @@ -119,7 +119,7 @@ RegisterBeepBootTimeHandlers (
>UnregisterBeepBootTimeHandlers,
> 
>NULL,
> 
>,
> 
> -  
> 
> +  
> 
>);
> 
>ASSERT_EFI_ERROR (Status);
> 
>  }
> 
> @@ -154,7 +154,7 @@ RuntimeDxeBeepStatusCodeHandlerLibConstructor (
>Status = gBS->LocateProtocol (
> 
>,
> 
>NULL,
> 
> -  (VOID **) 
> 
> +  (VOID **) 
> 
>);
> 
> 
> 
>if (!EFI_ERROR (Status)) {
> 
> diff --git
> a/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeS
> tatusCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.c
> b/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeS
> tatusCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.c
> index 59b531fe7c..65fd555cc0 100644
> ---
> a/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeS
> tatusCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.c
> +++
> b/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeS
> tatusCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.c
> @@ -18,9 +18,9 @@
>  #include 
> 
>  #include 
> 
> 
> 
> -EFI_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol   = NULL;
> 
> -EFI_EVENT mExitBootServicesEvent = NULL;
> 
> -BOOLEAN   

Re: [edk2-devel] [edk2-rfc] MdeModulePkg/StatusCodeHandler: Separate NULL class libraries for Memory and serial handlers from MdeModulePkg/Universal/StatusCodeHandler modules

2020-06-19 Thread Dong, Eric

From: devel@edk2.groups.io  On Behalf Of Brian J. Johnson
Sent: Saturday, June 20, 2020 1:29 AM
To: devel@edk2.groups.io; Bi, Dandan ; r...@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Wang, Jian J 
; Wu, Hao A ; Tan, Ming 

Subject: Re: [edk2-devel] [edk2-rfc] MdeModulePkg/StatusCodeHandler: Separate 
NULL class libraries for Memory and serial handlers from 
MdeModulePkg/Universal/StatusCodeHandler modules

On 6/18/20 2:01 AM, Dandan Bi wrote:
Hi All,

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2816

We plan to separate two kinds of NULL class libraries for Memory and serial 
handlers from MdeModulePkg/Universal/StatusCodeHandler/.../ 
StatusCodeHandlerPei/RuntimeDxe/Smm modules.
The benefit we want to gain from this separation is to 1) make the code clear 
and easy to maintain, 2) make platform flexible to choose any handler library 
they need, and it also can reduce image size since the unused handlers can be 
excluded.
If you have any concern or comments for this separation, please let me know.

We plan to add new separated NULL class library MemoryStausCodeHandlerLib and 
SerialStatusCodeHandlerLib with different phase implementation into 
MdeModulePkg\Library\ directory.
The main tree structure may like below:
MdeModulePkg\Library
|--MemoryStausCodeHandlerLib
|--|-- PeiMemoryStausCodeHandlerLib.inf
|--|-- RuntimeDxeMemoryStatusCodeHandlerLib.inf
|--|-- SmmMemoryStausCodeHandlerLib.inf
|--SerialStatusCodeHandlerLib
|--|-- PeiSerialStatusCodeHandlerLib.inf
|--|-- RuntimeDxeSerialStatusCodeHandlerLib.inf
|--|-- SmmSerialStatusCodeHandlerLib.inf


We will update existing platform use cases in edk2 and edk2-platform repo to 
cover the new NULL class library to make sure this change doesn't impact any 
platform.
After this separation, StatusCodeHandler module usage will like below, and it's 
also very flexible for platform to cover more handler libraries to meet their 
requirements.
MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf {
  
NULL|MdeModulePkg/Library/MemoryStausCodeHandlerLib/PeiMemoryStausCodeHandlerLib.inf
NULL|MdeModulePkg/Library/SerialStatusCodeHandlerLib/PeiSerialStatusCodeHandlerLib.inf
...
}

MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
  {
  
NULL|MdeModulePkg/Library/MemoryStausCodeHandlerLib/RuntimeDxeMemoryStausCodeHandlerLib.inf
NULL|MdeModulePkg/Library/SerialStatusCodeHandlerLib/RuntimeDxeSerialStatusCodeHandlerLib.inf
...
}

MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf {
  

NULL|MdeModulePkg/Library/MemoryStausCodeHandlerLib/SmmMemoryStausCodeHandlerLib.inf
NULL|MdeModulePkg/Library/SerialStatusCodeHandlerLib/SmmSerialStatusCodeHandlerLib.inf
...
}


Thanks,
Dandan



Dandan,

We'll have a lot of layers of indirection  The ReportStatusCodeRouter 
modules will call one or more StatusCodeHandlerModules, and the standard 
StatusCodeHandler modules will call multiple StatusCodeHandlerLib libraries.

How about adding StatusCodeHandlerLib support directly to the 
ReportStatusCodeRouter modules?  Then platforms could omit the 
StatusCodeHandler modules if they're only using the open-source code.  That 
sounds like less overhead since fewer modules would be needed



Hi Brain,

You are right. Current design truly has a lot of layers. The 
ReportStatusCodeRouter module provides the register logic and maintain the 
registered status code handlers. Now the platform may have more than one of 
drivers used to register the status code handler.  This RFC used to resolve the 
platform has more than one status code handler drivers' issue. We expect the 
platform only need one wrapper driver in MdeModulePkg to let the status code 
handler library to register its handler on it.

Thanks,

Eric



Thanks,
--

Brian J. Johnson
Enterprise X86 Lab

Hewlett Packard Enterprise

hpe.com<3D%22hpe.com%22>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61543): https://edk2.groups.io/g/devel/message/61543
Mute This Topic: https://groups.io/mt/74953841/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-06-19 Thread Dong, Eric


> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Lendacky, Thomas
> Sent: Friday, June 19, 2020 9:51 PM
> To: devel@edk2.groups.io; Dong, Eric 
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Justen, Jordan L ;
> Laszlo Ersek ; Gao, Liming ;
> Kinney, Michael D ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
> 
> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
> >
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of
> >> Lendacky, Thomas
> >> Sent: Thursday, June 18, 2020 10:09 PM
> >> To: Dong, Eric ; devel@edk2.groups.io
> >> Cc: Brijesh Singh ; Ard Biesheuvel
> >> ; Justen, Jordan L
> >> ; Laszlo Ersek ; Gao,
> >> Liming ; Kinney, Michael D
> >> ; Ni, Ray 
> >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement
> >> library support for VMGEXIT
> >>
> >> On 6/18/20 2:23 AM, Dong, Eric wrote:
> >>> Hi Tom,
> >>>
> >>> When use VS2015 to build this code, it reports below error. Please
> >>> help to
> >> fix it.
> >>>
> >>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220:
> >>> warning treated as error - no 'object' file generated
> >>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
> >>> file format detected: please convert the source file to either DOS
> >>> or UNIX format
> >>
> >> That is strange...  I didn't see this when I ran through the CI. When
> >> I do a file command against the file it reports:
> >>
> >> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with
> >> CRLF line terminators
> >>
> >> I'll investigate this and try and figure out what's going on, but if
> >> anyone else has some ideas, please let me know.
> >
> > Hi Tom,
> >
> > I met this error again when I trig below patch from AMD again for CPU
> change.
> > "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"
> 
> Hmmm... I think we could be running into issues with sending patches
> through our mail servers. Let me send you the patch series directly using
> some changes I made to my git config file to see if that helps. Would that be
> ok?

Yes, please do it.

Thanks,
Eric
> 
> Thanks,
> Tom
> 
> >
> > I'm not sure whether this is patch issue, or our internal test sever issue. 
> > I
> have reported this error to our internal team to check also.
> > Please check it from your side and make sure no error from your side. I will
> update the status from my side when I get the update.
> >
> > Thanks,
> > Eric
> >
> >>
> >> Thanks,
> >> Tom
> >>
> >>>
> >>> Thanks,
> >>> Eric
> >>>
> >>>> -Original Message-
> >>>> From: Tom Lendacky 
> >>>> Sent: Friday, June 5, 2020 9:27 PM
> >>>> To: devel@edk2.groups.io
> >>>> Cc: Brijesh Singh ; Ard Biesheuvel
> >>>> ; Dong, Eric ; Justen,
> >>>> Jordan L ; Laszlo Ersek
> >>>> ; Gao, Liming ; Kinney,
> >>>> Michael D ; Ni, Ray 
> >>>> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> >>>> VMGEXIT
> >>>>
> >>>> BZ:
> >>>>
> >>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbug
> >>>>
> >>
> zilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198data=02%7C01%7Ct
> >> ho
> >>>>
> >>
> mas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd
> >> 8961fe
> >>>>
> >>
> 4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842sdata=
> >> fBlK2B
> >>>>
> FkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3Dreserved=0
> >>>>
> >>>> To support handling #VC exceptions and issuing VMGEXIT
> >>>> instructions, create a library with functions that can be used to
> >>>> perform these #VC/VMGEXIT related operations. This includes
> functions for:
> >>>> - Handling #VC exceptions
> >>>> - Preparing for and issuing a VMGEXIT
> >>>> - Performing MMIO-related write operations to support flash
> emulation
> >>>> - Performing AP related boot opeations
> >>>>
> >>>> The base functions in thi

Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-06-19 Thread Dong, Eric


> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Lendacky, Thomas
> Sent: Thursday, June 18, 2020 10:09 PM
> To: Dong, Eric ; devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Justen, Jordan L ;
> Laszlo Ersek ; Gao, Liming ;
> Kinney, Michael D ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
> 
> On 6/18/20 2:23 AM, Dong, Eric wrote:
> > Hi Tom,
> >
> > When use VS2015 to build this code, it reports below error. Please help to
> fix it.
> >
> > k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning
> > treated as error - no 'object' file generated
> > k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
> > file format detected: please convert the source file to either DOS or
> > UNIX format
> 
> That is strange...  I didn't see this when I ran through the CI. When I do a 
> file
> command against the file it reports:
> 
> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with CRLF
> line terminators
> 
> I'll investigate this and try and figure out what's going on, but if anyone 
> else
> has some ideas, please let me know.

Hi Tom,

I met this error again when I trig below patch from AMD again for CPU change.
"UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"

I'm not sure whether this is patch issue, or our internal test sever issue. I 
have reported this error to our internal team to check also.
Please check it from your side and make sure no error from your side. I will 
update the status from my side when I get the update.

Thanks,
Eric

> 
> Thanks,
> Tom
> 
> >
> > Thanks,
> > Eric
> >
> >> -Original Message-
> >> From: Tom Lendacky 
> >> Sent: Friday, June 5, 2020 9:27 PM
> >> To: devel@edk2.groups.io
> >> Cc: Brijesh Singh ; Ard Biesheuvel
> >> ; Dong, Eric ; Justen,
> >> Jordan L ; Laszlo Ersek
> >> ; Gao, Liming ; Kinney,
> >> Michael D ; Ni, Ray 
> >> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> >> VMGEXIT
> >>
> >> BZ:
> >>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbug
> >>
> zilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198data=02%7C01%7Ct
> ho
> >>
> mas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd
> 8961fe
> >>
> 4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842sdata=
> fBlK2B
> >> FkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3Dreserved=0
> >>
> >> To support handling #VC exceptions and issuing VMGEXIT instructions,
> >> create a library with functions that can be used to perform these
> >> #VC/VMGEXIT related operations. This includes functions for:
> >>- Handling #VC exceptions
> >>- Preparing for and issuing a VMGEXIT
> >>- Performing MMIO-related write operations to support flash emulation
> >>- Performing AP related boot opeations
> >>
> >> The base functions in this driver will not do anything and will
> >> return an error if a return value is required. It is expected that
> >> other packages (like OvmfPkg) will create a version of the library to
> >> fully support an SEV-ES guest.
> >>
> >> Cc: Eric Dong 
> >> Cc: Ray Ni 
> >> Cc: Laszlo Ersek 
> >> Signed-off-by: Tom Lendacky 
> >> ---
> >>   UefiCpuPkg/UefiCpuPkg.dec|   3 +
> >>   UefiCpuPkg/UefiCpuPkg.dsc|   2 +
> >>   UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf |  27 +
> >>   UefiCpuPkg/Include/Library/VmgExitLib.h  | 103
> +
> >>   UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c   | 121
> >> 
> >>   UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni |  15 +++
> >>   6 files changed, 271 insertions(+)
> >>
> >> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> >> index df5d02bae6b4..cb92f34b6f55 100644
> >> --- a/UefiCpuPkg/UefiCpuPkg.dec
> >> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> >> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
> >> ##
> >>
> >> MpInitLib|Include/Library/MpInitLib.h
> >>
> >>
> >>
> >> +  ##  @libraryclass  Provides function to support VMGEXIT processing.
> >>
> >> +  VmgExitLib|Include/Library/VmgExitLib.h
> >>
> >> +
> >>
> >>   [Gu

Re: [edk2-devel] [PATCH v9 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector

2020-06-19 Thread Dong, Eric
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Lendacky, Thomas
> Sent: Thursday, June 18, 2020 10:51 PM
> To: Dong, Eric ; devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Justen, Jordan L ;
> Laszlo Ersek ; Gao, Liming ;
> Kinney, Michael D ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v9 43/46] OvmfPkg: Use the SEV-ES work
> area for the SEV-ES AP reset vector
> 
> On 6/18/20 2:43 AM, Dong, Eric wrote:
> > Hi Tom,
> 
> Hi Eric,
> 
> >
> > We use GCC5 to build the OVMF platform and report below errors, please
> help to check and fix it.
> 
> That's what I use when I build and have never encountered these errors. I
> also ran the patches through the EDK2 CI and didn't get any errors.
> 
> I've noticed that the dependencies aren't always handle properly for these
> files. Are you doing a clean build or an incremental build for this patch?
> Can you delete your Build directory and rebuild and see if you still get the
> errors?

I trig internal server build with your change and the build server found this 
issue. 
I think it should use clean build.

> 
> >
> >
> > I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/MdeModulePkg/
> > -I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/MdeModulePkg/Include/
> > -I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/
> > -I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/Include/
> > -
> I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/ResetVector/Vtf0
> /
> > -o
> >
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/
> X64/O
> > vmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin
> >
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/
> X64/O
> > vmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii
> >
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/
> X64/O
> > vmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii:72: error:
> > expression syntax error
> >
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/
> X64/O
> > vmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii:74: error: label
> > or instruction expected at start of line > Ia32/PageTables64.asm:27:
> > error: label or instruction expected at start
> of line
> > Ia32/PageTables64.asm:29: error: label or instruction expected at
> > start of line
> > Ia32/PageTables64.asm:30: error: label or instruction expected at
> > start of line
> > Ia32/PageTables64.asm:369: error: expression syntax error
> 
> Can you paste the relevant portion of these files in an email or send copies 
> of
> those files to me?

Because the build is in internal sever and I can't copy the build file from it.

If you think you have pass all the test, I can rerun the test and check the 
result again.

Thanks,
Eric
> 
> Thanks,
> Tom
> 
> > GNUmakefile:319: recipe for target
> >
> '/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/
> X64/
> > OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin' failed
> > make: ***
> >
> [/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5
> /X64/
> > OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin] Error 1
> >
> >
> > build.py...
> >   : error 7000: Failed to execute command
> >   make tbuild
> >
> [/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5
> /X64/
> > OvmfPkg/ResetVector/ResetVector]
> >
> >
> > build.py...
> >   : error F002: Failed to build module
> >
> >
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/OvmfPkg/ResetVector/ResetV
> ecto
> > r.inf [X64, GCC5, DEBUG]
> >
> > 
> > Related platform build configuration like below:
> >
> > WORKSPACE= /opt/TCAgent/work/f9b29f3e80472c44/Edk2
> > EDK_TOOLS_PATH   =
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/BaseTools
> > CONF_PATH        = /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Conf
> > PYTHON_COMMAND   = /usr/bin/python3.5
> >
> > Architecture(s)  = X64
> > Build target = DEBUG
> > Toolchain= GCC5
> >
> > Active Platform  =
> /opt/TCAgent/work/f9b29f3e80472c44/Edk2/OvmfPkg/OvmfPkgX64.dsc
> >
> >
> > Thanks,
> > Eric
> >> -Original Message-
> >> From: Tom Lendacky 
> >> Sent: Friday, June 5, 2020 9:28 PM
> >> To: devel@edk2.groups.io
> >> Cc: Brijesh Singh ; Ard Biesheuvel
> >> ; Dong, Eric ; Justen,
> >> Jordan L ; Laszlo Ersek
> >> ; Gao, Liming ; Kinney,
> >> Michael D ; Ni, Ray 
> &

Re: [edk2-devel] [PATCH v2 0/2] AMD procesor MSR_IA32_MISC_ENABLE

2020-06-18 Thread Dong, Eric
Hi Garrett,

I create a pull request to verify your changes and it reports some errors for 
your changes. 
https://github.com/tianocore/edk2/pull/710

please help to resolve these errors before sending your new version changes, 
also you can create your PR to verify your new changes.

Thanks,
Eric

> -Original Message-
> From: Garrett Kirkendall 
> Sent: Thursday, June 18, 2020 11:23 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [PATCH v2 0/2] AMD procesor MSR_IA32_MISC_ENABLE
> 
> AMD processor does not support MSR_IA32_MISC_ENABLE register.
> Accessing this register on AMD causes an unhandled exception in
> SmmEntry.nasm and a subsequent failure to boot since this is too early in
> SMM path for the exception handler to be loaded.
> 
> First, to distinguish between AMD and other processors, refactor
> StandardSignatureIsAuthenticAMD into BaseUefiCpuLib.  So there is only one
> copy in the source. All changed modules already include UefiCpuLib either
> directly or indirectly so could not easly split first patch.
> 
> Second, Skip manipulation of MSR_IA32_MISC_ENABLE register if running on
> an AMD processor.
> 
> Tested on AMD X64 hardware.
> OvmfIa32 and OvmfIa32X64 on Intel hardware.
> 
> Garrett Kirkendall (2):
>   UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib
>   UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE
> manipulation on
> AMD
> 
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf |  7 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf |  2 ++
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf |  2 ++
>  UefiCpuPkg/Include/Library/UefiCpuLib.h  | 14 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h   |  3 ++
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 38
> 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c   | 25 
> ++---
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c   | 25 ++--
> -
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c   |  9 -
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm | 19
> --
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm  | 20
> +--
>  12 files changed, 113 insertions(+), 74 deletions(-)  create mode 100644
> UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c
> 
> Changes at:
> https://github.com/gkirkendall-
> amd/edk2/tree/smmentry_nasm_skip_msr_xd_bit_on_amd_v2
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Garrett Kirkendall 
> 
> --
> 2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61507): https://edk2.groups.io/g/devel/message/61507
Mute This Topic: https://groups.io/mt/74960774/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [patch] MdeModulePkg/DisplayEngine: Add Debug message to show mismatch menu info

2020-06-18 Thread Dong, Eric
Hi Dandan,

Thanks for your detail explanation, add my comments below.

Thanks,
Eric
From: Bi, Dandan 
Sent: Thursday, June 18, 2020 4:39 PM
To: Dong, Eric ; devel@edk2.groups.io
Cc: Gao, Liming 
Subject: RE: [patch] MdeModulePkg/DisplayEngine: Add Debug message to show 
mismatch menu info

Hi Eric,

For example:

For one of, if its current value is 4, but there is no option with value 4, 
then it will pop up mismatch window and the debug message like below.
[DisplayEngine]: Mismatch Error: Current value not exists in the option 
list. <= it's better to add this line to show an 
overview of error info.
[DisplayEngine]: Mismatch Formset: Formset Guid = 
9E0C30BC-3F06-4BA6-8288-09179B855DBE.   Formset title = ""<= 
Title also needs if save happen in system level.
[DisplayEngine]: Mismatch Form : FormId = 4096,  Form title = Front 
Page.
[DisplayEngine]: Mismatch OneOf  : Named = Select Language.
[DisplayEngine]: Mismatch OneOf  : Current value = 4.
[DisplayEngine]: Option 0 : Option Name = Standard English. 
Option Value = 0.
[DisplayEngine]: Option 1 : Option Name = Standard 
Franτais. Option Value = 1.
[DisplayEngine]: Option 2 : Option Name = English. Option 
Value = 2.
[DisplayEngine]: Option 3 : Option Name = Franτais. Option 
Value = 3.

For OrderedList, its value is in the type of array, if one of array value is 4, 
but there is no option with value 4, then it will pop up mismatch window and 
the debug message like below.
[DisplayEngine]: Mismatch Error: Current one value not exists in 
the option list. <= same as above reason, you can 
provide better words if you have.
[DisplayEngine]: Mismatch Formset   : Formset Guid = 
A04A27F4-DF00-4D42-B552-39511302113D. Formset title = ""<= 
Title also needs if save happen in system level.
[DisplayEngine]: Mismatch Form: FormId = 1,  Form title = My First 
Setup Page.
[DisplayEngine]: Mismatch OrderedList: Name = Boot Order.
[DisplayEngine]: Mismatch OrderedList: Value Arrary:

Value[0] =4.

Value[1] =1.

Value[2] =3.

Value[3] =0.

Value[4] =0.

Value[5] =0.

Value[6] =0.

Value[7] =0.
[DisplayEngine]: Option 0: Option Name = ATAPI CD. 
Option Value = 2.
[DisplayEngine]: Option 1: Option Name = IDE HDD. 
Option Value = 1.
[DisplayEngine]: Option 2: Option Name = PXE. Option 
Value = 3.


Thanks,
Dandan
> -Original Message-
> From: Dong, Eric mailto:eric.d...@intel.com>>
> Sent: Thursday, June 18, 2020 2:28 PM
> To: Bi, Dandan mailto:dandan...@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Gao, Liming mailto:liming@intel.com>>
> Subject: RE: [patch] MdeModulePkg/DisplayEngine: Add Debug message to
> show mismatch menu info
>
> Hi Dandan,
>
> It's good to show more info about the mismatch error. Current end user
> doesn't know which question need to check if this error appears.
>
> Can you post an example about the error message for one of and for
> ordered list? We need to make sure the message is easy to be understood
> and the end user knows what need to do to fix this error.
>
> Thanks,
> Eric
>
> > -Original Message-
> > From: Bi, Dandan mailto:dandan...@intel.com>>
> > Sent: Thursday, June 18, 2020 11:24 AM
> > To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> > Cc: Gao, Liming mailto:liming@intel.com>>; Dong, 
> > Eric
> > mailto:eric.d...@intel.com>>
> > Subject: [patch] MdeModulePkg/DisplayEngine: Add Debug message to
> show
> > mismatch menu info
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2326
> >
> > Currently when meet mismatch case for one-of and ordered-list menu,
> > just show a popup window to indicate mismatch, no more info for
> debugging.
> > This patch is to add more debug message about mismatch menu info which
> > is helpful to debug.
> >
> > Cc: Liming Gao mailto:liming@intel.com>>
> > Cc: Eric Dong mailto:eric.d...@intel.com>>
&

Re: [edk2-devel] [PATCH v9 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector

2020-06-18 Thread Dong, Eric
Hi Tom,

We use GCC5 to build the OVMF platform and report below errors, please help to 
check and fix it.


I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/MdeModulePkg/ 
-I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/MdeModulePkg/Include/ 
-I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/ 
-I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/Include/ 
-I/opt/TCAgent/work/f9b29f3e80472c44/Edk2/UefiCpuPkg/ResetVector/Vtf0/ -o 
/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin
 
/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii
/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii:72:
 error: expression syntax error
/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.iii:74:
 error: label or instruction expected at start of line
Ia32/PageTables64.asm:27: error: label or instruction expected at start of line
Ia32/PageTables64.asm:29: error: label or instruction expected at start of line
Ia32/PageTables64.asm:30: error: label or instruction expected at start of line
Ia32/PageTables64.asm:369: error: expression syntax error
GNUmakefile:319: recipe for target 
'/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin'
 failed
make: *** 
[/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector/OUTPUT/ResetVector.bin]
 Error 1


build.py...
 : error 7000: Failed to execute command
make tbuild 
[/opt/TCAgent/work/f9b29f3e80472c44/Edk2/Build/OvmfX64/DEBUG_GCC5/X64/OvmfPkg/ResetVector/ResetVector]


build.py...
 : error F002: Failed to build module

/opt/TCAgent/work/f9b29f3e80472c44/Edk2/OvmfPkg/ResetVector/ResetVector.inf 
[X64, GCC5, DEBUG]


Related platform build configuration like below:

WORKSPACE= /opt/TCAgent/work/f9b29f3e80472c44/Edk2
EDK_TOOLS_PATH   = /opt/TCAgent/work/f9b29f3e80472c44/Edk2/BaseTools
CONF_PATH= /opt/TCAgent/work/f9b29f3e80472c44/Edk2/Conf
PYTHON_COMMAND   = /usr/bin/python3.5

Architecture(s)  = X64
Build target = DEBUG
Toolchain= GCC5

Active Platform  = 
/opt/TCAgent/work/f9b29f3e80472c44/Edk2/OvmfPkg/OvmfPkgX64.dsc


Thanks,
Eric
> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:28 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-
> ES AP reset vector
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> A hypervisor is not allowed to update an SEV-ES guest's register state,
> so when booting an SEV-ES guest AP, the hypervisor is not allowed to
> set the RIP to the guest requested value. Instead an SEV-ES AP must be
> re-directed from within the guest to the actual requested staring location
> as specified in the INIT-SIPI-SIPI sequence.
> 
> Use the SEV-ES work area for the reset vector code that contains support
> to jump to the desired RIP location after having been started. This is
> required for only the very first AP reset.
> 
> This new OVMF source file, ResetVectorVtf0.asm, is used in place of the
> original file through the use of the include path order set in
> OvmfPkg/ResetVector/ResetVector.inf under "[BuildOptions]".
> 
> Cc: Jordan Justen 
> Cc: Laszlo Ersek 
> Cc: Ard Biesheuvel 
> Reviewed-by: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 100
> 
>  OvmfPkg/ResetVector/ResetVector.nasmb|   1 +
>  2 files changed, 101 insertions(+)
> 
> diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
> b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
> new file mode 100644
> index ..980e0138e7fe
> --- /dev/null
> +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
> @@ -0,0 +1,100 @@
> +;--
> 
> +; @file
> 
> +; First code executed by processor after resetting.
> 
> +; Derived from UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm
> 
> +;
> 
> +; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
> 
> +; SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +;
> 
> +;--
> 
> +
> 
> +BITS16
> 
> +
> 
> +ALIGN   16
> 
> +
> 
> +;
> 
> +; Pad the image size to 4k

Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-06-18 Thread Dong, Eric
Hi Tom,

When use VS2015 to build this code, it reports below error. Please help to fix 
it.

k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning treated 
as error - no 'object' file generated
k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac file format 
detected: please convert the source file to either DOS or UNIX format

Thanks,
Eric

> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:27 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> VMGEXIT
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> To support handling #VC exceptions and issuing VMGEXIT instructions,
> create a library with functions that can be used to perform these
> #VC/VMGEXIT related operations. This includes functions for:
>   - Handling #VC exceptions
>   - Preparing for and issuing a VMGEXIT
>   - Performing MMIO-related write operations to support flash emulation
>   - Performing AP related boot opeations
> 
> The base functions in this driver will not do anything and will return
> an error if a return value is required. It is expected that other packages
> (like OvmfPkg) will create a version of the library to fully support an
> SEV-ES guest.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/UefiCpuPkg.dec|   3 +
>  UefiCpuPkg/UefiCpuPkg.dsc|   2 +
>  UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf |  27 +
>  UefiCpuPkg/Include/Library/VmgExitLib.h  | 103 +
>  UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c   | 121
> 
>  UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni |  15 +++
>  6 files changed, 271 insertions(+)
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> index df5d02bae6b4..cb92f34b6f55 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dec
> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
>##
> 
>MpInitLib|Include/Library/MpInitLib.h
> 
> 
> 
> +  ##  @libraryclass  Provides function to support VMGEXIT processing.
> 
> +  VmgExitLib|Include/Library/VmgExitLib.h
> 
> +
> 
>  [Guids]
> 
>gUefiCpuPkgTokenSpaceGuid  = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
> 
>gMsegSmramGuid = { 0x5802bce4, 0x, 0x4e33, { 0xa1, 
> 0x30,
> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index afa304128221..f0e58b90ff0a 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -56,6 +56,7 @@ [LibraryClasses]
> 
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> PeCoffGetEntryPointLib.inf
> 
> 
> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP
> eCoffExtraActionLibNull.inf
> 
> 
> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
> mMeasurementLibNull.inf
> 
> +  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> 
> 
> 
>  [LibraryClasses.common.SEC]
> 
> 
> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.i
> nf
> 
> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
> 
> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
> Null.inf
> 
>UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> 
>UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> 
> +  UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> 
>UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
> 
>UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
> 
>UefiCpuPkg/SecCore/SecCore.inf
> 
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> new file mode 100644
> index ..d8770a21c355
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> @@ -0,0 +1,27 @@
> +## @file
> 
> +#  VMGEXIT Support Library.
> 
> +#
> 
> +#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +##
> 
> +
> 
> +[Defines]
> 
> +  INF_VERSION= 0x00010005
> 
> +  BASE_NAME  = VmgExitLibNull
> 
> +  MODULE_UNI_FILE= V

Re: [edk2-devel] [patch] MdeModulePkg/DisplayEngine: Add Debug message to show mismatch menu info

2020-06-18 Thread Dong, Eric
Hi Dandan,

It's good to show more info about the mismatch error. Current end user doesn't 
know which question need to check if this error appears.

Can you post an example about the error message for one of and for ordered 
list? We need to make sure the message is easy to be understood and the end 
user knows what need to do to fix this error.

Thanks,
Eric

> -Original Message-
> From: Bi, Dandan 
> Sent: Thursday, June 18, 2020 11:24 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Dong, Eric 
> Subject: [patch] MdeModulePkg/DisplayEngine: Add Debug message to
> show mismatch menu info
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2326
> 
> Currently when meet mismatch case for one-of and ordered-list menu, just
> show a popup window to indicate mismatch, no more info for debugging.
> This patch is to add more debug message about mismatch menu info which is
> helpful to debug.
> 
> Cc: Liming Gao 
> Cc: Eric Dong 
> Signed-off-by: Dandan Bi 
> ---
>  .../DisplayEngineDxe/ProcessOptions.c | 78 +++
>  1 file changed, 78 insertions(+)
> 
> diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> b/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> index e7306f6d04..4331b2903c 100644
> --- a/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> +++ b/MdeModulePkg/Universal/DisplayEngineDxe/ProcessOptions.c
> @@ -911,10 +911,73 @@ PasswordProcess (
>FreePool (StringPtr);
> 
>return Status;
>  }
> 
> +/**
> +  Print some debug message about mismatched menu info.
> +
> +  @param  MenuOption The MenuOption for this Question.
> +
> +**/
> +VOID
> +PrintMismatchMenuInfo (
> +  IN  UI_MENU_OPTION  *MenuOption
> +)
> +{
> +  CHAR16  *FormTitleStr;
> +  CHAR16  *OneOfOptionStr;
> +  CHAR16  *QuestionName;
> +  LIST_ENTRY  *Link;
> +  FORM_DISPLAY_ENGINE_STATEMENT   *Question;
> +  EFI_IFR_ORDERED_LIST*OrderList;
> +  UINTN   Index;
> +  EFI_HII_VALUE   HiiValue;
> +  EFI_HII_VALUE   *QuestionValue;
> +  DISPLAY_QUESTION_OPTION *Option;
> +  UINT8   *ValueArray;
> +  UINT8   ValueType;
> +
> +  Question = MenuOption->ThisTag;
> +  FormTitleStr = GetToken (gFormData->FormTitle, gFormData->HiiHandle);
> +
> +  DEBUG ((DEBUG_ERROR, "\n[DisplayEngine]: Mismatch Formset:
> Formset Guid = %g.\n", >FormSetGuid));
> +  DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Mismatch Form   : FormId
> = %d,  Form title = %s.\n", gFormData->FormId, FormTitleStr));
> +
> +  if (Question->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
> +QuestionName = GetToken (((EFI_IFR_ORDERED_LIST*)MenuOption-
> >ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
> +Link = GetFirstNode (>OptionListHead);
> +Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
> +ValueType = Option->OptionOpCode->Type;
> +
> +DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Mismatch OrderedList: Name
> = %s.\n", QuestionName));
> +DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Mismatch OrderedList: Value
> + Arrary:\n"));
> +
> +OrderList = (EFI_IFR_ORDERED_LIST *) Question->OpCode;
> +for (Index = 0; Index < OrderList->MaxContainers; Index++) {
> +  ValueArray = Question->CurrentValue.Buffer;
> +  HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);
> +  DEBUG ((DEBUG_ERROR, "   Value[%d] 
> =%d.\n",Index,
> HiiValue.Value.u64));
> +}
> +  } else if (Question->OpCode->OpCode == EFI_IFR_ONE_OF_OP) {
> +QuestionName = GetToken (((EFI_IFR_ONE_OF*)MenuOption->ThisTag-
> >OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
> +QuestionValue = >CurrentValue;;
> +DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Mismatch OneOf  : Named
> = %s.\n", QuestionName));
> +DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Mismatch OneOf  : Current
> value = %d.\n",QuestionValue->Value.u8));
> +  }
> +
> +  Index = 0;
> +  Link = GetFirstNode (>OptionListHead);
> +  while (!IsNull (>OptionListHead, Link)) {
> +Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
> +OneOfOptionStr = GetToken (Option->OptionOpCode->Option,
> gFormData->HiiHandle);
> +DEBUG ((DEBUG_ERROR, "[DisplayEngine]: Option %d: Option
> Name = %s. Option Value = %d.\n",Index,OneOfOptionStr,Option-
> >Op

Re: [edk2-devel] [PATCH] Features/Intel/Readme.md: clarify feature package dependency rule

2020-06-17 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Ni, Ray 
> Sent: Wednesday, June 17, 2020 5:03 PM
> To: devel@edk2.groups.io
> Cc: Ray Ni ; Dong, Eric
> ; Chan, Amy ; Chaganty,
> Rangasai V ; Oram, Isaac W
> 
> Subject: [PATCH] Features/Intel/Readme.md: clarify feature package
> dependency rule
> 
> From: Ray Ni 
> 
> Original statement only says depending on another feature package
> is not allowed. It gives developers impression that board level
> packages are allowed to depend on.
> 
> This patch clarifies the package dependency rule.
> 
> Signed-off-by: Ray Ni 
> Cc: Eric Dong 
> Cc: Amy Chan 
> Cc: Rangasai V Chaganty 
> Cc: Isaac W Oram 
> ---
>  Features/Intel/Readme.md | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/Features/Intel/Readme.md b/Features/Intel/Readme.md
> index 9729f90a41..1a03a4c0d2 100644
> --- a/Features/Intel/Readme.md
> +++ b/Features/Intel/Readme.md
> @@ -17,8 +17,10 @@ document as needed.
>  ### Advanced Feature Attributes
> 
>  Advanced features should be:
> 
>  * _Cohesive_, the feature should not contain any functionality unrelated to
> the feature.
> 
> -* _Complete_, the feature must have a complete design that minimizes
> dependencies. A feature package cannot directly
> 
> -  depend on another feature package.
> 
> +* _Complete_, the feature must have a complete design that minimizes
> dependencies. A feature package can only depend
> 
> +  on following packages:
> 
> +  * edk2 repo: `MdePkg`, `MdeModulePkg`, `UefiCpuPkg`, `FmpDevicePkg`,
> `SecurityPkg`, `NetworkPkg`, `ShellPkg`.
> 
> +  * edk2-platforms repo: `MinPlatformPkg`, `IntelSiliconPkg`.
> 
>  * _Easy to Integrate_, the feature should expose well-defined software
> interfaces to use and configure the feature.
> 
>* It should also present a set of simple and well-documented standard EDK
> II configuration options such as PCDs to
> 
>configure the feature.
> 
> --
> 2.25.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61448): https://edk2.groups.io/g/devel/message/61448
Mute This Topic: https://groups.io/mt/74933867/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib

2020-06-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Kirkendall, Garrett
> Sent: Tuesday, June 16, 2020 2:30 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Laszlo
> Ersek 
> Subject: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Move
> StandardSignatureIsAuthenticAMD to BaseUefiCpuLib
> 
> Refactor StandardSignatureIsAuthenticAMD into BaseUefiCpuLib from
> separate copies in BaseXApicLib, BaseXApicX2ApicLib, and MpInitLib.
> This allows for future use of StandarSignatureIsAuthinticAMD without
> creating more instances in other modules.
> 
> This function allows IA32/X64 code to determine if it is running on an AMD
> brand processor.
> 
> UefiCpuLib is already included directly or indirectly in all modified modules.
> Complete move is made in this change.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Garrett Kirkendall 
> ---
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf |  7 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf |  2 ++
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf |  2 ++
>  UefiCpuPkg/Include/Library/UefiCpuLib.h  | 14 
>  UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.c   | 38
> 
>  UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c   | 25 
> ++---
>  UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c   | 25 ++--
> -
>  UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 
> 
>  8 files changed, 67 insertions(+), 69 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> index 006b7acbf14e..34d3a7bb4303 100644
> --- a/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> +++ b/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
> @@ -4,6 +4,7 @@
>  #  The library routines are UEFI specification compliant.
>  #
>  #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -29,6 +30,12 @@
> [Sources.IA32]  [Sources.X64]
>X64/InitializeFpu.nasm
> 
> +[Sources]
> +  BaseUefiCpuLib.c
> +
>  [Packages]
>MdePkg/MdePkg.dec
>UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> index bdb2ff372677..561baa44b0e6 100644
> --- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> +++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.inf
> @@ -5,6 +5,7 @@
>  #  where local APIC is disabled.
>  #
>  #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -37,6 +38,7 @@
> [LibraryClasses]
>TimerLib
>IoLib
>PcdLib
> +  UefiCpuLib
> 
>  [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuInitIpiDelayInMicroSeconds  ##
> SOMETIMES_CONSUMES diff --git
> a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> index ac1e0a1c9896..1e2a4f8b790f 100644
> --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
> @@ -5,6 +5,7 @@
>  #  where local APIC is disabled.
>  #
>  #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> +#  Copyright (c) 2020, AMD Inc. All rights reserved.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -37,6 +38,7 @@
> [LibraryClasses]
>TimerLib
>IoLib
>PcdLib
> +  UefiCpuLib
> 
>  [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuInitIpiDelayInMicroSeconds  ##
> SOMETIMES_CONSUMES diff --git
> a/UefiCpuPkg/Include/Library/UefiCpuLib.h
> b/UefiCpuPkg/Include/Library/UefiCpuLib.h
> index 82e53bab3a0f..5326e7246301 100644
> --- a/UefiCpuPkg/Include/Library/UefiCpuLib.h
> +++ b/UefiCpuPkg/Include/Library/UefiCpuLib.h
> @@ -5,6 +5,7 @@
>to be UEFI specification compliant.
> 
>Copyright (c) 2009, Intel Corporation. All rights reserved.
> +  Copyright (c) 2020, AMD Inc. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -29,4 +30,17 @@ InitializeFloatingPointUnits (
>VOID
>);
> 
> +/**
> +  Determine if the standard CPU signature is "AuthenticAMD".
> +
> +  @retval TRUE  The CPU signature matches.
> +  @retval FALSE The CPU signature does not match.
&

Re: [edk2-devel] [PATCH v9 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor

2020-06-16 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:28 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 40/46] UefiCpuPkg: Add a 16-bit protected mode code
> segment descriptor
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> A hypervisor is not allowed to update an SEV-ES guests register state, so
> when booting an SEV-ES guest AP, the hypervisor is not allowed to set the
> RIP to the guest requested value. Instead, an SEV-ES AP must be transition
> from 64-bit long mode to 16-bit real mode in response to an INIT-SIPI-SIPI
> sequence. This requires a 16-bit code segment descriptor.
> For PEI, create this descriptor in the reset vector GDT table. For DXE, create
> this descriptor from the newly reserved entry at location 0x28.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/CpuDxe/CpuGdt.h  | 4 ++--
>  UefiCpuPkg/CpuDxe/CpuGdt.c  | 8 
>  UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 +
>  3 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/CpuGdt.h
> index 3a0210b2f172..1c94487cbee8 100644
> --- a/UefiCpuPkg/CpuDxe/CpuGdt.h
> +++ b/UefiCpuPkg/CpuDxe/CpuGdt.h
> @@ -36,7 +36,7 @@ struct _GDT_ENTRIES {
>GDT_ENTRY LinearCode;   GDT_ENTRY SysData;   GDT_ENTRY SysCode;-
> GDT_ENTRY Spare4;+  GDT_ENTRY SysCode16;   GDT_ENTRY LinearData64;
> GDT_ENTRY LinearCode64;   GDT_ENTRY Spare5;@@ -49,7 +49,7 @@ struct
> _GDT_ENTRIES {
>  #define LINEAR_CODE_SEL   OFFSET_OF (GDT_ENTRIES, LinearCode)
> #define SYS_DATA_SEL  OFFSET_OF (GDT_ENTRIES, SysData) #define
> SYS_CODE_SEL  OFFSET_OF (GDT_ENTRIES, SysCode)-#define SPARE4_SEL
> OFFSET_OF (GDT_ENTRIES, Spare4)+#define SYS_CODE16_SELOFFSET_OF
> (GDT_ENTRIES, SysCode16) #define LINEAR_DATA64_SEL OFFSET_OF
> (GDT_ENTRIES, LinearData64) #define LINEAR_CODE64_SEL OFFSET_OF
> (GDT_ENTRIES, LinearCode64) #define SPARE5_SELOFFSET_OF
> (GDT_ENTRIES, Spare5)diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c
> b/UefiCpuPkg/CpuDxe/CpuGdt.c
> index 64efadeba601..a1ab543f2da5 100644
> --- a/UefiCpuPkg/CpuDxe/CpuGdt.c
> +++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
> @@ -70,14 +70,14 @@ STATIC GDT_ENTRIES GdtTemplate = {
>  0x0,   },   //-  // SPARE4_SEL+  // SYS_CODE16_SEL   //   {-0x0, 
>// limit
> 15:0+0x0,// limit 15:0 0x0,// base 15:0 
> 0x0,// base
> 23:16-0x0,// type-0x0,// limit 19:16, flags+  
>   0x09A,  //
> present, ring 0, code, execute/read+0x08F,  // page-granular, 
> 16-bit
> 0x0,// base 31:24   },   //diff --git
> a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
> b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
> index ce4ebfffb688..0e79a3984b16 100644
> --- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
> +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
> @@ -129,5 +129,14 @@ LINEAR_CODE64_SEL   equ $-GDT_BASE
>  DB  0; base 31:24 %endif +; linear code segment
> descriptor+LINEAR_CODE16_SEL equ $-GDT_BASE+DW  0x   ; 
> limit
> 15:0+DW  0; base 15:0+DB  0; base 
> 23:16+DB
> PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)+
> DB
> GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMI
> T(0xf)+DB  0; base 31:24+ GDT_END: --
> 2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61318): https://edk2.groups.io/g/devel/message/61318
Mute This Topic: https://groups.io/mt/74698711/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH 1/1 v2] MdeModulePkg/StatusCodeHandler: do not output \n\r for string data

2020-06-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Tan,
> Ming
> Sent: Monday, June 15, 2020 10:04 AM
> To: devel@edk2.groups.io
> Subject: [edk2-devel] [PATCH 1/1 v2] MdeModulePkg/StatusCodeHandler:
> do not output \n\r for string data
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2787
> 
> When output string data through serial port, will not ouput \n\r now.
> Caller can output several data in one line, and output \n\r when needed.
> 
> Signed-off-by: Ming Tan 
> ---
> V2: Make it as a standalone patch.
>  .../Universal/StatusCodeHandler/Pei/SerialStatusCodeWorker.c| 2 +-
>  .../StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c   | 2 +-
>  .../Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c| 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Universal/StatusCodeHandler/Pei/SerialStatusCodeWork
> er.c
> b/MdeModulePkg/Universal/StatusCodeHandler/Pei/SerialStatusCodeWork
> er.c
> index 2455f8b2a908..3aa5642b64fb 100644
> ---
> a/MdeModulePkg/Universal/StatusCodeHandler/Pei/SerialStatusCodeWork
> er.c
> +++
> b/MdeModulePkg/Universal/StatusCodeHandler/Pei/SerialStatusCodeWork
> er.c
> @@ -134,7 +134,7 @@ SerialStatusCodeReportWorker (
>  CharCount = AsciiSPrint (
>Buffer,
>sizeof (Buffer),
> -  "%a\n\r",
> +  "%a",
>((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
>);
>} else {
> diff --git
> a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusC
> odeWorker.c
> b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusC
> odeWorker.c
> index 2dc3ecfff52e..0b98e7ec6315 100644
> ---
> a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusC
> odeWorker.c
> +++
> b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusC
> odeWorker.c
> @@ -129,7 +129,7 @@ SerialStatusCodeReportWorker (
>  CharCount = AsciiSPrint (
>Buffer,
>sizeof (Buffer),
> -  "%a\n\r",
> +  "%a",
>((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
>);
>} else {
> diff --git
> a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWo
> rker.c
> b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWo
> rker.c
> index c0c907b32f5a..3df0a6712611 100644
> ---
> a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWo
> rker.c
> +++
> b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWo
> rker.c
> @@ -129,7 +129,7 @@ SerialStatusCodeReportWorker (
>  CharCount = AsciiSPrint (
>Buffer,
>sizeof (Buffer),
> -  "%a\n\r",
> +  "%a",
>((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
>);
>} else {
> --
> 2.24.0.windows.2
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61264): https://edk2.groups.io/g/devel/message/61264
Mute This Topic: https://groups.io/mt/74887116/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v6] Features/Intel/BeepDebugFeaturePkg: add it.

2020-06-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tan, Ming 
> Sent: Friday, June 12, 2020 11:41 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Gao, Liming 
> Subject: [PATCH v6] Features/Intel/BeepDebugFeaturePkg: add it.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2792
> 
> The BeepDebugFeaturePkg include some useful beep debug
> libraries, such as get beep value from status code and beep.
> 
> It provide a library BeepStatusCodeHandlerLib used by edk2
> StatusCodeHandler.efi, used to do beep if needed.
> It also provide a library of BeepMap lib, it map the status code
> to beep value.
> A library of Beep lib is needed by platform, and this pkg has a
> Null implementation.
> 
> Cc: Eric Dong 
> Cc: Liming Gao 
> Signed-off-by: Ming Tan 
> ---
> V6: Modify some bug when include the platform dsc file. And modify
> Readme.md.
> V5: In .inf files, remove some useless library.
> In RuntimeDxeBeepStatusCodeHandlerLib.c, add a variable to indicate
> whether need unregister.
> V4: Change Include/BeepDebugFeature.dsc, make it can be included in
> platform dsc file.
> V3: Modify according the Eric's review comments.
> V2: Delete the last empty line in
> BeepDebugFeaturePkg/Library/BeepMapLib/BeepMapLib.inf
>  .../BeepDebugFeaturePkg.dec   |  36 +++
>  .../BeepDebugFeaturePkg.dsc   |  30 ++
>  .../Include/BeepDebugFeature.dsc  | 201 +
>  .../Include/Library/BeepLib.h |  33 +++
>  .../Include/Library/BeepMapLib.h  |  32 +++
>  .../Library/BeepLib/BeepLibNull.c |  37 +++
>  .../Library/BeepLib/BeepLibNull.inf   |  26 ++
>  .../Library/BeepMapLib/BeepMapLib.c   | 116 
>  .../Library/BeepMapLib/BeepMapLib.inf |  27 ++
>  .../BeepMapLib/PlatformStatusCodesInternal.h  | 270
> ++
>  .../PeiBeepStatusCodeHandlerLib.c | 101 +++
>  .../PeiBeepStatusCodeHandlerLib.inf   |  49 
>  .../RuntimeDxeBeepStatusCodeHandlerLib.c  | 184 
>  .../RuntimeDxeBeepStatusCodeHandlerLib.inf|  51 
>  .../SmmBeepStatusCodeHandlerLib.c | 138 +
>  .../SmmBeepStatusCodeHandlerLib.inf   |  50 
>  .../Debugging/BeepDebugFeaturePkg/Readme.md   | 125 
>  17 files changed, 1506 insertions(+)
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/BeepDebugFeaturePkg.d
> ec
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/BeepDebugFeaturePkg.d
> sc
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Include/BeepDebugFeat
> ure.dsc
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Include/Library/BeepLib.
> h
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Include/Library/BeepMa
> pLib.h
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepLib/BeepLib
> Null.c
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepLib/BeepLib
> Null.inf
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepMapLib/Bee
> pMapLib.c
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepMapLib/Bee
> pMapLib.inf
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepMapLib/Plat
> formStatusCodesInternal.h
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/PeiBeepStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/PeiBeepStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/RuntimeDxeBeepStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/SmmBeepStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Library/BeepStatusCode
> HandlerLib/SmmBeepStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/BeepDebugFeaturePkg/Readme.md
> 
> diff --git
> a/Features/Intel/Debugging/BeepDebugFeaturePkg/BeepDebugFeaturePkg
> .dec
> b/Features/Intel/Debugging/BeepDebugFeaturePkg/BeepDebugFeaturePkg
> .dec
> new file mode 100644
> index 00..4f4b36b091
> --- /dev/null
> +++
> b/Features/Intel/Debugging/BeepDebugFeaturePkg/BeepDebugFeaturePkg
> .dec
> @@ -0,0 +1,36 @@
> +## @file
> 
> +#

Re: [edk2-devel] [PATCH v3] Features/Intel/PostCodeDebugFeaturePkg: add it.

2020-06-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tan, Ming 
> Sent: Friday, June 12, 2020 11:41 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Gao, Liming 
> Subject: [PATCH v3] Features/Intel/PostCodeDebugFeaturePkg: add it.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2478
> 
> The PostCodeDebugFeaturePkg include some useful post code debug
> libraries, such as get post code from status code and show it.
> 
> It provide a library PostCodeStatusCodeHandlerLib used by edk2
> StatusCodeHandler.efi, used to show the post code.
> It also provide a library of PostCodeMap lib, it map the status code
> to post code.
> 
> Cc: Eric Dong 
> Cc: Liming Gao 
> Signed-off-by: Ming Tan 
> ---
> V3: Modify according Eric's comments.
> Modify some bugs about dsc file when it is included.
> Update Readme.md.
> V2: Delete the last empty line in
> PostCodeDebugFeaturePkg/Library/PostCodeMapLib/PostCodeMapLib.inf
>  .../Include/Library/PostCodeMapLib.h  |  32 +++
>  .../Include/PostCodeDebugFeature.dsc  | 200 +
>  .../PlatformStatusCodesInternal.h | 270 ++
>  .../Library/PostCodeMapLib/PostCodeMapLib.c   | 207 ++
>  .../Library/PostCodeMapLib/PostCodeMapLib.inf |  27 ++
>  .../PeiPostCodeStatusCodeHandlerLib.c | 102 +++
>  .../PeiPostCodeStatusCodeHandlerLib.inf   |  49 
>  .../RuntimeDxePostCodeStatusCodeHandlerLib.c  | 188 
>  ...RuntimeDxePostCodeStatusCodeHandlerLib.inf |  51 
>  .../SmmPostCodeStatusCodeHandlerLib.c | 141 +
>  .../SmmPostCodeStatusCodeHandlerLib.inf   |  50 
>  .../PostCodeDebugFeaturePkg.dec   |  32 +++
>  .../PostCodeDebugFeaturePkg.dsc   |  30 ++
>  .../PostCodeDebugFeaturePkg/Readme.md | 117 
>  14 files changed, 1496 insertions(+)
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Include/Library/Post
> CodeMapLib.h
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Include/PostCodeDe
> bugFeature.dsc
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeMa
> pLib/PlatformStatusCodesInternal.h
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeMa
> pLib/PostCodeMapLib.c
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeMa
> pLib/PostCodeMapLib.inf
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/PeiPostCodeStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/PeiPostCodeStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/RuntimeDxePostCodeStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/SmmPostCodeStatusCodeHandlerLib.c
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Library/PostCodeStat
> usCodeHandlerLib/SmmPostCodeStatusCodeHandlerLib.inf
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/PostCodeDebugFeat
> urePkg.dec
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/PostCodeDebugFeat
> urePkg.dsc
>  create mode 100644
> Features/Intel/Debugging/PostCodeDebugFeaturePkg/Readme.md
> 
> diff --git
> a/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Include/Library/Po
> stCodeMapLib.h
> b/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Include/Library/Po
> stCodeMapLib.h
> new file mode 100644
> index 00..834be623a1
> --- /dev/null
> +++
> b/Features/Intel/Debugging/PostCodeDebugFeaturePkg/Include/Library/Po
> stCodeMapLib.h
> @@ -0,0 +1,32 @@
> +/** @file
> 
> +  This library class provides Platform PostCode Map.
> 
> +
> 
> +  Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef __POST_CODE_MAP_LIB__
> 
> +#define __POST_CODE_MAP_LIB__
> 
> +
> 
> +/**
> 
> +  Get PostCode from status code type and value.
> 
> +
> 
> +  @param  CodeType Indicates the type of status code being reported.
> 
> +  @param  ValueDescribes the current status of a hardware or
> 
> +   softwa

Re: [edk2-devel] [PATCH] Intel/Usb3DebugFeaturePkg: Remove the prefix path of Debugging/

2020-06-12 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tan, Ming 
> Sent: Friday, June 12, 2020 10:52 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Gao, Liming 
> Subject: [PATCH] Intel/Usb3DebugFeaturePkg: Remove the prefix path of
> Debugging/
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2795
> 
> In Features/Intel/Debugging/Usb3DebugFeaturePkg, remove the prefix
> path of Debugging/ in the .inf and .dsc files.
> 
> Now the PACKAGES_PATH already include the Features/Intel/Debugging/.
> 
> Cc: Eric Dong 
> Cc: Liming Gao 
> Signed-off-by: Ming Tan 
> ---
>  .../Include/Usb3DebugFeature.dsc | 16 
>  .../Usb3DebugPortLib/Usb3DebugPortLibDxe.inf |  4 ++--
>  .../Usb3DebugPortLibDxeIoMmu.inf |  4 ++--
>  .../Usb3DebugPortLib/Usb3DebugPortLibPei.inf |  4 ++--
>  .../Usb3DebugPortLibPeiIoMmu.inf |  4 ++--
>  .../Usb3DebugPortParamLibPcd.inf |  4 ++--
>  6 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git
> a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFea
> ture.dsc
> b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFea
> ture.dsc
> index 494dd7a342..95adb01a74 100644
> ---
> a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFea
> ture.dsc
> +++
> b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFea
> ture.dsc
> @@ -106,10 +106,10 @@
> 
> 
># Add library instances here that are not included in package components
> and should be tested
> 
># in the package build.
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibNull.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb
> 3DebugPortParamLibPcd.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibPei.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibPeiIoMmu.inf
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibNull.in
> f
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3DebugPor
> tParamLibPcd.inf
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibPei.inf
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibPeiIo
> Mmu.inf
> 
> 
> 
># Add components here that should be included in the package build.
> 
> 
> 
> @@ -126,10 +126,10 @@
> 
> 
># Add library instances here that are not included in package components
> and should be tested
> 
># in the package build.
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibNull.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb
> 3DebugPortParamLibPcd.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibDxe.inf
> 
> -
> Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugP
> ortLibDxeIoMmu.inf
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibNull.in
> f
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3DebugPor
> tParamLibPcd.inf
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibDxe.in
> f
> 
> +
> Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibDxeIo
> Mmu.inf
> 
> 
> 
># Add components here that should be included in the package build.
> 
> 
> 
> diff --git
> a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPort
> Lib/Usb3DebugPortLibDxe.inf
> b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPort
> Lib/Usb3DebugPortLibDxe.inf
> index 51671ce4e3..64a287a016 100644
> ---
> a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPort
> Lib/Usb3DebugPortLibDxe.inf
> +++
> b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPort
> Lib/Usb3DebugPortLibDxe.inf
> @@ -1,7 +1,7 @@
>  ## @file
> 
>  #  USB3 Debug port library.
> 
>  #
> 
> -# Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.
> 
> +# Copyright (c) 2013 - 2020, Intel Corporation. All rights reserved.
> 
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #
> 
>  ##
> 
> @@ -30,7 +30,7 @@
> 
> 
>  [Packages]
> 
>MdePkg/MdePkg.dec
> 
> -  Debugging/Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec
> 
> +  Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec
> 
> 
> 
>  [LibraryClasses]
> 
>BaseLib
> 
> diff --git
> a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPort
> Lib/Usb3D

Re: [edk2-devel] [PATCH v9 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled

2020-06-11 Thread Dong, Eric
Reviewed-by: Eric Dong 

Thanks,
Eric

> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:28 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to
> indicate if SEV-ES is enabled
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> When starting APs in an SMP configuration, the AP needs to know if it is
> running as an SEV-ES guest in order to assign a GHCB page.
> 
> Add a field to the CPU_MP_DATA structure that will indicate if SEV-ES is
> enabled. This new field is set during MP library initialization with the
> PCD value PcdSevEsIsEnabled. This flag can then be used to determine if
> SEV-ES is enabled.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 +
>  UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 +
>  UefiCpuPkg/Library/MpInitLib/MpLib.h  | 2 ++
>  UefiCpuPkg/Library/MpInitLib/MpLib.c  | 1 +
>  4 files changed, 5 insertions(+)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> index 9907f4157b09..583276595619 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
> @@ -71,4 +71,5 @@ [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode   ##
> CONSUMES
> 
>gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate   ##
> SOMETIMES_CONSUMES
> 
> 
> gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds
> ## CONSUMES
> 
> +  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled  ##
> CONSUMES
> 
>gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard  ##
> CONSUMES
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
> b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
> index 89ee9a79d8c5..4b3d39fbf36c 100644
> --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
> +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
> @@ -61,6 +61,7 @@ [Pcd]
>gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ##
> CONSUMES
> 
>gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode   ##
> CONSUMES
> 
>gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate   ##
> SOMETIMES_CONSUMES
> 
> +  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled  ##
> CONSUMES
> 
> 
> 
>  [Ppis]
> 
>gEdkiiPeiShadowMicrocodePpiGuid## SOMETIMES_CONSUMES
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index a8ca03efb8e3..5b46c295b6b2 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -276,6 +276,8 @@ struct _CPU_MP_DATA {
>// driver.
> 
>//
> 
>BOOLEANWakeUpByInitSipiSipi;
> 
> +
> 
> +  BOOLEANSevEsIsEnabled;
> 
>  };
> 
> 
> 
>  extern EFI_GUID mCpuInitMpLibHobGuid;
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index ab7a8ed6633a..a8b605f569bf 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -1727,6 +1727,7 @@ MpInitLibInitialize (
>CpuMpData->CpuData  = (CPU_AP_DATA *) (CpuMpData + 1);
> 
>CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData
> + MaxLogicalProcessorNumber);
> 
>InitializeSpinLock(>MpLock);
> 
> +  CpuMpData->SevEsIsEnabled = PcdGetBool (PcdSevEsIsEnabled);
> 
> 
> 
>//
> 
>// Make sure no memory usage outside of the allocated buffer.
> 
> --
> 2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61182): https://edk2.groups.io/g/devel/message/61182
Mute This Topic: https://groups.io/mt/74698713/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v9 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD

2020-06-11 Thread Dong, Eric
Reviewed-by: Eric Dong 

Thanks,
Eric

> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:27 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Create an SEV-ES workarea PCD. This PCD will be used for BSP
> communication
> during SEC and for AP startup during PEI and DXE phases, the latter is the
> reason for creating it in the UefiCpuPkg.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/UefiCpuPkg.dec | 8 
>  UefiCpuPkg/UefiCpuPkg.uni | 8 
>  2 files changed, 16 insertions(+)
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> index cb92f34b6f55..8c614f9b42bd 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dec
> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> @@ -161,6 +161,14 @@ [PcdsFixedAtBuild]
># @Prompt Specify the count of pre allocated SMM MP tokens per chunk.
> 
> 
> gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk|64|UI
> NT32|0x30002002
> 
> 
> 
> +  ## Area of memory where the SEV-ES work area block lives.
> 
> +  # @Prompt Configure the SEV-ES work area base
> 
> +
> gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|0x0|UINT32|0x30002
> 005
> 
> +
> 
> +  ## Size of teh area of memory where the SEV-ES work area block lives.
> 
> +  # @Prompt Configure the SEV-ES work area base
> 
> +
> gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize|0x0|UINT32|0x30002
> 006
> 
> +
> 
>  [PcdsFixedAtBuild, PcdsPatchableInModule]
> 
>## This value is the CPU Local APIC base address, which aligns the address
> on a 4-KByte boundary.
> 
># @Prompt Configure base address of CPU Local APIC
> 
> diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni
> index f4a0c72f6293..219c1963bf08 100644
> --- a/UefiCpuPkg/UefiCpuPkg.uni
> +++ b/UefiCpuPkg/UefiCpuPkg.uni
> @@ -281,3 +281,11 @@
> 
> 
>  #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT
> #language en-US "Specifies whether SEV-ES is enabled"
> 
>  #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP
> #language en-US "Set to TRUE when running as an SEV-ES guest, FALSE
> otherwise."
> 
> +
> 
> +#string
> STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_PROMPT
> #language en-US "Specify the address of the SEV-ES work area"
> 
> +
> 
> +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_HELP
> #language en-US "Specifies the address of the work area used by an SEV-ES
> guest."
> 
> +
> 
> +#string
> STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_PROMPT
> #language en-US "Specify the size of the SEV-ES work area"
> 
> +
> 
> +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_HELP
> #language en-US "Specifies the size of the work area used by an SEV-ES
> guest."
> 
> --
> 2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61181): https://edk2.groups.io/g/devel/message/61181
Mute This Topic: https://groups.io/mt/74692454/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v9 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception

2020-06-11 Thread Dong, Eric
Reviewed-by: Eric Dong 

Thanks,
Eric

> -Original Message-
> From: Tom Lendacky 
> Sent: Friday, June 5, 2020 9:27 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v9 11/46] UefiCpuPkg/CpuExceptionHandler: Add base
> support for the #VC exception
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Add base support to handle #VC exceptions. Update the common exception
> handlers to invoke the VmgExitHandleVc () function of the VmgExitLib
> library when a #VC is encountered. A non-zero return code will propagate
> to the targeted exception handler.
> 
> Under SEV-ES, a DR7 read or write intercept generates a #VC exception.
> To avoid exception recursion, a #VC exception will not try to read and
> push the actual debug registers into the EFI_SYSTEM_CONTEXT_X64 struct
> and instead push zeroes. The #VC exception handler does not make use of
> the debug registers from the saved context and the exception processing
> exit code does not attempt to restore the debug register values.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.in
> f  |  1 +
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
> |  1 +
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib
> .inf   |  1 +
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i
> nf  |  1 +
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHa
> ndlerLib.inf |  1 +
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
> | 10 +-
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
> | 20 +++-
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
> | 19 +++
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nas
> m   | 17 +
> 
> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA
> sm.nasm | 17 +
>  10 files changed, 86 insertions(+), 2 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.
> inf
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib
> .inf
> index 61e2ec30b089..07b34c92a892 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.
> inf
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib
> .inf
> @@ -57,3 +57,4 @@ [LibraryClasses]
>PeCoffGetEntryPointLib
> 
>MemoryAllocationLib
> 
>DebugLib
> 
> +  VmgExitLib
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i
> nf
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i
> nf
> index 093374944df6..feae7b3e06de 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i
> nf
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i
> nf
> @@ -52,6 +52,7 @@ [LibraryClasses]
>HobLib
> 
>MemoryAllocationLib
> 
>SynchronizationLib
> 
> +  VmgExitLib
> 
> 
> 
>  [Pcd]
> 
>gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard# CONSUMES
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler
> Lib.inf
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler
> Lib.inf
> index 6d25cafe2ca3..967cb61ba6d9 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler
> Lib.inf
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler
> Lib.inf
> @@ -48,3 +48,4 @@ [LibraryClasses]
>PrintLib
> 
>LocalApicLib
> 
>PeCoffGetEntryPointLib
> 
> +  VmgExitLib
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLi
> b.inf
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLi
> b.inf
> index 2ffbbccc302f..4cdb11c04ea0 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLi
> b.inf
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLi
> b.inf
> @@ -51,4 +51,5 @@ [LibraryClasses]
>LocalApicLib
> 
>PeCoffGetEntryPointLib
> 
>DebugLib
> 
> +  VmgExitLib
> 
> 
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuException
> HandlerLib.inf
> b/UefiCp

  1   2   3   4   5   >