Date   

[PATCH 2/4] CryptoPkg: add AeadAesGcm support.

Qi Zhang
 

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

Signed-off-by: Qi Zhang <qi1.zhang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Guomin Jiang <guomin.jiang@...>
---
.../Library/BaseCryptLib/BaseCryptLib.inf | 1 +
.../BaseCryptLib/Cipher/CryptAeadAesGcm.c | 279 ++++++++++++++++++
.../BaseCryptLib/Cipher/CryptAeadAesGcmNull.c | 100 +++++++
.../Library/BaseCryptLib/PeiCryptLib.inf | 1 +
.../Library/BaseCryptLib/RuntimeCryptLib.inf | 1 +
.../Library/BaseCryptLib/SmmCryptLib.inf | 1 +
.../BaseCryptLibNull/BaseCryptLibNull.inf | 1 +
.../Cipher/CryptAeadAesGcmNull.c | 100 +++++++
8 files changed, 484 insertions(+)
create mode 100644 CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcm.c
create mode 100644 CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcmNu=
ll.c
create mode 100644 CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAeadAesG=
cmNull.c

diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Li=
brary/BaseCryptLib/BaseCryptLib.inf
index 3d7b917103..3a00e16948 100644
--- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -38,6 +38,7 @@
Hmac/CryptHmacSha256.c=0D
Kdf/CryptHkdf.c=0D
Cipher/CryptAes.c=0D
+ Cipher/CryptAeadAesGcm.c=0D
Pk/CryptRsaBasic.c=0D
Pk/CryptRsaExt.c=0D
Pk/CryptPkcs1Oaep.c=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcm.c b/Cryp=
toPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcm.c
new file mode 100644
index 0000000000..b4c93d47a9
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcm.c
@@ -0,0 +1,279 @@
+/** @file=0D
+ AEAD (AES-GCM) Wrapper Implementation over OpenSSL.=0D
+=0D
+ RFC 5116 - An Interface and Algorithms for Authenticated Encryption=0D
+ NIST SP800-38d - Cipher Modes of Operation: Galois / Counter Mode(GCM) a=
nd GMAC=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "InternalCryptLib.h"=0D
+#include <openssl/aes.h>=0D
+#include <openssl/evp.h>=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated encryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be encrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[out] TagOut Pointer to a buffer that receives the authentic=
ation tag output.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the encryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated encryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated encryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmEncrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ OUT UINT8 *TagOut,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ EVP_CIPHER_CTX *Ctx;=0D
+ CONST EVP_CIPHER *Cipher;=0D
+ UINTN TempOutSize;=0D
+ BOOLEAN RetValue;=0D
+=0D
+ if (DataInSize > INT_MAX) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (ADataSize > INT_MAX) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (IvSize !=3D 12) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ switch (KeySize) {=0D
+ case 16:=0D
+ Cipher =3D EVP_aes_128_gcm ();=0D
+ break;=0D
+ case 24:=0D
+ Cipher =3D EVP_aes_192_gcm ();=0D
+ break;=0D
+ case 32:=0D
+ Cipher =3D EVP_aes_256_gcm ();=0D
+ break;=0D
+ default:=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if ((TagSize !=3D 12) && (TagSize !=3D 13) && (TagSize !=3D 14) && (TagS=
ize !=3D 15) && (TagSize !=3D 16)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (DataOutSize !=3D NULL) {=0D
+ if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {=0D
+ return FALSE;=0D
+ }=0D
+ }=0D
+=0D
+ Ctx =3D EVP_CIPHER_CTX_new ();=0D
+ if (Ctx =3D=3D NULL) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_EncryptInit_ex (Ctx, Cipher, NULL, NULL, NULL)=
;=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_IVLEN, =
(INT32)IvSize, NULL);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_EncryptInit_ex (Ctx, NULL, NULL, Key, Iv);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_EncryptUpdate (Ctx, NULL, (INT32 *)&TempOutSiz=
e, AData, (INT32)ADataSize);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_EncryptUpdate (Ctx, DataOut, (INT32 *)&TempOut=
Size, DataIn, (INT32)DataInSize);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_EncryptFinal_ex (Ctx, DataOut, (INT32 *)&TempO=
utSize);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_GET_TAG, (I=
NT32)TagSize, (VOID *)TagOut);=0D
+=0D
+Done:=0D
+ EVP_CIPHER_CTX_free (Ctx);=0D
+ if (!RetValue) {=0D
+ return RetValue;=0D
+ }=0D
+=0D
+ if (DataOutSize !=3D NULL) {=0D
+ *DataOutSize =3D DataInSize;=0D
+ }=0D
+=0D
+ return RetValue;=0D
+}=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated decryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+ If additional authenticated data verification fails, FALSE is returned.=
=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be decrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[in] Tag Pointer to a buffer that contains the authentic=
ation tag.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the decryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated decryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated decryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmDecrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ IN CONST UINT8 *Tag,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ EVP_CIPHER_CTX *Ctx;=0D
+ CONST EVP_CIPHER *Cipher;=0D
+ UINTN TempOutSize;=0D
+ BOOLEAN RetValue;=0D
+=0D
+ if (DataInSize > INT_MAX) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (ADataSize > INT_MAX) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (IvSize !=3D 12) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ switch (KeySize) {=0D
+ case 16:=0D
+ Cipher =3D EVP_aes_128_gcm ();=0D
+ break;=0D
+ case 24:=0D
+ Cipher =3D EVP_aes_192_gcm ();=0D
+ break;=0D
+ case 32:=0D
+ Cipher =3D EVP_aes_256_gcm ();=0D
+ break;=0D
+ default:=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if ((TagSize !=3D 12) && (TagSize !=3D 13) && (TagSize !=3D 14) && (TagS=
ize !=3D 15) && (TagSize !=3D 16)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (DataOutSize !=3D NULL) {=0D
+ if ((*DataOutSize > INT_MAX) || (*DataOutSize < DataInSize)) {=0D
+ return FALSE;=0D
+ }=0D
+ }=0D
+=0D
+ Ctx =3D EVP_CIPHER_CTX_new ();=0D
+ if (Ctx =3D=3D NULL) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_DecryptInit_ex (Ctx, Cipher, NULL, NULL, NULL)=
;=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_IVLEN, =
(INT32)IvSize, NULL);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_DecryptInit_ex (Ctx, NULL, NULL, Key, Iv);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_DecryptUpdate (Ctx, NULL, (INT32 *)&TempOutSiz=
e, AData, (INT32)ADataSize);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_DecryptUpdate (Ctx, DataOut, (INT32 *)&TempOut=
Size, DataIn, (INT32)DataInSize);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_CIPHER_CTX_ctrl (Ctx, EVP_CTRL_GCM_SET_TAG, (I=
NT32)TagSize, (VOID *)Tag);=0D
+ if (!RetValue) {=0D
+ goto Done;=0D
+ }=0D
+=0D
+ RetValue =3D (BOOLEAN)EVP_DecryptFinal_ex (Ctx, DataOut, (INT32 *)&TempO=
utSize);=0D
+=0D
+Done:=0D
+ EVP_CIPHER_CTX_free (Ctx);=0D
+ if (!RetValue) {=0D
+ return RetValue;=0D
+ }=0D
+=0D
+ if (DataOutSize !=3D NULL) {=0D
+ *DataOutSize =3D DataInSize;=0D
+ }=0D
+=0D
+ return RetValue;=0D
+}=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcmNull.c b/=
CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcmNull.c
new file mode 100644
index 0000000000..b9f9d16ff9
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcmNull.c
@@ -0,0 +1,100 @@
+/** @file=0D
+ AEAD Wrapper Implementation which does not provide real capabilities.=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "InternalCryptLib.h"=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated encryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be encrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[out] TagOut Pointer to a buffer that receives the authentic=
ation tag output.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the encryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated encryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated encryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmEncrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ OUT UINT8 *TagOut,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ ASSERT (FALSE);=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated decryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+ If additional authenticated data verification fails, FALSE is returned.=
=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be decrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[in] Tag Pointer to a buffer that contains the authentic=
ation tag.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the decryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated decryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated decryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmDecrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ IN CONST UINT8 *Tag,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ ASSERT (FALSE);=0D
+ return FALSE;=0D
+}=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/PeiCryptLib.inf
index 01de27e037..43b122d904 100644
--- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
@@ -44,6 +44,7 @@
Hmac/CryptHmacSha256.c=0D
Kdf/CryptHkdf.c=0D
Cipher/CryptAesNull.c=0D
+ Cipher/CryptAeadAesGcmNull.c=0D
Pk/CryptRsaBasic.c=0D
Pk/CryptRsaExtNull.c=0D
Pk/CryptPkcs1OaepNull.c=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf b/CryptoPkg=
/Library/BaseCryptLib/RuntimeCryptLib.inf
index d28fb98b66..291e30cf5e 100644
--- a/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
@@ -44,6 +44,7 @@
Hmac/CryptHmacSha256.c=0D
Kdf/CryptHkdf.c=0D
Cipher/CryptAes.c=0D
+ Cipher/CryptAeadAesGcmNull.c=0D
Pk/CryptRsaBasic.c=0D
Pk/CryptRsaExtNull.c=0D
Pk/CryptPkcs1OaepNull.c=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/SmmCryptLib.inf
index 91a1715095..6c65cc7a67 100644
--- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
@@ -45,6 +45,7 @@
Hmac/CryptHmacSha256.c=0D
Kdf/CryptHkdfNull.c=0D
Cipher/CryptAes.c=0D
+ Cipher/CryptAeadAesGcmNull.c=0D
Pk/CryptRsaBasic.c=0D
Pk/CryptRsaExtNull.c=0D
Pk/CryptPkcs1Oaep.c=0D
diff --git a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf b/Cryp=
toPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
index 63d1d82d19..bfc0d6a869 100644
--- a/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
+++ b/CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf
@@ -38,6 +38,7 @@
Hmac/CryptHmacSha256Null.c=0D
Kdf/CryptHkdfNull.c=0D
Cipher/CryptAesNull.c=0D
+ Cipher/CryptAeadAesGcmNull.c=0D
Pk/CryptRsaBasicNull.c=0D
Pk/CryptRsaExtNull.c=0D
Pk/CryptPkcs1OaepNull.c=0D
diff --git a/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAeadAesGcmNull.=
c b/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAeadAesGcmNull.c
new file mode 100644
index 0000000000..b9f9d16ff9
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAeadAesGcmNull.c
@@ -0,0 +1,100 @@
+/** @file=0D
+ AEAD Wrapper Implementation which does not provide real capabilities.=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "InternalCryptLib.h"=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated encryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be encrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[out] TagOut Pointer to a buffer that receives the authentic=
ation tag output.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the encryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated encryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated encryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmEncrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ OUT UINT8 *TagOut,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ ASSERT (FALSE);=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated decryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+ If additional authenticated data verification fails, FALSE is returned.=
=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be decrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[in] Tag Pointer to a buffer that contains the authentic=
ation tag.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the decryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated decryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated decryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmDecrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ IN CONST UINT8 *Tag,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ )=0D
+{=0D
+ ASSERT (FALSE);=0D
+ return FALSE;=0D
+}=0D
--=20
2.26.2.windows.1


[PATCH 1/4] CryptoPkg: add AeadAesGcm function() definition.

Qi Zhang
 

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

Signed-off-by: Qi Zhang <qi1.zhang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Guomin Jiang <guomin.jiang@...>
---
CryptoPkg/Include/Library/BaseCryptLib.h | 87 ++++++++++++++++++++++++
1 file changed, 87 insertions(+)

diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/L=
ibrary/BaseCryptLib.h
index 7d1499350a..b27ec28944 100644
--- a/CryptoPkg/Include/Library/BaseCryptLib.h
+++ b/CryptoPkg/Include/Library/BaseCryptLib.h
@@ -1172,6 +1172,93 @@ AesCbcDecrypt (
OUT UINT8 *Output=0D
);=0D
=0D
+// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D
+// Authenticated Encryption with Associated Data (AEAD) Cryptography Pr=
imitive=0D
+// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated encryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be encrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[out] TagOut Pointer to a buffer that receives the authentic=
ation tag output.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the encryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated encryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated encryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmEncrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ OUT UINT8 *TagOut,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ );=0D
+=0D
+/**=0D
+ Performs AEAD AES-GCM authenticated decryption on a data buffer and addi=
tional authenticated data (AAD).=0D
+=0D
+ IvSize must be 12, otherwise FALSE is returned.=0D
+ KeySize must be 16, 24 or 32, otherwise FALSE is returned.=0D
+ TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.=0D
+ If additional authenticated data verification fails, FALSE is returned.=
=0D
+=0D
+ @param[in] Key Pointer to the encryption key.=0D
+ @param[in] KeySize Size of the encryption key in bytes.=0D
+ @param[in] Iv Pointer to the IV value.=0D
+ @param[in] IvSize Size of the IV value in bytes.=0D
+ @param[in] AData Pointer to the additional authenticated data (A=
AD).=0D
+ @param[in] ADataSize Size of the additional authenticated data (AAD)=
in bytes.=0D
+ @param[in] DataIn Pointer to the input data buffer to be decrypte=
d.=0D
+ @param[in] DataInSize Size of the input data buffer in bytes.=0D
+ @param[in] Tag Pointer to a buffer that contains the authentic=
ation tag.=0D
+ @param[in] TagSize Size of the authentication tag in bytes.=0D
+ @param[out] DataOut Pointer to a buffer that receives the decryptio=
n output.=0D
+ @param[out] DataOutSize Size of the output data buffer in bytes.=0D
+=0D
+ @retval TRUE AEAD AES-GCM authenticated decryption succeeded.=0D
+ @retval FALSE AEAD AES-GCM authenticated decryption failed.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+AeadAesGcmDecrypt (=0D
+ IN CONST UINT8 *Key,=0D
+ IN UINTN KeySize,=0D
+ IN CONST UINT8 *Iv,=0D
+ IN UINTN IvSize,=0D
+ IN CONST UINT8 *AData,=0D
+ IN UINTN ADataSize,=0D
+ IN CONST UINT8 *DataIn,=0D
+ IN UINTN DataInSize,=0D
+ IN CONST UINT8 *Tag,=0D
+ IN UINTN TagSize,=0D
+ OUT UINT8 *DataOut,=0D
+ OUT UINTN *DataOutSize=0D
+ );=0D
+=0D
// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D
// Asymmetric Cryptography Primitive=0D
// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D
--=20
2.26.2.windows.1


[PATCH 0/4] CryptoPkg: add AeadAesGcm support.

Qi Zhang
 

Add AeadAesGcm Encrypt and Decrypt.
With this change, the size increase of BaseCyrptLib is about 60K bytes.
The new functions are verifed by the Host UnitTest.
And also it has been integratd in
https://github.com/tianocore/edk2-staging/tree/DeviceSecurity and been
verified.

All the code change is on the PR https://github.com/tianocore/edk2/pull/3252.


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

Signed-off-by: Qi Zhang <qi1.zhang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Guomin Jiang <guomin.jiang@...>

Qi Zhang (4):
CryptoPkg: add AeadAesGcm function() definition.
CryptoPkg: add AeadAesGcm support.
CryptoPkg: add AeadAesGcm to Crypto Service.
CryptoPkg: add UnitTest for AeadAesGcm.

CryptoPkg/CryptoPkg.dsc | 2 +
CryptoPkg/Driver/Crypto.c | 94 +++++-
CryptoPkg/Include/Library/BaseCryptLib.h | 87 ++++++
.../Pcd/PcdCryptoServiceFamilyEnable.h | 7 +
.../Library/BaseCryptLib/BaseCryptLib.inf | 1 +
.../BaseCryptLib/Cipher/CryptAeadAesGcm.c | 279 ++++++++++++++++++
.../BaseCryptLib/Cipher/CryptAeadAesGcmNull.c | 100 +++++++
.../Library/BaseCryptLib/PeiCryptLib.inf | 1 +
.../Library/BaseCryptLib/RuntimeCryptLib.inf | 1 +
.../Library/BaseCryptLib/SmmCryptLib.inf | 1 +
.../BaseCryptLib/UnitTestHostBaseCryptLib.inf | 1 +
.../BaseCryptLibNull/BaseCryptLibNull.inf | 1 +
.../Cipher/CryptAeadAesGcmNull.c | 100 +++++++
.../BaseCryptLibOnProtocolPpi/CryptLib.c | 93 ++++++
CryptoPkg/Private/Protocol/Crypto.h | 86 ++++++
.../Library/BaseCryptLib/AeadAesGcmTests.c | 112 +++++++
.../BaseCryptLib/BaseCryptLibUnitTests.c | 1 +
.../Library/BaseCryptLib/TestBaseCryptLib.h | 3 +
.../BaseCryptLib/TestBaseCryptLibHost.inf | 1 +
.../BaseCryptLib/TestBaseCryptLibShell.inf | 1 +
20 files changed, 971 insertions(+), 1 deletion(-)
create mode 100644 CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcm.c
create mode 100644 CryptoPkg/Library/BaseCryptLib/Cipher/CryptAeadAesGcmNull.c
create mode 100644 CryptoPkg/Library/BaseCryptLibNull/Cipher/CryptAeadAesGcmNull.c
create mode 100644 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/AeadAesGcmTests.c

--
2.26.2.windows.1


回复: [edk2-devel] [PATCH edk2-stable202208 1/1] BaseTools: Fix DevicePath GNUmakefile for macOS

gaoliming
 

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Michael D
Kinney
发送时间: 2022年8月26日 9:39
收件人: devel@edk2.groups.io; rebecca@...; Andrew Fish
<afish@...>; Leif Lindholm <quic_llindhol@...>; Feng, Bob C
<bob.c.feng@...>; Gao, Liming <gaoliming@...>; Chen,
Christine <yuwei.chen@...>; Kinney, Michael D
<michael.d.kinney@...>
主题: Re: [edk2-devel] [PATCH edk2-stable202208 1/1] BaseTools: Fix
DevicePath GNUmakefile for macOS

Reviewed-by: Michael D Kinney <michael.d.kinney@...>

I approve for edk2-stable202208

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Rebecca Cran
Sent: Thursday, August 25, 2022 6:32 PM
To: devel@edk2.groups.io; Andrew Fish <afish@...>; Leif Lindholm
<quic_llindhol@...>; Kinney, Michael D
<michael.d.kinney@...>; Feng, Bob C <bob.c.feng@...>; Gao,
Liming <gaoliming@...>; Chen, Christine
<yuwei.chen@...>
Cc: Rebecca Cran <rebecca@...>
Subject: [edk2-devel] [PATCH edk2-stable202208 1/1] BaseTools: Fix
DevicePath GNUmakefile for macOS

On macOS, /usr/bin/gcc is clang, and so doesn't have
the -Wno-error=stringop-overflow flag that was added
for gcc 12.
Update the GNUmakefile for DevicePath to skip setting
that on macOS.

Signed-off-by: Rebecca Cran <rebecca@...>
---
BaseTools/Source/C/DevicePath/GNUmakefile | 2 ++
1 file changed, 2 insertions(+)

diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile
b/BaseTools/Source/C/DevicePath/GNUmakefile
index c217674345b1..17f213879e82 100644
--- a/BaseTools/Source/C/DevicePath/GNUmakefile
+++ b/BaseTools/Source/C/DevicePath/GNUmakefile
@@ -16,10 +16,12 @@ include $(MAKEROOT)/Makefiles/app.makefile
GCCVERSION = $(shell gcc -dumpversion | awk -F'.' '{print $$1}')
ifneq ("$(GCCVERSION)", "5")
ifneq ($(CXX), llvm)
+ifneq ($(DARWIN),Darwin)
# gcc 12 trips over device path handling
BUILD_CFLAGS += -Wno-error=stringop-overflow
endif
endif
+endif

LIBS = -lCommon
ifeq ($(CYGWIN), CYGWIN)
--
2.30.1 (Apple Git-130)








回复: [edk2-devel] [edk2-stable202208 0/3] Revert three patches for edk2 stable tag 202208

gaoliming
 

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Ard
Biesheuvel
发送时间: 2022年8月27日 17:16
收件人: devel@edk2.groups.io; gaoliming@...
主题: Re: [edk2-devel] [edk2-stable202208 0/3] Revert three patches for
edk2 stable tag 202208

On Fri, 26 Aug 2022 at 04:15, gaoliming via groups.io
<gaoliming@...> wrote:

Two features will be merged after the stable tag 202208 is created.
One behavior change will be discussed further.

Liming Gao (3):
Revert "UefiCpuPkg/CpuPageTableLib/UnitTest: Add host based unit
test"
Revert "ShellPkg: Adds Local APIC parser to AcpiView"
Revert "BaseTools: Fix DSC LibraryClass precedence rule"
Acked-by: Ard Biesheuvel <ardb@...>




回复: [edk2-devel] FW: [PATCH] ShellPkg: Displaying SMBIOS Type38 fields in formatted manner

gaoliming
 

Prakash:
Yes. I get this mail. Zhichao is ShellPkg maintainer. I include him to
review this change.


Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Prakash K via
groups.io
发送时间: 2022年8月26日 12:08
收件人: gaoliming@...; devel@edk2.groups.io
抄送: Vasudevan Sambandan <vasudevans@...>; Sundaresan S
<sundaresans@...>; Gayathri Thunuguntla <gayathrit@...>
主题: [edk2-devel] FW: [PATCH] ShellPkg: Displaying SMBIOS Type38 fields
in
formatted manner

Hi Gaoliming

Regarding Bugzilla Bug 3755, I have sent the patch to devel@edk2.groups.io
and you have updated that you have received the patch. But the changes are
not merged into EDK2 source.
The sent patch is in the below mail thread.
Kindly let us know the status of Bug 3755.

Thanks,
Prakash K

-----Original Message-----
From: Prakash K <prakashk@...>
Sent: Wednesday, December 29, 2021 5:37 PM
To: devel@edk2.groups.io; Prakash K <prakashk@...>
Cc: Vasudevan Sambandan <vasudevans@...>; Sundaresan S
<sundaresans@...>; Gayathri Thunuguntla <gayathrit@...>
Subject: [PATCH] ShellPkg: Displaying SMBIOS Type38 fields in formatted
manner

In smbiosview command, modified the below SMBIOS Type38 fields to display
in formatted manner 1. Base Address 2. IPMI Specification Version 3. NV
Storage Device Address 4. I2C Slave Address

Signed-off-by: Prakash K<prakashk@...>
---
.../SmbiosView/PrintInfo.c | 20
+++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git
a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
index b144600a25..0a8dd4afba 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
+++
b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
@@ -1158,10 +1158,22 @@ SmbiosPrintStructure (
//

case 38:

DisplayIPMIDIBMCInterfaceType (Struct->Type38->InterfaceType,
Option);

- PRINT_STRUCT_VALUE_H (Struct, Type38, IPMISpecificationRevision);

- PRINT_STRUCT_VALUE_H (Struct, Type38, I2CSlaveAddress);

- PRINT_STRUCT_VALUE_H (Struct, Type38, NVStorageDeviceAddress);

- PRINT_STRUCT_VALUE_LH (Struct, Type38, BaseAddress);

+ ShellPrintEx(-1,-1,L"IPMISpecificationRevision: %d.%d\n",
+ Struct->Type38->IPMISpecificationRevision >> 4,

+
+ Struct->Type38->IPMISpecificationRevision & 0x0F);

+

+ ShellPrintEx(-1, -1,L"I2CSlaveAddress: 0x%x\n",Struct->
+ Type38->I2CSlaveAddress >>1);

+

+ if (Struct->Type38->NVStorageDeviceAddress == 0xFF) {

+ ShellPrintEx(-1,-1,L"NVStorageDevice: Not Present\n");

+ } else {

+ PRINT_STRUCT_VALUE_H (Struct, Type38,
NVStorageDeviceAddress);

+ }

+

+ if (Struct->Type38->InterfaceType ==
+ IPMIDeviceInfoInterfaceTypeSSIF) {

+ ShellPrintEx(-1, -1,L"BaseAddress: 0x%x\n",Struct-> Type38->
+ BaseAddress >>1);

+ } else {

+ PRINT_STRUCT_VALUE_LH (Struct, Type38, BaseAddress);

+ }

break;



//

--
2.18.0.windows.1

This e-mail is intended for the use of the addressee only and may contain
privileged, confidential, or proprietary information that is exempt from
disclosure under law. If you have received this message in error, please
inform
us promptly by reply e-mail, then delete the e-mail and destroy any
printed
copy. Thank you.
-The information contained in this message may be confidential and
proprietary to American Megatrends (AMI). This communication is intended
to
be read only by the individual or entity to whom it is addressed or by
their
designee. If the reader of this message is not the intended recipient, you
are
on notice that any distribution of this message, in any form, is strictly
prohibited. Please promptly notify the sender by reply e-mail or by
telephone
at 770-246-8600, and then delete or destroy all copies of the
transmission.




Event: Tools, CI, Code base construction meeting series - 08/29/2022 #cal-reminder

Group Notification <noreply@...>
 

Reminder: Tools, CI, Code base construction meeting series

When:
08/29/2022
4:30pm to 5:30pm
(UTC-07:00) America/Los Angeles

Where:
https://github.com/tianocore/edk2/discussions/2614

View Event

Description:

TianoCore community,

Microsoft and Intel will be hosting a series of open meetings to discuss build, CI, tools, and other related topics. If you are interested, have ideas/opinions please join us. These meetings will be Monday 4:30pm Pacific Time on Microsoft Teams.

MS Teams Link in following discussion: * https://github.com/tianocore/edk2/discussions/2614

Anyone is welcome to join.

MS Teams Browser Clients * https://docs.microsoft.com/en-us/microsoftteams/get-clients?tabs=Windows#browser-client


[PATCH v1 1/1] MdePkg: Remove the restriction of SmmCpuRendezvousLibNull.

Li, Zhihao
 

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

In the implementation of SmmCpuRendezvousLib null version,
there is a restriction in [LIBRARY_CLASS] section.
So removing the restriction that other type driver
can use SmmCpuRendezvousLib null version implemented.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>

Signed-off-by: Zhihao Li <zhihao.li@...>
---
MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c | 2 +-
MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c b/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c
index 769f4c673802..23284caee0f2 100644
--- a/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c
+++ b/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c
@@ -6,7 +6,7 @@

**/

