Re: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support input UPD as NULL.

2022-11-03 Thread Chiu, Chasel


Patch merged: 
https://github.com/tianocore/edk2/commit/b84f32ae5b475ce657ea1c9db29d4e4ec7711948

Thanks,
Chasel


> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chiu,
> Chasel
> Sent: Tuesday, November 1, 2022 10:46 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel ; Desimone, Nathaniel L
> ; Zeng, Star 
> Subject: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support input
> UPD as NULL.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4114
> 
> FSP specification supports input UPD as NULL cases which FSP will use built-
> in UPD region instead.
> FSP should not return INVALID_PARAMETER in such cases.
> 
> In FSP-T entry point case, the valid FSP-T UPD region pointer will be passed
> to platform FSP code to consume.
> In FSP-M and FSP-S cases, valid UPD pointer will be decided when updating
> corresponding pointer field in FspGlobalData.
> 
> Cc: Nate DeSimone 
> Cc: Star Zeng 
> Signed-off-by: Chasel Chiu 
> ---
>  IntelFsp2Pkg/FspSecCore/SecFspApiChk.c | 12 ++--
>  IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm | 73
> +++--
> 
>  IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm  | 40
> ++--
>  3 files changed, 91 insertions(+), 34 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> index a44fbf2a50..5f59938518 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> @@ -44,6 +44,8 @@ FspApiCallingCheck (
>  // if (((UINTN)FspData != MAX_ADDRESS) && ((UINTN)FspData !=
> MAX_UINT32)) {   Status = EFI_UNSUPPORTED;+} else if (ApiParam ==
> NULL) {+  Status = EFI_SUCCESS; } else if (EFI_ERROR
> (FspUpdSignatureCheck (ApiIdx, ApiParam))) {   Status =
> EFI_INVALID_PARAMETER; }@@ -67,9 +69,13 @@ FspApiCallingCheck (
>  } else {   if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE)
> { Status = EFI_UNSUPPORTED;-  } else if (EFI_ERROR
> (FspUpdSignatureCheck (FspSiliconInitApiIndex, ApiParam))) {-Status =
> EFI_INVALID_PARAMETER;   } else if (ApiIdx == FspSiliconInitApiIndex) {+
> if (ApiParam == NULL) {+  Status = EFI_SUCCESS;+} else if
> (EFI_ERROR (FspUpdSignatureCheck (FspSiliconInitApiIndex, ApiParam))) {+
> Status = EFI_INVALID_PARAMETER;+}+ // // Reset 
> MultiPhase
> NumberOfPhases to zero //@@ -89,6 +95,8 @@ FspApiCallingCheck (
>  } else {   if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE)
> { Status = EFI_UNSUPPORTED;+  } else if (ApiParam == NULL) {+
> Status = EFI_SUCCESS;   } else if (EFI_ERROR (FspUpdSignatureCheck
> (FspSmmInitApiIndex, ApiParam))) { Status =
> EFI_INVALID_PARAMETER;   }diff --git
> a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> index 61030a843b..73821ad22a 100644
> --- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> +++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> @@ -21,7 +21,7 @@ extern   ASM_PFX(PcdGet32
> (PcdFspReservedBufferSize))
>  ; Following functions will be provided in PlatformSecLib ; extern
> ASM_PFX(AsmGetFspBaseAddress)-extern
> ASM_PFX(AsmGetFspInfoHeader)+extern
> ASM_PFX(AsmGetFspInfoHeaderNoStack) ;extern
> ASM_PFX(LoadMicrocode); @todo: needs a weak implementation extern
> ASM_PFX(SecPlatformInit)   ; @todo: needs a weak implementation extern
> ASM_PFX(SecCarInit)@@ -160,6 +160,47 @@ endstruc
>   RET_ESI_EXT   mm7 %endmacro +%macro CALL_EDI  1++  mov edi,
> %%ReturnAddress+  jmp %1+%%ReturnAddress:++%endmacro++%macro
> CALL_EBP 1+  mov ebp, %%ReturnAddress+  jmp
> %1+%%ReturnAddress:+%endmacro++%macro RET_EBP 0+  jmp
> ebp   ; restore EIP from EBP+%endmacro++;+; Load UPD
> region pointer in ECX+;+global
> ASM_PFX(LoadUpdPointerToECX)+ASM_PFX(LoadUpdPointerToECX):+  ;+  ;
> esp + 4 is input UPD parameter+  ; If esp + 4 is NULL the default UPD should
> be used+  ; ecx will be the UPD region that should be used+  ;+  mov   
> ecx,
> dword [esp + 4]+  cmp   ecx, 0+  jnz   ParamValid++  ;+  ; Fall back 
> to
> default UPD region+  ;+  CALL_EDI
> ASM_PFX(AsmGetFspInfoHeaderNoStack)+  mov   ecx, DWORD [eax +
> 01Ch]  ; Read FsptImageBaseAddress+  add   ecx, DWORD [eax +
> 024h]  ; Get Cfg Region base address = FsptImageBaseAddress +
> CfgRegionOffset+ParamValid:+  RET_EBP+ ; ; @todo: The strong/weak
> implementation does not work. ;This needs to be reviewed later.@@ -
> 187,10 +228,9 @@ endstruc
>  global ASM_PFX(LoadMicrocodeDefault)
> ASM_PFX(LoadMicrocodeDefault):; Inputs:-   ;   esp ->
> LoadMicrocodeParams pointer+   ;   ecx -> UPD region contains
> LoadMicrocodeParams pointer; Register Usage:-   ;   esp  Preserved-   ;
> All others destroyed+   ;   All are destroyed; Assumptions:;   No
> 

[edk2-devel] [Patch 7/7] MdePkg/Test: Add port of BaseSafeIntLib unit tests to GoogleTest

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

Cc: Liming Gao 
Cc: Zhiguang Liu 
Signed-off-by: Michael D Kinney 
---
 .../GoogleTestBaseSafeIntLib.inf  |   37 +
 .../GoogleTestBaseSafeIntLib.uni  |   13 +
 .../SafeIntLibUintnIntnUnitTests32.cpp|  425 +++
 .../SafeIntLibUintnIntnUnitTests64.cpp|  429 
 .../BaseSafeIntLib/TestBaseSafeIntLib.cpp | 2274 +
 MdePkg/Test/MdePkgHostTest.dsc|1 +
 6 files changed, 3179 insertions(+)
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.inf
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.uni
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests32.cpp
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests64.cpp
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.cpp

diff --git 
a/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.inf 
b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.inf
new file mode 100644
index ..f609bfa57f7b
--- /dev/null
+++ b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.inf
@@ -0,0 +1,37 @@
+## @file
+# Host OS based Application that Unit Tests the SafeIntLib using Google Test
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION = 0x00010005
+  BASE_NAME   = GoogleTestBaseSafeIntLib
+  MODULE_UNI_FILE = GoogleTestBaseSafeIntLib.uni
+  FILE_GUID   = 2D9C1796-B0D2-4DA7-9529-1F8D9CCC11D3
+  MODULE_TYPE = HOST_APPLICATION
+  VERSION_STRING  = 1.0
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64
+#
+
+[Sources]
+  TestBaseSafeIntLib.cpp
+
+[Sources.IA32]
+  SafeIntLibUintnIntnUnitTests32.cpp
+
+[Sources.X64]
+  SafeIntLibUintnIntnUnitTests64.cpp
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+  GoogleTestLib
+  SafeIntLib
diff --git 
a/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.uni 
b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.uni
new file mode 100644
index ..1c11b9e05205
--- /dev/null
+++ b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.uni
@@ -0,0 +1,13 @@
+// /** @file
+// Application that Unit Tests the SafeIntLib using Google Test
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Application that Unit 
Tests the SafeIntLib using Google Test"
+
+#string STR_MODULE_DESCRIPTION  #language en-US "Application that Unit 
Tests the SafeIntLib using Google Test."
+
diff --git 
a/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests32.cpp
 
b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests32.cpp
new file mode 100644
index ..6fbf302c1c5e
--- /dev/null
+++ 
b/MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests32.cpp
@@ -0,0 +1,425 @@
+/** @file
+  IA32-specific functions for unit-testing INTN and UINTN functions in
+  SafeIntLib.
+
+  Copyright (c) Microsoft Corporation.
+  Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+extern "C" {
+  #include 
+  #include 
+}
+
+TEST(ConversionTestSuite, TestSafeInt32ToUintn) {
+  RETURN_STATUS  Status;
+  INT32   Operand;
+  UINTN   Result;
+
+  //
+  // If Operand is non-negative, then it's a cast
+  //
+  Operand = 0x5bababab;
+  Result  = 0;
+  Status  = SafeInt32ToUintn (Operand, );
+  ASSERT_EQ (Status, RETURN_SUCCESS);
+  ASSERT_EQ ((UINTN)0x5bababab, Result);
+
+  //
+  // Otherwise should result in an error status
+  //
+  Operand = (-1537977259);
+  Status  = SafeInt32ToUintn (Operand, );
+  ASSERT_EQ (RETURN_BUFFER_TOO_SMALL, Status);
+}
+
+TEST(ConversionTestSuite, TestSafeUint32ToIntn) {
+  RETURN_STATUS  Status;
+  UINT32  Operand;
+  INTNResult;
+
+  //
+  // If Operand is <= MAX_INTN, then it's a cast
+  //
+  Operand = 0x5bababab;
+  Result  = 0;
+  Status  = SafeUint32ToIntn (Operand, );
+  ASSERT_EQ (Status, RETURN_SUCCESS);
+  ASSERT_EQ (0x5bababab, Result);
+
+  //
+  // Otherwise should result in an error status
+  //
+  Operand = (0xabababab);
+  Status  = SafeUint32ToIntn (Operand, );
+  ASSERT_EQ (RETURN_BUFFER_TOO_SMALL, Status);
+}
+
+TEST(ConversionTestSuite, TestSafeIntnToInt32) {
+  RETURN_STATUS  Status;
+  INTNOperand;
+  INT32   Result;
+
+  //
+  // INTN is same as INT32 in IA32, so this is just a cast
+  //
+  Operand = 

[edk2-devel] [Patch 5/7] .pytool: Add googletest submodule to CISettings.py

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Liming Gao 
Signed-off-by: Michael D Kinney 
---
 .pytool/CISettings.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py
index cc2214071c96..76ac2b09dba6 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -192,6 +192,8 @@ class Settings(CiBuildSettingsManager, 
UpdateSettingsManager, SetupSettingsManag
 "CryptoPkg/Library/OpensslLib/openssl", False))
 rs.append(RequiredSubmodule(
 "UnitTestFrameworkPkg/Library/CmockaLib/cmocka", False))
+rs.append(RequiredSubmodule(
+"UnitTestFrameworkPkg/Library/GoogleTestLib/googletest", False))
 rs.append(RequiredSubmodule(
 "MdeModulePkg/Universal/RegularExpressionDxe/oniguruma", False))
 rs.append(RequiredSubmodule(
-- 
2.37.1.windows.1



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




[edk2-devel] [Patch 3/7] UnitTestFrameworkPkg: Add googletest submodule and GoogleTestLib

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

Add submodule for googletest and add GoogleTestLib that is
required for GoogleTest based unit tests. Add GoogleTest
documentation to Readme.md along with a port of the sample
unit test to the GoogleTest style.

Cc: Michael Kubacki 
Cc: Sean Brogan 
Cc: Bret Barkelew 
Signed-off-by: Michael D Kinney 
---
 .gitmodules   |   3 +
 .../Include/Library/GoogleTestLib.h   |  14 +
 .../Library/GoogleTestLib/GoogleTestLib.inf   |  36 +++
 .../Library/GoogleTestLib/GoogleTestLib.uni   |  14 +
 .../Library/GoogleTestLib/googletest  |   1 +
 UnitTestFrameworkPkg/ReadMe.md| 235 ++--
 .../SampleGoogleTest/SampleGoogleTest.cpp | 263 ++
 .../SampleGoogleTest/SampleGoogleTestHost.inf |  35 +++
 .../Test/UnitTestFrameworkPkgHostTest.dsc |   4 +-
 .../UnitTestFrameworkPkg.ci.yaml  |   4 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec |   8 +
 .../UnitTestFrameworkPkgHost.dsc.inc  |   4 +-
 12 files changed, 590 insertions(+), 31 deletions(-)
 create mode 100644 UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
 create mode 100644 UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
 create mode 100644 UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni
 create mode 16 UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
 create mode 100644 
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp
 create mode 100644 
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf

diff --git a/.gitmodules b/.gitmodules
index b845c9ee3ff0..8011a88d9d25 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -20,3 +20,6 @@
 [submodule "RedfishPkg/Library/JsonLib/jansson"]
path = RedfishPkg/Library/JsonLib/jansson
url = https://github.com/akheron/jansson
+[submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
+   path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
+   url = https://github.com/google/googletest.git
diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h 
b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
new file mode 100644
index ..ebec766d4cf7
--- /dev/null
+++ b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
@@ -0,0 +1,14 @@
+/** @file
+  GoogleTestLib class with APIs from the googletest project
+
+  Copyright (c) 2022, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef GOOGLE_TEST_LIB_H_
+#define GOOGLE_TEST_LIB_H_
+
+#include 
+
+#endif
diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf 
b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
new file mode 100644
index ..68db75d7023f
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
@@ -0,0 +1,36 @@
+## @file
+#  This module provides GoogleTest Library implementation.
+#
+#  Copyright (c) 2022, Intel Corporation. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION = 0x00010005
+  BASE_NAME   = GoogleTestLib
+  MODULE_UNI_FILE = GoogleTestLib.uni
+  FILE_GUID   = A90E4751-AD30-43CC-980B-01E356B49ADF
+  MODULE_TYPE = BASE
+  VERSION_STRING  = 0.1
+  LIBRARY_CLASS   = GoogleTestLib|HOST_APPLICATION
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+  googletest/googletest/src/gtest-all.cc
+
+[Packages]
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS == /c /EHsc /Zi
+  MSFT:NOOPT_*_*_CC_FLAGS =  /Od
+
+  GCC:*_*_*_CC_FLAGS == -g -c
+
+  GCC:NOOPT_*_*_CC_FLAGS =  -O0
+  GCC:*_*_IA32_CC_FLAGS  =  -m32
+  GCC:*_*_X64_CC_FLAGS   =  -m64
diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni 
b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni
new file mode 100644
index ..14c862a23744
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni
@@ -0,0 +1,14 @@
+// /** @file
+// This module provides GoogleTest Library implementation.
+//
+// This module provides GoogleTest Library implementation.
+//
+// Copyright (c) 2022, Intel Corporation. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "GoogleTest Library 
implementation"
+
+#string STR_MODULE_DESCRIPTION  #language en-US "This module provides 
GoogleTest Library implementation."
diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/googletest 
b/UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
new file mode 16
index ..86add13493e5
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
@@ -0,0 +1 @@
+Subproject commit 86add13493e5c881d7e4ba77fb91c1f57752b3a4
diff --git a/UnitTestFrameworkPkg/ReadMe.md 

[edk2-devel] [Patch 6/7] BaseTools/Plugin/HostBaseUnitTestRunner: Enable gtest xml output

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

Set environment variable GTEST_OUTPUT to specify the output
format of XML and the output file name.  Both CMOCKA_XML_FILE
and GTEST_OUTPUT are set for each host based unit test to
support both cmocka unit tests and gtest unit tests.

Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yuwei Chen 
Signed-off-by: Michael D Kinney 
---
 .../HostBasedUnitTestRunner/HostBasedUnitTestRunner.py | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git 
a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py 
b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py
index c1eeaf26251e..a8220aacd396 100644
--- a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py
+++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py
@@ -85,9 +85,12 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin):
 raise NotImplementedError("Unsupported Operating System")
 
 for test in testList:
-# Configure output name.
+# Configure output name if test uses cmocka.
 shell_env.set_shell_var(
-'CMOCKA_XML_FILE', test + ".%g." + arch + ".result.xml")
+'CMOCKA_XML_FILE', test + ".CMOCKA.%g." + arch + 
".result.xml")
+# Configure output name if test uses gtest.
+shell_env.set_shell_var(
+'GTEST_OUTPUT', "xml:" + test + ".GTEST." + arch + 
".result.xml")
 
 # Run the test.
 ret = RunCmd('"' + test + '"', "", workingdir=cp)
-- 
2.37.1.windows.1



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




[edk2-devel] [Patch 4/7] UnitTestFrameworkPkg/Library/CmockaLib: Enable symbol files.

2022-11-03 Thread Michael D Kinney
Cc: Michael Kubacki 
Cc: Sean Brogan 
Cc: Bret Barkelew 
Signed-off-by: Michael D Kinney 
---
 UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf 
b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
index 07da7a88e952..052c7f557210 100644
--- a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
+++ b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
@@ -26,7 +26,7 @@ [Packages]
   UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
 
 [BuildOptions]
-  MSFT:*_*_*_CC_FLAGS == /c -DHAVE_VSNPRINTF -DHAVE_SNPRINTF
+  MSFT:*_*_*_CC_FLAGS == /c -DHAVE_VSNPRINTF -DHAVE_SNPRINTF /Zi
   MSFT:NOOPT_*_*_CC_FLAGS =  /Od
 
   GCC:*_*_*_CC_FLAGS == -g -DHAVE_SIGNAL_H
-- 
2.37.1.windows.1



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




[edk2-devel] [Patch 0/7] Add GoogleTest to UnitTestFrameworkPkg

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

PR: https://github.com/tianocore/edk2/pull/3566
Branch: https://github.com/mdkinney/edk2/tree/Bug_4134_AddGoogleTest

Add GoogleTest support to UnitTestFrameworkPkg to provide an
additional host-based unit test framework to developers.

Code: https://github.com/google/googletest
Docs: https://google.github.io/googletest

GoogleTest is implemented in C++, but does support implementing
unit tests for C code.  This patch series makes a few updates for C++
compatibility and build issues related to multiple definitions of _ASSERT().
The GoogleTest git submodule is added to the UnitTestFrameworkPkg
and .pytools/CISettings.py file along with an update to the host-based
test runner plugin to set the GTEST_OUTPUT environment variable to 
specify the XML output file format and location.

A port of the unit tests for the the MdePkg BaseSafeIntLib are included
to provide an example that is in both the current unit test style and the
GoogleTest style.

Cc: Liming Gao 
Cc: Zhiguang Liu 
Cc: Bob Feng 
Cc: Liming Gao 
Cc: Yuwei Chen 
Cc: Sean Brogan 
Cc: Bret Barkelew 
Signed-off-by: Michael D Kinney 

Michael D Kinney (7):
  MdePkg/Include: Update Base.h to improve C++ compatibility
  MdePkg/Include/Library: Undefine _ASSERT() if already defined
  UnitTestFrameworkPkg: Add googletest submodule and GoogleTestLib
  UnitTestFrameworkPkg/Library/CmockaLib: Enable symbol files.
  .pytool: Add googletest submodule to CISettings.py
  BaseTools/Plugin/HostBaseUnitTestRunner: Enable gtest xml output
  MdePkg/Test: Add port of BaseSafeIntLib unit tests to GoogleTest

 .gitmodules   |3 +
 .pytool/CISettings.py |2 +
 .../HostBasedUnitTestRunner.py|7 +-
 MdePkg/Include/Base.h |   12 +-
 MdePkg/Include/Library/DebugLib.h |3 +
 .../GoogleTestBaseSafeIntLib.inf  |   37 +
 .../GoogleTestBaseSafeIntLib.uni  |   13 +
 .../SafeIntLibUintnIntnUnitTests32.cpp|  425 +++
 .../SafeIntLibUintnIntnUnitTests64.cpp|  429 
 .../BaseSafeIntLib/TestBaseSafeIntLib.cpp | 2274 +
 MdePkg/Test/MdePkgHostTest.dsc|1 +
 .../Include/Library/GoogleTestLib.h   |   14 +
 .../Library/CmockaLib/CmockaLib.inf   |2 +-
 .../Library/GoogleTestLib/GoogleTestLib.inf   |   36 +
 .../Library/GoogleTestLib/GoogleTestLib.uni   |   14 +
 .../Library/GoogleTestLib/googletest  |1 +
 UnitTestFrameworkPkg/ReadMe.md|  235 +-
 .../SampleGoogleTest/SampleGoogleTest.cpp |  263 ++
 .../SampleGoogleTest/SampleGoogleTestHost.inf |   35 +
 .../Test/UnitTestFrameworkPkgHostTest.dsc |4 +-
 .../UnitTestFrameworkPkg.ci.yaml  |4 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec |8 +
 .../UnitTestFrameworkPkgHost.dsc.inc  |4 +-
 23 files changed, 3790 insertions(+), 36 deletions(-)
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.inf
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/GoogleTestBaseSafeIntLib.uni
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests32.cpp
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests64.cpp
 create mode 100644 
MdePkg/Test/GoogleTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.cpp
 create mode 100644 UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
 create mode 100644 UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
 create mode 100644 UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.uni
 create mode 16 UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
 create mode 100644 
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp
 create mode 100644 
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTestHost.inf

-- 
2.37.1.windows.1



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




[edk2-devel] [Patch 1/7] MdePkg/Include: Update Base.h to improve C++ compatibility

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

* Map NULL to nullptr or __null when c++ compiler is used.
* Map STATIC_ASSERT to static_assert when a c++ compiler is used.
* Typecast RETURN_SUCCESS to type RETURN_STATUS to match type used
  by all return error/warning status codes.  C++ has stricter type
  checking and found this inconsistency.

Cc: Liming Gao 
Cc: Zhiguang Liu 
Signed-off-by: Michael D Kinney 
---
 MdePkg/Include/Base.h | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index d19ddfe4bba7..d209e6de280a 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -309,7 +309,15 @@ struct _LIST_ENTRY {
 ///
 /// NULL pointer (VOID *)
 ///
+#if defined (__cplusplus)
+  #if defined (_MSC_EXTENSIONS)
+#define NULL  nullptr
+  #else
+#define NULL  __null
+  #endif
+#else
 #define NULL  ((VOID *) 0)
+#endif
 
 //
 // Null character
@@ -760,7 +768,7 @@ typedef UINTN *BASE_LIST;
 **/
 #ifdef MDE_CPU_EBC
 #define STATIC_ASSERT(Expression, Message)