-#include <Library/DebugLib.h>
+#include <Uefi.h>
#include <Library/SmmCpuRendezvousLib.h>

/**
diff --git a/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf b/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
index 7c9bac9af2ff..bc513d432a21 100644
--- a/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
+++ b/MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
@@ -13,8 +13,8 @@ [Defines]
INF_VERSION = 0x00010005
BASE_NAME = SmmCpuRendezvousLibNull
FILE_GUID = 1e5790ea-d013-4d7b-9047-b4342a762027
- MODULE_TYPE = DXE_SMM_DRIVER
- LIBRARY_CLASS = SmmCpuRendezvousLib|MM_STANDALONE DXE_SMM_DRIVER
+ MODULE_TYPE = BASE
+ LIBRARY_CLASS = SmmCpuRendezvousLib

[Sources]
SmmCpuRendezvousLibNull.c
--
2.26.2.windows.1


[PATCH] edk2-staging/RedfishClientPkg: Update Redfish converter lib

Chang, Abner
 

From: Abner Chang <abner.chang@...>

Temporary modified on the auto-generated lib to support
Redfish BIOS attributes. RedfishScemaToCStructure python
script needs to be updated for fixing this issue.

Signed-off-by: Abner Chang <abner.chang@...>
Cc: Yang Atom <Atom.Yang@...>
Cc: Nick Ramirez <nramirez@...>
Cc: Nickle Wang <nickle@...>
Cc: Igor Kulchytskyy <igork@...>
---
.../ConverterLib/src/Bios/Bios.V1_0_9/Bios.V1_0_9.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/RedfishClientPkg/ConverterLib/src/Bios/Bios.V1_0_9/Bios.V1_0_9.c b/RedfishClientPkg/ConverterLib/src/Bios/Bios.V1_0_9/Bios.V1_0_9.c
index d698321886..1ec97db891 100644
--- a/RedfishClientPkg/ConverterLib/src/Bios/Bios.V1_0_9/Bios.V1_0_9.c
+++ b/RedfishClientPkg/ConverterLib/src/Bios/Bios.V1_0_9/Bios.V1_0_9.c
@@ -367,17 +367,17 @@ Error:;
}
static RedfishCS_status CS_To_JSON_Attributes(json_t *CsJson, char *Key, RedfishBios_V1_0_9_Attributes_CS *CSPtr)
{
- json_t *CsParentJson;
+ //json_t *CsParentJson;

if (CSPtr == NULL) {
return RedfishCS_status_success;
}

- CsParentJson = CsJson;
- CsJson = json_object();
- if (CsJson == NULL) {
- return RedfishCS_status_unsupported;
- }
+ //CsParentJson = CsJson;
+ //CsJson = json_object();
+ //if (CsJson == NULL) {
+ // return RedfishCS_status_unsupported;
+ //}

// Check if this is RedfishCS_Type_CS_EmptyProp.
CsEmptyPropLinkToJson(CsJson, Key, &CSPtr->Prop);
--
2.37.1.windows.1


Re: How to restrict HTTPS boot to a single address

Sivaraman Nainar
 

Hello Rafael.

 

HttpBootCheckUriScheme() in HttpBootDxe\HttpBootSupport.c should be the right place to filter the URI.

 

Please give a try.

 

-Siva

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rafael Machado via groups.io
Sent: Friday, August 26, 2022 7:46 PM
To: devel@edk2.groups.io
Subject: [EXTERNAL] [edk2-devel] How to restrict HTTPS boot to a single address

 

 

**CAUTION: The e-mail below is from an external source. Please exercise caution before opening attachments, clicking links, or following guidance.**

Hello everyone.

 

Quick question for the ones that understand better the HTTPBoot architecture at the edk2 structure.

 

Suppose I have to restrict HTTPS boot to accept only the download of images from a specific url.

For example, instead of allowing the download of images from any valid CA certificate address, I would like to restrict HTTPSBoot to allow only downloads from some specific domain I have.

 

Probably filtering some information, CN or something like that, from the url certificate.

 

What is the best way to do that?

In which driver/library should this logic be added?

 

Thanks

Rafael

-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.


Re: [edk2-stable202208 0/3] Revert three patches for edk2 stable tag 202208

Ard Biesheuvel
 

On Fri, 26 Aug 2022 at 04:15, gaoliming via groups.io
<gaoliming@...> wrote:

Two features will be merged after the stable tag 202208 is created.
One behavior change will be discussed further.

Liming Gao (3):
Revert "UefiCpuPkg/CpuPageTableLib/UnitTest: Add host based unit test"
Revert "ShellPkg: Adds Local APIC parser to AcpiView"
Revert "BaseTools: Fix DSC LibraryClass precedence rule"
Acked-by: Ard Biesheuvel <ardb@...>


[PATCH V2 14/14] MdeModulePkg: Pool and page functions accept memory when OOM occurs

Min Xu
 

From: Jiaqi Gao <jiaqi.gao@...>

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

When CoreAllocatePages() / CoreAllocatePool() meets error of
EFI_OUT_OF_RESOURCES, locate the EdkiiMemoryAcceptProtocol and accept extra
memory dynamically.

Firstly, find the unaccpeted memory region with enough size in GCD
entries. Then locate the EdkiiMemoryAcceptProtocol and accept the memory.
Finally, update the GCD memory and gMemoryMap entries.

After updating the memory infomation, CoreInternalAllocatePages() /
CoreInternalAllocatePool() will be recalled to allocate pages / pool.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Liming Gao <gaoliming@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Jiaqi Gao <jiaqi.gao@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdeModulePkg/Core/Dxe/DxeMain.inf | 1 +
MdeModulePkg/Core/Dxe/Mem/Imem.h | 16 +++
MdeModulePkg/Core/Dxe/Mem/Page.c | 190 ++++++++++++++++++++++++++++++
MdeModulePkg/Core/Dxe/Mem/Pool.c | 14 +++
4 files changed, 221 insertions(+)

diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf
index e4bca895773d..371ba45357be 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain.inf
+++ b/MdeModulePkg/Core/Dxe/DxeMain.inf
@@ -169,6 +169,7 @@
gEfiVariableArchProtocolGuid ## CONSUMES
gEfiCapsuleArchProtocolGuid ## CONSUMES
gEfiWatchdogTimerArchProtocolGuid ## CONSUMES
+ gEdkiiMemoryAcceptProtocolGuid ## CONSUMES

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressBootTimeCodePageNumber ## SOMETIMES_CONSUMES
diff --git a/MdeModulePkg/Core/Dxe/Mem/Imem.h b/MdeModulePkg/Core/Dxe/Mem/Imem.h
index 2f0bf2bf631f..22e0d0e44030 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Imem.h
+++ b/MdeModulePkg/Core/Dxe/Mem/Imem.h
@@ -47,6 +47,22 @@ typedef struct {
// Internal prototypes
//

+/**
+ Internal function. Used by the pool and page functions to accept memory
+ when OOM occurs.
+
+ @param Type The type of allocation to perform.
+ @param AcceptSize Size of memory to be accepted.
+ @param Memory Accept memory address
+
+**/
+EFI_STATUS
+AcceptMemoryResource (
+ IN EFI_ALLOCATE_TYPE Type,
+ IN UINTN AcceptSize,
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory
+ );
+
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 160289c1f9ec..513792a7fe04 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -10,6 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Imem.h"
#include "HeapGuard.h"
#include <Pi/PrePiDxeCis.h>
+#include <Protocol/MemoryAccept.h>

//
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
@@ -379,6 +380,176 @@ CoreFreeMemoryMapStack (
mFreeMapStack -= 1;
}

+/**
+ Used to accept memory when OOM occurs.
+
+ @param Type The type of allocation to perform.
+ @param AcceptSize Size of memory to be accepted.
+ @param Memory Accept memory address
+
+**/
+EFI_STATUS
+AcceptMemoryResource (
+ IN EFI_ALLOCATE_TYPE Type,
+ IN UINTN AcceptSize,
+ IN OUT EFI_PHYSICAL_ADDRESS *Memory
+ )
+{
+ #ifdef MDE_CPU_X64
+
+ LIST_ENTRY *Link;
+ EFI_GCD_MAP_ENTRY *GcdEntry;
+ EFI_GCD_MAP_ENTRY UnacceptedEntry;
+ EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;
+ UINTN Start;
+ UINTN End;
+ EFI_STATUS Status;
+
+ //
+ // We accept n*32MB at one time to improve the efficiency.
+ //
+ AcceptSize = (AcceptSize + SIZE_32MB - 1) & ~(SIZE_32MB - 1);
+
+ if (AcceptSize == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (VOID **)&MemoryAcceptProtocol);
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Type == AllocateAddress) {
+ Start = *Memory;
+ End = *Memory + AcceptSize;
+ }
+
+ if (Type == AllocateMaxAddress) {
+ if (*Memory < EFI_PAGE_MASK) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((*Memory & EFI_PAGE_MASK) != EFI_PAGE_MASK) {
+ //
+ // Change MaxAddress to be 1 page lower
+ //
+ *Memory -= EFI_PAGE_SIZE;
+
+ //
+ // Set MaxAddress to a page boundary
+ //
+ *Memory &= ~(UINT64)EFI_PAGE_MASK;
+
+ //
+ // Set MaxAddress to end of the page
+ //
+ *Memory |= EFI_PAGE_MASK;
+ }
+ }
+
+ //
+ // Traverse the mGcdMemorySpaceMap to find out the unaccepted
+ // memory entry with big enough size.
+ //
+ Link = mGcdMemorySpaceMap.ForwardLink;
+ while (Link != &mGcdMemorySpaceMap) {
+ GcdEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
+ if (GcdEntry->GcdMemoryType == EFI_GCD_MEMORY_TYPE_UNACCEPTED) {
+ if (Type == AllocateMaxAddress) {
+ if (GcdEntry->BaseAddress + AcceptSize - 1 > *Memory) {
+ Link = Link->ForwardLink;
+ continue;
+ }
+ } else if (Type == AllocateAddress) {
+ if ((GcdEntry->BaseAddress > *Memory) || (GcdEntry->EndAddress < *Memory + AcceptSize - 1)) {
+ Link = Link->ForwardLink;
+ continue;
+ }
+ }
+
+ //
+ // Is the entry big enough?
+ //
+ if (AcceptSize <= GcdEntry->EndAddress - GcdEntry->BaseAddress + 1) {
+ UnacceptedEntry = *GcdEntry;
+ if (Type != AllocateAddress) {
+ Start = UnacceptedEntry.BaseAddress;
+ End = UnacceptedEntry.BaseAddress + AcceptSize - 1;
+ }
+
+ break;
+ }
+ }
+
+ Link = Link->ForwardLink;
+ }
+
+ if (Link == &mGcdMemorySpaceMap) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Accept memory using the interface provide by the protocol.
+ //
+ Status = MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, Start, AcceptSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // If memory is accepted successfully, remove the target memory space from GCD.
+ //
+ CoreRemoveMemorySpace (UnacceptedEntry.BaseAddress, UnacceptedEntry.EndAddress - UnacceptedEntry.BaseAddress + 1);
+
+ //
+ // Add the remain lower part of unaccepted memory to the
+ // Gcd memory space and memory map.
+ //
+ if (Start > UnacceptedEntry.BaseAddress) {
+ CoreAddMemorySpace (
+ EFI_GCD_MEMORY_TYPE_UNACCEPTED,
+ UnacceptedEntry.BaseAddress,
+ Start - UnacceptedEntry.BaseAddress,
+ UnacceptedEntry.Capabilities
+ );
+ }
+
+ //
+ // Update accepted part of the memory entry to type of EfiGcdMemoryTypeSystemMemory
+ // and add the range to the memory map.
+ //
+ CoreAddMemorySpace (
+ EfiGcdMemoryTypeSystemMemory,
+ Start,
+ AcceptSize,
+ //
+ // Hardcode memory space attributes.
+ //
+ EFI_MEMORY_CPU_CRYPTO | EFI_MEMORY_XP | EFI_MEMORY_RO | EFI_MEMORY_RP
+ );
+
+ //
+ // Add the remain higher part of unaccepted memory to the
+ // Gcd memory space and memory map.
+ //
+ if (UnacceptedEntry.EndAddress > End) {
+ CoreAddMemorySpace (
+ EFI_GCD_MEMORY_TYPE_UNACCEPTED,
+ End + 1,
+ UnacceptedEntry.EndAddress - End,
+ UnacceptedEntry.Capabilities
+ );
+ }
+
+ return EFI_SUCCESS;
+
+ #else
+
+ return EFI_UNSUPPORTED;
+
+ #endif
+}
+
/**
Find untested but initialized memory regions in GCD map and convert them to be DXE allocatable.

@@ -1486,6 +1657,25 @@ CoreAllocatePages (
Memory,
NeedGuard
);
+ #ifdef MDE_CPU_X64
+
+ if (Status == EFI_OUT_OF_RESOURCES) {
+ Status = AcceptMemoryResource (Type, NumberOfPages << EFI_PAGE_SHIFT, Memory);
+ if (!EFI_ERROR (Status)) {
+ Status = CoreInternalAllocatePages (
+ Type,
+ MemoryType,
+ NumberOfPages,
+ Memory,
+ NeedGuard
+ );
+ } else {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ #endif
+
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
index 7aaf501600cf..9e8c8611c1ef 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
@@ -273,6 +273,20 @@ CoreAllocatePool (
EFI_STATUS Status;

Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
+
+ #ifdef MDE_CPU_X64
+
+ if (Status == EFI_OUT_OF_RESOURCES) {
+ Status = AcceptMemoryResource (AllocateAnyPages, Size, NULL);
+ if (!EFI_ERROR (Status)) {
+ Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
+ } else {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ #endif
+
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
--
2.29.2.windows.2


[PATCH V2 13/14] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

After EdkiiMemoryAcceptProtocol is implemented in TdxDxe driver, we can
call it to accept pages in DXE phase.

Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf | 3 +++
.../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
index a8abfec12fa3..11768825f8ca 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
@@ -42,3 +42,6 @@

[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
+
+[Protocols]
+ gEdkiiMemoryAcceptProtocolGuid
diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
index 9d11c6e4df72..503f626d75c6 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
@@ -27,6 +27,8 @@
#include "VirtualMemory.h"
#include <IndustryStandard/Tdx.h>
#include <Library/TdxLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MemoryAccept.h>
#include <ConfidentialComputingGuestAttr.h>

typedef enum {
@@ -517,8 +519,9 @@ SetOrClearSharedBit (
IN UINT64 Length
)
{
- UINT64 AddressEncMask;
- UINT64 Status;
+ UINT64 AddressEncMask;
+ UINT64 Status;
+ EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;

AddressEncMask = GetMemEncryptionAddressMask ();

@@ -539,7 +542,10 @@ SetOrClearSharedBit (
// If changing shared to private, must accept-page again
//
if (Mode == ClearSharedBit) {
- TdAcceptPages (PhysicalAddress, Length / EFI_PAGE_SIZE, EFI_PAGE_SIZE);
+ Status = gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (VOID **)&MemoryAcceptProtocol);
+ ASSERT (!EFI_ERROR (Status));
+ Status = MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, PhysicalAddress, Length);
+ ASSERT (!EFI_ERROR (Status));
}

DEBUG ((
--
2.29.2.windows.2


[PATCH V2 12/14] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

Memory usage may exceed the amount accepted at the begining (SEC), TDVF
needs to accept memory dynamically when OUT_OF_RESOURCE occurs.

EdkiiMemoryAcceptProtocol is defined in MdePkg and is implementated /
installed in TdxDxe for Intel TDX memory acceptance.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++++++++++++++++++++++
OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
2 files changed, 105 insertions(+)

diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c
index 2318db989792..ca948522a42c 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.c
+++ b/OvmfPkg/TdxDxe/TdxDxe.c
@@ -24,6 +24,7 @@
#include <Library/HobLib.h>
#include <Protocol/Cpu.h>
#include <Protocol/MpInitLibDepProtocols.h>
+#include <Protocol/MemoryAccept.h>
#include <Library/UefiBootServicesTableLib.h>
#include <ConfidentialComputingGuestAttr.h>
#include <IndustryStandard/Tdx.h>
@@ -32,6 +33,95 @@
#include <TdxAcpiTable.h>
#include <Library/MemEncryptTdxLib.h>

+#define ALIGNED_2MB_MASK 0x1fffff
+EFI_HANDLE mTdxDxeHandle = NULL;
+
+EFI_STATUS
+EFIAPI
+TdxMemoryAccept (
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ )
+{
+ EFI_STATUS Status;
+ UINT32 AcceptPageSize;
+ UINT64 StartAddress1;
+ UINT64 StartAddress2;
+ UINT64 StartAddress3;
+ UINT64 Length1;
+ UINT64 Length2;
+ UINT64 Length3;
+ UINT64 Pages;
+
+ AcceptPageSize = FixedPcdGet32 (PcdTdxAcceptPageSize);
+ StartAddress1 = 0;
+ StartAddress2 = 0;
+ StartAddress3 = 0;
+ Length1 = 0;
+ Length2 = 0;
+ Length3 = 0;
+
+ if (Size == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if (ALIGN_VALUE (StartAddress, SIZE_2MB) != StartAddress) {
+ StartAddress1 = StartAddress;
+ Length1 = ALIGN_VALUE (StartAddress, SIZE_2MB) - StartAddress;
+ if (Length1 >= Size) {
+ Length1 = Size;
+ }
+
+ StartAddress += Length1;
+ Size -= Length1;
+ }
+
+ if (Size > SIZE_2MB) {
+ StartAddress2 = StartAddress;
+ Length2 = Size & ~(UINT64)ALIGNED_2MB_MASK;
+ StartAddress += Length2;
+ Size -= Length2;
+ }
+
+ if (Size) {
+ StartAddress3 = StartAddress;
+ Length3 = Size;
+ }
+
+ Status = EFI_SUCCESS;
+ if (Length1 > 0) {
+ Pages = Length1 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress1, Pages, SIZE_4KB);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length2 > 0) {
+ Pages = Length2 / AcceptPageSize;
+ Status = TdAcceptPages (StartAddress2, Pages, AcceptPageSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length3 > 0) {
+ Pages = Length3 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress3, Pages, SIZE_4KB);
+ ASSERT (!EFI_ERROR (Status));
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ return Status;
+}
+
+EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = {
+ TdxMemoryAccept
+};
+
VOID
SetPcdSettings (
EFI_HOB_PLATFORM_INFO *PlatformInfoHob
@@ -277,6 +367,19 @@ TdxDxeEntryPoint (
NULL
);

+ //
+ // Install MemoryAccept protocol for TDX
+ //
+ Status = gBS->InstallProtocolInterface (
+ &mTdxDxeHandle,
+ &gEdkiiMemoryAcceptProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mMemoryAcceptProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Install EdkiiMemoryAcceptProtocol failed.\n"));
+ }
+
//
// Call TDINFO to get actual number of cpus in domain
//
diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf
index a7e0abda1522..9be021f28648 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.inf
+++ b/OvmfPkg/TdxDxe/TdxDxe.inf
@@ -52,6 +52,7 @@
gEfiAcpiTableProtocolGuid ## CONSUMES
gEfiMpInitLibMpDepProtocolGuid
gEfiMpInitLibUpDepProtocolGuid
+ gEdkiiMemoryAcceptProtocolGuid

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
@@ -68,3 +69,4 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
+ gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
--
2.29.2.windows.2


[PATCH V2 11/14] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol

Min Xu
 

From: Jiaqi Gao <jiaqi.gao@...>

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

EdkiiMemoryAcceptProtocol is defined in MdePkg, the method AcceptMemory()
can be called when memory needs to be accepted.

EdkiiMemoryAcceptProtocol can be installed by architecture-specific
drivers such as TdxDxe. This allows different isolation architectures
to realize their own low-level methods to accept memory.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Jiaqi Gao <jiaqi.gao@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdePkg/Include/Protocol/MemoryAccept.h | 37 ++++++++++++++++++++++++++
MdePkg/MdePkg.dec | 3 +++
2 files changed, 40 insertions(+)
create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h

diff --git a/MdePkg/Include/Protocol/MemoryAccept.h b/MdePkg/Include/Protocol/MemoryAccept.h
new file mode 100644
index 000000000000..f7646e04d8a1
--- /dev/null
+++ b/MdePkg/Include/Protocol/MemoryAccept.h
@@ -0,0 +1,37 @@
+/** @file
+ The file provides the protocol to provide interface to accept memory.
+
+ Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MEMORY_ACCEPT_H_
+#define MEMORY_ACCEPT_H_
+
+#define EDKII_MEMORY_ACCEPT_PROTOCOL_GUID \
+ { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 } };
+
+typedef struct _EDKII_MEMORY_ACCEPT_PROTOCOL EDKII_MEMORY_ACCEPT_PROTOCOL;
+
+/**
+ @param This A pointer to a EDKII_MEMORY_ACCEPT_PROTOCOL.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EDKII_ACCEPT_MEMORY)(
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ );
+
+///
+/// The EDKII_MEMORY_ACCEPT_PROTOCOL provides the ability for memory services
+/// to accept memory.
+///
+struct _EDKII_MEMORY_ACCEPT_PROTOCOL {
+ EDKII_ACCEPT_MEMORY AcceptMemory;
+};
+
+extern EFI_GUID gEdkiiMemoryAcceptProtocolGuid;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index f1ebf9e251c1..6b6bfbec29b3 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1019,6 +1019,9 @@
gEfiPeiDelayedDispatchPpiGuid = { 0x869c711d, 0x649c, 0x44fe, { 0x8b, 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }}

[Protocols]
+ ## Include/Protocol/MemoryAccept.h
+ gEdkiiMemoryAcceptProtocolGuid = { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 }}
+
## Include/Protocol/Pcd.h
gPcdProtocolGuid = { 0x11B34006, 0xD85B, 0x4D0A, { 0xA2, 0x90, 0xD5, 0xA5, 0x71, 0x31, 0x0E, 0xF7 }}

--
2.29.2.windows.2


[PATCH V2 10/14] OvmfPkg: Update ConstructFwHobList for lazy accept

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

In TDVF the hob list is constructed at the memory region which is the
largest one below 4GB. After lazy accept is introduced, the
MaxAcceptedMemoryAddress (which is tha max accpeted memory address in
lazy accept) should be considered.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 23 ++++++++++++++++++-
.../PeilessStartupLib/PeilessStartupLib.inf | 1 +
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index a9b92b5fbaba..884490af68fd 100644
--- a/OvmfPkg/Library/PeilessStartupLib/Hob.c
+++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c
@@ -21,6 +21,7 @@
#include <Library/PlatformInitLib.h>
#include <OvmfPlatforms.h>
#include <Pi/PrePiHob.h>
+#include <WorkArea.h>
#include "PeilessStartupInternal.h"

/**
@@ -74,10 +75,13 @@ ConstructFwHobList (
)
{
EFI_PEI_HOB_POINTERS Hob;
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
UINT64 ResourceLength;
EFI_PHYSICAL_ADDRESS LowMemoryStart;
UINT64 LowMemoryLength;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;

ASSERT (VmmHobList != NULL);

@@ -86,14 +90,31 @@ ConstructFwHobList (
LowMemoryLength = 0;
LowMemoryStart = 0;

+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }
+
//
// Parse the HOB list until end of list or matching type is found.
//
while (!END_OF_HOB_LIST (Hob)) {
if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
- if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
+ if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) && (Hob.ResourceDescriptor->PhysicalStart < MaxAcceptedMemoryAddress)) {
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+ PhysicalStart = Hob.ResourceDescriptor->PhysicalStart;
+
+ if ((PhysicalEnd >= MaxAcceptedMemoryAddress) && (PhysicalStart < MaxAcceptedMemoryAddress)) {
+ //
+ // This memory region is split into 2 parts. The left part is accepted.
+ //
+ PhysicalEnd = MaxAcceptedMemoryAddress;
+ ResourceLength = PhysicalEnd - PhysicalStart;
+ }

if (PhysicalEnd <= BASE_4GB) {
if (ResourceLength > LowMemoryLength) {
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
index def50b4b019e..eed9f27d3d01 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
@@ -88,3 +88,4 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
--
2.29.2.windows.2


[PATCH V2 09/14] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

There are below major changes in PlatformInitLib/PlatformPei
1. ProcessHobList
The unaccepted memory is accepted if the accumulated accepted memory is
smaller than the LazyAcceptMemSize. If a EFI_RESOURCE_MEMORY_UNACCEPTED
hob is cross the LazyAcceptMemSize, it will be split into 2 parts and
only the left one is accepted. The max accepted memory address is
stored in Tdx workarea which will be used in TransferTdxHobList.

Please be noted: in current stage, we only accept the memory under 4G.

2. TransferTdxHobList
Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob
if it is accepted. As it is mentioned in 1), there may be a
EFI_RESOURCE_MEMORY_UNACCEPTED hob which only part of the memory
describes in the hob is accepted. We also handles this situation
in TransferTdxHobList.

3. PlatformAdjustSystemMemorySizeBelow4gbForLazyAccep
The system memory size below 4GB may be larger than the accepted
memory. This function is used to handle this situation.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Include/Library/PlatformInitLib.h | 6 +
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 152 ++++++++++++++++--
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 27 ++++
.../PlatformInitLib/PlatformInitLib.inf | 1 +
OvmfPkg/PlatformPei/MemDetect.c | 5 +
5 files changed, 180 insertions(+), 11 deletions(-)

diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index 2987a367cc9c..187efcf34e14 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -144,6 +144,12 @@ PlatformGetSystemMemorySizeBelow4gb (
IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
);

+UINT32
+EFIAPI
+PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept (
+ IN UINT32 LowerMemorySize
+ );
+
/**
Initialize the PhysMemAddressWidth field in PlatformInfoHob based on guest RAM size.
**/
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index 396b14d919d2..5c408758756e 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -7,6 +7,7 @@