-#elif defined (_MSC_EXTENSIONS)
+#elif defined (_MSC_EXTENSIONS) || defined (__cplusplus)
 #define STATIC_ASSERT  static_assert
 #else
 #define STATIC_ASSERT  _Static_assert
@@ -959,7 +967,7 @@ typedef UINTN RETURN_STATUS;
 ///
 /// The operation completed successfully.
 ///
-#define RETURN_SUCCESS  0
+#define RETURN_SUCCESS  (RETURN_STATUS)(0)
 
 ///
 /// The image failed to load.
-- 
2.37.1.windows.1



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




[edk2-devel] [Patch 2/7] MdePkg/Include/Library: Undefine _ASSERT() if already defined

2022-11-03 Thread Michael D Kinney
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134

When unit testing is enabled, make sure _ASSERT() is not already
defined by the host environment before defining _ASSERT().  This
avoids conflicts with VS20xx builds of GoogleTest based unit tests.

Cc: Liming Gao 
Cc: Zhiguang Liu 
Signed-off-by: Michael D Kinney 
---
 MdePkg/Include/Library/DebugLib.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MdePkg/Include/Library/DebugLib.h 
b/MdePkg/Include/Library/DebugLib.h
index 8d3d08638d73..9110be2f41b3 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -337,6 +337,9 @@ UnitTestDebugAssert (
   IN CONST CHAR8  *Description
   );
 
+  #if defined (_ASSERT)
+#undef _ASSERT
+  #endif
   #if defined (__clang__) && defined (__FILE_NAME__)
 #define _ASSERT(Expression)  UnitTestDebugAssert (__FILE_NAME__, 
DEBUG_LINE_NUMBER, DEBUG_EXPRESSION_STRING (Expression))
   #else
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95941): https://edk2.groups.io/g/devel/message/95941
Mute This Topic: https://groups.io/mt/94799426/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/9] Rename VmgExitLib to CcExitLib

2022-11-03 Thread Yao, Jiewen
For the series, reviewed-by: Jiewen Yao 

> -Original Message-
> From: Xu, Min M 
> Sent: Friday, November 4, 2022 7:20 AM
> To: devel@edk2.groups.io
> Cc: Xu, Min M ; Dong, Eric ;
> Ni, Ray ; Brijesh Singh ; Aktas,
> Erdem ; Gerd Hoffmann ;
> James Bottomley ; Yao, Jiewen
> ; Tom Lendacky ;
> Dong, Guo ; Rhodes, Sean ;
> Lu, James ; Guo, Gua ; Kinney,
> Michael D ; Gao, Liming
> 
> Subject: [PATCH V2 0/9] Rename VmgExitLib to CcExitLib
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123
> 
> VmgExitLib once was designed to provide interfaces to support #VC handler
> and issue VMGEXIT instruction. After TDVF (enable TDX feature in OVMF) is
> introduced, this library is updated to support #VE as well. Now the name
> of VmgExitLib cannot reflect what the lib does.
> 
> This patch-set creates CcExitLib which is a simple copy of VmgExitLib
> except some of the API names are renamed with a CcExitLib prefix. For
> example VmgExit is renamed as CcExitLibVmgExit.
> 
> To make sure the build will not be broken by the renaming, this patch-set
> first creates CcExitLib (Patch #1/2). Then VmgExitLib is replaced by
> CcExitLib in UefiCpuPkg/UefiPayloadPkg/OvmfPkg (Patch #3/4/5/6). After
> that VmgExitLib is deleted (Patch #7/8). At last Maintainers.txt
> is updated (Patch #9).
> 
> Code: https://github.com/mxu9/edk2/tree/CcExitLib.v2
> 
> v2 changes:
>  - Patch #3 is added to import CcExitLib in OvmfPkg's *.dsc. This is to
>prevent the building from being broken in the following patches.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Brijesh Singh 
> Cc: Erdem Aktas 
> Cc: Gerd Hoffmann 
> Cc: James Bottomley 
> Cc: Jiewen Yao 
> Cc: Tom Lendacky 
> Cc: Guo Dong 
> Cc: Sean Rhodes 
> Cc: James Lu 
> Cc: Gua Guo 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Signed-off-by: Min Xu 
> 
> Min M Xu (9):
>   UefiCpuPkg: Add CcExitLib
>   OvmfPkg: Implement CcExitLib
>   OvmfPkg: Add CcExitLib in *.dsc
>   UefiCpuPkg: Use CcExitLib instead of VmgExitLib
>   UefiPayloadPkg: Use CcExitLib instead of VmgExitLib
>   OvmfPkg: Use CcExitLib instead of VmgExitLib
>   OvmfPkg: Delete VmgExitLib
>   UefiCpuPkg: Delete VmgExitLib
>   Maintainers: Update the VmgExitLib to CcExitLib
> 
>  Maintainers.txt   |   2 +-
>  OvmfPkg/AmdSev/AmdSevX64.dsc  |   4 +-
>  OvmfPkg/Bhyve/BhyveX64.dsc|   2 +-
>  OvmfPkg/CloudHv/CloudHvX64.dsc|   6 +-
>  OvmfPkg/IntelTdx/IntelTdxX64.dsc  |   4 +-
>  .../DxeMemEncryptSevLib.inf   |   2 +-
>  .../PeiMemEncryptSevLib.inf   |   2 +-
>  .../SecMemEncryptSevLib.inf   |   2 +-
>  .../X64/SnpPageStateChangeInternal.c  |  10 +-
>  .../VmgExitLib.c => CcExitLib/CcExitLib.c}|  23 +--
>  .../CcExitLib.inf}|  19 +--
>  .../CcExitTd.h}   |   6 +-
>  .../CcExitVcHandler.c}| 133 +-
>  .../CcExitVcHandler.h}|  10 +-
>  .../CcExitVeHandler.c}|   8 +-
>  .../PeiDxeCcExitVcHandler.c}  |  12 +-
>  .../SecCcExitLib.inf} |  16 +--
>  .../SecCcExitVcHandler.c} |  12 +-
>  .../X64/TdVmcallCpuid.nasm|   4 +-
>  OvmfPkg/Microvm/MicrovmX64.dsc|   4 +-
>  OvmfPkg/OvmfPkgIa32.dsc   |   4 +-
>  OvmfPkg/OvmfPkgIa32X64.dsc|   4 +-
>  OvmfPkg/OvmfPkgX64.dsc|   6 +-
>  OvmfPkg/OvmfXen.dsc   |   2 +-
>  OvmfPkg/PlatformPei/AmdSev.c  |  10 +-
>  OvmfPkg/PlatformPei/PlatformPei.inf   |   2 +-
>  .../FvbServicesRuntimeDxe.inf |   2 +-
>  .../QemuFlashDxe.c|  10 +-
>  .../Library/{VmgExitLib.h => CcExitLib.h} |  29 ++--
>  .../CcExitLibNull.c}  |  47 +--
>  .../CcExitLibNull.inf}|  14 +-
>  .../Library/CcExitLibNull/CcExitLibNull.uni   |  14 ++
>  .../DxeCpuExceptionHandlerLib.inf |   2 +-
>  .../PeiCpuExceptionHandlerLib.inf |   2 +-
>  .../PeiDxeSmmCpuException.c   |   6 +-
>  .../SecPeiCpuException.c  |   6 +-
>  .../SecPeiCpuExceptionHandlerLib.inf  |   2 +-
>  .../SmmCpuExceptionHandlerLib.inf |   2 +-
>  .../Xcode5SecPeiCpuExceptionHandlerLib.inf|   2 +-
>  UefiCpuPkg/Library/MpInitLib/AmdSev.c |  10 +-
>  UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   2 +-
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |   8 +-
>  UefiCpuPkg/Library/MpInitLib/MpLib.c  |   2 +-
>  UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   2 +-
>  UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c |  10 +-
>  .../Library/VmgExitLibNull/VmTdExitNull.c |  38 -
>  .../Library/VmgExitLibNull/VmgExitLibNull.uni |  15 --
>  UefiCpuPkg/UefiCpuPkg.dec   

Re: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support input UPD as NULL.

2022-11-03 Thread Kuo, Ted
Reviewed-by: Ted Kuo 

-Original Message-
From: Chiu, Chasel  
Sent: Friday, November 4, 2022 1:02 AM
To: Kuo, Ted ; devel@edk2.groups.io
Cc: Desimone, Nathaniel L ; Zeng, Star 

Subject: RE: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support input UPD 
as NULL.


Hi Ted,

Please see my reply below inline.

Thanks,
Chasel