**/

+#include <Base.h>
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
@@ -24,7 +25,8 @@
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>

-#define ALIGNED_2MB_MASK 0x1fffff
+#define ALIGNED_2MB_MASK 0x1fffff
+#define MEGABYTE_SHIFT 20

/**
This function will be called to accept pages. Only BSP accepts pages.
@@ -375,15 +377,33 @@ ProcessHobList (
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ TDX_WORK_AREA *WorkArea;
+ UINT64 ResourceLength;
+ UINT64 AccumulateAcceptedMemory;
+ UINT64 LazyAcceptMemSize;
+ UINT64 MaxAcceptedMemoryAddress;

Status = EFI_SUCCESS;
ASSERT (VmmHobList != NULL);
Hob.Raw = (UINT8 *)VmmHobList;

+ AccumulateAcceptedMemory = 0;
+ MaxAcceptedMemoryAddress = 0;
+ LazyAcceptMemSize = FixedPcdGet64 (PcdLazyAcceptPartialMemorySize);
+ //
+ // If specified accept size is zero, accept all of the memory.
+ // Else transfer the size in megabyte to the number in byte.
+ //
+ if (LazyAcceptMemSize == 0) {
+ LazyAcceptMemSize = MAX_UINT64;
+ } else {
+ LazyAcceptMemSize <<= MEGABYTE_SHIFT;
+ }
+
//
// Parse the HOB list until end of list or matching type is found.
//
- while (!END_OF_HOB_LIST (Hob)) {
+ while (!END_OF_HOB_LIST (Hob) && AccumulateAcceptedMemory < LazyAcceptMemSize) {
if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
DEBUG ((DEBUG_INFO, "\nResourceType: 0x%x\n", Hob.ResourceDescriptor->ResourceType));

@@ -393,7 +413,26 @@ ProcessHobList (
DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescriptor->ResourceLength));
DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owner));

- PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+
+ if (AccumulateAcceptedMemory + ResourceLength > LazyAcceptMemSize) {
+ //
+ // If the memory can't be accepted completely, accept the part of it to meet the
+ // PcdLazyAcceptPartialMemorySize.
+ //
+ ResourceLength = LazyAcceptMemSize - AccumulateAcceptedMemory;
+ PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + ResourceLength;
+ }
+
+ if (PhysicalEnd > SIZE_4GB) {
+ //
+ // In current stage, we only accept the memory under 4G
+ //
+ ResourceLength -= (PhysicalEnd - SIZE_4GB);
+ LazyAcceptMemSize -= (PhysicalEnd - SIZE_4GB);
+ PhysicalEnd = SIZE_4GB;
+ }

Status = BspAcceptMemoryResourceRange (
Hob.ResourceDescriptor->PhysicalStart,
@@ -402,12 +441,25 @@ ProcessHobList (
if (EFI_ERROR (Status)) {
break;
}
+
+ AccumulateAcceptedMemory += ResourceLength;
+ MaxAcceptedMemoryAddress = PhysicalEnd;
}
}

Hob.Raw = GET_NEXT_HOB (Hob);
}

+ //
+ // Record MaxAcceptedMemoryAddress in OvmfWorkArea.
+ // This information is useful later but in SEC phase we cannot use a global
+ // variable to pass this value. So it is stored in OvmfWorkarea.
+ //
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress = MaxAcceptedMemoryAddress;
+
return Status;
}

@@ -460,6 +512,74 @@ ProcessTdxHobList (
return Status;
}

+/**
+ * Build ResourceDescriptorHob for the unaccepted memory region.
+ * This memory region may be splitted into 2 parts because of lazy accept.
+ *
+ * @param Hob Point to the EFI_HOB_RESOURCE_DESCRIPTOR
+ * @param MaxAcceptedMemoryAddress The max accepted memory address
+ * @return VOID
+ */
+VOID
+BuildResourceDescriptorHobForUnacceptedMemory (
+ IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob,
+ IN UINT64 MaxAcceptedMemoryAddress
+ )
+{
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
+ EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ UINT64 ResourceLength;
+ EFI_RESOURCE_TYPE ResourceType;
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 AcceptedResourceLength;
+
+ ASSERT (Hob->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED);
+
+ ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED;
+ ResourceAttribute = Hob->ResourceAttribute;
+ PhysicalStart = Hob->PhysicalStart;
+ ResourceLength = Hob->ResourceLength;
+ PhysicalEnd = PhysicalStart + ResourceLength;
+
+ if (PhysicalEnd <= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region has been accepted.
+ //
+ ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
+ ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ } else if (PhysicalStart >= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region hasn't been accepted.
+ // So keep the ResourceType and ResourceAttribute unchange.
+ //
+ } else {
+ //
+ // This memory region is splitted into 2 parts:
+ // the accepted and unaccepted.
+ //
+ AcceptedResourceLength = MaxAcceptedMemoryAddress - Hob->PhysicalStart;
+
+ // We build the ResourceDescriptorHob for the accepted part.
+ // The unaccepted part will be build out side the if-else block.
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttribute | (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED),
+ Hob->PhysicalStart,
+ AcceptedResourceLength
+ );
+
+ PhysicalStart = Hob->PhysicalStart + AcceptedResourceLength;
+ ResourceLength -= AcceptedResourceLength;
+ }
+
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ PhysicalStart,
+ ResourceLength
+ );
+}
+
/**
Transfer the incoming HobList for the TD to the final HobList for Dxe.
The Hobs transferred in this function are ResourceDescriptor hob and
@@ -477,6 +597,16 @@ TransferTdxHobList (
EFI_PEI_HOB_POINTERS Hob;
EFI_RESOURCE_TYPE ResourceType;
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;
+
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }

//
// PcdOvmfSecGhcbBase is used as the TD_HOB in Tdx guest.
@@ -489,16 +619,16 @@ TransferTdxHobList (
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;

if (ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
- ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
- ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescriptor, MaxAcceptedMemoryAddress);
+ } else {
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ Hob.ResourceDescriptor->PhysicalStart,
+ Hob.ResourceDescriptor->ResourceLength
+ );
}

- BuildResourceDescriptorHob (
- ResourceType,
- ResourceAttribute,
- Hob.ResourceDescriptor->PhysicalStart,
- Hob.ResourceDescriptor->ResourceLength
- );
break;
case EFI_HOB_TYPE_MEMORY_ALLOCATION:
BuildMemoryAllocationHob (
diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
index 942eaf89cfcf..d7c8b938f263 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -42,6 +42,8 @@ Module Name:

#include <Library/PlatformInitLib.h>

+#define MEGABYTE_SHIFT 20
+
VOID
EFIAPI
PlatformQemuUc32BaseInitialization (
@@ -289,6 +291,31 @@ GetHighestSystemMemoryAddressFromPvhMemmap (
return HighestAddress;
}

+UINT32
+EFIAPI
+PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept (
+ IN UINT32 LowerMemorySize
+ )
+{
+ #ifdef MDE_CPU_X64
+ UINT64 LazyAcceptMemSize;
+
+ LazyAcceptMemSize = FixedPcdGet64 (PcdLazyAcceptPartialMemorySize);
+ //
+ // If specified accept size is not zero,
+ // transfer the size in megabyte to the number in byte.
+ //
+ if (LazyAcceptMemSize != 0) {
+ LazyAcceptMemSize <<= MEGABYTE_SHIFT;
+ if (LazyAcceptMemSize < LowerMemorySize) {
+ LowerMemorySize = (UINT32)(UINTN)LazyAcceptMemSize;
+ }
+ }
+
+ #endif
+ return LowerMemorySize;
+}
+
UINT32
EFIAPI
PlatformGetSystemMemorySizeBelow4gb (
diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
index d2fa2d998df8..1c5ed1067ad4 100644
--- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
+++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -96,6 +96,7 @@
gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize

gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize

[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 2e47b1322990..acc1d7f63ee8 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -279,6 +279,11 @@ PublishPeiMemory (
LowerMemorySize -= mPlatformInfoHob.Q35TsegMbytes * SIZE_1MB;
}

+ //
+ // Adjustment for Lazy accept because it may accept part of the memory.
+ //
+ LowerMemorySize = PlatformAdjustSystemMemorySizeBelow4gbForLazyAccept (LowerMemorySize);
+
S3AcpiReservedMemoryBase = 0;
S3AcpiReservedMemorySize = 0;

--
2.29.2.windows.2


[PATCH V2 08/14] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

In lazy-accept the MaxAcceptedMemoryAddress is needed in
TransferTdxHobList and ContructFwHobList(at PeilessStartupLib). But in
SEC phase we cannot use a global variable to pass this value. So we add
a new field (MaxAcceptedMemoryAddress) in Tdx work area.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Include/WorkArea.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/OvmfPkg/Include/WorkArea.h b/OvmfPkg/Include/WorkArea.h
index bf56fc4a6f65..2c2a5816b0dc 100644
--- a/OvmfPkg/Include/WorkArea.h
+++ b/OvmfPkg/Include/WorkArea.h
@@ -71,6 +71,7 @@ typedef struct _SEC_TDX_WORK_AREA {
UINT32 PageTableReady;
UINT32 Gpaw;
UINT64 HobList;
+ UINT64 MaxAcceptedMemoryAddress;
} SEC_TDX_WORK_AREA;

typedef struct _TDX_WORK_AREA {
--
2.29.2.windows.2


[PATCH V2 07/14] OvmfPkg: Add PCD and DEFINEs for Lazy Accept page.

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

Lazy accept page can be controlled in build time like below:
-D LAZY_ACCEPT_PARTIAL_MEM=512

The unit is MB. If it is 0 then it means Lazy-accept is turned off.

Lazy-accept is turned off by default in OvmfPkgX64.
Lazy-accept is turned on with 512MB by default in IntelTdxX64.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 8 ++++++++
OvmfPkg/OvmfPkg.dec | 4 ++++
OvmfPkg/OvmfPkgX64.dsc | 9 +++++++++
3 files changed, 21 insertions(+)

diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 71b1cf8e7090..7ab2dc6fffe4 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -62,6 +62,11 @@
#
DEFINE UP_CPU_DXE_GUID = 6490f1c5-ebcc-4665-8892-0075b9bb49b7

+ #
+ # Define the size of lazy accepted memory. The unit is MB.
+ #
+ DEFINE LAZY_ACCEPT_PARTIAL_MEM = 512
+
[BuildOptions]
GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG
@@ -453,6 +458,9 @@
# Point to the MdeModulePkg/Application/UiApp/UiApp.inf
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }

+ # The partial memory size in Lazy accept
+ gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|$(LAZY_ACCEPT_PARTIAL_MEM)
+
################################################################################
#
# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 5af76a540529..49fc20831ad0 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -399,6 +399,10 @@
## The Tdx accept page size. 0x1000(4k),0x200000(2M)
gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize|0x200000|UINT32|0x65

+ ## The partial memory size in Lazy accept. Its unit is MB.
+ ## The default value is 0 which means lazy accept is turned off.
+ gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|0|UINT64|0x68
+
[PcdsDynamic, PcdsDynamicEx]
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 6e68f60dc90f..026251ae7e69 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -78,6 +78,12 @@
DEFINE UP_CPU_PEI_GUID = 280251c4-1d09-4035-9062-839acb5f18c1
DEFINE UP_CPU_DXE_GUID = 6490f1c5-ebcc-4665-8892-0075b9bb49b7

+ #
+ # Define the size of lazy accepted memory. The unit is MB.
+ # In OvmfPkgX64, the lazy accept page is disabled by default.
+ #
+ DEFINE LAZY_ACCEPT_PARTIAL_MEM = 0
+
[BuildOptions]
GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG
@@ -600,6 +606,9 @@
# Point to the MdeModulePkg/Application/UiApp/UiApp.inf
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }

+ # The partial memory size in Lazy accept
+ gUefiOvmfPkgTokenSpaceGuid.PcdLazyAcceptPartialMemorySize|$(LAZY_ACCEPT_PARTIAL_MEM)
+
################################################################################
#
# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
--
2.29.2.windows.2


[PATCH V2 06/14] ShellPkg: Update shell command memmap to show unaccepted memory

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

ShellCommandRunMemMap() is updated to handle the case of unaccepted
memory type.

Cc: Ray Ni <ray.ni@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 13 +++++++++++++
.../UefiShellDebug1CommandsLib.uni | 3 ++-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index 72f3c58b0970..a089953b286f 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -26,6 +26,7 @@ STATIC CONST CHAR16 NameEfiACPIMemoryNVS[] = L"ACPIMemoryNVS";
STATIC CONST CHAR16 NameEfiMemoryMappedIO[] = L"MemoryMappedIO";
STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MemoryMappedIOPortSpace";
STATIC CONST CHAR16 NameEfiPalCode[] = L"PalCode";
+STATIC CONST CHAR16 NameEfiUnacceptedMemoryType[] = L"Unaccepted";

//
// Need short names for some memory types
@@ -151,6 +152,8 @@ ShellCommandRunMemMap (
UINT64 UnusableMemoryPagesSize;
UINT64 PalCodePages;
UINT64 PalCodePagesSize;
+ UINT64 UnacceptedPages;
+ UINT64 UnacceptedPagesSize;
UINT64 PersistentPages;
UINT64 PersistentPagesSize;
BOOLEAN Sfo;
@@ -175,6 +178,7 @@ ShellCommandRunMemMap (
PalCodePages = 0;
PersistentPages = 0;
Size = 0;
+ UnacceptedPages = 0;
Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -303,6 +307,11 @@ ShellCommandRunMemMap (
TotalPages += Walker->NumberOfPages;
PalCodePages += Walker->NumberOfPages;
break;
+ case EfiUnacceptedMemoryType:
+ ShellPrintHiiEx (-1, -1, NULL, (EFI_STRING_ID)(!Sfo ? STRING_TOKEN (STR_MEMMAP_LIST_ITEM) : STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiUnacceptedMemoryType, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64 (SIZE_4KB, Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ UnacceptedPages += Walker->NumberOfPages;
+ break;
default:
//
// Shell Spec defines the SFO format.
@@ -335,6 +344,7 @@ ShellCommandRunMemMap (
MmioSpacePagesSize = MultU64x64 (SIZE_4KB, MmioSpacePages);
MmioPortPagesSize = MultU64x64 (SIZE_4KB, MmioPortPages);
PalCodePagesSize = MultU64x64 (SIZE_4KB, PalCodePages);
+ UnacceptedPagesSize = MultU64x64 (SIZE_4KB, UnacceptedPages);
PersistentPagesSize = MultU64x64 (SIZE_4KB, PersistentPages);
UnusableMemoryPagesSize = MultU64x64 (SIZE_4KB, UnusableMemoryPages);
if (!Sfo) {
@@ -368,6 +378,8 @@ ShellCommandRunMemMap (
MmioPortPagesSize,
PalCodePages,
PalCodePagesSize,
+ UnacceptedPages,
+ UnacceptedPagesSize,
AvailPages,
AvailPagesSize,
PersistentPages,
@@ -422,6 +434,7 @@ ShellCommandRunMemMap (
AcpiReclaimPagesSize,
AcpiNvsPagesSize,
PalCodePagesSize,
+ UnacceptedPagesSize,
PersistentPagesSize
);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
index 6693be26e699..b1d239ed37ea 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
@@ -88,13 +88,14 @@
" MMIO : %,14ld Pages (%,ld Bytes)\r\n"
" MMIO_Port : %,14ld Pages (%,ld Bytes)\r\n"
" PalCode : %,14ld Pages (%,ld Bytes)\r\n"
+ " Unaccepted: %,14ld Pages (%,ld Bytes)\r\n"
" Available : %,14ld Pages (%,ld Bytes)\r\n"
" Persistent: %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM2 #language en-US " -------------- \r\n"
"Total Memory: %,14ld MB (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_ITEM_SFO #language en-US "MemoryMap,"%s","%LX","%LX","%LX","%LX"\r\n"
-#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld"\r\n"
+#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld", "%Ld"\r\n"

#string STR_EFI_COMPRESS_FAIL #language en-US "Unable to compress: %r.\r\n"
#string STR_EFI_DECOMPRESS_FAIL #language en-US "Unable to decompress: %r.\r\n"
--
2.29.2.windows.2

6461 - 6480 of 99273