> -Original Message-
> From: Kuo, Ted 
> Sent: Wednesday, November 2, 2022 7:32 PM
> To: devel@edk2.groups.io; Chiu, Chasel 
> Cc: Desimone, Nathaniel L ; Zeng, Star 
> 
> Subject: RE: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support 
> input UPD as NULL.
> 
> Hi Chasel,
> 
> I have few comments. Please find [Ted] inline.
> 
> Thanks,
> Ted
> 
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chiu, 
> Chasel
> Sent: Wednesday, November 2, 2022 1:46 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel ; Desimone, Nathaniel L 
> ; Zeng, Star 
> Subject: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support 
> input UPD as NULL.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4114
> 
> FSP specification supports input UPD as NULL cases which FSP will use 
> built- in UPD region instead.
> FSP should not return INVALID_PARAMETER in such cases.
> 
> In FSP-T entry point case, the valid FSP-T UPD region pointer will be 
> passed to platform FSP code to consume.
> In FSP-M and FSP-S cases, valid UPD pointer will be decided when 
> updating corresponding pointer field in FspGlobalData.
> 
> Cc: Nate DeSimone 
> Cc: Star Zeng 
> Signed-off-by: Chasel Chiu 
> ---
>  IntelFsp2Pkg/FspSecCore/SecFspApiChk.c | 12 ++--
>  IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm | 73
> +++--
> 
>  IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm  | 40
> ++--
>  3 files changed, 91 insertions(+), 34 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> index a44fbf2a50..5f59938518 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> @@ -44,6 +44,8 @@ FspApiCallingCheck (
>  //
>  if (((UINTN)FspData != MAX_ADDRESS) && ((UINTN)FspData !=
> MAX_UINT32)) {
>Status = EFI_UNSUPPORTED;
> +} else if (ApiParam == NULL) {
> +  Status = EFI_SUCCESS;
>  } else if (EFI_ERROR (FspUpdSignatureCheck (ApiIdx, ApiParam))) {
>Status = EFI_INVALID_PARAMETER;
>  }
> @@ -67,9 +69,13 @@ FspApiCallingCheck (
>  } else {
>if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
>  Status = EFI_UNSUPPORTED;
> -  } else if (EFI_ERROR (FspUpdSignatureCheck (FspSiliconInitApiIndex,
> ApiParam))) {
> -Status = EFI_INVALID_PARAMETER;
>} else if (ApiIdx == FspSiliconInitApiIndex) {
> +if (ApiParam == NULL) {
> +  Status = EFI_SUCCESS;
> +} else if (EFI_ERROR (FspUpdSignatureCheck 
> + (FspSiliconInitApiIndex,
> ApiParam))) {
> +  Status = EFI_INVALID_PARAMETER;
> +}
> +
>  //
>  // Reset MultiPhase NumberOfPhases to zero
>  //
> @@ -89,6 +95,8 @@ FspApiCallingCheck (
>  } else {
>if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
>  Status = EFI_UNSUPPORTED;
> +  } else if (ApiParam == NULL) {
> +Status = EFI_SUCCESS;
>} else if (EFI_ERROR (FspUpdSignatureCheck (FspSmmInitApiIndex,
> ApiParam))) {
>  Status = EFI_INVALID_PARAMETER;
>}
> diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> index 61030a843b..73821ad22a 100644
> --- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> +++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> @@ -21,7 +21,7 @@ extern   ASM_PFX(PcdGet32
> (PcdFspReservedBufferSize))
>  ; Following functions will be provided in PlatformSecLib  ;  extern
> ASM_PFX(AsmGetFspBaseAddress) -extern
> ASM_PFX(AsmGetFspInfoHeader)
> +extern ASM_PFX(AsmGetFspInfoHeaderNoStack)
>  ;extern ASM_PFX(LoadMicrocode); @todo: needs a weak
> implementation
>  extern ASM_PFX(SecPlatformInit)   ; @todo: needs a weak implementation
>  extern ASM_PFX(SecCarInit)
> @@ -160,6 +160,47 @@ endstruc
>   RET_ESI_EXT   mm7
>  %endmacro
> 
> +%macro CALL_EDI  1
> +
> +  mov edi,  %%ReturnAddress
> +  jmp %1
> +%%ReturnAddress:
> +
> +%endmacro
> +
> +%macro CALL_EBP 1
> +  mov ebp, %%ReturnAddress
> +  jmp %1
> +%%ReturnAddress:
> +%endmacro
> +
> +%macro RET_EBP 0
> +  jmp ebp   ; restore EIP from EBP
> +%endmacro
> +
> +;
> +; Load UPD region pointer in ECX
> +;
> +global ASM_PFX(LoadUpdPointerToECX)
> +ASM_PFX(LoadUpdPointerToECX):
> +  ;
> +  ; esp + 4 is input UPD parameter
> +  ; If esp + 4 is NULL the default UPD should be used
> +  ; ecx will be the UPD region that should be used
> +  ;
> +  mov   ecx, dword [esp + 4]
> +  cmp   ecx, 0
> +  

[edk2-devel] 回复: [PATCH v3 1/1] MdePkg/BaseLib: Fix out-of-bounds reads in SafeString

2022-11-03 Thread gaoliming via groups.io
Reviewed-by: Liming Gao 

> -邮件原件-
> 发件人: Pedro Falcato 
> 发送时间: 2022年11月3日 9:12
> 收件人: devel@edk2.groups.io
> 抄送: Pedro Falcato ; Vitaly Cheptsov
> ; Marvin Häuser ;
> Michael D Kinney ; Liming Gao
> ; Zhiguang Liu ; Jiewen
> Yao 
> 主题: [PATCH v3 1/1] MdePkg/BaseLib: Fix out-of-bounds reads in SafeString
> 
> There was a OOB access in *StrHexTo* functions, when passed strings like
> "XDEADBEEF".
> 
> OpenCore folks established an ASAN-equipped project to fuzz Ext4Dxe,
> which was able to catch these (mostly harmless) issues.
> 
> Cc: Vitaly Cheptsov 
> Cc: Marvin Häuser 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Zhiguang Liu 
> Signed-off-by: Pedro Falcato 
> Acked-by: Michael D Kinney 
> Reviewed-by: Jiewen Yao 
> ---
>  MdePkg/Library/BaseLib/SafeString.c | 25 +
>  1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/MdePkg/Library/BaseLib/SafeString.c
> b/MdePkg/Library/BaseLib/SafeString.c
> index f338a32a3a41..b75b33381732 100644
> --- a/MdePkg/Library/BaseLib/SafeString.c
> +++ b/MdePkg/Library/BaseLib/SafeString.c
> @@ -863,6 +863,9 @@ StrHexToUintnS (
>OUT   UINTN   *Data
>)
>  {
> +  BOOLEAN  FoundLeadingZero;
> +
> +  FoundLeadingZero = FALSE;
>ASSERT (((UINTN)String & BIT0) == 0);
> 
>//
> @@ -892,12 +895,14 @@ StrHexToUintnS (
>//
>// Ignore leading Zeros after the spaces
>//
> +
> +  FoundLeadingZero = *String == L'0';
>while (*String == L'0') {
>  String++;
>}
> 
>if (CharToUpper (*String) == L'X') {
> -if (*(String - 1) != L'0') {
> +if (!FoundLeadingZero) {
>*Data = 0;
>return RETURN_SUCCESS;
>  }
> @@ -992,6 +997,9 @@ StrHexToUint64S (
>OUT   UINT64  *Data
>)
>  {
> +  BOOLEAN  FoundLeadingZero;
> +
> +  FoundLeadingZero = FALSE;
>ASSERT (((UINTN)String & BIT0) == 0);
> 
>//
> @@ -1021,12 +1029,13 @@ StrHexToUint64S (
>//
>// Ignore leading Zeros after the spaces
>//
> +  FoundLeadingZero = *String == L'0';
>while (*String == L'0') {
>  String++;
>}
> 
>if (CharToUpper (*String) == L'X') {
> -if (*(String - 1) != L'0') {
> +if (!FoundLeadingZero) {
>*Data = 0;
>return RETURN_SUCCESS;
>  }
> @@ -2393,6 +2402,9 @@ AsciiStrHexToUintnS (
>OUT   UINTN  *Data
>)
>  {
> +  BOOLEAN  FoundLeadingZero;
> +
> +  FoundLeadingZero = FALSE;
>//
>// 1. Neither String nor Data shall be a null pointer.
>//
> @@ -2420,12 +2432,13 @@ AsciiStrHexToUintnS (
>//
>// Ignore leading Zeros after the spaces
>//
> +  FoundLeadingZero = *String == '0';
>while (*String == '0') {
>  String++;
>}
> 
>if (AsciiCharToUpper (*String) == 'X') {
> -if (*(String - 1) != '0') {
> +if (!FoundLeadingZero) {
>*Data = 0;
>return RETURN_SUCCESS;
>  }
> @@ -2517,6 +2530,9 @@ AsciiStrHexToUint64S (
>OUT   UINT64  *Data
>)
>  {
> +  BOOLEAN  FoundLeadingZero;
> +
> +  FoundLeadingZero = FALSE;
>//
>// 1. Neither String nor Data shall be a null pointer.
>//
> @@ -2544,12 +2560,13 @@ AsciiStrHexToUint64S (
>//
>// Ignore leading Zeros after the spaces
>//
> +  FoundLeadingZero = *String == '0';
>while (*String == '0') {
>  String++;
>}
> 
>if (AsciiCharToUpper (*String) == 'X') {
> -if (*(String - 1) != '0') {
> +if (!FoundLeadingZero) {
>*Data = 0;
>return RETURN_SUCCESS;
>  }
> --
> 2.38.1





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




[edk2-devel] 回复: [PATCH v9 00/19] Add Raw algorithm support using Arm TRNG interface

2022-11-03 Thread gaoliming via groups.io
Sami, Leif, Ard:
  Can you give your Reviewed-by for this patch set this week? If so, this
feature can catch stable tag 202211.
  
  Stable202211 tag soft feature freeze will start on next Monday Nov 7th. 

Thanks
Liming
> -邮件原件-
> 发件人: Yao, Jiewen 
> 发送时间: 2022年11月1日 16:56
> 收件人: pierre.gond...@arm.com; devel@edk2.groups.io
> 抄送: Sami Mujawar ; Leif Lindholm
> ; Ard Biesheuvel ;
> Rebecca Cran ; Kinney, Michael D
> ; Gao, Liming ;
> Wang, Jian J 
> 主题: RE: [PATCH v9 00/19] Add Raw algorithm support using Arm TRNG
> interface
> 
> Thanks for the update.
> 
> For SecurityPkg (11~18), Acked-by: Jiewen Yao 
> Since the update is for AARCH64, I recommend to have an ARM people to give
> Reviewed-by.
> 
> Thank you
> Yao Jiewen
> 
> 
> > -Original Message-
> > From: pierre.gond...@arm.com 
> > Sent: Friday, October 28, 2022 11:33 PM
> > To: devel@edk2.groups.io
> > Cc: Sami Mujawar ; Leif Lindholm
> > ; Ard Biesheuvel
> > ; Rebecca Cran ;
> Kinney,
> > Michael D ; Gao, Liming
> > ; Yao, Jiewen ; Wang,
> > Jian J 
> > Subject: [PATCH v9 00/19] Add Raw algorithm support using Arm TRNG
> > interface
> >
> > From: Pierre Gondois 
> >
> > Bugzilla: Bug 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)
> >
> > The Arm True Random Number Generator Firmware, Interface 1.0,
> > specification
> > defines an interface between an Operating System (OS) executing at EL1
> and
> > Firmware (FW) exposing a conditioned entropy source that is provided by
a
> > TRNG back end.
> > This patch-set:
> > - defines an Arm TRNG library class that provides an interface to access
> >   the entropy source on a platform.
> > - implements an Arm TRNG library instance that uses the Arm FW-TRNG
> >   interface.
> > - Adds RawAlgorithm support to RngDxe for Arm architecture using the Arm
> >   TRNG interface.
> > - Enables RNG support using Arm TRNG interface for Kvmtool Guest/Virtual
> >   firmware.
> >
> > This patch-set is based on the v2 from Sami Mujawar:
> > [PATCH v2 0/8] Add Raw algorithm support using Arm FW-TRNG interface
> > v2:
> > https://edk2.groups.io/g/devel/message/83775
> > v3:
> > https://edk2.groups.io/g/devel/message/90845
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v3
> > v4:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v4
> > v5:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v5
> > v6:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v6
> > v7:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v7
> > v8:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v8
> > v9:
> > https://github.com/PierreARM/edk2/tree/Arm_Trng_v9
> >
> > v9:
> >  - Added BaseArmTrngLibNull as default in MdePkg/MdeLibs.dsc.inc.
> [Liming]
> >  - Renamed TrngLib to ArmTrngLib and updated documentation, commit
> >messages, function names accordingly. [Jiewen, Leif]
> > v8:
> >  - Added Reviewed-by/Acked-by from Leif on ArmPkg/SecurityPkg
> >patches. [Leif]
> >  - Renamed FID_TRNG_* macros to ARM_SMC_ID_TRNG_*. [Leif]
> > v7:
> >  - Removed Reviewed-by from Leif.
> >  - Remove Sami's Signed-off.
> > V6:
> >  - Added my signed-off on patches authored by Sami. [Leif]
> >  - New patch to make it easier to add new libraries in alphabetical
> >order: ArmPkg: Sort HVC/SMC section alphbetically in ArmPkg.dsc
[Leif]
> >  - Renmaed ArmHvcNullLib to ArmHvcLibNull. [Leif]
> >  - Added RISCV64 to the list of VALID_ARCHITECTURES for
> BaseTrngLibNull.
> > [Leif]
> >  - Removed unnecessary space in function parameter documentation
> >('[in, out]'). [Rebecca]
> >  - Updated INF_VERSION to latest spec (1.29) for new libraries.
[Rebecca]
> >  - Dropped the following patches [Leif]:
> >   - ArmPkg/ArmLib: Add ArmHasRngExt()
> >   - ArmPkg/ArmLib: Add ArmReadIdIsar0() helper
> >   - MdePkg/BaseRngLib: Rename ArmReadIdIsar0() to ArmGetFeatRng()
> > V5:
> >  - Removed references in Trnglib.h to 'Special Publication'
> >800-90A and 800-90C, and only reference 'Arm True Random
> >Number Generator Firmware, Interface 1.0' in the Arm
> >implementation of the TrngLib. [Jiewen]
> > V4:
> >  - Removed dependencies on ArmPkg and dropped patch:
> > [PATCH v3 12/22] SecurityPkg: Update Securitypkg.ci.yaml
> >[Jiewen]
> >  - Use a dynamically allocated array to hold available algorithms.
> >The array is freed in a new UNLOAD_IMAGE function and
> >allocated in arch specific implementations of
> >GetAvailableAlgorithms(), available in AArch64/AArch64Algo.c
> >and Arm/ArmAlgo.c.
> >  - Correctly reference gEfiRngAlgorithmSp80090Ctr256Guid
> >Guid by copying its address (add missing '&'). [Jiewen]
> > V3:
> >  - Address Leif's comment (moving definitions, optimizations, ...)
> >  - Add ArmMonitorLib to choose Hvc/Smc conduit depending on a Pcd.
> >  - Re-factor some parts of SecurityPkg/RngDxe/ to ease the addition
> >of new algorithms.
> >  - Add ArmHasRngExt() function to check Arm's FEAT_RNG extension.
> > V2:
> >  - Updates TrngLib definitions to use RETURN_STATUS as the 

回复: [edk2-devel] [PATCH] ShellPkg:Improved Smbios Type 9 data under smbiosview

2022-11-03 Thread gaoliming via groups.io
Sainadh:
  The change is good. Can you create pull request for this change in Edk2
project?

Thanks
Liming
> -邮件原件-
> 发件人: devel@edk2.groups.io  代表 Sainadh
> Nagolu via groups.io
> 发送时间: 2022年11月2日 12:30
> 收件人: devel@edk2.groups.io; Sainadh Nagolu 
> 抄送: Vasudevan S ; Sundaresan S
> 
> 主题: [edk2-devel] [PATCH] ShellPkg:Improved Smbios Type 9 data under
> smbiosview
> 
> Added spec version check while publishing new fields, added Slot Pitch
field
> which was missing and corrected the publishing order as per Smbios spec.
> 
> Signed-off-by: Sainadh Nagolu 
> 
> ---
>  .../SmbiosView/PrintInfo.c | 18
> --
>  .../SmbiosView/SmbiosViewStrings.uni   |  2 ++
>  2 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
> index bf5306205b..595de36b40 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
> @@ -638,12 +638,18 @@ SmbiosPrintStructure (
>  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_SMBIOSVIEW_PRINTINFO_DATA_BUS_WIDTH), gShellDebug1HiiHandle,
> PeerGroupPtr[Index].DataBusWidth);
> 
>}
> 
> 
> 
> -  // Since PeerGroups has a variable number of entries, new
fields
> added after PeerGroups are defined in
> 
> -  // a extended structure. Those fields can be referenced using
> SMBIOS_TABLE_TYPE9_EXTENDED structure.
> 
> -  Type9ExtendedStruct = (SMBIOS_TABLE_TYPE9_EXTENDED
> *)((UINT8 *)PeerGroupPtr + (PeerGroupCount * sizeof
> (MISC_SLOT_PEER_GROUP)));
> 
> -  DisplaySystemSlotHeight (Type9ExtendedStruct->SlotHeight,
> Option);
> 
> -  DisplaySystemSlotPhysicalWidth
> (Type9ExtendedStruct->SlotPhysicalWidth, Option);
> 
> -  DisplaySystemSlotInformation
> (Type9ExtendedStruct->SlotInformation, Option);
> 
> +
> 
> +  if (AE_SMBIOS_VERSION (0x3, 0x4)) {
> 
> +  // Since PeerGroups has a variable number of entries, new
> fields added after PeerGroups are defined in
> 
> +  // a extended structure. Those fields can be referenced
> using SMBIOS_TABLE_TYPE9_EXTENDED structure.
> 
> +  Type9ExtendedStruct =
> (SMBIOS_TABLE_TYPE9_EXTENDED *)((UINT8 *)PeerGroupPtr +
> (PeerGroupCount * sizeof (MISC_SLOT_PEER_GROUP)));
> 
> +  DisplaySystemSlotInformation
> (Type9ExtendedStruct->SlotInformation, Option);
> 
> +  DisplaySystemSlotPhysicalWidth
> (Type9ExtendedStruct->SlotPhysicalWidth, Option);
> 
> +  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PITCH),
> gShellDebug1HiiHandle, Type9ExtendedStruct->SlotPitch);
> 
> +  if (AE_SMBIOS_VERSION (0x3, 0x5)) {
> 
> +  DisplaySystemSlotHeight
> (Type9ExtendedStruct->SlotHeight, Option);
> 
> +  }
> 
> +  }
> 
>  }
> 
>}
> 
> 
> 
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewS
> trings.uni
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewS
> trings.uni
> index 68211ce7ab..c24f7d5716 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewS
> trings.uni
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewS
> trings.uni
> @@ -1,6 +1,7 @@
>  // /**
> 
>  //
> 
>  // Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
> 
> +// Copyright (c) 1985 - 2022, American Megatrends International LLC.
> 
>  // (C) Copyright 2014-2015 Hewlett-Packard Development Company,
> L.P.
> 
>  // (C) Copyright 2015-2019 Hewlett Packard Enterprise Development
> LP
> 
>  // SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -417,6 +418,7 @@
>  #string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_INFORMATION
> #language en-US "System Slot Information: "
> 
>  #string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_HEIGHT
> #language en-US "System Slot Height: "
> 
>  #string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PHYSICAL_WIDTH
> #language en-US "System Slot Physical Width: "
> 
> +#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PITCH
> #language en-US "Slot Pitch: %d\r\n"
> 
>  #string STR_SMBIOSVIEW_QUERYTABLE_ONBOARD_DEVICE_TYPE
> #language en-US "Onboard Device Type: "
> 
>  #string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_EVENT_LOG_TYPE
> #language en-US "System Event Log Type: "
> 
>  #string STR_SMBIOSVIEW_QUERYTABLE_EVENT_LOG_VAR_DATA_FORMAT
> #language en-US "Event Log Variable Data Format Types: "
> 
> --
> 2.36.0.windows.1
> -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 

Re: [edk2-devel] [PATCH v1 0/2] UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib

2022-11-03 Thread Michael D Kinney
Reviewed-by: Michael D Kinney 

> -Original Message-
> From: mikub...@linux.microsoft.com 
> Sent: Thursday, November 3, 2022 5:25 PM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Sean Brogan 
> 
> Subject: [PATCH v1 0/2] UnitTestFrameworkPkg: Add 
> UnitTestUefiBootServicesTableLib
> 
> From: Michael Kubacki 
> 
> This patch series moves a library that is useful for stubbing UEFI
> Boot Services from PrmPkg to UnitTestFrameworkPkg.
> 
> An example of library usage that makes use of mocked protocol
> interfaces to retain protocol state is here:
> 
> https://github.com/tianocore/edk2/blob/master/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLibUnitTest.c
> 
> Over the last few months, I've had several people contact me about
> such mocking and I've pointed them to the library instance in
> PrmPkg.
> 
> I've also heard they would like to contribute and consider it for
> use in features outside PrmPkg so I'd like to propose moving the
> library instance to UnitTestFrameworkPkg so it can be more widely
> available and accessible for others to improve upon.
> 
> Cc: Michael D Kinney 
> Cc: Sean Brogan 
> Signed-off-by: Michael Kubacki 
> 
> Michael Kubacki (2):
>   UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib
>   PrmPkg: Use UnitTestFrameworkPkg UEFI BS library
> 
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
>  |  4 ++--
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTimer.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTimer.c
>  |  2 +-
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestImage.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibImage.c
>|  2 +-
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMemory.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMemory.c
>  |  2 +-
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMisc.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMisc.c
>  |  2 +-
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.c
>  |  2 +-
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestTpl.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibTpl.c
>|  2 +-
>  PrmPkg/PrmPkg.dsc
> |  1 -
>  PrmPkg/Test/PrmPkgHostTest.dsc
> |  6 -
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.h
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.h
>  |  0
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.inf
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.inf
>  | 24
> ++--
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibTest.uni
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.uni
>  |  0
>  
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.h
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.h
>  |  2 +-
>  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc
> |  1 +
>  UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
> |  1 +
>  15 files changed, 23 insertions(+), 28 deletions(-)
>  rename 
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
>  (97%)
>  rename 
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTimer.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTimer.c
>  (95%)
>  rename 
> PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestImage.c
>  =>
> UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibImage.c
>  (96%)
>  rename 
> 

Re: [edk2-devel] [PATCH v3 2/2] .github: Add initial CodeQL config and workflow files

2022-11-03 Thread Michael D Kinney
Reviewed-by: Michael D Kinney 


> -Original Message-
> From: mikub...@linux.microsoft.com 
> Sent: Thursday, November 3, 2022 5:33 PM
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Kinney, Michael D 
> ; Gao, Liming
> 
> Subject: [PATCH v3 2/2] .github: Add initial CodeQL config and workflow files
> 
> From: Michael Kubacki 
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4115
> 
> Adds initial support for enabling CodeQL Code Scanning in this
> repository per the RFC:
> 
>   https://github.com/tianocore/edk2/discussions/3258
> 
> Adds the following new files:
>   - .github/workflows/codql-analysis.yml - The main GitHub workflow
> file used to setup CodeQL in the repo.
>   - .github/codeql/codeql-config.yml - The main CodeQL configuration
> file used to customize the queries and other resources the repo
> is using for CodeQL.
> 
> Cc: Sean Brogan 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Signed-off-by: Michael Kubacki 
> ---
>  .github/codeql/codeql-config.yml  | 30 +++
>  .github/codeql/edk2.qls   | 12 +++
>  .github/workflows/codeql-analysis.yml | 91 
>  3 files changed, 133 insertions(+)
> 
> diff --git a/.github/codeql/codeql-config.yml 
> b/.github/codeql/codeql-config.yml
> new file mode 100644
> index ..3e27c2fb0d28
> --- /dev/null
> +++ b/.github/codeql/codeql-config.yml
> @@ -0,0 +1,30 @@
> +## @file
> +# CodeQL configuration file for edk2.
> +#
> +# Copyright (c) Microsoft Corporation.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +name: "CodeQL config"
> +
> +# The following line disables the default queries. This is used because we 
> want to enable on query at a time by
> +# explicitly specifying each query in a "queries" array as they are enabled.
> +#
> +# See the following for more information about adding custom queries:
> +# 
> https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-
> errors/configuring-code-scanning#using-a-custom-configuration-file
> +
> +#disable-default-queries: true
> +
> +queries:
> +  - name: EDK2 CodeQL Query List
> +uses: ./.github/codeql/edk2.qls
> +
> +# We must specify a query for CodeQL to run. Until the first query is 
> enabled, enable the security query suite but
> +# exclude all problem levels from impacting the results. After the first 
> query is enabled, this filter can be relaxed
> +# to find the level of problems desired from the query.
> +query-filters:
> +- exclude:
> +problem.severity:
> +  - error
> +  - warning
> +  - recommendation
> diff --git a/.github/codeql/edk2.qls b/.github/codeql/edk2.qls
> new file mode 100644
> index ..0efc7dca52db
> --- /dev/null
> +++ b/.github/codeql/edk2.qls
> @@ -0,0 +1,12 @@
> +---
> +- description: EDK2 (C++) queries
> +
> +# Bring in all queries from the official cpp-queries suite so individual 
> queries can be explicitly enabled.
> +
> +- queries: '.'
> +  from: codeql/cpp-queries
> +
> +# Enable individual queries below.
> +
> +- include:
> +id: cpp/conditionallyuninitializedvariable
> diff --git a/.github/workflows/codeql-analysis.yml 
> b/.github/workflows/codeql-analysis.yml
> new file mode 100644
> index ..2eacb9c9e1a1
> --- /dev/null
> +++ b/.github/workflows/codeql-analysis.yml
> @@ -0,0 +1,91 @@
> +# @file
> +# GitHub Workflow for CodeQL Analysis
> +#
> +# Copyright (c) Microsoft Corporation.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +name: "CodeQL"
> +
> +on:
> +  push:
> +branches:
> +  - master
> +  pull_request:
> +branches:
> +  - master
> +paths-ignore:
> +  - '**/*.bat'
> +  - '**/*.md'
> +  - '**/*.py'
> +  - '**/*.rst'
> +  - '**/*.sh'
> +  - '**/*.txt'
> +
> +  schedule:
> +# https://crontab.guru/#20_23_*_*_4
> +- cron: '20 23 * * 4'
> +
> +jobs:
> +  analyze:
> +name: Analyze
> +runs-on: windows-2019
> +permissions:
> +  actions: read
> +  contents: read
> +  security-events: write
> +
> +strategy:
> +  fail-fast: false
> +  matrix:
> +package: [
> +  "ArmPkg",
> +  "CryptoPkg",
> +  "DynamicTablesPkg",
> +  "FatPkg",
> +  "FmpDevicePkg",
> +  "IntelFsp2Pkg",
> +  "IntelFsp2WrapperPkg",
> +  "MdeModulePkg",
> +  "MdePkg",
> +  "PcAtChipsetPkg",
> +  "PrmPkg",
> +  "SecurityPkg",
> +  "ShellPkg",
> +  "SourceLevelDebugPkg",
> +  "StandaloneMmPkg",
> +  "UefiCpuPkg",
> +  "UnitTestFrameworkPkg"]
> +
> +steps:
> +- name: Checkout repository
> +  uses: actions/checkout@v3
> +
> +# Initializes the CodeQL tools for scanning.
> +- name: Initialize CodeQL
> +  uses: github/codeql-action/init@v2
> +  with:
> +languages: 'cpp'
> +# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 
> 

Re: [edk2-devel] [PATCH v2 2/2] .github: Add initial CodeQL config and workflow files

2022-11-03 Thread Michael Kubacki
Hi Mike,

Node.js and cspell are not needed. I confirmed the GitHub workflow with them 
removed here:
Enable CodeQL · tianocore/edk2@ad62416 (github.com) ( 
https://github.com/tianocore/edk2/actions/runs/3390100498 )

v3 has been sent with that change:
[PATCH v3 0/2] Enable Initial CodeQL Support (groups.io) ( 
https://edk2.groups.io/g/devel/message/95927 )

Thanks,
Michael


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




[edk2-devel] [PATCH v3 2/2] .github: Add initial CodeQL config and workflow files

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

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

Adds initial support for enabling CodeQL Code Scanning in this
repository per the RFC:

  https://github.com/tianocore/edk2/discussions/3258

Adds the following new files:
  - .github/workflows/codql-analysis.yml - The main GitHub workflow
file used to setup CodeQL in the repo.
  - .github/codeql/codeql-config.yml - The main CodeQL configuration
file used to customize the queries and other resources the repo
is using for CodeQL.

Cc: Sean Brogan 
Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Michael Kubacki 
---
 .github/codeql/codeql-config.yml  | 30 +++
 .github/codeql/edk2.qls   | 12 +++
 .github/workflows/codeql-analysis.yml | 91 
 3 files changed, 133 insertions(+)

diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml
new file mode 100644
index ..3e27c2fb0d28
--- /dev/null
+++ b/.github/codeql/codeql-config.yml
@@ -0,0 +1,30 @@
+## @file
+# CodeQL configuration file for edk2.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+name: "CodeQL config"
+
+# The following line disables the default queries. This is used because we 
want to enable on query at a time by
+# explicitly specifying each query in a "queries" array as they are enabled.
+#
+# See the following for more information about adding custom queries:
+# 
https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-a-custom-configuration-file
+
+#disable-default-queries: true
+
+queries:
+  - name: EDK2 CodeQL Query List
+uses: ./.github/codeql/edk2.qls
+
+# We must specify a query for CodeQL to run. Until the first query is enabled, 
enable the security query suite but
+# exclude all problem levels from impacting the results. After the first query 
is enabled, this filter can be relaxed
+# to find the level of problems desired from the query.
+query-filters:
+- exclude:
+problem.severity:
+  - error
+  - warning
+  - recommendation
diff --git a/.github/codeql/edk2.qls b/.github/codeql/edk2.qls
new file mode 100644
index ..0efc7dca52db
--- /dev/null
+++ b/.github/codeql/edk2.qls
@@ -0,0 +1,12 @@
+---
+- description: EDK2 (C++) queries
+
+# Bring in all queries from the official cpp-queries suite so individual 
queries can be explicitly enabled.
+
+- queries: '.'
+  from: codeql/cpp-queries
+
+# Enable individual queries below.
+
+- include:
+id: cpp/conditionallyuninitializedvariable
diff --git a/.github/workflows/codeql-analysis.yml 
b/.github/workflows/codeql-analysis.yml
new file mode 100644
index ..2eacb9c9e1a1
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,91 @@
+# @file
+# GitHub Workflow for CodeQL Analysis
+#
+# Copyright (c) Microsoft Corporation.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+name: "CodeQL"
+
+on:
+  push:
+branches:
+  - master
+  pull_request:
+branches:
+  - master
+paths-ignore:
+  - '**/*.bat'
+  - '**/*.md'
+  - '**/*.py'
+  - '**/*.rst'
+  - '**/*.sh'
+  - '**/*.txt'
+
+  schedule:
+# https://crontab.guru/#20_23_*_*_4
+- cron: '20 23 * * 4'
+
+jobs:
+  analyze:
+name: Analyze
+runs-on: windows-2019
+permissions:
+  actions: read
+  contents: read
+  security-events: write
+
+strategy:
+  fail-fast: false
+  matrix:
+package: [
+  "ArmPkg",
+  "CryptoPkg",
+  "DynamicTablesPkg",
+  "FatPkg",
+  "FmpDevicePkg",
+  "IntelFsp2Pkg",
+  "IntelFsp2WrapperPkg",
+  "MdeModulePkg",
+  "MdePkg",
+  "PcAtChipsetPkg",
+  "PrmPkg",
+  "SecurityPkg",
+  "ShellPkg",
+  "SourceLevelDebugPkg",
+  "StandaloneMmPkg",
+  "UefiCpuPkg",
+  "UnitTestFrameworkPkg"]
+
+steps:
+- name: Checkout repository
+  uses: actions/checkout@v3
+
+# Initializes the CodeQL tools for scanning.
+- name: Initialize CodeQL
+  uses: github/codeql-action/init@v2
+  with:
+languages: 'cpp'
+# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 
'python', 'ruby' ]
+# Learn more about CodeQL language support at 
https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/
+config-file: ./.github/codeql/codeql-config.yml
+# Note: Add new queries to codeql-config.yml file as they are enabled.
+
+- name: Install/Upgrade pip Modules
+  run: pip install -r pip-requirements.txt --upgrade
+
+- name: Setup
+  run: stuart_setup -c .pytool/CISettings.py -t DEBUG -a IA32,X64 
TOOL_CHAIN_TAG=VS2019
+
+- name: Update
+  run: stuart_update -c .pytool/CISettings.py -t DEBUG -a IA32,X64 
TOOL_CHAIN_TAG=VS2019
+
+- name: Build 

[edk2-devel] [PATCH v3 0/2] Enable Initial CodeQL Support

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

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

This patch series enables initial CodeQL support within the edk2
repository.

After this patch, a CodeQL Analyze step will run on a subset of
edk2 packages in Pull Requests. The plan to scale additional CodeQL
queries is documented in the RFC and it is recommeneded to read
that for more detail:

https://github.com/tianocore/edk2/discussions/3258#discussioncomment-3682099

In summary, this change will:

- Main workflow file - .github/workflows/codeql-analysis.yml

1. Add a code scanning workflow with the CodeQL Analysis GitHub action
2. Build packages on Windows + VS2019
3. Perform CodeQL analysis on the build results

- Custom configuration file - .github/codeql/codeql-config.yml

1. Specify the edk2 CodeQL query set
2. Apply a query filter to exclude errors, warnings, and
   recommendations

- edk2 query set file - .github/codeql/edk2.qls

1. Enable a single query: cpp/conditionallyuninitializedvariable

Per the RFC, this enables CodeQL but does not allow any alerts
by suppressing all of the severity levels.

When the code changes necessary to resolve problems found with
cpp/conditionallyuninitializedvariable are checked in, the severity
filter can be adjusted such that query is enabled.

V3 Changes:

1. Remove Node.js and cspell installation from workflow

These are not needed for the build used for CodeQL.

V2 Changes:

1. Switch from Ubuntu + GCC5

As noted in the v1 series, there is an occassional issue with
filesystem paths on Ubuntu + GCC at the moment that prevents this
change from being checked in. A bug has been filed against CodeQL
and  the CodeQL team has confirmed this is a bug. They were not
aware of the bug until this report.

https://github.com/github/codeql-action/issues/1338

In the meantime, this v2 patch series places the workflow on
Windows with VS2019 which has been reliable across testing.

Cc: Andrew Fish 
Cc: Leif Lindholm 
Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Sean Brogan 
Signed-off-by: Michael Kubacki 

Michael Kubacki (2):
  Maintainers.txt: Add .github maintainers and reviewers
  .github: Add initial CodeQL config and workflow files

 .github/codeql/codeql-config.yml  | 30 +++
 .github/codeql/edk2.qls   | 12 +++
 .github/workflows/codeql-analysis.yml | 91 
 Maintainers.txt   |  6 ++
 4 files changed, 139 insertions(+)
 create mode 100644 .github/codeql/codeql-config.yml
 create mode 100644 .github/codeql/edk2.qls
 create mode 100644 .github/workflows/codeql-analysis.yml

-- 
2.28.0.windows.1



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




[edk2-devel] [PATCH v1 2/2] PrmPkg: Use UnitTestFrameworkPkg UEFI BS library

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

Updates PrmPkg to use UnitTestUefiBootServicesTableLib from
UnitTestFrameworkPkg instead of UefiBootServicesTableLibUnitTest
in PrmPkg.

Cc: Michael D Kinney 
Cc: Sean Brogan 
Signed-off-by: Michael Kubacki 
---
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
   |  119 --
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTimer.c
 |  180 ---
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestImage.c
  |  163 --
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMemory.c
 |  145 --
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMisc.c
   |  198 ---
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.c
   | 1650 
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestTpl.c
|   43 -
 PrmPkg/PrmPkg.dsc  
|1 -
 PrmPkg/Test/PrmPkgHostTest.dsc 
|6 -
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibTest.uni
 |   12 -
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.h
   | 1042 
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.inf
 |   46 -
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.h
   |  120 --
 13 files changed, 3725 deletions(-)

diff --git 
a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
 
b/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
deleted file mode 100644
index ea3235e448a2..
--- 
a/PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/** @file
-  This library supports a Boot Services table library implementation that 
allows code dependent
-  upon UefiBootServicesTableLib to operate in an isolated execution 
environment such as within
-  the context of a host-based unit test framework.
-
-  The unit test should initialize the Boot Services database with any required 
elements
-  (e.g. protocols, events, handles, etc.) prior to the services being invoked 
by code under test.
-
-  It is strongly recommended to clean any global databases (e.g. protocol, 
event, handles, etc.) after
-  every unit test so the tests execute in a predictable manner from a clean 
state.
-
-  Copyright (c) Microsoft Corporation
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "UefiBootServicesTableLibUnitTest.h"
-
-EFI_HANDLEgImageHandle = NULL;
-EFI_SYSTEM_TABLE  *gST = NULL;
-
-STATIC EFI_BOOT_SERVICES  mBootServices = {
-  {
-EFI_BOOT_SERVICES_SIGNATURE,   
   // Signature
-EFI_BOOT_SERVICES_REVISION,
   // Revision
-sizeof (EFI_BOOT_SERVICES),
   // HeaderSize
-0, 
   // CRC32
-0  
   // Reserved
-  },
-  (EFI_RAISE_TPL)UnitTestRaiseTpl, 
   // RaiseTPL
-  (EFI_RESTORE_TPL)UnitTestRestoreTpl, 
   // RestoreTPL
-  (EFI_ALLOCATE_PAGES)UnitTestAllocatePages,   
   // AllocatePages
-  (EFI_FREE_PAGES)UnitTestFreePages,   
   // FreePages
-  (EFI_GET_MEMORY_MAP)UnitTestGetMemoryMap,
   // GetMemoryMap
-  (EFI_ALLOCATE_POOL)UnitTestAllocatePool, 
   // AllocatePool
-  (EFI_FREE_POOL)UnitTestFreePool, 
   // FreePool
-  (EFI_CREATE_EVENT)UnitTestCreateEvent,   
   // CreateEvent
-  (EFI_SET_TIMER)UnitTestSetTimer, 
   // SetTimer
-  (EFI_WAIT_FOR_EVENT)UnitTestWaitForEvent,
   // WaitForEvent
-  (EFI_SIGNAL_EVENT)UnitTestSignalEvent,   
   // SignalEvent
-  (EFI_CLOSE_EVENT)UnitTestCloseEvent,

[edk2-devel] [PATCH v1 1/2] UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

This library supports a Boot Services table library implementation
that allows code dependent upon UefiBootServicesTableLib to operate
in an isolated execution environment such as within
the context of a host-based unit test framework.

The unit test should initialize the Boot Services database with any
required elements (e.g. protocols, events, handles, etc.) prior to
the services being invoked by code under test.

It is strongly recommended to clean any global databases (e.g.
protocol, event, handles, etc.) after every unit test so the tests
execute in a predictable manner from a clean state.

This library is being moved here from PrmPkg so it can be made more
generally available to other packages and improved upon for others
use.

Cc: Michael D Kinney 
Cc: Sean Brogan 
Signed-off-by: Michael Kubacki 
---
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
   |  119 ++
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTimer.c
 |  180 +++
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibImage.c
  |  163 ++
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMemory.c
 |  145 ++
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMisc.c
   |  198 +++
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.c
   | 1650 
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibTpl.c
|   43 +
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.h
   | 1042 
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.inf
 |   46 +
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.uni
 |   12 +
 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.h
   |  120 ++
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc  
|1 +
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc  
|1 +
 13 files changed, 3720 insertions(+)

diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
 
b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
new file mode 100644
index ..a6fc13e7d21e
--- /dev/null
+++ 
b/UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
@@ -0,0 +1,119 @@
+/** @file
+  This library supports a Boot Services table library implementation that 
allows code dependent
+  upon UefiBootServicesTableLib to operate in an isolated execution 
environment such as within
+  the context of a host-based unit test framework.
+
+  The unit test should initialize the Boot Services database with any required 
elements
+  (e.g. protocols, events, handles, etc.) prior to the services being invoked 
by code under test.
+
+  It is strongly recommended to clean any global databases (e.g. protocol, 
event, handles, etc.) after
+  every unit test so the tests execute in a predictable manner from a clean 
state.
+
+  Copyright (c) Microsoft Corporation
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UnitTestUefiBootServicesTableLib.h"
+
+EFI_HANDLEgImageHandle = NULL;
+EFI_SYSTEM_TABLE  *gST = NULL;
+
+STATIC EFI_BOOT_SERVICES  mBootServices = {
+  {
+EFI_BOOT_SERVICES_SIGNATURE,   
   // Signature
+EFI_BOOT_SERVICES_REVISION,
   // Revision
+sizeof (EFI_BOOT_SERVICES),
   // HeaderSize
+0, 
   // CRC32
+0  
   // Reserved
+  },
+  (EFI_RAISE_TPL)UnitTestRaiseTpl, 
   // RaiseTPL
+  (EFI_RESTORE_TPL)UnitTestRestoreTpl, 
   // RestoreTPL
+  (EFI_ALLOCATE_PAGES)UnitTestAllocatePages,   
   // AllocatePages
+  (EFI_FREE_PAGES)UnitTestFreePages,   
   // FreePages
+  (EFI_GET_MEMORY_MAP)UnitTestGetMemoryMap,
   // GetMemoryMap
+  (EFI_ALLOCATE_POOL)UnitTestAllocatePool, 
   // AllocatePool

[edk2-devel] [PATCH v1 0/2] UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

This patch series moves a library that is useful for stubbing UEFI
Boot Services from PrmPkg to UnitTestFrameworkPkg.

An example of library usage that makes use of mocked protocol
interfaces to retain protocol state is here:

https://github.com/tianocore/edk2/blob/master/PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLibUnitTest.c

Over the last few months, I've had several people contact me about
such mocking and I've pointed them to the library instance in
PrmPkg.

I've also heard they would like to contribute and consider it for
use in features outside PrmPkg so I'd like to propose moving the
library instance to UnitTestFrameworkPkg so it can be more widely
available and accessible for others to improve upon.

Cc: Michael D Kinney 
Cc: Sean Brogan 
Signed-off-by: Michael Kubacki 

Michael Kubacki (2):
  UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib
  PrmPkg: Use UnitTestFrameworkPkg UEFI BS library

 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
 |  4 ++--
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTimer.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTimer.c
 |  2 +-
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestImage.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibImage.c
   |  2 +-
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMemory.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMemory.c
 |  2 +-
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestMisc.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMisc.c
 |  2 +-
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.c
 |  2 +-
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestTpl.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibTpl.c
   |  2 +-
 PrmPkg/PrmPkg.dsc  

  |  1 -
 PrmPkg/Test/PrmPkgHostTest.dsc 

  |  6 -
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.h
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.h
 |  0
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.inf
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.inf
 | 24 ++--
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibTest.uni
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.uni
 |  0
 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestProtocol.h
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibProtocol.h
 |  2 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc  

  |  1 +
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc  

  |  1 +
 15 files changed, 23 insertions(+), 28 deletions(-)
 rename 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLib.c
 (97%)
 rename 
PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTestEventTimer.c
 => 
UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibEventTimer.c
 (95%)
 rename 

[edk2-devel] [PATCH V2 7/9] OvmfPkg: Delete VmgExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

Delete VmgExitLib because it is replaced by CcExitLib.

Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 .../VmgExitLib/PeiDxeVmgExitVcHandler.c   |  103 -
 OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf  |   48 -
 .../Library/VmgExitLib/SecVmgExitVcHandler.c  |  109 -
 OvmfPkg/Library/VmgExitLib/VmTdExitHandler.h  |   32 -
 .../Library/VmgExitLib/VmTdExitVeHandler.c|  559 
 OvmfPkg/Library/VmgExitLib/VmgExitLib.c   |  238 --
 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf |   45 -
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 2356 -
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.h |   53 -
 .../Library/VmgExitLib/X64/TdVmcallCpuid.nasm |  146 -
 10 files changed, 3689 deletions(-)
 delete mode 100644 OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c
 delete mode 100644 OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
 delete mode 100644 OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmTdExitHandler.h
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmTdExitVeHandler.c
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.c
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
 delete mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.h
 delete mode 100644 OvmfPkg/Library/VmgExitLib/X64/TdVmcallCpuid.nasm

diff --git a/OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c
deleted file mode 100644
index e3d071583750..
--- a/OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/** @file
-  X64 #VC Exception Handler functon.
-
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "VmgExitVcHandler.h"
-
-/**
-  Handle a #VC exception.
-
-  Performs the necessary processing to handle a #VC exception.
-
-  @param[in, out]  ExceptionType  Pointer to an EFI_EXCEPTION_TYPE to be set
-  as value to use on error.
-  @param[in, out]  SystemContext  Pointer to EFI_SYSTEM_CONTEXT
-
-  @retval  EFI_SUCCESSException handled
-  @retval  EFI_UNSUPPORTED#VC not supported, (new) exception value to
-  propagate provided
-  @retval  EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
-  propagate provided
-
-**/
-EFI_STATUS
-EFIAPI
-VmgExitHandleVc (
-  IN OUT EFI_EXCEPTION_TYPE  *ExceptionType,
-  IN OUT EFI_SYSTEM_CONTEXT  SystemContext
-  )
-{
-  MSR_SEV_ES_GHCB_REGISTER  Msr;
-  GHCB  *Ghcb;
-  GHCB  *GhcbBackup;
-  EFI_STATUSVcRet;
-  BOOLEAN   InterruptState;
-  SEV_ES_PER_CPU_DATA   *SevEsData;
-
-  InterruptState = GetInterruptState ();
-  if (InterruptState) {
-DisableInterrupts ();
-  }
-
-  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
-  ASSERT (Msr.GhcbInfo.Function == 0);
-  ASSERT (Msr.Ghcb != 0);
-
-  Ghcb   = Msr.Ghcb;
-  GhcbBackup = NULL;
-
-  SevEsData = (SEV_ES_PER_CPU_DATA *)(Ghcb + 1);
-  SevEsData->VcCount++;
-
-  //
-  // Check for maximum PEI/DXE #VC nesting.
-  //
-  if (SevEsData->VcCount > VMGEXIT_MAXIMUM_VC_COUNT) {
-VmgExitIssueAssert (SevEsData);
-  } else if (SevEsData->VcCount > 1) {
-//
-// Nested #VC
-//
-if (SevEsData->GhcbBackupPages == NULL) {
-  VmgExitIssueAssert (SevEsData);
-}
-
-//
-// Save the active GHCB to a backup page.
-//   To access the correct backup page, increment the backup page pointer
-//   based on the current VcCount.
-//
-GhcbBackup  = (GHCB *)SevEsData->GhcbBackupPages;
-GhcbBackup += (SevEsData->VcCount - 2);
-
-CopyMem (GhcbBackup, Ghcb, sizeof (*Ghcb));
-  }
-
-  VcRet = InternalVmgExitHandleVc (Ghcb, ExceptionType, SystemContext);
-
-  if (GhcbBackup != NULL) {
-//
-// Restore the active GHCB from the backup page.
-//
-CopyMem (Ghcb, GhcbBackup, sizeof (*Ghcb));
-  }
-
-  SevEsData->VcCount--;
-
-  if (InterruptState) {
-EnableInterrupts ();
-  }
-
-  return VcRet;
-}
diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf 
b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
deleted file mode 100644
index f9bd4974f6dc..
--- a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
+++ /dev/null
@@ -1,48 +0,0 @@
-## @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  = SecVmgExitLib
-  FILE_GUID  

[edk2-devel] [PATCH V2 9/9] Maintainers: Update the VmgExitLib to CcExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib is renamed as CcExitLib. The related section in
Maintainers.txt should be updated as well.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Reviewed-by: Michael D Kinney 
Signed-off-by: Min Xu 
---
 Maintainers.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Maintainers.txt b/Maintainers.txt
index 889990fa566f..454b93420da4 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -475,7 +475,7 @@ F: OvmfPkg/Include/Library/MemEncryptSevLib.h
 F: OvmfPkg/IoMmuDxe/AmdSevIoMmu.*
 F: OvmfPkg/Library/BaseMemEncryptSevLib/
 F: OvmfPkg/Library/PlatformBootManagerLibGrub/
-F: OvmfPkg/Library/VmgExitLib/
+F: OvmfPkg/Library/CcExitLib/
 F: OvmfPkg/PlatformPei/AmdSev.c
 F: OvmfPkg/ResetVector/
 F: OvmfPkg/Sec/
-- 
2.29.2.windows.2



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




[edk2-devel] [PATCH V2 8/9] UefiCpuPkg: Delete VmgExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib is replaced by CcExitLib. So it is deleted from UefiCpuPkg.

Cc: Guo Dong 
Cc: Ray Ni 
Signed-off-by: Min Xu 
---
 UefiCpuPkg/Include/Library/VmgExitLib.h   | 173 --
 .../Library/VmgExitLibNull/VmTdExitNull.c |  38 
 .../Library/VmgExitLibNull/VmgExitLibNull.c   | 165 -
 .../Library/VmgExitLibNull/VmgExitLibNull.inf |  28 ---
 .../Library/VmgExitLibNull/VmgExitLibNull.uni |  15 --
 UefiCpuPkg/UefiCpuPkg.dec |   3 -
 UefiCpuPkg/UefiCpuPkg.dsc |   2 -
 7 files changed, 424 deletions(-)
 delete mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h
 delete mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmTdExitNull.c
 delete mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
 delete mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 delete mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni

diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h 
b/UefiCpuPkg/Include/Library/VmgExitLib.h
deleted file mode 100644
index f9f911099a7b..
--- a/UefiCpuPkg/Include/Library/VmgExitLib.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/** @file
-  Public header file for the VMGEXIT Support library class.
-
-  This library class defines some routines used when invoking the VMGEXIT
-  instruction in support of SEV-ES and to handle #VC exceptions.
-
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef __VMG_EXIT_LIB_H__
-#define __VMG_EXIT_LIB_H__
-
-#include 
-#include 
-
-#define VE_EXCEPTION  20
-
-/**
-  Perform VMGEXIT.
-
-  Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
-  then handles the return actions.
-
-  @param[in, out]  Ghcb   A pointer to the GHCB
-  @param[in]   ExitCode   VMGEXIT code to be assigned to the SwExitCode
-  field of the GHCB.
-  @param[in]   ExitInfo1  VMGEXIT information to be assigned to the
-  SwExitInfo1 field of the GHCB.
-  @param[in]   ExitInfo2  VMGEXIT information to be assigned to the
-  SwExitInfo2 field of the GHCB.
-
-  @retval  0  VMGEXIT succeeded.
-  @return Exception number to be propagated, VMGEXIT
-  processing did not succeed.
-
-**/
-UINT64
-EFIAPI
-VmgExit (
-  IN OUT GHCB*Ghcb,
-  IN UINT64  ExitCode,
-  IN UINT64  ExitInfo1,
-  IN UINT64  ExitInfo2
-  );
-
-/**
-  Perform pre-VMGEXIT initialization/preparation.
-
-  Performs the necessary steps in preparation for invoking VMGEXIT. Must be
-  called before setting any fields within the GHCB.
-
-  @param[in, out]  GhcbA pointer to the GHCB
-  @param[in, out]  InterruptState  A pointer to hold the current interrupt
-   state, used for restoring in VmgDone ()
-
-**/
-VOID
-EFIAPI
-VmgInit (
-  IN OUT GHCB *Ghcb,
-  IN OUT BOOLEAN  *InterruptState
-  );
-
-/**
-  Perform post-VMGEXIT cleanup.
-
-  Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
-  called after obtaining needed fields within the GHCB.
-
-  @param[in, out]  GhcbA pointer to the GHCB
-  @param[in]   InterruptState  An indicator to conditionally (re)enable
-   interrupts
-
-**/
-VOID
-EFIAPI
-VmgDone (
-  IN OUT GHCB *Ghcb,
-  IN BOOLEAN  InterruptState
-  );
-
-/**
-  Marks a specified offset as valid in the GHCB.
-
-  The ValidBitmap area represents the areas of the GHCB that have been marked
-  valid. Set the bit in ValidBitmap for the input offset.
-
-  @param[in, out]  Ghcb   A pointer to the GHCB
-  @param[in]   Offset Qword offset in the GHCB to mark valid
-
-**/
-VOID
-EFIAPI
-VmgSetOffsetValid (
-  IN OUT GHCB   *Ghcb,
-  IN GHCB_REGISTER  Offset
-  );
-
-/**
-  Checks if a specified offset is valid in the GHCB.
-
-  The ValidBitmap area represents the areas of the GHCB that have been marked
-  valid. Return whether the bit in the ValidBitmap is set for the input offset.
-
-  @param[in]  GhcbA pointer to the GHCB
-  @param[in]  Offset  Qword offset in the GHCB to mark valid
-
-  @retval TRUEOffset is marked valid in the GHCB
-  @retval FALSE   Offset is not marked valid in the GHCB
-
-**/
-BOOLEAN
-EFIAPI
-VmgIsOffsetValid (
-  IN GHCB   *Ghcb,
-  IN GHCB_REGISTER  Offset
-  );
-
-/**
-  Handle a #VC exception.
-
-  Performs the necessary processing to handle a #VC exception.
-
-  The base library function returns an error equal to VC_EXCEPTION,
-  to be propagated to the standard exception handling stack.
-
-  @param[in, out]  ExceptionType  Pointer to an EFI_EXCEPTION_TYPE to be set
-  as value to use on error.
-  @param[in, out]  

[edk2-devel] [PATCH V2 6/9] OvmfPkg: Use CcExitLib instead of VmgExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib is renamed as CcExitLib. See the description in BZ4123.
So OvmfPkg should be updated to this rename.

Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 OvmfPkg/AmdSev/AmdSevX64.dsc   |  2 --
 OvmfPkg/Bhyve/BhyveX64.dsc |  1 -
 OvmfPkg/CloudHv/CloudHvX64.dsc |  3 ---
 OvmfPkg/IntelTdx/IntelTdxX64.dsc   |  2 --
 .../BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf   |  2 +-
 .../BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf   |  2 +-
 .../BaseMemEncryptSevLib/SecMemEncryptSevLib.inf   |  2 +-
 .../X64/SnpPageStateChangeInternal.c   | 10 +-
 OvmfPkg/Microvm/MicrovmX64.dsc |  2 --
 OvmfPkg/OvmfPkgIa32.dsc|  2 --
 OvmfPkg/OvmfPkgIa32X64.dsc |  2 --
 OvmfPkg/OvmfPkgX64.dsc |  3 ---
 OvmfPkg/OvmfXen.dsc|  1 -
 OvmfPkg/PlatformPei/AmdSev.c   | 10 +-
 OvmfPkg/PlatformPei/PlatformPei.inf|  2 +-
 .../FvbServicesRuntimeDxe.inf  |  2 +-
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c  | 10 +-
 17 files changed, 20 insertions(+), 38 deletions(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 1b324fa48d09..8f7cae787e97 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -205,7 +205,6 @@
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
 [LibraryClasses.common.SEC]
@@ -231,7 +230,6 @@
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
   CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
 
 [LibraryClasses.common.PEI_CORE]
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 3e90ae365682..e3bb367b6bf6 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -233,7 +233,6 @@
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
-  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
 [LibraryClasses.common.SEC]
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index 56d061464dbf..ce277cb2398b 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -252,7 +252,6 @@
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
 [LibraryClasses.common.SEC]
@@ -277,7 +276,6 @@
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
   CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
 
 [LibraryClasses.common.PEI_CORE]
@@ -918,7 +916,6 @@
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf {
 
 CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
-VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
   }
   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf {
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 8c6edfbc2363..345892651520 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -216,7 +216,6 @@
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf
   PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -239,7 +238,6 @@
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
   CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
-  VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
   

[edk2-devel] [PATCH V2 5/9] UefiPayloadPkg: Use CcExitLib instead of VmgExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib is renamed as CcExitLib. So UefiPayloadPkg.dsc should be
updated as well.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: Sean Rhodes 
Cc: James Lu 
Cc: Gua Guo 
Reviewed-by: James Lu 
Reviewed-by: Gua Guo 
Signed-off-by: Min Xu 
---
 UefiPayloadPkg/UefiPayloadPkg.dsc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc 
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 1150be6acd0e..723a50a42284 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -301,7 +301,7 @@
   
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
-  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
+  CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
 
 [LibraryClasses.common]
-- 
2.29.2.windows.2



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




[edk2-devel] [PATCH V2 4/9] UefiCpuPkg: Use CcExitLib instead of VmgExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib once was designed to provide interfaces to support #VC handler
and issue VMGEXIT instruction. After TDVF (enable TDX feature in OVMF) is
introduced, this library is updated to support #VE as well. Now the name
of VmgExitLib cannot reflect what the lib does. So VmgExitLib is replaced
by CcExitLib.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 .../DxeCpuExceptionHandlerLib.inf  |  2 +-
 .../PeiCpuExceptionHandlerLib.inf  |  2 +-
 .../CpuExceptionHandlerLib/PeiDxeSmmCpuException.c |  6 +++---
 .../CpuExceptionHandlerLib/SecPeiCpuException.c|  6 +++---
 .../SecPeiCpuExceptionHandlerLib.inf   |  2 +-
 .../SmmCpuExceptionHandlerLib.inf  |  2 +-
 .../Xcode5SecPeiCpuExceptionHandlerLib.inf |  2 +-
 UefiCpuPkg/Library/MpInitLib/AmdSev.c  | 10 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf  |  2 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c|  8 
 UefiCpuPkg/Library/MpInitLib/MpLib.c   |  2 +-
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf  |  2 +-
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c  | 10 +-
 UefiCpuPkg/UefiCpuPkg.dsc  |  2 ++
 14 files changed, 30 insertions(+), 28 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
index e7a81bebdb13..d0f82095cf92 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -60,4 +60,4 @@
   PeCoffGetEntryPointLib
   MemoryAllocationLib
   DebugLib
-  VmgExitLib
+  CcExitLib
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
index 7c2ec3b2db4c..5339f8e60404 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
@@ -52,7 +52,7 @@
   HobLib
   MemoryAllocationLib
   SynchronizationLib
-  VmgExitLib
+  CcExitLib
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard# CONSUMES
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
index a7d0897ef1f9..748cf8d3bfc6 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
@@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
 #include 
-#include 
+#include 
 #include "CpuExceptionCommon.h"
 
 /**
@@ -40,7 +40,7 @@ CommonExceptionHandlerWorker (
   //   On other   - ExceptionType contains (possibly new) exception
   //value
   //
-  Status = VmgExitHandleVc (, SystemContext);
+  Status = CcExitHandleVc (, SystemContext);
   if (!EFI_ERROR (Status)) {
 return;
   }
@@ -57,7 +57,7 @@ CommonExceptionHandlerWorker (
   //   On other   - ExceptionType contains (possibly new) exception
   //value
   //
-  Status = VmTdExitHandleVe (, SystemContext);
+  Status = CcExitHandleVe (, SystemContext);
   if (!EFI_ERROR (Status)) {
 return;
   }
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
index ad5e0e9ed4f1..497cd1649930 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
@@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
 #include 
-#include 
+#include 
 #include "CpuExceptionCommon.h"
 
 CONST UINTN  mDoFarReturnFlag = 0;
@@ -39,7 +39,7 @@ CommonExceptionHandler (
   //   On other   - ExceptionType contains (possibly new) exception
   //value
   //
-  Status = VmgExitHandleVc (, SystemContext);
+  Status = CcExitHandleVc (, SystemContext);
   if (!EFI_ERROR (Status)) {
 return;
   }
@@ -57,7 +57,7 @@ CommonExceptionHandler (
   //   On other   - ExceptionType contains (possibly new) exception
   //value
   //
-  Status = VmTdExitHandleVe (, SystemContext);
+  Status = CcExitHandleVe (, SystemContext);
   if (!EFI_ERROR (Status)) {
 return;
   }
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
index 

[edk2-devel] [PATCH V2 2/9] OvmfPkg: Implement CcExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

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

The base CcExitLib library provides a default limited interface. As it
does not provide full support, create an OVMF version of this library to
begin the process of providing full support of Cc guest (such as SEV-ES,
TDX) within OVMF.

Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 OvmfPkg/Library/CcExitLib/CcExitLib.c |  239 ++
 OvmfPkg/Library/CcExitLib/CcExitLib.inf   |   46 +
 OvmfPkg/Library/CcExitLib/CcExitTd.h  |   32 +
 OvmfPkg/Library/CcExitLib/CcExitVcHandler.c   | 2355 +
 OvmfPkg/Library/CcExitLib/CcExitVcHandler.h   |   53 +
 OvmfPkg/Library/CcExitLib/CcExitVeHandler.c   |  559 
 .../Library/CcExitLib/PeiDxeCcExitVcHandler.c |  103 +
 OvmfPkg/Library/CcExitLib/SecCcExitLib.inf|   48 +
 .../Library/CcExitLib/SecCcExitVcHandler.c|  109 +
 .../Library/CcExitLib/X64/TdVmcallCpuid.nasm  |  146 +
 10 files changed, 3690 insertions(+)
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitLib.c
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitLib.inf
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitTd.h
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitVcHandler.h
 create mode 100644 OvmfPkg/Library/CcExitLib/CcExitVeHandler.c
 create mode 100644 OvmfPkg/Library/CcExitLib/PeiDxeCcExitVcHandler.c
 create mode 100644 OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
 create mode 100644 OvmfPkg/Library/CcExitLib/SecCcExitVcHandler.c
 create mode 100644 OvmfPkg/Library/CcExitLib/X64/TdVmcallCpuid.nasm

diff --git a/OvmfPkg/Library/CcExitLib/CcExitLib.c 
b/OvmfPkg/Library/CcExitLib/CcExitLib.c
new file mode 100644
index ..2e9ce141f33b
--- /dev/null
+++ b/OvmfPkg/Library/CcExitLib/CcExitLib.c
@@ -0,0 +1,239 @@
+/** @file
+  CcExitLib Support Library.
+
+  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  Copyright (C) 2020 - 2022, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Check for VMGEXIT error
+
+  Check if the hypervisor has returned an error after completion of the VMGEXIT
+  by examining the SwExitInfo1 field of the GHCB.
+
+  @param[in]  Ghcb   A pointer to the GHCB
+
+  @retval  0 VMGEXIT succeeded.
+  @returnException number to be propagated, VMGEXIT processing
+ did not succeed.
+
+**/
+STATIC
+UINT64
+VmgExitErrorCheck (
+  IN GHCB  *Ghcb
+  )
+{
+  GHCB_EVENT_INJECTION  Event;
+  GHCB_EXIT_INFOExitInfo;
+  UINT64Status;
+
+  ExitInfo.Uint64 = Ghcb->SaveArea.SwExitInfo1;
+  ASSERT (
+(ExitInfo.Elements.Lower32Bits == 0) ||
+(ExitInfo.Elements.Lower32Bits == 1)
+);
+
+  Status = 0;
+  if (ExitInfo.Elements.Lower32Bits == 0) {
+return Status;
+  }
+
+  if (ExitInfo.Elements.Lower32Bits == 1) {
+ASSERT (Ghcb->SaveArea.SwExitInfo2 != 0);
+
+//
+// Check that the return event is valid
+//
+Event.Uint64 = Ghcb->SaveArea.SwExitInfo2;
+if (Event.Elements.Valid &&
+(Event.Elements.Type == GHCB_EVENT_INJECTION_TYPE_EXCEPTION))
+{
+  switch (Event.Elements.Vector) {
+case GP_EXCEPTION:
+case UD_EXCEPTION:
+  //
+  // Use returned event as return code
+  //
+  Status = Event.Uint64;
+  }
+}
+  }
+
+  if (Status == 0) {
+GHCB_EVENT_INJECTION  GpEvent;
+
+GpEvent.Uint64  = 0;
+GpEvent.Elements.Vector = GP_EXCEPTION;
+GpEvent.Elements.Type   = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
+GpEvent.Elements.Valid  = 1;
+
+Status = GpEvent.Uint64;
+  }
+
+  return Status;
+}
+
+/**
+  Perform VMGEXIT.
+
+  Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
+  then handles the return actions.
+
+  @param[in, out]  Ghcb   A pointer to the GHCB
+  @param[in]   ExitCode   VMGEXIT code to be assigned to the SwExitCode
+  field of the GHCB.
+  @param[in]   ExitInfo1  VMGEXIT information to be assigned to the
+  SwExitInfo1 field of the GHCB.
+  @param[in]   ExitInfo2  VMGEXIT information to be assigned to the
+  SwExitInfo2 field of the GHCB.
+
+  @retval  0  VMGEXIT succeeded.
+  @return Exception number to be propagated, VMGEXIT
+  processing did not succeed.
+
+**/
+UINT64
+EFIAPI
+CcExitLibVmgExit (
+  IN OUT GHCB*Ghcb,
+  IN UINT64  ExitCode,
+  IN UINT64  ExitInfo1,
+  IN UINT64  ExitInfo2
+  )
+{
+  Ghcb->SaveArea.SwExitCode  = ExitCode;
+  Ghcb->SaveArea.SwExitInfo1 = ExitInfo1;
+  Ghcb->SaveArea.SwExitInfo2 = ExitInfo2;
+
+  CcExitLibVmgSetOffsetValid (Ghcb, GhcbSwExitCode);
+  

[edk2-devel] [PATCH V2 3/9] OvmfPkg: Add CcExitLib in *.dsc

2022-11-03 Thread Min Xu
From: Min M Xu 

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

CcExitLib is designed to replace VmgExitLib. This patch adds CcExitLib in
*.dsc which import VmgExitLib. VmgExitLib in these *.dsc will be deleted
in the follwing patch so that the build will not be broken.

Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 OvmfPkg/AmdSev/AmdSevX64.dsc | 2 ++
 OvmfPkg/Bhyve/BhyveX64.dsc   | 1 +
 OvmfPkg/CloudHv/CloudHvX64.dsc   | 3 +++
 OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 ++
 OvmfPkg/Microvm/MicrovmX64.dsc   | 2 ++
 OvmfPkg/OvmfPkgIa32.dsc  | 2 ++
 OvmfPkg/OvmfPkgIa32X64.dsc   | 2 ++
 OvmfPkg/OvmfPkgX64.dsc   | 3 +++
 OvmfPkg/OvmfXen.dsc  | 1 +
 9 files changed, 18 insertions(+)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 90e8a213ef77..1b324fa48d09 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -204,6 +204,7 @@
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
@@ -229,6 +230,7 @@
 !else
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
+  CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
 
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 475b88b21a4c..3e90ae365682 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -232,6 +232,7 @@
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
   VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index 10b16104acd7..56d061464dbf 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -251,6 +251,7 @@
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
@@ -275,6 +276,7 @@
 !else
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
+  CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
 
@@ -915,6 +917,7 @@
   #
   OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf {
 
+CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
 VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
   }
   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index c0c1a15b0926..8c6edfbc2363 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -215,6 +215,7 @@
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf
@@ -237,6 +238,7 @@
 !else
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
+  CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
   
PrePiHobListPointerLib|OvmfPkg/IntelTdx/PrePiHobListPointerLibTdx/PrePiHobListPointerLibTdx.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 7eff8e2a88d9..98da7a3c9138 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -249,6 +249,7 @@
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
   
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
@@ -277,6 +278,7 @@
 !else
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
 !endif
+  CcExitLib|OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
   VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
   

[edk2-devel] [PATCH V2 1/9] UefiCpuPkg: Add CcExitLib

2022-11-03 Thread Min Xu
From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

CcExitLib is designed to support handling #VC/#VE exceptions and issuing
VMGEXIT instructions. It can be used to perform these:
  - Handling #VC exceptions
  - Handling #VE 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
CC gueste (such as SEV-ES and TDX).

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Signed-off-by: Min Xu 
---
 UefiCpuPkg/Include/Library/CcExitLib.h| 176 
 .../Library/CcExitLibNull/CcExitLibNull.c | 194 ++
 .../Library/CcExitLibNull/CcExitLibNull.inf   |  28 +++
 .../Library/CcExitLibNull/CcExitLibNull.uni   |  14 ++
 UefiCpuPkg/UefiCpuPkg.dec |   3 +
 5 files changed, 415 insertions(+)
 create mode 100644 UefiCpuPkg/Include/Library/CcExitLib.h
 create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c
 create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
 create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.uni

diff --git a/UefiCpuPkg/Include/Library/CcExitLib.h 
b/UefiCpuPkg/Include/Library/CcExitLib.h
new file mode 100644
index ..40372e10b39e
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/CcExitLib.h
@@ -0,0 +1,176 @@
+/** @file
+  Public header file for the CcExitLib.
+
+  This library class defines some routines used for below CcExit handler.
+   - Invoking the VMGEXIT instruction in support of SEV-ES and to handle
+ #VC exceptions.
+   - Handle #VE exception in TDX.
+
+  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef CC_EXIT_LIB_H_
+#define CC_EXIT_LIB_H_
+
+#include 
+#include 
+
+#define VE_EXCEPTION  20
+
+/**
+  Perform VMGEXIT.
+
+  Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
+  then handles the return actions.
+
+  @param[in, out]  Ghcb   A pointer to the GHCB
+  @param[in]   ExitCode   VMGEXIT code to be assigned to the SwExitCode
+  field of the GHCB.
+  @param[in]   ExitInfo1  VMGEXIT information to be assigned to the
+  SwExitInfo1 field of the GHCB.
+  @param[in]   ExitInfo2  VMGEXIT information to be assigned to the
+  SwExitInfo2 field of the GHCB.
+
+  @retval  0  VMGEXIT succeeded.
+  @return Exception number to be propagated, VMGEXIT
+  processing did not succeed.
+
+**/
+UINT64
+EFIAPI
+CcExitLibVmgExit (
+  IN OUT GHCB*Ghcb,
+  IN UINT64  ExitCode,
+  IN UINT64  ExitInfo1,
+  IN UINT64  ExitInfo2
+  );
+
+/**
+  Perform pre-VMGEXIT initialization/preparation.
+
+  Performs the necessary steps in preparation for invoking VMGEXIT. Must be
+  called before setting any fields within the GHCB.
+
+  @param[in, out]  GhcbA pointer to the GHCB
+  @param[in, out]  InterruptState  A pointer to hold the current interrupt
+   state, used for restoring in 
CcExitLibVmgDone ()
+
+**/
+VOID
+EFIAPI
+CcExitLibVmgInit (
+  IN OUT GHCB *Ghcb,
+  IN OUT BOOLEAN  *InterruptState
+  );
+
+/**
+  Perform post-VMGEXIT cleanup.
+
+  Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
+  called after obtaining needed fields within the GHCB.
+
+  @param[in, out]  GhcbA pointer to the GHCB
+  @param[in]   InterruptState  An indicator to conditionally (re)enable
+   interrupts
+
+**/
+VOID
+EFIAPI
+CcExitLibVmgDone (
+  IN OUT GHCB *Ghcb,
+  IN BOOLEAN  InterruptState
+  );
+
+/**
+  Marks a specified offset as valid in the GHCB.
+
+  The ValidBitmap area represents the areas of the GHCB that have been marked
+  valid. Set the bit in ValidBitmap for the input offset.
+
+  @param[in, out]  Ghcb   A pointer to the GHCB
+  @param[in]   Offset Qword offset in the GHCB to mark valid
+
+**/
+VOID
+EFIAPI
+CcExitLibVmgSetOffsetValid (
+  IN OUT GHCB   *Ghcb,
+  IN GHCB_REGISTER  Offset
+  );
+
+/**
+  Checks if a specified offset is valid in the GHCB.
+
+  The ValidBitmap area represents the areas of the GHCB that have been marked
+  valid. Return whether the bit in the ValidBitmap is set for the input offset.
+
+  @param[in]  GhcbA pointer to the GHCB
+  @param[in]  Offset  Qword offset in the GHCB to mark valid
+
+  @retval TRUEOffset is 

[edk2-devel] [PATCH V2 0/9] Rename VmgExitLib to CcExitLib

2022-11-03 Thread Min Xu
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib once was designed to provide interfaces to support #VC handler
and issue VMGEXIT instruction. After TDVF (enable TDX feature in OVMF) is
introduced, this library is updated to support #VE as well. Now the name
of VmgExitLib cannot reflect what the lib does.

This patch-set creates CcExitLib which is a simple copy of VmgExitLib
except some of the API names are renamed with a CcExitLib prefix. For
example VmgExit is renamed as CcExitLibVmgExit.

To make sure the build will not be broken by the renaming, this patch-set
first creates CcExitLib (Patch #1/2). Then VmgExitLib is replaced by
CcExitLib in UefiCpuPkg/UefiPayloadPkg/OvmfPkg (Patch #3/4/5/6). After
that VmgExitLib is deleted (Patch #7/8). At last Maintainers.txt
is updated (Patch #9).

Code: https://github.com/mxu9/edk2/tree/CcExitLib.v2

v2 changes:
 - Patch #3 is added to import CcExitLib in OvmfPkg's *.dsc. This is to
   prevent the building from being broken in the following patches.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Brijesh Singh 
Cc: Erdem Aktas 
Cc: Gerd Hoffmann 
Cc: James Bottomley 
Cc: Jiewen Yao 
Cc: Tom Lendacky 
Cc: Guo Dong 
Cc: Sean Rhodes 
Cc: James Lu 
Cc: Gua Guo 
Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Min Xu 

Min M Xu (9):
  UefiCpuPkg: Add CcExitLib
  OvmfPkg: Implement CcExitLib
  OvmfPkg: Add CcExitLib in *.dsc
  UefiCpuPkg: Use CcExitLib instead of VmgExitLib
  UefiPayloadPkg: Use CcExitLib instead of VmgExitLib
  OvmfPkg: Use CcExitLib instead of VmgExitLib
  OvmfPkg: Delete VmgExitLib
  UefiCpuPkg: Delete VmgExitLib
  Maintainers: Update the VmgExitLib to CcExitLib

 Maintainers.txt   |   2 +-
 OvmfPkg/AmdSev/AmdSevX64.dsc  |   4 +-
 OvmfPkg/Bhyve/BhyveX64.dsc|   2 +-
 OvmfPkg/CloudHv/CloudHvX64.dsc|   6 +-
 OvmfPkg/IntelTdx/IntelTdxX64.dsc  |   4 +-
 .../DxeMemEncryptSevLib.inf   |   2 +-
 .../PeiMemEncryptSevLib.inf   |   2 +-
 .../SecMemEncryptSevLib.inf   |   2 +-
 .../X64/SnpPageStateChangeInternal.c  |  10 +-
 .../VmgExitLib.c => CcExitLib/CcExitLib.c}|  23 +--
 .../CcExitLib.inf}|  19 +--
 .../CcExitTd.h}   |   6 +-
 .../CcExitVcHandler.c}| 133 +-
 .../CcExitVcHandler.h}|  10 +-
 .../CcExitVeHandler.c}|   8 +-
 .../PeiDxeCcExitVcHandler.c}  |  12 +-
 .../SecCcExitLib.inf} |  16 +--
 .../SecCcExitVcHandler.c} |  12 +-
 .../X64/TdVmcallCpuid.nasm|   4 +-
 OvmfPkg/Microvm/MicrovmX64.dsc|   4 +-
 OvmfPkg/OvmfPkgIa32.dsc   |   4 +-
 OvmfPkg/OvmfPkgIa32X64.dsc|   4 +-
 OvmfPkg/OvmfPkgX64.dsc|   6 +-
 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/PlatformPei/AmdSev.c  |  10 +-
 OvmfPkg/PlatformPei/PlatformPei.inf   |   2 +-
 .../FvbServicesRuntimeDxe.inf |   2 +-
 .../QemuFlashDxe.c|  10 +-
 .../Library/{VmgExitLib.h => CcExitLib.h} |  29 ++--
 .../CcExitLibNull.c}  |  47 +--
 .../CcExitLibNull.inf}|  14 +-
 .../Library/CcExitLibNull/CcExitLibNull.uni   |  14 ++
 .../DxeCpuExceptionHandlerLib.inf |   2 +-
 .../PeiCpuExceptionHandlerLib.inf |   2 +-
 .../PeiDxeSmmCpuException.c   |   6 +-
 .../SecPeiCpuException.c  |   6 +-
 .../SecPeiCpuExceptionHandlerLib.inf  |   2 +-
 .../SmmCpuExceptionHandlerLib.inf |   2 +-
 .../Xcode5SecPeiCpuExceptionHandlerLib.inf|   2 +-
 UefiCpuPkg/Library/MpInitLib/AmdSev.c |  10 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   2 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |   8 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c  |   2 +-
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   2 +-
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c |  10 +-
 .../Library/VmgExitLibNull/VmTdExitNull.c |  38 -
 .../Library/VmgExitLibNull/VmgExitLibNull.uni |  15 --
 UefiCpuPkg/UefiCpuPkg.dec |   4 +-
 UefiCpuPkg/UefiCpuPkg.dsc |   4 +-
 UefiPayloadPkg/UefiPayloadPkg.dsc |   2 +-
 50 files changed, 269 insertions(+), 275 deletions(-)
 rename OvmfPkg/Library/{VmgExitLib/VmgExitLib.c => CcExitLib/CcExitLib.c} (89%)
 rename OvmfPkg/Library/{VmgExitLib/VmgExitLib.inf => CcExitLib/CcExitLib.inf} 
(60%)
 rename OvmfPkg/Library/{VmgExitLib/VmTdExitHandler.h => CcExitLib/CcExitTd.h} 
(84%)
 rename OvmfPkg/Library/{VmgExitLib/VmgExitVcHandler.c => 
CcExitLib/CcExitVcHandler.c} (90%)
 rename OvmfPkg/Library/{VmgExitLib/VmgExitVcHandler.h => 
CcExitLib/CcExitVcHandler.h} (85%)
 rename 

Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread d.meneses via groups.io
I might be using the wrong term, I'm still in the beginning of learning this 
field so I apologise if I am out of my depth.
Maybe I just meant ROM memory... I thought that ROM memory was stored in flash 
memory.
The program is currently shipped in a manner that changing or formatting the 
hard drive doesn't impact its functioning.

Cheers,
Diogo Meneses


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




Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread Pedro Falcato
On Thu, Nov 3, 2022 at 10:02 PM d.meneses via groups.io  wrote:

> It needs to run from FLASH and not an EFI partition.
>
Why flash?

> It needs to run at startup before the boot loader and OS.
> This is in order to make it non-removable and unskippable, unlike apps in
> /EFI/BOOT.
> I am aware of the other options you've mentioned, I've even done it on a
> real machine.
> 
>
>

-- 
Pedro Falcato


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




Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread d.meneses via groups.io
It needs to run from FLASH and not an EFI partition.
It needs to run at startup before the boot loader and OS.
This is in order to make it non-removable and unskippable, unlike apps in 
/EFI/BOOT.
I am aware of the other options you've mentioned, I've even done it on a real 
machine.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95911): https://edk2.groups.io/g/devel/message/95911
Mute This Topic: https://groups.io/mt/94734592/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/2] .github: Add initial CodeQL config and workflow files

2022-11-03 Thread Michael D Kinney
Glad to see this works on Windows agents.  I know it will be good to switch 
back to Linux agents when stable.

See comments below.

Mike

> -Original Message-
> From: mikub...@linux.microsoft.com 
> Sent: Thursday, November 3, 2022 2:41 PM
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Kinney, Michael D 
> ; Gao, Liming
> 
> Subject: [PATCH v2 2/2] .github: Add initial CodeQL config and workflow files
> 
> From: Michael Kubacki 
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4115
> 
> Adds initial support for enabling CodeQL Code Scanning in this
> repository per the RFC:
> 
>   https://github.com/tianocore/edk2/discussions/3258
> 
> Adds the following new files:
>   - .github/workflows/codql-analysis.yml - The main GitHub workflow
> file used to setup CodeQL in the repo.
>   - .github/codeql/codeql-config.yml - The main CodeQL configuration
> file used to customize the queries and other resources the repo
> is using for CodeQL.
> 
> Cc: Sean Brogan 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Signed-off-by: Michael Kubacki 
> ---
>  .github/codeql/codeql-config.yml  | 30 ++
>  .github/codeql/edk2.qls   | 12 +++
>  .github/workflows/codeql-analysis.yml | 99 
>  3 files changed, 141 insertions(+)
> 
> diff --git a/.github/codeql/codeql-config.yml 
> b/.github/codeql/codeql-config.yml
> new file mode 100644
> index ..3e27c2fb0d28
> --- /dev/null
> +++ b/.github/codeql/codeql-config.yml
> @@ -0,0 +1,30 @@
> +## @file
> +# CodeQL configuration file for edk2.
> +#
> +# Copyright (c) Microsoft Corporation.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +name: "CodeQL config"
> +
> +# The following line disables the default queries. This is used because we 
> want to enable on query at a time by
> +# explicitly specifying each query in a "queries" array as they are enabled.
> +#
> +# See the following for more information about adding custom queries:
> +# 
> https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-
> errors/configuring-code-scanning#using-a-custom-configuration-file
> +
> +#disable-default-queries: true
> +
> +queries:
> +  - name: EDK2 CodeQL Query List
> +uses: ./.github/codeql/edk2.qls
> +
> +# We must specify a query for CodeQL to run. Until the first query is 
> enabled, enable the security query suite but
> +# exclude all problem levels from impacting the results. After the first 
> query is enabled, this filter can be relaxed
> +# to find the level of problems desired from the query.
> +query-filters:
> +- exclude:
> +problem.severity:
> +  - error
> +  - warning
> +  - recommendation
> diff --git a/.github/codeql/edk2.qls b/.github/codeql/edk2.qls
> new file mode 100644
> index ..0efc7dca52db
> --- /dev/null
> +++ b/.github/codeql/edk2.qls
> @@ -0,0 +1,12 @@
> +---
> +- description: EDK2 (C++) queries
> +
> +# Bring in all queries from the official cpp-queries suite so individual 
> queries can be explicitly enabled.
> +
> +- queries: '.'
> +  from: codeql/cpp-queries
> +
> +# Enable individual queries below.
> +
> +- include:
> +id: cpp/conditionallyuninitializedvariable
> diff --git a/.github/workflows/codeql-analysis.yml 
> b/.github/workflows/codeql-analysis.yml
> new file mode 100644
> index ..4ab8be04ecbe
> --- /dev/null
> +++ b/.github/workflows/codeql-analysis.yml
> @@ -0,0 +1,99 @@
> +# @file
> +# GitHub Workflow for CodeQL Analysis
> +#
> +# Copyright (c) Microsoft Corporation.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +name: "CodeQL"
> +
> +on:
> +  push:
> +branches:
> +  - master
> +  pull_request:
> +branches:
> +  - master
> +paths-ignore:
> +  - '**/*.bat'
> +  - '**/*.md'
> +  - '**/*.py'
> +  - '**/*.rst'
> +  - '**/*.sh'
> +  - '**/*.txt'
> +
> +  schedule:
> +# https://crontab.guru/#20_23_*_*_4
> +- cron: '20 23 * * 4'
> +
> +jobs:
> +  analyze:
> +name: Analyze
> +runs-on: windows-2019
> +permissions:
> +  actions: read
> +  contents: read
> +  security-events: write
> +
> +strategy:
> +  fail-fast: false
> +  matrix:
> +package: [
> +  "ArmPkg",
> +  "CryptoPkg",
> +  "DynamicTablesPkg",
> +  "FatPkg",
> +  "FmpDevicePkg",
> +  "IntelFsp2Pkg",
> +  "IntelFsp2WrapperPkg",
> +  "MdeModulePkg",
> +  "MdePkg",
> +  "PcAtChipsetPkg",
> +  "PrmPkg",
> +  "SecurityPkg",
> +  "ShellPkg",
> +  "SourceLevelDebugPkg",
> +  "StandaloneMmPkg",
> +  "UefiCpuPkg",
> +  "UnitTestFrameworkPkg"]
> +
> +steps:
> +- name: Checkout repository
> +  uses: actions/checkout@v3
> +
> +# Initializes the CodeQL tools for scanning.
> +- name: Initialize CodeQL
> +  uses: github/codeql-action/init@v2
> +  with:
> +  

Re: [edk2-devel] [PATCH v2 1/2] Maintainers.txt: Add .github maintainers and reviewers

2022-11-03 Thread Michael D Kinney
Reviewed-by: Michael D Kinney 

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Michael Kubacki
> Sent: Thursday, November 3, 2022 2:40 PM
> To: devel@edk2.groups.io
> Cc: Andrew Fish ; Leif Lindholm ; 
> Kinney, Michael D ;
> Sean Brogan 
> Subject: [edk2-devel] [PATCH v2 1/2] Maintainers.txt: Add .github maintainers 
> and reviewers
> 
> From: Michael Kubacki 
> 
> Adds the maintainers and reviewers for the new .github directory
> being added to hold GitHub workflows files.
> 
> Cc: Andrew Fish 
> Cc: Leif Lindholm 
> Cc: Michael D Kinney 
> Cc: Sean Brogan 
> Signed-off-by: Michael Kubacki 
> ---
>  Maintainers.txt | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Maintainers.txt b/Maintainers.txt
> index 889990fa566f..a2727fa7bd42 100644
> --- a/Maintainers.txt
> +++ b/Maintainers.txt
> @@ -117,6 +117,12 @@ M: Michael Kubacki  
> [makubacki]
>  R: Michael D Kinney  [mdkinney]
>  R: Liming Gao  [lgao4]
> 
> +.github/
> +F: .github/
> +M: Sean Brogan  [spbrogan]
> +M: Michael Kubacki  [makubacki]
> +R: Michael D Kinney  [mdkinney]
> +
>  .mergify/
>  F: .mergify/
>  M: Michael D Kinney  [mdkinney]
> --
> 2.28.0.windows.1
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#95907): https://edk2.groups.io/g/devel/message/95907
> Mute This Topic: https://groups.io/mt/94793993/1643496
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [michael.d.kin...@intel.com]
> -=-=-=-=-=-=
> 



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




[edk2-devel] [PATCH v2 2/2] .github: Add initial CodeQL config and workflow files

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

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

Adds initial support for enabling CodeQL Code Scanning in this
repository per the RFC:

  https://github.com/tianocore/edk2/discussions/3258

Adds the following new files:
  - .github/workflows/codql-analysis.yml - The main GitHub workflow
file used to setup CodeQL in the repo.
  - .github/codeql/codeql-config.yml - The main CodeQL configuration
file used to customize the queries and other resources the repo
is using for CodeQL.

Cc: Sean Brogan 
Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Michael Kubacki 
---
 .github/codeql/codeql-config.yml  | 30 ++
 .github/codeql/edk2.qls   | 12 +++
 .github/workflows/codeql-analysis.yml | 99 
 3 files changed, 141 insertions(+)

diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml
new file mode 100644
index ..3e27c2fb0d28
--- /dev/null
+++ b/.github/codeql/codeql-config.yml
@@ -0,0 +1,30 @@
+## @file
+# CodeQL configuration file for edk2.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+name: "CodeQL config"
+
+# The following line disables the default queries. This is used because we 
want to enable on query at a time by
+# explicitly specifying each query in a "queries" array as they are enabled.
+#
+# See the following for more information about adding custom queries:
+# 
https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-a-custom-configuration-file
+
+#disable-default-queries: true
+
+queries:
+  - name: EDK2 CodeQL Query List
+uses: ./.github/codeql/edk2.qls
+
+# We must specify a query for CodeQL to run. Until the first query is enabled, 
enable the security query suite but
+# exclude all problem levels from impacting the results. After the first query 
is enabled, this filter can be relaxed
+# to find the level of problems desired from the query.
+query-filters:
+- exclude:
+problem.severity:
+  - error
+  - warning
+  - recommendation
diff --git a/.github/codeql/edk2.qls b/.github/codeql/edk2.qls
new file mode 100644
index ..0efc7dca52db
--- /dev/null
+++ b/.github/codeql/edk2.qls
@@ -0,0 +1,12 @@
+---
+- description: EDK2 (C++) queries
+
+# Bring in all queries from the official cpp-queries suite so individual 
queries can be explicitly enabled.
+
+- queries: '.'
+  from: codeql/cpp-queries
+
+# Enable individual queries below.
+
+- include:
+id: cpp/conditionallyuninitializedvariable
diff --git a/.github/workflows/codeql-analysis.yml 
b/.github/workflows/codeql-analysis.yml
new file mode 100644
index ..4ab8be04ecbe
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,99 @@
+# @file
+# GitHub Workflow for CodeQL Analysis
+#
+# Copyright (c) Microsoft Corporation.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+name: "CodeQL"
+
+on:
+  push:
+branches:
+  - master
+  pull_request:
+branches:
+  - master
+paths-ignore:
+  - '**/*.bat'
+  - '**/*.md'
+  - '**/*.py'
+  - '**/*.rst'
+  - '**/*.sh'
+  - '**/*.txt'
+
+  schedule:
+# https://crontab.guru/#20_23_*_*_4
+- cron: '20 23 * * 4'
+
+jobs:
+  analyze:
+name: Analyze
+runs-on: windows-2019
+permissions:
+  actions: read
+  contents: read
+  security-events: write
+
+strategy:
+  fail-fast: false
+  matrix:
+package: [
+  "ArmPkg",
+  "CryptoPkg",
+  "DynamicTablesPkg",
+  "FatPkg",
+  "FmpDevicePkg",
+  "IntelFsp2Pkg",
+  "IntelFsp2WrapperPkg",
+  "MdeModulePkg",
+  "MdePkg",
+  "PcAtChipsetPkg",
+  "PrmPkg",
+  "SecurityPkg",
+  "ShellPkg",
+  "SourceLevelDebugPkg",
+  "StandaloneMmPkg",
+  "UefiCpuPkg",
+  "UnitTestFrameworkPkg"]
+
+steps:
+- name: Checkout repository
+  uses: actions/checkout@v3
+
+# Initializes the CodeQL tools for scanning.
+- name: Initialize CodeQL
+  uses: github/codeql-action/init@v2
+  with:
+languages: 'cpp'
+# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 
'python', 'ruby' ]
+# Learn more about CodeQL language support at 
https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/
+config-file: ./.github/codeql/codeql-config.yml
+# Note: Add new queries to codeql-config.yml file as they are enabled.
+
+- name: Install/Upgrade pip Modules
+  run: pip install -r pip-requirements.txt --upgrade
+
+- name: Use Node.js 19.x
+  uses: actions/setup-node@v3
+  with:
+  node-version: 19.x
+
+- name: Install cspell npm
+  run: npm install -g cspell@5.20.0
+
+- name: Setup
+  run: stuart_setup -c 

[edk2-devel] [PATCH v2 0/2] Enable Initial CodeQL Support

2022-11-03 Thread Michael Kubacki
From: Michael Kubacki 

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

This patch series enables initial CodeQL support within the edk2
repository.

After this patch, a CodeQL Analyze step will run on a subset of
edk2 packages in Pull Requests. The plan to scale additional CodeQL
queries is documented in the RFC and it is recommeneded to read
that for more detail:

https://github.com/tianocore/edk2/discussions/3258#discussioncomment-3682099

In summary, this change will:

- Main workflow file - .github/workflows/codeql-analysis.yml

1. Add a code scanning workflow with the CodeQL Analysis GitHub action
2. Build packages on Windows + VS2019
3. Perform CodeQL analysis on the build results

- Custom configuration file - .github/codeql/codeql-config.yml

1. Specify the edk2 CodeQL query set
2. Apply a query filter to exclude errors, warnings, and
   recommendations

- edk2 query set file - .github/codeql/edk2.qls

1. Enable a single query: cpp/conditionallyuninitializedvariable

Per the RFC, this enables CodeQL but does not allow any alerts
by suppressing all of the severity levels.

When the code changes necessary to resolve problems found with
cpp/conditionallyuninitializedvariable are checked in, the severity
filter can be adjusted such that query is enabled.

V2 Changes:

1. Switch from Ubuntu + GCC5

As noted in the v1 series, there is an occassional issue with
filesystem paths on Ubuntu + GCC at the moment that prevents this
change from being checked in. A bug has been filed against CodeQL
and  the CodeQL team has confirmed this is a bug. They were not
aware of the bug until this report.

https://github.com/github/codeql-action/issues/1338

In the meantime, this v2 patch series places the workflow on
Windows with VS2019 which has been reliable across testing.

Cc: Andrew Fish 
Cc: Leif Lindholm 
Cc: Liming Gao 
Cc: Michael D Kinney 
Cc: Sean Brogan 
Signed-off-by: Michael Kubacki 

Michael Kubacki (2):
  Maintainers.txt: Add .github maintainers and reviewers
  .github: Add initial CodeQL config and workflow files

 .github/codeql/codeql-config.yml  | 30 ++
 .github/codeql/edk2.qls   | 12 +++
 .github/workflows/codeql-analysis.yml | 99 
 Maintainers.txt   |  6 ++
 4 files changed, 147 insertions(+)
 create mode 100644 .github/codeql/codeql-config.yml
 create mode 100644 .github/codeql/edk2.qls
 create mode 100644 .github/workflows/codeql-analysis.yml

-- 
2.28.0.windows.1



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




Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread Andrew Fish via groups.io


> On Nov 3, 2022, at 12:11 PM, d.meneses via groups.io 
>  wrote:
> 
> Yes I also believe I'm threading a XY problem. 
> 
> Let's simplify my learning and set the goal to: add an UEFI application to 
> OVMF so that it runs natively on startup.
> 
> Does this make more sense?
> 
> I followed the same process and I can use UEFITool to confirm there's an 
> UefiApplication inside the OVMF image.
> 
> How can I make it run?

Do you need to run it from FLASH? Or do you just want to run it? 

What I usually do with QEMU is pass -hda fat:rw:Build/OvmfX64/DEBUG_XCODE5/X64 
to mount a directory on my system in QEMU. This should show up in the UEFI 
Shell as FS0: if you don’t have any other disks. The path is the build output, 
so you need to match what you built. So DEBUG_GCC??? Vs DEBUG_XCODE, as this 
path encodes the build target, compiler, etc.

Then when you boot to the UEFI Shell you just need to mount the disk and run 
your app. 

Fs0:
MyApp.efi

You can also redirect the text output of your app to a file, and since fs0: is 
just your build directory you can get the output out of the VM. 

>From the UEFI Shell you can `reset -s` to shut down the VM.

If you place a startup.nsh the UEFI Shell command should run those commands 
when launched. 

It is also possible to make a FAT32 disk image and boot your app directly, just 
like an OS loader[1]. Just copy your app to /EFI/BOOT/BOOTx64.EFI in the disk 
image and mount the disk image from the QEMU command line.

[1] 
https://uefi.org/specs/UEFI/2.10/03_Boot_Manager.html#removable-media-boot-behavior

Thanks,

Andrew Fish


> 



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




Re: [edk2-devel] [PATCH V4] MdeModulePkg: Memory Corruption Error in CapsuleRuntimeDxe

2022-11-03 Thread Michael D Kinney
Also...would it be a simpler policy to fail the capsule update all together if 
any of the
3 allocations fail?  That way, there is no case where is "may fail".

Mike

> -Original Message-
> From: Kinney, Michael D 
> Sent: Thursday, November 3, 2022 2:21 PM
> To: Desimone, Nathaniel L ; 
> devel@edk2.groups.io; Kinney, Michael D 
> Cc: Gao, Liming ; Jiang, Guomin 
> ; Wang, Jian J 
> Subject: RE: [PATCH V4] MdeModulePkg: Memory Corruption Error in 
> CapsuleRuntimeDxe
> 
> Hi Nate,
> 
> The "may fail" messages look a bit odd.  Is this due to the fact that 
> CapsuleRuntimeDxe is in X64 mode,
> but this module does not know if PEI Phase will process the capsule in IA32 
> or X64 execution mode?
> 
> We have a PCD that is set if the DXE IPL needs to switch modes.  Can we use 
> that information?
> 
> These "may fail" messages will only be generated if there is enough memory to 
> allocate the capsule
> image, but not the page tables and/or stack.  Correct?
> 
> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: Desimone, Nathaniel L 
> > Sent: Tuesday, October 25, 2022 3:30 PM
> > To: devel@edk2.groups.io
> > Cc: Gao, Liming ; Jiang, Guomin 
> > ; Wang, Jian J ;
> > Kinney, Michael D 
> > Subject: [PATCH V4] MdeModulePkg: Memory Corruption Error in 
> > CapsuleRuntimeDxe
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4112
> >
> > In AllocateReservedMemoryBelow4G(), if gBS->AllocatePages()
> > returns an error, and ASSERTs are disabled, then the
> > function will overwrite memory from 0x -> (0x + Size).
> >
> > Cc: Liming Gao 
> > Cc: Guomin Jiang 
> > Cc: Jian J Wang 
> > Cc: Michael D Kinney 
> > Signed-off-by: Nate DeSimone 
> > ---
> >  .../X64/SaveLongModeContext.c | 25 ---
> >  1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git 
> > a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> > b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> > index dab297dd0a..a8c5de8764 100644
> > --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> > @@ -38,6 +38,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> >@param  Size  Size of memory to allocate.
> >
> >@return Allocated Address for output.
> > +  @return NULL - Memory allocation failed.
> >
> >  **/
> >  VOID *
> > @@ -59,7 +60,15 @@ AllocateReservedMemoryBelow4G (
> >Pages,
> >
> >);
> > -  ASSERT_EFI_ERROR (Status);
> > +  if (EFI_ERROR (Status)) {
> > +DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): %r\n", 
> > Status));
> > +return NULL;
> > +  }
> > +
> > +  if (Address == 0) {
> > +DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): 
> > AllocatePages() returned NULL"));
> > +return NULL;
> > +  }
> >
> >Buffer = (VOID *)(UINTN)Address;
> >ZeroMem (Buffer, Size);
> > @@ -159,14 +168,23 @@ PrepareContextForCapsulePei (
> >DEBUG ((DEBUG_INFO, "CapsuleRuntimeDxe X64 TotalPagesNum - 0x%x 
> > pages\n", TotalPagesNum));
> >
> >LongModeBuffer.PageTableAddress = 
> > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G 
> > (EFI_PAGES_TO_SIZE
> > (TotalPagesNum));
> > -  ASSERT (LongModeBuffer.PageTableAddress != 0);
> > +  if (LongModeBuffer.PageTableAddress == 0) {
> > +DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> > saved, "));
> > +DEBUG ((DEBUG_ERROR, "PageTableAddress allocation failed. Capsule in 
> > PEI may fail!\n"));
> > +return;
> > +  }
> >
> >//
> >// Allocate stack
> >//
> >LongModeBuffer.StackSize= PcdGet32 
> > (PcdCapsulePeiLongModeStackSize);
> >LongModeBuffer.StackBaseAddress = 
> > (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (PcdGet32
> > (PcdCapsulePeiLongModeStackSize));
> > -  ASSERT (LongModeBuffer.StackBaseAddress != 0);
> > +  if (LongModeBuffer.StackBaseAddress == 0) {
> > +DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> > saved, "));
> > +DEBUG ((DEBUG_ERROR, "StackBaseAddress allocation failed. Capsule in 
> > PEI may fail!\n"));
> > +gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum);
> > +return;
> > +  }
> >
> >Status = gRT->SetVariable (
> >EFI_CAPSULE_LONG_MODE_BUFFER_NAME,
> > @@ -189,6 +207,7 @@ PrepareContextForCapsulePei (
> >);
> >} else {
> >  DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> > saved: %r. Capsule in PEI may fail!\n", Status));
> > +gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum);
> >  gBS->FreePages (LongModeBuffer.StackBaseAddress, EFI_SIZE_TO_PAGES 
> > (LongModeBuffer.StackSize));
> >}
> >  }
> > --
> > 2.27.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online 

Re: [edk2-devel] [PATCH V4] MdeModulePkg: Memory Corruption Error in CapsuleRuntimeDxe

2022-11-03 Thread Michael D Kinney
Hi Nate,

The "may fail" messages look a bit odd.  Is this due to the fact that 
CapsuleRuntimeDxe is in X64 mode,
but this module does not know if PEI Phase will process the capsule in IA32 or 
X64 execution mode?

We have a PCD that is set if the DXE IPL needs to switch modes.  Can we use 
that information?

These "may fail" messages will only be generated if there is enough memory to 
allocate the capsule
image, but not the page tables and/or stack.  Correct?

Thanks,

Mike

> -Original Message-
> From: Desimone, Nathaniel L 
> Sent: Tuesday, October 25, 2022 3:30 PM
> To: devel@edk2.groups.io
> Cc: Gao, Liming ; Jiang, Guomin 
> ; Wang, Jian J ;
> Kinney, Michael D 
> Subject: [PATCH V4] MdeModulePkg: Memory Corruption Error in CapsuleRuntimeDxe
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4112
> 
> In AllocateReservedMemoryBelow4G(), if gBS->AllocatePages()
> returns an error, and ASSERTs are disabled, then the
> function will overwrite memory from 0x -> (0x + Size).
> 
> Cc: Liming Gao 
> Cc: Guomin Jiang 
> Cc: Jian J Wang 
> Cc: Michael D Kinney 
> Signed-off-by: Nate DeSimone 
> ---
>  .../X64/SaveLongModeContext.c | 25 ---
>  1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git 
> a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> index dab297dd0a..a8c5de8764 100644
> --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c
> @@ -38,6 +38,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>@param  Size  Size of memory to allocate.
> 
>@return Allocated Address for output.
> +  @return NULL - Memory allocation failed.
> 
>  **/
>  VOID *
> @@ -59,7 +60,15 @@ AllocateReservedMemoryBelow4G (
>Pages,
>
>);
> -  ASSERT_EFI_ERROR (Status);
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): %r\n", 
> Status));
> +return NULL;
> +  }
> +
> +  if (Address == 0) {
> +DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): 
> AllocatePages() returned NULL"));
> +return NULL;
> +  }
> 
>Buffer = (VOID *)(UINTN)Address;
>ZeroMem (Buffer, Size);
> @@ -159,14 +168,23 @@ PrepareContextForCapsulePei (
>DEBUG ((DEBUG_INFO, "CapsuleRuntimeDxe X64 TotalPagesNum - 0x%x pages\n", 
> TotalPagesNum));
> 
>LongModeBuffer.PageTableAddress = 
> (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (EFI_PAGES_TO_SIZE
> (TotalPagesNum));
> -  ASSERT (LongModeBuffer.PageTableAddress != 0);
> +  if (LongModeBuffer.PageTableAddress == 0) {
> +DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> saved, "));
> +DEBUG ((DEBUG_ERROR, "PageTableAddress allocation failed. Capsule in PEI 
> may fail!\n"));
> +return;
> +  }
> 
>//
>// Allocate stack
>//
>LongModeBuffer.StackSize= PcdGet32 
> (PcdCapsulePeiLongModeStackSize);
>LongModeBuffer.StackBaseAddress = 
> (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (PcdGet32
> (PcdCapsulePeiLongModeStackSize));
> -  ASSERT (LongModeBuffer.StackBaseAddress != 0);
> +  if (LongModeBuffer.StackBaseAddress == 0) {
> +DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> saved, "));
> +DEBUG ((DEBUG_ERROR, "StackBaseAddress allocation failed. Capsule in PEI 
> may fail!\n"));
> +gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum);
> +return;
> +  }
> 
>Status = gRT->SetVariable (
>EFI_CAPSULE_LONG_MODE_BUFFER_NAME,
> @@ -189,6 +207,7 @@ PrepareContextForCapsulePei (
>);
>} else {
>  DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be 
> saved: %r. Capsule in PEI may fail!\n", Status));
> +gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum);
>  gBS->FreePages (LongModeBuffer.StackBaseAddress, EFI_SIZE_TO_PAGES 
> (LongModeBuffer.StackSize));
>}
>  }
> --
> 2.27.0.windows.1



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




Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread d.meneses via groups.io
Yes I also believe I'm threading a XY problem.

Let's simplify my learning and set the goal to: add an UEFI application to OVMF 
so that it runs natively on startup.

Does this make more sense?

I followed the same process and I can use UEFITool to confirm there's an 
UefiApplication inside the OVMF image.

How can I make it run?


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95902): https://edk2.groups.io/g/devel/message/95902
Mute This Topic: https://groups.io/mt/94734592/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] MdeModulePkg:Add Warm Reset for Xhc

2022-11-03 Thread Pedro Falcato
On Thu, Nov 3, 2022 at 3:53 PM zhoucheng  wrote:

> Description according to Chapter 7.5.2 of USB 3.2 spec protocol.
> When the Usb state machine is in Inactive, the software is required
> to perform a warm reset operation.
>
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Cheng Zhou 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 14 ++
>  1 file changed, 14 insertions(+)
>
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index c05431ff30ec..938c8e2e28f7 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -558,6 +558,20 @@ XhcSetRootHubPortFeature (
>State |= XHC_PORTSC_RESET;
>XhcWriteOpReg (Xhc, Offset, State);
>XhcWaitOpRegBit (Xhc, Offset, XHC_PORTSC_PRC, TRUE,
> XHC_GENERIC_TIMEOUT);
> +
> +  //
> +  // Usb 3.2 spec 7.5.2
> +  // When the USB state machine is Inactive state, the device is
> abnormal.
> +  // eSS.Inactive is a state where a link has failed Enhanced
> SuperSpeed operation.Software
> +  // is required for warm reset intervention.This flag only applies
> to USB3 protocol ports.
> +  //
> +  State = XhcReadOpReg (Xhc, Offset);
> +  if State & 0x1e0) >> 5) == 6) && ((State & 3) == 0)) {
> +State |= 0x8000;
>
Please use defines for all of these magic values, it improves readability
so much.

> +XhcWriteOpReg (Xhc, Offset, State);
> +XhcWaitOpRegBit (Xhc, Offset, XHC_PORTSC_PRC, TRUE,
> XHC_GENERIC_TIMEOUT);
> +DEBUG ((DEBUG_INFO, "Warm Reset Successful! \n"));
> +  }
>break;
>
>  case EfiUsbPortPower:
> --
> 2.17.1
>
>
>
> 
>
>
>

-- 
Pedro Falcato


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95901): https://edk2.groups.io/g/devel/message/95901
Mute This Topic: https://groups.io/mt/94760214/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] IntelFsp2Pkg: FSP should support input UPD as NULL.

2022-11-03 Thread Chiu, Chasel


Hi Ted,

Please see my reply below inline.

Thanks,
Chasel


> -Original Message-
> From: Kuo, Ted 
> Sent: Wednesday, November 2, 2022 7:32 PM
> To: devel@edk2.groups.io; Chiu, Chasel 
> Cc: Desimone, Nathaniel L ; Zeng, Star
> 
> Subject: RE: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support
> input UPD as NULL.
> 
> Hi Chasel,
> 
> I have few comments. Please find [Ted] inline.
> 
> Thanks,
> Ted
> 
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chiu,
> Chasel
> Sent: Wednesday, November 2, 2022 1:46 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel ; Desimone, Nathaniel L
> ; Zeng, Star 
> Subject: [edk2-devel] [PATCH v2] IntelFsp2Pkg: FSP should support input
> UPD as NULL.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4114
> 
> FSP specification supports input UPD as NULL cases which FSP will use built-
> in UPD region instead.
> FSP should not return INVALID_PARAMETER in such cases.
> 
> In FSP-T entry point case, the valid FSP-T UPD region pointer will be passed
> to platform FSP code to consume.
> In FSP-M and FSP-S cases, valid UPD pointer will be decided when updating
> corresponding pointer field in FspGlobalData.
> 
> Cc: Nate DeSimone 
> Cc: Star Zeng 
> Signed-off-by: Chasel Chiu 
> ---
>  IntelFsp2Pkg/FspSecCore/SecFspApiChk.c | 12 ++--
>  IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm | 73
> +++--
> 
>  IntelFsp2Pkg/FspSecCore/X64/FspApiEntryT.nasm  | 40
> ++--
>  3 files changed, 91 insertions(+), 34 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> index a44fbf2a50..5f59938518 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFspApiChk.c
> @@ -44,6 +44,8 @@ FspApiCallingCheck (
>  //
>  if (((UINTN)FspData != MAX_ADDRESS) && ((UINTN)FspData !=
> MAX_UINT32)) {
>Status = EFI_UNSUPPORTED;
> +} else if (ApiParam == NULL) {
> +  Status = EFI_SUCCESS;
>  } else if (EFI_ERROR (FspUpdSignatureCheck (ApiIdx, ApiParam))) {
>Status = EFI_INVALID_PARAMETER;
>  }
> @@ -67,9 +69,13 @@ FspApiCallingCheck (
>  } else {
>if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
>  Status = EFI_UNSUPPORTED;
> -  } else if (EFI_ERROR (FspUpdSignatureCheck (FspSiliconInitApiIndex,
> ApiParam))) {
> -Status = EFI_INVALID_PARAMETER;
>} else if (ApiIdx == FspSiliconInitApiIndex) {
> +if (ApiParam == NULL) {
> +  Status = EFI_SUCCESS;
> +} else if (EFI_ERROR (FspUpdSignatureCheck (FspSiliconInitApiIndex,
> ApiParam))) {
> +  Status = EFI_INVALID_PARAMETER;
> +}
> +
>  //
>  // Reset MultiPhase NumberOfPhases to zero
>  //
> @@ -89,6 +95,8 @@ FspApiCallingCheck (
>  } else {
>if (FspData->Signature != FSP_GLOBAL_DATA_SIGNATURE) {
>  Status = EFI_UNSUPPORTED;
> +  } else if (ApiParam == NULL) {
> +Status = EFI_SUCCESS;
>} else if (EFI_ERROR (FspUpdSignatureCheck (FspSmmInitApiIndex,
> ApiParam))) {
>  Status = EFI_INVALID_PARAMETER;
>}
> diff --git a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> index 61030a843b..73821ad22a 100644
> --- a/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> +++ b/IntelFsp2Pkg/FspSecCore/Ia32/FspApiEntryT.nasm
> @@ -21,7 +21,7 @@ extern   ASM_PFX(PcdGet32
> (PcdFspReservedBufferSize))
>  ; Following functions will be provided in PlatformSecLib  ;  extern
> ASM_PFX(AsmGetFspBaseAddress) -extern
> ASM_PFX(AsmGetFspInfoHeader)
> +extern ASM_PFX(AsmGetFspInfoHeaderNoStack)
>  ;extern ASM_PFX(LoadMicrocode); @todo: needs a weak
> implementation
>  extern ASM_PFX(SecPlatformInit)   ; @todo: needs a weak implementation
>  extern ASM_PFX(SecCarInit)
> @@ -160,6 +160,47 @@ endstruc
>   RET_ESI_EXT   mm7
>  %endmacro
> 
> +%macro CALL_EDI  1
> +
> +  mov edi,  %%ReturnAddress
> +  jmp %1
> +%%ReturnAddress:
> +
> +%endmacro
> +
> +%macro CALL_EBP 1
> +  mov ebp, %%ReturnAddress
> +  jmp %1
> +%%ReturnAddress:
> +%endmacro
> +
> +%macro RET_EBP 0
> +  jmp ebp   ; restore EIP from EBP
> +%endmacro
> +
> +;
> +; Load UPD region pointer in ECX
> +;
> +global ASM_PFX(LoadUpdPointerToECX)
> +ASM_PFX(LoadUpdPointerToECX):
> +  ;
> +  ; esp + 4 is input UPD parameter
> +  ; If esp + 4 is NULL the default UPD should be used
> +  ; ecx will be the UPD region that should be used
> +  ;
> +  mov   ecx, dword [esp + 4]
> +  cmp   ecx, 0
> +  jnz   ParamValid
> +
> +  ;
> +  ; Fall back to default UPD region
> +  ;
> +  CALL_EDI  ASM_PFX(AsmGetFspInfoHeaderNoStack)
> +  mov   ecx, DWORD [eax + 01Ch]  ; Read FsptImageBaseAddress
> +  add   ecx, DWORD [eax + 024h]  ; Get Cfg Region base address =
> 

Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread Pedro Falcato
Hi,

DEPEX (AIUI, I might be playing loose with language here) is essentially a
bunch of conditions you can package with your .efi that explain how your
.efi depends on protocols.
If you set it to TRUE, it will *always* run. If you set it to FALSE, it
will *never* run (because it will always evaluate to FALSE).

On Thu, Nov 3, 2022 at 3:23 PM d.meneses via groups.io  wrote:

> Thank you Andrew for this information.
> I set it to *true* cause the builder was asking for a *Depex section*.
> Setting it to *false allows QEMU* to boot properly.
>
By setting DEPEX to False, you're making sure it will *never* run ;)

Do note that UEFI_DRIVER does not require a DEPEX section, only DXE_DRIVERs
do.
Per
https://edk2-docs.gitbook.io/edk-ii-inf-specification/3_edk_ii_inf_file_format/314_-depex-_sections
:
"Drivers with MODULE_TYPE set to SEC, PEI_CORE, DXE_CORE, SMM_CORE,
UEFI_DRIVER and UEFI_APPLICATION cannot have [Depex] sections. Libraries
and modules that are USER_DEFINED may have a [Depex] section. All remaining
drivers, PEIM, DXE_DRIVER, DXE_SAL_DRIVER, DXE_RUNTIME_DRIVER and
DXE_SMM_DRIVER module types must have a [Depex] section."

> Nonetheless, the driver *doesn't seem to be called*... yet.
>
> Concerning Pedro's suggestion (Olá!!!), thank you for pointing me to the
> DebugLib, I'll look into it.
>
Olá! :)

> Nonetheless, I'll need to *use ConInt and ConOut in production*.
>
Are you sure you need ConIn and ConOut in a driver? Maybe you have your
priorities wrong.
IMO it only makes sense on a UEFI app (where you would do app-like things,
like under a normal operating system), and not on a UEFI driver (for which
I find printing to an actual screen or getting input really backwards).

> I am aware of a DXE program that does it. Maybe I was passed the wrong
> information and the program is running on another phase...
> Anyhow, in theory I'd be able to install the I/O protocols in the DXE
> phase in order to be able to use them. Right?
> The *TerminalDxe.inf*, a *UEFI driver*, states:
> *Terminal module installs Simple Text Input(ex)/Out protocols for serial
> devices*
>
I think you could in theory add the Simple Text In/Output protocols to your
depex. But why???
This smells like an X Y problem through and through.

>
> I think assumed erroneously that the *OvmfX64.fdf* is setting the
> ordering of the DXE drivers.
> After Andrew's answer I realised that may actually be done in the *Depex
> Section?*
>
AIUI, generally you're not supposed to give a damn about ordering if you're
a well behaved UEFI driver model driver, hence why UEFI_DRIVER doesn't even
support DEPEX.

>
> I'll read its specification now in order to better understand how to use
> it.
>
> Nonetheless, I tried turning it from a *DXE_DRIVER* into a *UEFI_DRIVER*
> and it's still not natively being listed in EFI Shell's *drivers *command.
> I don't see yet how mine differs from *TerminalDxe*. Maybe it's crashing
> and being unloaded.
>
> Maybe it's simpler than all of this.
> My true goal is: my program needs to be shipped with the BIOS image in
> ROM and run for sure on every boot, with no possibility of being
> *circumvented*.
> I have also read that some DXE drivers are not guaranteed to run if
> something like fast boot is activated.
> Taking that in consideration, what module type should I create to achieve
> my goal?
>
Is it a program? Is it a driver? Do you want it to run on DXE or on PEI?

> Finally, is there any documentation on actual programming using EDK2?
>
Yes. See the UEFI spec, UEFI PI spec (if you're programming for PEI).
For more EDK2-ish and less official stuff, see
https://edk2-docs.gitbook.io/edk-ii-module-writer-s-guide/ (and other
similar specs if needed).

> Say, which functions can I use to read user input?
> Or what dependencies do I have to include as LibraryClasses if I want to
> use a certain function?
>

Go to the library you want to pull, see the .inf. It should have a
LIBRARY_CLASS. Add it to your [LibraryClasses] for your module's .inf.
Then in your .dsc add that same library class as
LIBRARYCLASS|. Note that you may need to add that
library's package to your .inf's [Packages].

Why is this so convoluted? EDK2 is stupidly overridable and generic. For
example, your driver may depend on a OrderedCollectionLib, but the person
building a platform may want you to use
a  instead of MdePkg's
BaseOrderedCollectionRedBlackTreeLib, so they override it in their .dsc.

Note that this is all very complex and described by a spec (
https://edk2-docs.gitbook.io/edk-ii-build-specification/) plus whatever
nuggets of wisdom the Intel EFI OGs put out from time to time :)

I (biasedly) recommend you look into my Ext4Pkg (
https://github.com/tianocore/edk2-platforms/tree/master/Features/Ext4Pkg)
for a good example of a simple DXE driver with some dependencies on other
libraries.
If you want to take a look at a manageable, smaller platform that overrides
a bunch of libraries (and see the e x t e n s i b l e in action!), see our

Re: [edk2-devel] [PATCH] CryptoPkg/Readme.md: typo and grammar fixes

2022-11-03 Thread Michael D Kinney
Hi Laszlo,

I think we should consider expending the meaning of PCD to allow
multiple algos and update lib implementation to support multiple.

This should not have a size impact for platforms that only want one
algo.  And should also be backwards compatible to expand meaning to
support multiple.

Let's go with your updated patch that leaves it single algo to get
the Readme.md fixed now.  We can enter new BZs feature requests to
expand PCD from single to multiple and expand lib to support multiple.

Thanks,

Mike

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Laszlo Ersek
> Sent: Thursday, November 3, 2022 7:35 AM
> To: Kinney, Michael D ; devel@edk2.groups.io
> Cc: Zurcher, Christopher ; Jiang, Guomin 
> ; Wang, Jian J
> ; Yao, Jiewen ; Lu, Xiaoyu1 
> ; Sukerkar, Amol N
> 
> Subject: Re: [edk2-devel] [PATCH] CryptoPkg/Readme.md: typo and grammar fixes
> 
> Hi Mike,
> 
> On 11/02/22 17:48, Kinney, Michael D wrote:
> > Hi Laszlo,
> >
> > Thank you for all the updates.  One comment below.
> >
> > Mike
> >
> >> -Original Message-
> >> From: Laszlo Ersek 
> >> Sent: Wednesday, November 2, 2022 2:37 AM
> >> To: devel@edk2.groups.io; ler...@redhat.com
> >> Cc: Zurcher, Christopher ; Jiang, 
> >> Guomin ; Wang, Jian J
> >> ; Yao, Jiewen ; Kinney, 
> >> Michael D ; Lu, Xiaoyu1
> >> 
> >> Subject: [PATCH] CryptoPkg/Readme.md: typo and grammar fixes
> >>
> >> Commit 244ce33bdd2f ("CryptoPkg: Add Readme.md", 2022-10-24) had added the
> >> long-awaited documentation on the dynamic crypto services. Fix some of the
> >> typos and arguable grammar errors in "Readme.md". A few light
> >> clarifications are also snuck in.
> >>
> >> Cc: Christopher Zurcher 
> >> Cc: Guomin Jiang 
> >> Cc: Jian J Wang 
> >> Cc: Jiewen Yao 
> >> Cc: Michael D Kinney 
> >> Cc: Xiaoyu Lu 
> >> Signed-off-by: Laszlo Ersek 
> >> ---
> >>
> >> Notes:
> >> Best displayed as a word-diff for review, for example with the command
> >>
> >>   git show --word-diff
> >>
> >> or on the web at
> >>
> >>   
> >> https://pagure.io/lersek/edk2/c/a7269f170437?branch=cryptopkg_readme_typos
> >>
> >>  CryptoPkg/Readme.md | 48 ++--
> >>  1 file changed, 24 insertions(+), 24 deletions(-)
> >>
> >> diff --git a/CryptoPkg/Readme.md b/CryptoPkg/Readme.md
> >> index 946aa1e99e7d..9dd3a951836b 100644
> >> --- a/CryptoPkg/Readme.md
> >> +++ b/CryptoPkg/Readme.md
> >> @@ -39,7 +39,7 @@ provides the smallest overall firmware overhead.
> >>
> >>  ## Statically Linking Cryptographic Services
> >>
> >> -The figure below shows an example of a firmware modules that requires the 
> >> use of
> >> +The figure below shows an example of a firmware module that requires the 
> >> use of
> >>  cryptographic services. The cryptographic services are provided by three 
> >> library
> >>  classes called BaseCryptLib, TlsLib, and HashApiLib. These library 
> >> classes are
> >>  implemented using APIs from the OpenSSL project that are abstracted by the
> >> @@ -49,7 +49,7 @@ full C runtime library for firmware components. Instead, 
> >> the CryptoPkg includes
> >>  the smallest subset of services required to build the OpenSSL project in 
> >> the
> >>  private library class called IntrinsicLib.
> >>
> >> -The CryptoPkg provides several instances if the BaseCryptLib and 
> >> OpensslLib with
> >> +The CryptoPkg provides several instances of the BaseCryptLib and 
> >> OpensslLib with
> >>  different cryptographic service features and performance optimizations. 
> >> The
> >>  platform developer must select the correct instances based on 
> >> cryptographic
> >>  service requirements in each UEFI/PI firmware phase (SEC, PEI, DXE, UEFI,
> >> @@ -97,9 +97,9 @@ linking is not available for SEC or UEFI RT modules.
> >>
> >>  The EDK II modules/libraries that require cryptographic services use the 
> >> same
> >>  BaseCryptLib/TlsLib/HashApiLib APIs. This means no source changes are 
> >> required
> >> -to use static linking or dynamic linking. It is a platform configuration 
> >> options
> >> -to select static linking or dynamic linking. This choice can be make 
> >> globally,
> >> -per firmware module type, or individual modules.
> >> +to use static linking or dynamic linking. It is a platform configuration 
> >> option
> >> +to select static linking or dynamic linking. This choice can be made 
> >> globally,
> >> +per firmware module type, or for individual modules.
> >>
> >>  ```
> >>  +===++===+ +===+
> >> @@ -159,7 +159,7 @@ The table below provides a summary of the supported 
> >> cryptographic services. It
> >>  indicates if the family or service is deprecated or recommended to not be 
> >> used.
> >>  It also shows which *CryptLib library instances support the family or 
> >> service.
> >>  If a cell is blank then the service or family is always disabled and the
> >> -`PcdCryptoServiceFamilyEnable` settings for that family or service is 
> >> ignored.
> >> 

[edk2-devel] [PATCH v1 0/1] MdeModulePkg:Add Warm Reset for Xhc

2022-11-03 Thread zhoucheng
Description according to Chapter 7.5.2 of USB 3.2 spec protocol.
When the Usb state machine is in Inactive, the software is required 
to perform a warm reset operation.

Cc: Ray Ni 
Cc: Liming Gao 
Cc: Wang Jian J 
Reviewed-by: Wu Hao A 
Signed-off-by: Cheng Zhou 

zhoucheng (1):
  MdeModulePkg:Add Warm Reset for Xhc

 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 14 ++
 1 file changed, 14 insertions(+)

-- 
2.17.1



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




[edk2-devel] [PATCH v1 1/1] MdeModulePkg:Add Warm Reset for Xhc

2022-11-03 Thread zhoucheng
Description according to Chapter 7.5.2 of USB 3.2 spec protocol.
When the Usb state machine is in Inactive, the software is required
to perform a warm reset operation.

Cc: Liming Gao 
Cc: Hao A Wu 
Cc: Ray Ni 
Signed-off-by: Cheng Zhou 
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index c05431ff30ec..938c8e2e28f7 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -558,6 +558,20 @@ XhcSetRootHubPortFeature (
   State |= XHC_PORTSC_RESET;
   XhcWriteOpReg (Xhc, Offset, State);
   XhcWaitOpRegBit (Xhc, Offset, XHC_PORTSC_PRC, TRUE, XHC_GENERIC_TIMEOUT);
+
+  //
+  // Usb 3.2 spec 7.5.2
+  // When the USB state machine is Inactive state, the device is abnormal.
+  // eSS.Inactive is a state where a link has failed Enhanced SuperSpeed 
operation.Software
+  // is required for warm reset intervention.This flag only applies to 
USB3 protocol ports.
+  //
+  State = XhcReadOpReg (Xhc, Offset);
+  if State & 0x1e0) >> 5) == 6) && ((State & 3) == 0)) {
+State |= 0x8000;
+XhcWriteOpReg (Xhc, Offset, State);
+XhcWaitOpRegBit (Xhc, Offset, XHC_PORTSC_PRC, TRUE, 
XHC_GENERIC_TIMEOUT);
+DEBUG ((DEBUG_INFO, "Warm Reset Successful! \n"));
+  }
   break;
 
 case EfiUsbPortPower:
-- 
2.17.1



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




Re: [edk2-devel] How to add a DXE driver to an OVMF image?

2022-11-03 Thread d.meneses via groups.io
Thank you Andrew for this information.
I set it to *true* cause the builder was asking for a *Depex section*.
Setting it to *false allows QEMU* to boot properly.
Nonetheless, the driver *doesn't seem to be called*... yet.

Concerning Pedro's suggestion (Olá!!!), thank you for pointing me to the 
DebugLib, I'll look into it.
Nonetheless, I'll need to *use ConInt and ConOut in production*.
I am aware of a DXE program that does it. Maybe I was passed the wrong 
information and the program is running on another phase...
Anyhow, in theory I'd be able to install the I/O protocols in the DXE phase in 
order to be able to use them. Right?
The *TerminalDxe.inf* , a *UEFI driver* , states: *Terminal module installs 
Simple Text Input(ex)/Out protocols for serial devices
*
I think assumed erroneously that the *OvmfX64.fdf* is setting the ordering of 
the DXE drivers.
After Andrew's answer I realised that may actually be done in the *Depex 
Section?*
I'll read its specification now in order to better understand how to use it.

Nonetheless, I tried turning it from a *DXE_DRIVER* into a *UEFI_DRIVER* and 
it's still not natively being listed in EFI Shell's *drivers* command.
I don't see yet how mine differs from *TerminalDxe*. Maybe it's crashing and 
being unloaded.

Maybe it's simpler than all of this.
My true goal is: my program needs to be shipped with the BIOS image in ROM and 
run for sure on every boot, with no possibility of being *circumvented*.
I have also read that some DXE drivers are not guaranteed to run if something 
like fast boot is activated.
Taking that in consideration, what module type should I create to achieve my 
goal?

Finally, is there any documentation on actual programming using EDK2 ?
Say, which functions can I use to read user input?
Or what dependencies do I have to include as LibraryClasses if I want to use a 
certain function?
Is reading source code the only way to go ?
I have also used DoxyGen to generate docs, but it's far from ideal.

Cheers,
Diogo


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




Re: [edk2-devel] [PATCH] CryptoPkg/Readme.md: typo and grammar fixes

2022-11-03 Thread Laszlo Ersek
Hi Mike,

On 11/02/22 17:48, Kinney, Michael D wrote:
> Hi Laszlo,
> 
> Thank you for all the updates.  One comment below.
> 
> Mike
> 
>> -Original Message-
>> From: Laszlo Ersek 
>> Sent: Wednesday, November 2, 2022 2:37 AM
>> To: devel@edk2.groups.io; ler...@redhat.com
>> Cc: Zurcher, Christopher ; Jiang, Guomin 
>> ; Wang, Jian J
>> ; Yao, Jiewen ; Kinney, Michael 
>> D ; Lu, Xiaoyu1
>> 
>> Subject: [PATCH] CryptoPkg/Readme.md: typo and grammar fixes
>>
>> Commit 244ce33bdd2f ("CryptoPkg: Add Readme.md", 2022-10-24) had added the
>> long-awaited documentation on the dynamic crypto services. Fix some of the
>> typos and arguable grammar errors in "Readme.md". A few light
>> clarifications are also snuck in.
>>
>> Cc: Christopher Zurcher 
>> Cc: Guomin Jiang 
>> Cc: Jian J Wang 
>> Cc: Jiewen Yao 
>> Cc: Michael D Kinney 
>> Cc: Xiaoyu Lu 
>> Signed-off-by: Laszlo Ersek 
>> ---
>>
>> Notes:
>> Best displayed as a word-diff for review, for example with the command
>>
>>   git show --word-diff
>>
>> or on the web at
>>
>>   
>> https://pagure.io/lersek/edk2/c/a7269f170437?branch=cryptopkg_readme_typos
>>
>>  CryptoPkg/Readme.md | 48 ++--
>>  1 file changed, 24 insertions(+), 24 deletions(-)
>>
>> diff --git a/CryptoPkg/Readme.md b/CryptoPkg/Readme.md
>> index 946aa1e99e7d..9dd3a951836b 100644
>> --- a/CryptoPkg/Readme.md
>> +++ b/CryptoPkg/Readme.md
>> @@ -39,7 +39,7 @@ provides the smallest overall firmware overhead.
>>
>>  ## Statically Linking Cryptographic Services
>>
>> -The figure below shows an example of a firmware modules that requires the 
>> use of
>> +The figure below shows an example of a firmware module that requires the 
>> use of
>>  cryptographic services. The cryptographic services are provided by three 
>> library
>>  classes called BaseCryptLib, TlsLib, and HashApiLib. These library classes 
>> are
>>  implemented using APIs from the OpenSSL project that are abstracted by the
>> @@ -49,7 +49,7 @@ full C runtime library for firmware components. Instead, 
>> the CryptoPkg includes
>>  the smallest subset of services required to build the OpenSSL project in the
>>  private library class called IntrinsicLib.
>>
>> -The CryptoPkg provides several instances if the BaseCryptLib and OpensslLib 
>> with
>> +The CryptoPkg provides several instances of the BaseCryptLib and OpensslLib 
>> with
>>  different cryptographic service features and performance optimizations. The
>>  platform developer must select the correct instances based on cryptographic
>>  service requirements in each UEFI/PI firmware phase (SEC, PEI, DXE, UEFI,
>> @@ -97,9 +97,9 @@ linking is not available for SEC or UEFI RT modules.
>>
>>  The EDK II modules/libraries that require cryptographic services use the 
>> same
>>  BaseCryptLib/TlsLib/HashApiLib APIs. This means no source changes are 
>> required
>> -to use static linking or dynamic linking. It is a platform configuration 
>> options
>> -to select static linking or dynamic linking. This choice can be make 
>> globally,
>> -per firmware module type, or individual modules.
>> +to use static linking or dynamic linking. It is a platform configuration 
>> option
>> +to select static linking or dynamic linking. This choice can be made 
>> globally,
>> +per firmware module type, or for individual modules.
>>
>>  ```
>>  +===++===+ +===+
>> @@ -159,7 +159,7 @@ The table below provides a summary of the supported 
>> cryptographic services. It
>>  indicates if the family or service is deprecated or recommended to not be 
>> used.
>>  It also shows which *CryptLib library instances support the family or 
>> service.
>>  If a cell is blank then the service or family is always disabled and the
>> -`PcdCryptoServiceFamilyEnable` settings for that family or service is 
>> ignored.
>> +`PcdCryptoServiceFamilyEnable` setting for that family or service is 
>> ignored.
>>  If the cell is not blank, then the service or family is configurable using
>>  `PcdCryptoServiceFamilyEnable` as long as the correct OpensslLib or TlsLib 
>> is
>>  also configured.
>> @@ -234,10 +234,10 @@ phases (SEC, PEI, DXE, UEFI, SMM, UEFI RT).
>>
>>  The following table can be used to help select the best OpensslLib instance 
>> for
>>  each phase. The Size column only shows the estimated size increase for a
>> -compressed IA32/X64 modules that uses the cryptographic services with
>> +compressed IA32/X64 module that uses the cryptographic services with
>>  `OpensslLib.inf` as the baseline size. The actual size increase depends on 
>> the
>>  specific set of enabled cryptographic services. If ECC services are not
>> -required, then size can be reduced by using OpensslLib.inf instead of
>> +required, then the size can be reduced by using OpensslLib.inf instead of
>>  `OpensslLibFull.inf`. Performance optimization requires a size increase.
>>
>>  | OpensslLib Instance | SSL | ECC | Perf Opt | CPU Arch | Size  |
>> @@ 

Re: [edk2-devel] [PATCH v3 8/9] UefiPayloadPkg: Remove UefiCpuLib from module INFs.

2022-11-03 Thread Guo Dong
Reviewed-by: Guo Dong 

-Original Message-
From: Liu, Zhiguang  
Sent: Tuesday, November 1, 2022 12:59 AM
To: devel@edk2.groups.io
Cc: Yu Pu ; Dong, Guo ; Ni, Ray 
; Maurice Ma ; You, Benjamin 
; Rhodes, Sean 
Subject: [PATCH v3 8/9] UefiPayloadPkg: Remove UefiCpuLib from module INFs.

From: Yu Pu 

Because UefiCpuPkg/UefiCpuLib is merged to MdePkg/CpuLib, remove the dependency 
of UefiCpuLib.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: Maurice Ma 
Cc: Benjamin You 
Cc: Sean Rhodes 
Signed-off-by: Yu Pu 
Reviewed-by: Ray Ni 
---
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h| 1 -
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf  | 1 -
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 1 -
 UefiPayloadPkg/UefiPayloadPkg.dsc | 1 -
 4 files changed, 4 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h 
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
index d1c7425b28..ad8a9fd22b 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -24,7 +24,6 @@
 #include 
 #include   #include  -#include 
  #include   #include 

 #include 
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf 
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index 95446dd997..d47e8e76cf 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -55,7 +55,6 @@
   PeCoffLib
   PlatformSupportLib
   CpuLib
-  UefiCpuLib
 
 [Guids]
   gEfiMemoryTypeInformationGuid
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf 
b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
index 3b4836042a..c4f4f28eaa 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
@@ -53,7 +53,6 @@
   HobLib
   PeCoffLib
   CpuLib
-  UefiCpuLib
 
 [Guids]
   gEfiMemoryTypeInformationGuid
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc 
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 1150be6acd..b7712d4de1 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -221,7 +221,6 @@
   
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
   DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
   
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
-  UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
   SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
 
   #
--
2.31.1.windows.1



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




Re: [edk2-devel] [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

2022-11-03 Thread Guo Dong


Reviewed-by: Guo Dong 

-Original Message-
From: Hsu, VictorX  
Sent: Thursday, November 3, 2022 2:11 AM
To: devel@edk2.groups.io
Cc: Hsu, VictorX ; Dong, Guo ; Ni, 
Ray ; Lu, James ; Guo, Gua 

Subject: [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

From: VictorX Hsu 

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

System will depend on Boot Mode value to do different behavior Update during 
Capsule Update process. So UPL need to support update boot mode.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: James Lu 
Cc: Gua Guo 
Signed-off-by: VictorX Hsu 
---
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
index edb3c20471..2ae6b088ab 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
@@ -309,6 +309,7 @@ BuildHobs (
   EFI_HOB_FIRMWARE_VOLUME   *FvHob;   UNIVERSAL_PAYLOAD_ACPI_TABLE  
*AcpiTable;   ACPI_BOARD_INFO   *AcpiBoardInfo;+  
EFI_HOB_HANDOFF_INFO_TABLE*HobInfo;Hob.Raw   = (UINT8 
*)BootloaderParameter;   MinimalNeededSize = FixedPcdGet32 
(PcdSystemMemoryUefiRegionSize);@@ -368,7 +369,8 @@ BuildHobs (
 MemoryTop= FreeMemoryTop;   } -  HobConstructor ((VOID 
*)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo = 
HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo->BootMode = 
Hob.HandoffInformationTable->BootMode;   //   // From now on, mHobList will 
point to the new Hob range.   //-- 
2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#95892): https://edk2.groups.io/g/devel/message/95892
Mute This Topic: https://groups.io/mt/94752793/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/8] UefiPayloadPkg: Use CcExitLib instead of VmgExitLib

2022-11-03 Thread Guo Dong
Reviewed-by: Guo Dong 

-Original Message-
From: Xu, Min M  
Sent: Tuesday, November 1, 2022 10:11 PM
To: devel@edk2.groups.io
Cc: Xu, Min M ; Dong, Guo ; Ni, Ray 
; Rhodes, Sean ; Lu, James 
; Guo, Gua 
Subject: [PATCH 4/8] UefiPayloadPkg: Use CcExitLib instead of VmgExitLib

From: Min M Xu 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123

VmgExitLib is renamed as CcExitLib. So UefiPayloadPkg.dsc should be updated as 
well.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: Sean Rhodes 
Cc: James Lu 
Cc: Gua Guo 
Signed-off-by: Min Xu 
---
 UefiPayloadPkg/UefiPayloadPkg.dsc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc 
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 1150be6acd0e..723a50a42284 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -301,7 +301,7 @@
   
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
-  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
+  CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
 
 [LibraryClasses.common]
--
2.29.2.windows.2



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




[edk2-devel] Now: TianoCore edk2-test Bug Triage Meeting - 11/03/2022 #cal-notice

2022-11-03 Thread Group Notification
*TianoCore edk2-test Bug Triage Meeting*

*When:*
11/03/2022
10:00pm to 11:00pm
(UTC+08:00) Asia/Shanghai

*Where:*
https://armltd.zoom.us/j/91247522013?pwd=ei9nUndTbG9oWEROS2M1aVREZkpiQT09=addon

*Organizer:* Edhaya Chandran edhaya.chand...@arm.com ( 
edhaya.chand...@arm.com?subject=Re:%20Event:%20TianoCore%20edk2-test%20Bug%20Triage%20Meeting
 )

View Event ( https://edk2.groups.io/g/devel/viewevent?eventid=1621541 )

*Description:*


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




[edk2-devel] Event: TianoCore edk2-test Bug Triage Meeting - 11/03/2022 #cal-reminder

2022-11-03 Thread Group Notification
*Reminder: TianoCore edk2-test Bug Triage Meeting*

*When:*
11/03/2022
10:00pm to 11:00pm
(UTC+08:00) Asia/Shanghai

*Where:*
https://armltd.zoom.us/j/91247522013?pwd=ei9nUndTbG9oWEROS2M1aVREZkpiQT09=addon

*Organizer:* Edhaya Chandran edhaya.chand...@arm.com ( 
edhaya.chand...@arm.com?subject=Re:%20Event:%20TianoCore%20edk2-test%20Bug%20Triage%20Meeting
 )

View Event ( https://edk2.groups.io/g/devel/viewevent?eventid=1621541 )

*Description:*


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




[edk2-devel] [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

2022-11-03 Thread victorx . hsu
From: VictorX Hsu 

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

System will depend on Boot Mode value to do different behavior
Update during Capsule Update process. So UPL need to support
update boot mode.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: James Lu 
Cc: Gua Guo 
Signed-off-by: VictorX Hsu 
---
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
index edb3c20471..2ae6b088ab 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
@@ -309,6 +309,7 @@ BuildHobs (
   EFI_HOB_FIRMWARE_VOLUME   *FvHob;
   UNIVERSAL_PAYLOAD_ACPI_TABLE  *AcpiTable;
   ACPI_BOARD_INFO   *AcpiBoardInfo;
+  EFI_HOB_HANDOFF_INFO_TABLE*HobInfo;
 
   Hob.Raw   = (UINT8 *)BootloaderParameter;
   MinimalNeededSize = FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
@@ -368,7 +369,8 @@ BuildHobs (
 MemoryTop= FreeMemoryTop;
   }
 
-  HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);
+  HobInfo = HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID 
*)(UINTN)MemoryTop, (VOID *)(UINTN)FreeMemoryBottom, (VOID 
*)(UINTN)FreeMemoryTop);
+  HobInfo->BootMode = Hob.HandoffInformationTable->BootMode;
   //
   // From now on, mHobList will point to the new Hob range.
   //
-- 
2.28.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

2022-11-03 Thread Lu, James
Reviewed-by: James Lu 

-Original Message-
From: Hsu, VictorX  
Sent: Thursday, November 3, 2022 5:11 PM
To: devel@edk2.groups.io
Cc: Hsu, VictorX ; Dong, Guo ; Ni, 
Ray ; Lu, James ; Guo, Gua 

Subject: [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

From: VictorX Hsu 

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

System will depend on Boot Mode value to do different behavior Update during 
Capsule Update process. So UPL need to support update boot mode.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: James Lu 
Cc: Gua Guo 
Signed-off-by: VictorX Hsu 
---
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
index edb3c20471..2ae6b088ab 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
@@ -309,6 +309,7 @@ BuildHobs (
   EFI_HOB_FIRMWARE_VOLUME   *FvHob;   UNIVERSAL_PAYLOAD_ACPI_TABLE  
*AcpiTable;   ACPI_BOARD_INFO   *AcpiBoardInfo;+  
EFI_HOB_HANDOFF_INFO_TABLE*HobInfo;Hob.Raw   = (UINT8 
*)BootloaderParameter;   MinimalNeededSize = FixedPcdGet32 
(PcdSystemMemoryUefiRegionSize);@@ -368,7 +369,8 @@ BuildHobs (
 MemoryTop= FreeMemoryTop;   } -  HobConstructor ((VOID 
*)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo = 
HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo->BootMode = 
Hob.HandoffInformationTable->BootMode;   //   // From now on, mHobList will 
point to the new Hob range.   //-- 
2.28.0.windows.1



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




Re: [edk2-devel] [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

2022-11-03 Thread Guo, Gua
Give + 1, it can help to unlock Capsule Update through have correct Boot Mode 
value.

Reviewed-by: Gua Guo 
-Original Message-
From: Hsu, VictorX  
Sent: Thursday, November 3, 2022 5:11 PM
To: devel@edk2.groups.io
Cc: Hsu, VictorX ; Dong, Guo ; Ni, 
Ray ; Lu, James ; Guo, Gua 

Subject: [PATCH] UefiPayloadPkg: Boot mode in PHIT HOB will not be updated

From: VictorX Hsu 

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

System will depend on Boot Mode value to do different behavior Update during 
Capsule Update process. So UPL need to support update boot mode.

Cc: Guo Dong 
Cc: Ray Ni 
Cc: James Lu 
Cc: Gua Guo 
Signed-off-by: VictorX Hsu 
---
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
index edb3c20471..2ae6b088ab 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
@@ -309,6 +309,7 @@ BuildHobs (
   EFI_HOB_FIRMWARE_VOLUME   *FvHob;   UNIVERSAL_PAYLOAD_ACPI_TABLE  
*AcpiTable;   ACPI_BOARD_INFO   *AcpiBoardInfo;+  
EFI_HOB_HANDOFF_INFO_TABLE*HobInfo;Hob.Raw   = (UINT8 
*)BootloaderParameter;   MinimalNeededSize = FixedPcdGet32 
(PcdSystemMemoryUefiRegionSize);@@ -368,7 +369,8 @@ BuildHobs (
 MemoryTop= FreeMemoryTop;   } -  HobConstructor ((VOID 
*)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo = 
HobConstructor ((VOID *)(UINTN)MemoryBottom, (VOID *)(UINTN)MemoryTop, (VOID 
*)(UINTN)FreeMemoryBottom, (VOID *)(UINTN)FreeMemoryTop);+  HobInfo->BootMode = 
Hob.HandoffInformationTable->BootMode;   //   // From now on, mHobList will 
point to the new Hob range.   //-- 
2.28.0.windows.1



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