BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
To support handling #VC exceptions and issuing VMGEXIT instructions,
create a library with functions that can be used to perform these
#VC/VMGEXIT related operations. This includes functions for:
- Handling #VC exceptions
- Preparing for and issuing a VMGEXIT
- Performing MMIO-related write operations to support flash emulation
- Performing AP related boot opeations
The base functions in this driver will not do anything and will return
an error if a return value is required. It is expected that other packages
(like OvmfPkg) will create a version of the library to fully support an
SEV-ES guest.
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
UefiCpuPkg/UefiCpuPkg.dec | 3 +
UefiCpuPkg/UefiCpuPkg.dsc | 2 +
UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++++
UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121 ++++++++++++++++++++
UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
6 files changed, 271 insertions(+)
diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index df5d02bae6b4..cb92f34b6f55 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
##
MpInitLib|Include/Library/MpInitLib.h
+ ## @libraryclass Provides function to support VMGEXIT processing.
+ VmgExitLib|Include/Library/VmgExitLib.h
+
[Guids]
gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index afa304128221..f0e58b90ff0a 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -56,6 +56,7 @@ [LibraryClasses]
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
+ VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
[LibraryClasses.common.SEC]
PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
@@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+ UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
UefiCpuPkg/SecCore/SecCore.inf
diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
new file mode 100644
index 000000000000..d8770a21c355
--- /dev/null
+++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
@@ -0,0 +1,27 @@
+## @file
+# VMGEXIT Support Library.
+#
+# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = VmgExitLibNull
+ MODULE_UNI_FILE = VmgExitLibNull.uni
+ FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = VmgExitLib
+
+[Sources.common]
+ VmgExitLibNull.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+ BaseLib
+
diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h b/UefiCpuPkg/Include/Library/VmgExitLib.h
new file mode 100644
index 000000000000..0b2f39026a4a
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
@@ -0,0 +1,103 @@
+/** @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.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __VMG_EXIT_LIB_H__
+#define __VMG_EXIT_LIB_H__
+
+#include <Protocol/DebugSupport.h>
+#include <Register/Amd/Ghcb.h>
+
+
+/**
+ 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.
+
+ @return 0 VMGEXIT succeeded.
+ @return Others VMGEXIT processing did not succeed. Exception
+ number to be propagated.
+
+**/
+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] Ghcb A pointer to the GHCB
+
+**/
+VOID
+EFIAPI
+VmgInit (
+ IN OUT GHCB *Ghcb
+ );
+
+/**
+ 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] Ghcb A pointer to the GHCB
+
+**/
+VOID
+EFIAPI
+VmgDone (
+ IN OUT GHCB *Ghcb
+ );
+
+/**
+ 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
+
+ @retval EFI_SUCCESS Exception 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
+ );
+
+#endif
diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
new file mode 100644
index 000000000000..30a239df298e
--- /dev/null
+++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
@@ -0,0 +1,121 @@
+/** @file
+ VMGEXIT Base Support Library.
+
+ Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/VmgExitLib.h>
+
+/**
+ Perform VMGEXIT.
+
+ Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
+ then handles the return actions.
+
+ The base library function returns an error in the form of a
+ GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
+
+ @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.
+
+ @return 0 VMGEXIT succeeded.
+ @return Others VMGEXIT processing did not succeed. Exception
+ event to be propagated.
+
+**/
+UINT64
+EFIAPI
+VmgExit (
+ IN OUT GHCB *Ghcb,
+ IN UINT64 ExitCode,
+ IN UINT64 ExitInfo1,
+ IN UINT64 ExitInfo2
+ )
+{
+ GHCB_EVENT_INJECTION Event;
+
+ Event.Uint64 = 0;
+ Event.Elements.Vector = GP_EXCEPTION;
+ Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
+ Event.Elements.Valid = 1;
+
+ return Event.Uint64;
+}
+
+/**
+ Perform pre-VMGEXIT initialization/preparation.
+
+ Performs the necessary steps in preparation for invoking VMGEXIT. Must be
+ called before setting any fields within the GHCB.
+
+ The base library function does nothing.
+
+ @param[in, out] Ghcb A pointer to the GHCB
+
+**/
+VOID
+EFIAPI
+VmgInit (
+ IN OUT GHCB *Ghcb
+ )
+{
+}
+
+/**
+ Perform post-VMGEXIT cleanup.
+
+ Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
+ called after obtaining needed fields within the GHCB.
+
+ The base library function does nothing.
+
+ @param[in, out] Ghcb A pointer to the GHCB
+
+**/
+VOID
+EFIAPI
+VmgDone (
+ IN OUT GHCB *Ghcb
+ )
+{
+}
+
+/**
+ 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
+
+ @retval EFI_SUCCESS Exception 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
+ )
+{
+ *ExceptionType = VC_EXCEPTION;
+
+ return EFI_UNSUPPORTED;
+}
diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
new file mode 100644
index 000000000000..8639bc0e8ce9
--- /dev/null
+++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
@@ -0,0 +1,15 @@
+// /** @file
+// VMGEXIT support library instance.
+//
+// VMGEXIT support library instance.
+//
+// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support NULL library instance"
+
+#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT support NULL library instance."
+
--
2.27.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#60778): https://edk2.groups.io/g/devel/message/60778
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Eric Dong <eric.dong@intel.com>
Thanks,
Eric
> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Friday, June 5, 2020 9:27 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek <lersek@redhat.com>;
> Gao, Liming <liming.gao@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> VMGEXIT
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
>
> To support handling #VC exceptions and issuing VMGEXIT instructions,
> create a library with functions that can be used to perform these
> #VC/VMGEXIT related operations. This includes functions for:
> - Handling #VC exceptions
> - Preparing for and issuing a VMGEXIT
> - Performing MMIO-related write operations to support flash emulation
> - Performing AP related boot opeations
>
> The base functions in this driver will not do anything and will return
> an error if a return value is required. It is expected that other packages
> (like OvmfPkg) will create a version of the library to fully support an
> SEV-ES guest.
>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> UefiCpuPkg/UefiCpuPkg.dec | 3 +
> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
> UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++++
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
> ++++++++++++++++++++
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
> 6 files changed, 271 insertions(+)
>
> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> index df5d02bae6b4..cb92f34b6f55 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dec
> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
> ##
>
> MpInitLib|Include/Library/MpInitLib.h
>
>
>
> + ## @libraryclass Provides function to support VMGEXIT processing.
>
> + VmgExitLib|Include/Library/VmgExitLib.h
>
> +
>
> [Guids]
>
> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
>
> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30,
> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
>
> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index afa304128221..f0e58b90ff0a 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -56,6 +56,7 @@ [LibraryClasses]
>
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> PeCoffGetEntryPointLib.inf
>
>
> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP
> eCoffExtraActionLibNull.inf
>
>
> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
> mMeasurementLibNull.inf
>
> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>
>
>
> [LibraryClasses.common.SEC]
>
>
> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.i
> nf
>
> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
>
> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
> Null.inf
>
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
>
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
>
> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>
> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
>
> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
>
> UefiCpuPkg/SecCore/SecCore.inf
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> new file mode 100644
> index 000000000000..d8770a21c355
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> @@ -0,0 +1,27 @@
> +## @file
>
> +# VMGEXIT Support Library.
>
> +#
>
> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +#
>
> +##
>
> +
>
> +[Defines]
>
> + INF_VERSION = 0x00010005
>
> + BASE_NAME = VmgExitLibNull
>
> + MODULE_UNI_FILE = VmgExitLibNull.uni
>
> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
>
> + MODULE_TYPE = BASE
>
> + VERSION_STRING = 1.0
>
> + LIBRARY_CLASS = VmgExitLib
>
> +
>
> +[Sources.common]
>
> + VmgExitLibNull.c
>
> +
>
> +[Packages]
>
> + MdePkg/MdePkg.dec
>
> + UefiCpuPkg/UefiCpuPkg.dec
>
> +
>
> +[LibraryClasses]
>
> + BaseLib
>
> +
>
> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
> b/UefiCpuPkg/Include/Library/VmgExitLib.h
> new file mode 100644
> index 000000000000..0b2f39026a4a
> --- /dev/null
> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
> @@ -0,0 +1,103 @@
> +/** @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.<BR>
>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#ifndef __VMG_EXIT_LIB_H__
>
> +#define __VMG_EXIT_LIB_H__
>
> +
>
> +#include <Protocol/DebugSupport.h>
>
> +#include <Register/Amd/Ghcb.h>
>
> +
>
> +
>
> +/**
>
> + 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.
>
> +
>
> + @return 0 VMGEXIT succeeded.
>
> + @return Others VMGEXIT processing did not succeed. Exception
>
> + number to be propagated.
>
> +
>
> +**/
>
> +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] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgInit (
>
> + IN OUT GHCB *Ghcb
>
> + );
>
> +
>
> +/**
>
> + 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] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgDone (
>
> + IN OUT GHCB *Ghcb
>
> + );
>
> +
>
> +/**
>
> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>
> +
>
> + @retval EFI_SUCCESS Exception 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
>
> + );
>
> +
>
> +#endif
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> new file mode 100644
> index 000000000000..30a239df298e
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> @@ -0,0 +1,121 @@
> +/** @file
>
> + VMGEXIT Base Support Library.
>
> +
>
> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include <Base.h>
>
> +#include <Uefi.h>
>
> +#include <Library/VmgExitLib.h>
>
> +
>
> +/**
>
> + Perform VMGEXIT.
>
> +
>
> + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction
> and
>
> + then handles the return actions.
>
> +
>
> + The base library function returns an error in the form of a
>
> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
>
> +
>
> + @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.
>
> +
>
> + @return 0 VMGEXIT succeeded.
>
> + @return Others VMGEXIT processing did not succeed. Exception
>
> + event to be propagated.
>
> +
>
> +**/
>
> +UINT64
>
> +EFIAPI
>
> +VmgExit (
>
> + IN OUT GHCB *Ghcb,
>
> + IN UINT64 ExitCode,
>
> + IN UINT64 ExitInfo1,
>
> + IN UINT64 ExitInfo2
>
> + )
>
> +{
>
> + GHCB_EVENT_INJECTION Event;
>
> +
>
> + Event.Uint64 = 0;
>
> + Event.Elements.Vector = GP_EXCEPTION;
>
> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
>
> + Event.Elements.Valid = 1;
>
> +
>
> + return Event.Uint64;
>
> +}
>
> +
>
> +/**
>
> + Perform pre-VMGEXIT initialization/preparation.
>
> +
>
> + Performs the necessary steps in preparation for invoking VMGEXIT. Must
> be
>
> + called before setting any fields within the GHCB.
>
> +
>
> + The base library function does nothing.
>
> +
>
> + @param[in, out] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgInit (
>
> + IN OUT GHCB *Ghcb
>
> + )
>
> +{
>
> +}
>
> +
>
> +/**
>
> + Perform post-VMGEXIT cleanup.
>
> +
>
> + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
>
> + called after obtaining needed fields within the GHCB.
>
> +
>
> + The base library function does nothing.
>
> +
>
> + @param[in, out] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgDone (
>
> + IN OUT GHCB *Ghcb
>
> + )
>
> +{
>
> +}
>
> +
>
> +/**
>
> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>
> +
>
> + @retval EFI_SUCCESS Exception 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
>
> + )
>
> +{
>
> + *ExceptionType = VC_EXCEPTION;
>
> +
>
> + return EFI_UNSUPPORTED;
>
> +}
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> new file mode 100644
> index 000000000000..8639bc0e8ce9
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> @@ -0,0 +1,15 @@
> +// /** @file
>
> +// VMGEXIT support library instance.
>
> +//
>
> +// VMGEXIT support library instance.
>
> +//
>
> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +//
>
> +// **/
>
> +
>
> +
>
> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support
> NULL library instance"
>
> +
>
> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
> support NULL library instance."
>
> +
>
> --
> 2.27.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61179): https://edk2.groups.io/g/devel/message/61179
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Tom,
When use VS2015 to build this code, it reports below error. Please help to fix it.
k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning treated as error - no 'object' file generated
k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
Thanks,
Eric
> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Friday, June 5, 2020 9:27 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek <lersek@redhat.com>;
> Gao, Liming <liming.gao@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> VMGEXIT
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
>
> To support handling #VC exceptions and issuing VMGEXIT instructions,
> create a library with functions that can be used to perform these
> #VC/VMGEXIT related operations. This includes functions for:
> - Handling #VC exceptions
> - Preparing for and issuing a VMGEXIT
> - Performing MMIO-related write operations to support flash emulation
> - Performing AP related boot opeations
>
> The base functions in this driver will not do anything and will return
> an error if a return value is required. It is expected that other packages
> (like OvmfPkg) will create a version of the library to fully support an
> SEV-ES guest.
>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> UefiCpuPkg/UefiCpuPkg.dec | 3 +
> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
> UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++++
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
> ++++++++++++++++++++
> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
> 6 files changed, 271 insertions(+)
>
> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> index df5d02bae6b4..cb92f34b6f55 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dec
> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
> ##
>
> MpInitLib|Include/Library/MpInitLib.h
>
>
>
> + ## @libraryclass Provides function to support VMGEXIT processing.
>
> + VmgExitLib|Include/Library/VmgExitLib.h
>
> +
>
> [Guids]
>
> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
>
> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30,
> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
>
> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index afa304128221..f0e58b90ff0a 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -56,6 +56,7 @@ [LibraryClasses]
>
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> PeCoffGetEntryPointLib.inf
>
>
> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP
> eCoffExtraActionLibNull.inf
>
>
> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
> mMeasurementLibNull.inf
>
> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>
>
>
> [LibraryClasses.common.SEC]
>
>
> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.i
> nf
>
> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
>
> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
> Null.inf
>
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
>
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
>
> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>
> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
>
> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
>
> UefiCpuPkg/SecCore/SecCore.inf
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> new file mode 100644
> index 000000000000..d8770a21c355
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> @@ -0,0 +1,27 @@
> +## @file
>
> +# VMGEXIT Support Library.
>
> +#
>
> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +#
>
> +##
>
> +
>
> +[Defines]
>
> + INF_VERSION = 0x00010005
>
> + BASE_NAME = VmgExitLibNull
>
> + MODULE_UNI_FILE = VmgExitLibNull.uni
>
> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
>
> + MODULE_TYPE = BASE
>
> + VERSION_STRING = 1.0
>
> + LIBRARY_CLASS = VmgExitLib
>
> +
>
> +[Sources.common]
>
> + VmgExitLibNull.c
>
> +
>
> +[Packages]
>
> + MdePkg/MdePkg.dec
>
> + UefiCpuPkg/UefiCpuPkg.dec
>
> +
>
> +[LibraryClasses]
>
> + BaseLib
>
> +
>
> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
> b/UefiCpuPkg/Include/Library/VmgExitLib.h
> new file mode 100644
> index 000000000000..0b2f39026a4a
> --- /dev/null
> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
> @@ -0,0 +1,103 @@
> +/** @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.<BR>
>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#ifndef __VMG_EXIT_LIB_H__
>
> +#define __VMG_EXIT_LIB_H__
>
> +
>
> +#include <Protocol/DebugSupport.h>
>
> +#include <Register/Amd/Ghcb.h>
>
> +
>
> +
>
> +/**
>
> + 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.
>
> +
>
> + @return 0 VMGEXIT succeeded.
>
> + @return Others VMGEXIT processing did not succeed. Exception
>
> + number to be propagated.
>
> +
>
> +**/
>
> +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] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgInit (
>
> + IN OUT GHCB *Ghcb
>
> + );
>
> +
>
> +/**
>
> + 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] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgDone (
>
> + IN OUT GHCB *Ghcb
>
> + );
>
> +
>
> +/**
>
> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>
> +
>
> + @retval EFI_SUCCESS Exception 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
>
> + );
>
> +
>
> +#endif
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> new file mode 100644
> index 000000000000..30a239df298e
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> @@ -0,0 +1,121 @@
> +/** @file
>
> + VMGEXIT Base Support Library.
>
> +
>
> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include <Base.h>
>
> +#include <Uefi.h>
>
> +#include <Library/VmgExitLib.h>
>
> +
>
> +/**
>
> + Perform VMGEXIT.
>
> +
>
> + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction
> and
>
> + then handles the return actions.
>
> +
>
> + The base library function returns an error in the form of a
>
> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
>
> +
>
> + @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.
>
> +
>
> + @return 0 VMGEXIT succeeded.
>
> + @return Others VMGEXIT processing did not succeed. Exception
>
> + event to be propagated.
>
> +
>
> +**/
>
> +UINT64
>
> +EFIAPI
>
> +VmgExit (
>
> + IN OUT GHCB *Ghcb,
>
> + IN UINT64 ExitCode,
>
> + IN UINT64 ExitInfo1,
>
> + IN UINT64 ExitInfo2
>
> + )
>
> +{
>
> + GHCB_EVENT_INJECTION Event;
>
> +
>
> + Event.Uint64 = 0;
>
> + Event.Elements.Vector = GP_EXCEPTION;
>
> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
>
> + Event.Elements.Valid = 1;
>
> +
>
> + return Event.Uint64;
>
> +}
>
> +
>
> +/**
>
> + Perform pre-VMGEXIT initialization/preparation.
>
> +
>
> + Performs the necessary steps in preparation for invoking VMGEXIT. Must
> be
>
> + called before setting any fields within the GHCB.
>
> +
>
> + The base library function does nothing.
>
> +
>
> + @param[in, out] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgInit (
>
> + IN OUT GHCB *Ghcb
>
> + )
>
> +{
>
> +}
>
> +
>
> +/**
>
> + Perform post-VMGEXIT cleanup.
>
> +
>
> + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
>
> + called after obtaining needed fields within the GHCB.
>
> +
>
> + The base library function does nothing.
>
> +
>
> + @param[in, out] Ghcb A pointer to the GHCB
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +VmgDone (
>
> + IN OUT GHCB *Ghcb
>
> + )
>
> +{
>
> +}
>
> +
>
> +/**
>
> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>
> +
>
> + @retval EFI_SUCCESS Exception 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
>
> + )
>
> +{
>
> + *ExceptionType = VC_EXCEPTION;
>
> +
>
> + return EFI_UNSUPPORTED;
>
> +}
>
> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> new file mode 100644
> index 000000000000..8639bc0e8ce9
> --- /dev/null
> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> @@ -0,0 +1,15 @@
> +// /** @file
>
> +// VMGEXIT support library instance.
>
> +//
>
> +// VMGEXIT support library instance.
>
> +//
>
> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>
> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +//
>
> +// **/
>
> +
>
> +
>
> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support
> NULL library instance"
>
> +
>
> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
> support NULL library instance."
>
> +
>
> --
> 2.27.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61468): https://edk2.groups.io/g/devel/message/61468
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 6/18/20 2:23 AM, Dong, Eric wrote:
> Hi Tom,
>
> When use VS2015 to build this code, it reports below error. Please help to fix it.
>
> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning treated as error - no 'object' file generated
> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
That is strange... I didn't see this when I ran through the CI. When I do
a file command against the file it reports:
UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with CRLF line terminators
I'll investigate this and try and figure out what's going on, but if
anyone else has some ideas, please let me know.
Thanks,
Tom
>
> Thanks,
> Eric
>
>> -----Original Message-----
>> From: Tom Lendacky <thomas.lendacky@amd.com>
>> Sent: Friday, June 5, 2020 9:27 PM
>> To: devel@edk2.groups.io
>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
>> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
>> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek <lersek@redhat.com>;
>> Gao, Liming <liming.gao@intel.com>; Kinney, Michael D
>> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
>> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
>> VMGEXIT
>>
>> BZ: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842&sdata=fBlK2BFkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3D&reserved=0
>>
>> To support handling #VC exceptions and issuing VMGEXIT instructions,
>> create a library with functions that can be used to perform these
>> #VC/VMGEXIT related operations. This includes functions for:
>> - Handling #VC exceptions
>> - Preparing for and issuing a VMGEXIT
>> - Performing MMIO-related write operations to support flash emulation
>> - Performing AP related boot opeations
>>
>> The base functions in this driver will not do anything and will return
>> an error if a return value is required. It is expected that other packages
>> (like OvmfPkg) will create a version of the library to fully support an
>> SEV-ES guest.
>>
>> Cc: Eric Dong <eric.dong@intel.com>
>> Cc: Ray Ni <ray.ni@intel.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
>> ---
>> UefiCpuPkg/UefiCpuPkg.dec | 3 +
>> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
>> UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++++
>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
>> ++++++++++++++++++++
>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
>> 6 files changed, 271 insertions(+)
>>
>> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
>> index df5d02bae6b4..cb92f34b6f55 100644
>> --- a/UefiCpuPkg/UefiCpuPkg.dec
>> +++ b/UefiCpuPkg/UefiCpuPkg.dec
>> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
>> ##
>>
>> MpInitLib|Include/Library/MpInitLib.h
>>
>>
>>
>> + ## @libraryclass Provides function to support VMGEXIT processing.
>>
>> + VmgExitLib|Include/Library/VmgExitLib.h
>>
>> +
>>
>> [Guids]
>>
>> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
>> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
>>
>> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30,
>> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
>>
>> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
>> index afa304128221..f0e58b90ff0a 100644
>> --- a/UefiCpuPkg/UefiCpuPkg.dsc
>> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
>> @@ -56,6 +56,7 @@ [LibraryClasses]
>>
>> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
>> PeCoffGetEntryPointLib.inf
>>
>>
>> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP
>> eCoffExtraActionLibNull.inf
>>
>>
>> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
>> mMeasurementLibNull.inf
>>
>> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>
>>
>>
>> [LibraryClasses.common.SEC]
>>
>>
>> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.i
>> nf
>>
>> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
>>
>> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
>> Null.inf
>>
>> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
>>
>> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
>>
>> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>
>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
>>
>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
>>
>> UefiCpuPkg/SecCore/SecCore.inf
>>
>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>> new file mode 100644
>> index 000000000000..d8770a21c355
>> --- /dev/null
>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>> @@ -0,0 +1,27 @@
>> +## @file
>>
>> +# VMGEXIT Support Library.
>>
>> +#
>>
>> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>>
>> +# SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> +#
>>
>> +##
>>
>> +
>>
>> +[Defines]
>>
>> + INF_VERSION = 0x00010005
>>
>> + BASE_NAME = VmgExitLibNull
>>
>> + MODULE_UNI_FILE = VmgExitLibNull.uni
>>
>> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
>>
>> + MODULE_TYPE = BASE
>>
>> + VERSION_STRING = 1.0
>>
>> + LIBRARY_CLASS = VmgExitLib
>>
>> +
>>
>> +[Sources.common]
>>
>> + VmgExitLibNull.c
>>
>> +
>>
>> +[Packages]
>>
>> + MdePkg/MdePkg.dec
>>
>> + UefiCpuPkg/UefiCpuPkg.dec
>>
>> +
>>
>> +[LibraryClasses]
>>
>> + BaseLib
>>
>> +
>>
>> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
>> b/UefiCpuPkg/Include/Library/VmgExitLib.h
>> new file mode 100644
>> index 000000000000..0b2f39026a4a
>> --- /dev/null
>> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
>> @@ -0,0 +1,103 @@
>> +/** @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.<BR>
>>
>> + SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> +
>>
>> +**/
>>
>> +
>>
>> +#ifndef __VMG_EXIT_LIB_H__
>>
>> +#define __VMG_EXIT_LIB_H__
>>
>> +
>>
>> +#include <Protocol/DebugSupport.h>
>>
>> +#include <Register/Amd/Ghcb.h>
>>
>> +
>>
>> +
>>
>> +/**
>>
>> + 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.
>>
>> +
>>
>> + @return 0 VMGEXIT succeeded.
>>
>> + @return Others VMGEXIT processing did not succeed. Exception
>>
>> + number to be propagated.
>>
>> +
>>
>> +**/
>>
>> +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] Ghcb A pointer to the GHCB
>>
>> +
>>
>> +**/
>>
>> +VOID
>>
>> +EFIAPI
>>
>> +VmgInit (
>>
>> + IN OUT GHCB *Ghcb
>>
>> + );
>>
>> +
>>
>> +/**
>>
>> + 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] Ghcb A pointer to the GHCB
>>
>> +
>>
>> +**/
>>
>> +VOID
>>
>> +EFIAPI
>>
>> +VmgDone (
>>
>> + IN OUT GHCB *Ghcb
>>
>> + );
>>
>> +
>>
>> +/**
>>
>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>>
>> +
>>
>> + @retval EFI_SUCCESS Exception 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
>>
>> + );
>>
>> +
>>
>> +#endif
>>
>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>> new file mode 100644
>> index 000000000000..30a239df298e
>> --- /dev/null
>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>> @@ -0,0 +1,121 @@
>> +/** @file
>>
>> + VMGEXIT Base Support Library.
>>
>> +
>>
>> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>>
>> + SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> +
>>
>> +**/
>>
>> +
>>
>> +#include <Base.h>
>>
>> +#include <Uefi.h>
>>
>> +#include <Library/VmgExitLib.h>
>>
>> +
>>
>> +/**
>>
>> + Perform VMGEXIT.
>>
>> +
>>
>> + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction
>> and
>>
>> + then handles the return actions.
>>
>> +
>>
>> + The base library function returns an error in the form of a
>>
>> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
>>
>> +
>>
>> + @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.
>>
>> +
>>
>> + @return 0 VMGEXIT succeeded.
>>
>> + @return Others VMGEXIT processing did not succeed. Exception
>>
>> + event to be propagated.
>>
>> +
>>
>> +**/
>>
>> +UINT64
>>
>> +EFIAPI
>>
>> +VmgExit (
>>
>> + IN OUT GHCB *Ghcb,
>>
>> + IN UINT64 ExitCode,
>>
>> + IN UINT64 ExitInfo1,
>>
>> + IN UINT64 ExitInfo2
>>
>> + )
>>
>> +{
>>
>> + GHCB_EVENT_INJECTION Event;
>>
>> +
>>
>> + Event.Uint64 = 0;
>>
>> + Event.Elements.Vector = GP_EXCEPTION;
>>
>> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
>>
>> + Event.Elements.Valid = 1;
>>
>> +
>>
>> + return Event.Uint64;
>>
>> +}
>>
>> +
>>
>> +/**
>>
>> + Perform pre-VMGEXIT initialization/preparation.
>>
>> +
>>
>> + Performs the necessary steps in preparation for invoking VMGEXIT. Must
>> be
>>
>> + called before setting any fields within the GHCB.
>>
>> +
>>
>> + The base library function does nothing.
>>
>> +
>>
>> + @param[in, out] Ghcb A pointer to the GHCB
>>
>> +
>>
>> +**/
>>
>> +VOID
>>
>> +EFIAPI
>>
>> +VmgInit (
>>
>> + IN OUT GHCB *Ghcb
>>
>> + )
>>
>> +{
>>
>> +}
>>
>> +
>>
>> +/**
>>
>> + Perform post-VMGEXIT cleanup.
>>
>> +
>>
>> + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
>>
>> + called after obtaining needed fields within the GHCB.
>>
>> +
>>
>> + The base library function does nothing.
>>
>> +
>>
>> + @param[in, out] Ghcb A pointer to the GHCB
>>
>> +
>>
>> +**/
>>
>> +VOID
>>
>> +EFIAPI
>>
>> +VmgDone (
>>
>> + IN OUT GHCB *Ghcb
>>
>> + )
>>
>> +{
>>
>> +}
>>
>> +
>>
>> +/**
>>
>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>>
>> +
>>
>> + @retval EFI_SUCCESS Exception 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
>>
>> + )
>>
>> +{
>>
>> + *ExceptionType = VC_EXCEPTION;
>>
>> +
>>
>> + return EFI_UNSUPPORTED;
>>
>> +}
>>
>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>> new file mode 100644
>> index 000000000000..8639bc0e8ce9
>> --- /dev/null
>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>> @@ -0,0 +1,15 @@
>> +// /** @file
>>
>> +// VMGEXIT support library instance.
>>
>> +//
>>
>> +// VMGEXIT support library instance.
>>
>> +//
>>
>> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
>>
>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>>
>> +//
>>
>> +// **/
>>
>> +
>>
>> +
>>
>> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support
>> NULL library instance"
>>
>> +
>>
>> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
>> support NULL library instance."
>>
>> +
>>
>> --
>> 2.27.0
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61486): https://edk2.groups.io/g/devel/message/61486
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> Lendacky, Thomas
> Sent: Thursday, June 18, 2020 10:09 PM
> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io
> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>;
> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
>
> On 6/18/20 2:23 AM, Dong, Eric wrote:
> > Hi Tom,
> >
> > When use VS2015 to build this code, it reports below error. Please help to
> fix it.
> >
> > k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning
> > treated as error - no 'object' file generated
> > k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
> > file format detected: please convert the source file to either DOS or
> > UNIX format
>
> That is strange... I didn't see this when I ran through the CI. When I do a file
> command against the file it reports:
>
> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with CRLF
> line terminators
>
> I'll investigate this and try and figure out what's going on, but if anyone else
> has some ideas, please let me know.
Hi Tom,
I met this error again when I trig below patch from AMD again for CPU change.
"UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"
I'm not sure whether this is patch issue, or our internal test sever issue. I have reported this error to our internal team to check also.
Please check it from your side and make sure no error from your side. I will update the status from my side when I get the update.
Thanks,
Eric
>
> Thanks,
> Tom
>
> >
> > Thanks,
> > Eric
> >
> >> -----Original Message-----
> >> From: Tom Lendacky <thomas.lendacky@amd.com>
> >> Sent: Friday, June 5, 2020 9:27 PM
> >> To: devel@edk2.groups.io
> >> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> >> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
> >> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek
> >> <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; Kinney,
> >> Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> >> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> >> VMGEXIT
> >>
> >> BZ:
> >>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbug
> >>
> zilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Ct
> ho
> >>
> mas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd
> 8961fe
> >>
> 4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842&sdata=
> fBlK2B
> >> FkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3D&reserved=0
> >>
> >> To support handling #VC exceptions and issuing VMGEXIT instructions,
> >> create a library with functions that can be used to perform these
> >> #VC/VMGEXIT related operations. This includes functions for:
> >> - Handling #VC exceptions
> >> - Preparing for and issuing a VMGEXIT
> >> - Performing MMIO-related write operations to support flash emulation
> >> - Performing AP related boot opeations
> >>
> >> The base functions in this driver will not do anything and will
> >> return an error if a return value is required. It is expected that
> >> other packages (like OvmfPkg) will create a version of the library to
> >> fully support an SEV-ES guest.
> >>
> >> Cc: Eric Dong <eric.dong@intel.com>
> >> Cc: Ray Ni <ray.ni@intel.com>
> >> Cc: Laszlo Ersek <lersek@redhat.com>
> >> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> >> ---
> >> UefiCpuPkg/UefiCpuPkg.dec | 3 +
> >> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
> >> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
> >> UefiCpuPkg/Include/Library/VmgExitLib.h | 103
> +++++++++++++++++
> >> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
> >> ++++++++++++++++++++
> >> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
> >> 6 files changed, 271 insertions(+)
> >>
> >> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> >> index df5d02bae6b4..cb92f34b6f55 100644
> >> --- a/UefiCpuPkg/UefiCpuPkg.dec
> >> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> >> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
> >> ##
> >>
> >> MpInitLib|Include/Library/MpInitLib.h
> >>
> >>
> >>
> >> + ## @libraryclass Provides function to support VMGEXIT processing.
> >>
> >> + VmgExitLib|Include/Library/VmgExitLib.h
> >>
> >> +
> >>
> >> [Guids]
> >>
> >> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
> >> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
> >>
> >> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30,
> >> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
> >>
> >> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> >> index afa304128221..f0e58b90ff0a 100644
> >> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> >> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> >> @@ -56,6 +56,7 @@ [LibraryClasses]
> >>
> >>
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> >> PeCoffGetEntryPointLib.inf
> >>
> >>
> >>
> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/Base
> >> PeCoffExtraActionLib|P
> >> eCoffExtraActionLibNull.inf
> >>
> >>
> >>
> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
> >> mMeasurementLibNull.inf
> >>
> >> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>
> >>
> >>
> >> [LibraryClasses.common.SEC]
> >>
> >>
> >>
> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNu
> >> PlatformSecLib|ll.i
> >> nf
> >>
> >> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
> >>
> >>
> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
> >> Null.inf
> >>
> >> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> >>
> >> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> >>
> >> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>
> >> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
> >>
> >> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
> >>
> >> UefiCpuPkg/SecCore/SecCore.inf
> >>
> >> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >> new file mode 100644
> >> index 000000000000..d8770a21c355
> >> --- /dev/null
> >> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >> @@ -0,0 +1,27 @@
> >> +## @file
> >>
> >> +# VMGEXIT Support Library.
> >>
> >> +#
> >>
> >> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >> +reserved.<BR>
> >>
> >> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +#
> >>
> >> +##
> >>
> >> +
> >>
> >> +[Defines]
> >>
> >> + INF_VERSION = 0x00010005
> >>
> >> + BASE_NAME = VmgExitLibNull
> >>
> >> + MODULE_UNI_FILE = VmgExitLibNull.uni
> >>
> >> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
> >>
> >> + MODULE_TYPE = BASE
> >>
> >> + VERSION_STRING = 1.0
> >>
> >> + LIBRARY_CLASS = VmgExitLib
> >>
> >> +
> >>
> >> +[Sources.common]
> >>
> >> + VmgExitLibNull.c
> >>
> >> +
> >>
> >> +[Packages]
> >>
> >> + MdePkg/MdePkg.dec
> >>
> >> + UefiCpuPkg/UefiCpuPkg.dec
> >>
> >> +
> >>
> >> +[LibraryClasses]
> >>
> >> + BaseLib
> >>
> >> +
> >>
> >> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
> >> b/UefiCpuPkg/Include/Library/VmgExitLib.h
> >> new file mode 100644
> >> index 000000000000..0b2f39026a4a
> >> --- /dev/null
> >> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
> >> @@ -0,0 +1,103 @@
> >> +/** @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.<BR>
> >>
> >> + SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#ifndef __VMG_EXIT_LIB_H__
> >>
> >> +#define __VMG_EXIT_LIB_H__
> >>
> >> +
> >>
> >> +#include <Protocol/DebugSupport.h>
> >>
> >> +#include <Register/Amd/Ghcb.h>
> >>
> >> +
> >>
> >> +
> >>
> >> +/**
> >>
> >> + 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.
> >>
> >> +
> >>
> >> + @return 0 VMGEXIT succeeded.
> >>
> >> + @return Others VMGEXIT processing did not succeed. Exception
> >>
> >> + number to be propagated.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +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] Ghcb A pointer to the GHCB
> >>
> >> +
> >>
> >> +**/
> >>
> >> +VOID
> >>
> >> +EFIAPI
> >>
> >> +VmgInit (
> >>
> >> + IN OUT GHCB *Ghcb
> >>
> >> + );
> >>
> >> +
> >>
> >> +/**
> >>
> >> + 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] Ghcb A pointer to the GHCB
> >>
> >> +
> >>
> >> +**/
> >>
> >> +VOID
> >>
> >> +EFIAPI
> >>
> >> +VmgDone (
> >>
> >> + IN OUT GHCB *Ghcb
> >>
> >> + );
> >>
> >> +
> >>
> >> +/**
> >>
> >> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
> >>
> >> +
> >>
> >> + @retval EFI_SUCCESS Exception 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
> >>
> >> + );
> >>
> >> +
> >>
> >> +#endif
> >>
> >> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >> new file mode 100644
> >> index 000000000000..30a239df298e
> >> --- /dev/null
> >> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >> @@ -0,0 +1,121 @@
> >> +/** @file
> >>
> >> + VMGEXIT Base Support Library.
> >>
> >> +
> >>
> >> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >> + reserved.<BR>
> >>
> >> + SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +
> >>
> >> +**/
> >>
> >> +
> >>
> >> +#include <Base.h>
> >>
> >> +#include <Uefi.h>
> >>
> >> +#include <Library/VmgExitLib.h>
> >>
> >> +
> >>
> >> +/**
> >>
> >> + Perform VMGEXIT.
> >>
> >> +
> >>
> >> + Sets the necessary fields of the GHCB, invokes the VMGEXIT
> >> + instruction
> >> and
> >>
> >> + then handles the return actions.
> >>
> >> +
> >>
> >> + The base library function returns an error in the form of a
> >>
> >> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
> >>
> >> +
> >>
> >> + @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.
> >>
> >> +
> >>
> >> + @return 0 VMGEXIT succeeded.
> >>
> >> + @return Others VMGEXIT processing did not succeed. Exception
> >>
> >> + event to be propagated.
> >>
> >> +
> >>
> >> +**/
> >>
> >> +UINT64
> >>
> >> +EFIAPI
> >>
> >> +VmgExit (
> >>
> >> + IN OUT GHCB *Ghcb,
> >>
> >> + IN UINT64 ExitCode,
> >>
> >> + IN UINT64 ExitInfo1,
> >>
> >> + IN UINT64 ExitInfo2
> >>
> >> + )
> >>
> >> +{
> >>
> >> + GHCB_EVENT_INJECTION Event;
> >>
> >> +
> >>
> >> + Event.Uint64 = 0;
> >>
> >> + Event.Elements.Vector = GP_EXCEPTION;
> >>
> >> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
> >>
> >> + Event.Elements.Valid = 1;
> >>
> >> +
> >>
> >> + return Event.Uint64;
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> + Perform pre-VMGEXIT initialization/preparation.
> >>
> >> +
> >>
> >> + Performs the necessary steps in preparation for invoking VMGEXIT.
> >> + Must
> >> be
> >>
> >> + called before setting any fields within the GHCB.
> >>
> >> +
> >>
> >> + The base library function does nothing.
> >>
> >> +
> >>
> >> + @param[in, out] Ghcb A pointer to the GHCB
> >>
> >> +
> >>
> >> +**/
> >>
> >> +VOID
> >>
> >> +EFIAPI
> >>
> >> +VmgInit (
> >>
> >> + IN OUT GHCB *Ghcb
> >>
> >> + )
> >>
> >> +{
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> + Perform post-VMGEXIT cleanup.
> >>
> >> +
> >>
> >> + Performs the necessary steps to cleanup after invoking VMGEXIT.
> >> + Must be
> >>
> >> + called after obtaining needed fields within the GHCB.
> >>
> >> +
> >>
> >> + The base library function does nothing.
> >>
> >> +
> >>
> >> + @param[in, out] Ghcb A pointer to the GHCB
> >>
> >> +
> >>
> >> +**/
> >>
> >> +VOID
> >>
> >> +EFIAPI
> >>
> >> +VmgDone (
> >>
> >> + IN OUT GHCB *Ghcb
> >>
> >> + )
> >>
> >> +{
> >>
> >> +}
> >>
> >> +
> >>
> >> +/**
> >>
> >> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
> >>
> >> +
> >>
> >> + @retval EFI_SUCCESS Exception 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
> >>
> >> + )
> >>
> >> +{
> >>
> >> + *ExceptionType = VC_EXCEPTION;
> >>
> >> +
> >>
> >> + return EFI_UNSUPPORTED;
> >>
> >> +}
> >>
> >> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >> new file mode 100644
> >> index 000000000000..8639bc0e8ce9
> >> --- /dev/null
> >> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >> @@ -0,0 +1,15 @@
> >> +// /** @file
> >>
> >> +// VMGEXIT support library instance.
> >>
> >> +//
> >>
> >> +// VMGEXIT support library instance.
> >>
> >> +//
> >>
> >> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >> +reserved.<BR>
> >>
> >> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> >>
> >> +//
> >>
> >> +// **/
> >>
> >> +
> >>
> >> +
> >>
> >> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT
> support
> >> NULL library instance"
> >>
> >> +
> >>
> >> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
> >> support NULL library instance."
> >>
> >> +
> >>
> >> --
> >> 2.27.0
> >
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61512): https://edk2.groups.io/g/devel/message/61512
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
>
>
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
>> Lendacky, Thomas
>> Sent: Thursday, June 18, 2020 10:09 PM
>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io
>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
>> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>;
>> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
>> support for VMGEXIT
>>
>> On 6/18/20 2:23 AM, Dong, Eric wrote:
>>> Hi Tom,
>>>
>>> When use VS2015 to build this code, it reports below error. Please help to
>> fix it.
>>>
>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning
>>> treated as error - no 'object' file generated
>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
>>> file format detected: please convert the source file to either DOS or
>>> UNIX format
>>
>> That is strange... I didn't see this when I ran through the CI. When I do a file
>> command against the file it reports:
>>
>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with CRLF
>> line terminators
>>
>> I'll investigate this and try and figure out what's going on, but if anyone else
>> has some ideas, please let me know.
>
> Hi Tom,
>
> I met this error again when I trig below patch from AMD again for CPU change.
> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"
Hmmm... I think we could be running into issues with sending patches
through our mail servers. Let me send you the patch series directly using
some changes I made to my git config file to see if that helps. Would that
be ok?
Thanks,
Tom
>
> I'm not sure whether this is patch issue, or our internal test sever issue. I have reported this error to our internal team to check also.
> Please check it from your side and make sure no error from your side. I will update the status from my side when I get the update.
>
> Thanks,
> Eric
>
>>
>> Thanks,
>> Tom
>>
>>>
>>> Thanks,
>>> Eric
>>>
>>>> -----Original Message-----
>>>> From: Tom Lendacky <thomas.lendacky@amd.com>
>>>> Sent: Friday, June 5, 2020 9:27 PM
>>>> To: devel@edk2.groups.io
>>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
>>>> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
>>>> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek
>>>> <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; Kinney,
>>>> Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
>>>> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
>>>> VMGEXIT
>>>>
>>>> BZ:
>>>>
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbug
>>>>
>> zilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Ct
>> ho
>>>>
>> mas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd
>> 8961fe
>>>>
>> 4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842&sdata=
>> fBlK2B
>>>> FkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3D&reserved=0
>>>>
>>>> To support handling #VC exceptions and issuing VMGEXIT instructions,
>>>> create a library with functions that can be used to perform these
>>>> #VC/VMGEXIT related operations. This includes functions for:
>>>> - Handling #VC exceptions
>>>> - Preparing for and issuing a VMGEXIT
>>>> - Performing MMIO-related write operations to support flash emulation
>>>> - Performing AP related boot opeations
>>>>
>>>> The base functions in this driver will not do anything and will
>>>> return an error if a return value is required. It is expected that
>>>> other packages (like OvmfPkg) will create a version of the library to
>>>> fully support an SEV-ES guest.
>>>>
>>>> Cc: Eric Dong <eric.dong@intel.com>
>>>> Cc: Ray Ni <ray.ni@intel.com>
>>>> Cc: Laszlo Ersek <lersek@redhat.com>
>>>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
>>>> ---
>>>> UefiCpuPkg/UefiCpuPkg.dec | 3 +
>>>> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
>>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
>>>> UefiCpuPkg/Include/Library/VmgExitLib.h | 103
>> +++++++++++++++++
>>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
>>>> ++++++++++++++++++++
>>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
>>>> 6 files changed, 271 insertions(+)
>>>>
>>>> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
>>>> index df5d02bae6b4..cb92f34b6f55 100644
>>>> --- a/UefiCpuPkg/UefiCpuPkg.dec
>>>> +++ b/UefiCpuPkg/UefiCpuPkg.dec
>>>> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
>>>> ##
>>>>
>>>> MpInitLib|Include/Library/MpInitLib.h
>>>>
>>>>
>>>>
>>>> + ## @libraryclass Provides function to support VMGEXIT processing.
>>>>
>>>> + VmgExitLib|Include/Library/VmgExitLib.h
>>>>
>>>> +
>>>>
>>>> [Guids]
>>>>
>>>> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,
>>>> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
>>>>
>>>> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30,
>>>> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
>>>>
>>>> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
>>>> index afa304128221..f0e58b90ff0a 100644
>>>> --- a/UefiCpuPkg/UefiCpuPkg.dsc
>>>> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
>>>> @@ -56,6 +56,7 @@ [LibraryClasses]
>>>>
>>>>
>> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
>>>> PeCoffGetEntryPointLib.inf
>>>>
>>>>
>>>>
>> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/Base
>>>> PeCoffExtraActionLib|P
>>>> eCoffExtraActionLibNull.inf
>>>>
>>>>
>>>>
>> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
>>>> mMeasurementLibNull.inf
>>>>
>>>> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>>>
>>>>
>>>>
>>>> [LibraryClasses.common.SEC]
>>>>
>>>>
>>>>
>> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNu
>>>> PlatformSecLib|ll.i
>>>> nf
>>>>
>>>> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
>>>>
>>>>
>> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
>>>> Null.inf
>>>>
>>>> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
>>>>
>>>> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
>>>>
>>>> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>>>
>>>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
>>>>
>>>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
>>>>
>>>> UefiCpuPkg/SecCore/SecCore.inf
>>>>
>>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>>> new file mode 100644
>>>> index 000000000000..d8770a21c355
>>>> --- /dev/null
>>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>>>> @@ -0,0 +1,27 @@
>>>> +## @file
>>>>
>>>> +# VMGEXIT Support Library.
>>>>
>>>> +#
>>>>
>>>> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
>>>> +reserved.<BR>
>>>>
>>>> +# SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>
>>>> +#
>>>>
>>>> +##
>>>>
>>>> +
>>>>
>>>> +[Defines]
>>>>
>>>> + INF_VERSION = 0x00010005
>>>>
>>>> + BASE_NAME = VmgExitLibNull
>>>>
>>>> + MODULE_UNI_FILE = VmgExitLibNull.uni
>>>>
>>>> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
>>>>
>>>> + MODULE_TYPE = BASE
>>>>
>>>> + VERSION_STRING = 1.0
>>>>
>>>> + LIBRARY_CLASS = VmgExitLib
>>>>
>>>> +
>>>>
>>>> +[Sources.common]
>>>>
>>>> + VmgExitLibNull.c
>>>>
>>>> +
>>>>
>>>> +[Packages]
>>>>
>>>> + MdePkg/MdePkg.dec
>>>>
>>>> + UefiCpuPkg/UefiCpuPkg.dec
>>>>
>>>> +
>>>>
>>>> +[LibraryClasses]
>>>>
>>>> + BaseLib
>>>>
>>>> +
>>>>
>>>> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
>>>> b/UefiCpuPkg/Include/Library/VmgExitLib.h
>>>> new file mode 100644
>>>> index 000000000000..0b2f39026a4a
>>>> --- /dev/null
>>>> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
>>>> @@ -0,0 +1,103 @@
>>>> +/** @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.<BR>
>>>>
>>>> + SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +
>>>>
>>>> +#ifndef __VMG_EXIT_LIB_H__
>>>>
>>>> +#define __VMG_EXIT_LIB_H__
>>>>
>>>> +
>>>>
>>>> +#include <Protocol/DebugSupport.h>
>>>>
>>>> +#include <Register/Amd/Ghcb.h>
>>>>
>>>> +
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + 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.
>>>>
>>>> +
>>>>
>>>> + @return 0 VMGEXIT succeeded.
>>>>
>>>> + @return Others VMGEXIT processing did not succeed. Exception
>>>>
>>>> + number to be propagated.
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +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] Ghcb A pointer to the GHCB
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +VOID
>>>>
>>>> +EFIAPI
>>>>
>>>> +VmgInit (
>>>>
>>>> + IN OUT GHCB *Ghcb
>>>>
>>>> + );
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + 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] Ghcb A pointer to the GHCB
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +VOID
>>>>
>>>> +EFIAPI
>>>>
>>>> +VmgDone (
>>>>
>>>> + IN OUT GHCB *Ghcb
>>>>
>>>> + );
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>>>>
>>>> +
>>>>
>>>> + @retval EFI_SUCCESS Exception 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
>>>>
>>>> + );
>>>>
>>>> +
>>>>
>>>> +#endif
>>>>
>>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>>>> new file mode 100644
>>>> index 000000000000..30a239df298e
>>>> --- /dev/null
>>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
>>>> @@ -0,0 +1,121 @@
>>>> +/** @file
>>>>
>>>> + VMGEXIT Base Support Library.
>>>>
>>>> +
>>>>
>>>> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
>>>> + reserved.<BR>
>>>>
>>>> + SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +
>>>>
>>>> +#include <Base.h>
>>>>
>>>> +#include <Uefi.h>
>>>>
>>>> +#include <Library/VmgExitLib.h>
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + Perform VMGEXIT.
>>>>
>>>> +
>>>>
>>>> + Sets the necessary fields of the GHCB, invokes the VMGEXIT
>>>> + instruction
>>>> and
>>>>
>>>> + then handles the return actions.
>>>>
>>>> +
>>>>
>>>> + The base library function returns an error in the form of a
>>>>
>>>> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
>>>>
>>>> +
>>>>
>>>> + @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.
>>>>
>>>> +
>>>>
>>>> + @return 0 VMGEXIT succeeded.
>>>>
>>>> + @return Others VMGEXIT processing did not succeed. Exception
>>>>
>>>> + event to be propagated.
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +UINT64
>>>>
>>>> +EFIAPI
>>>>
>>>> +VmgExit (
>>>>
>>>> + IN OUT GHCB *Ghcb,
>>>>
>>>> + IN UINT64 ExitCode,
>>>>
>>>> + IN UINT64 ExitInfo1,
>>>>
>>>> + IN UINT64 ExitInfo2
>>>>
>>>> + )
>>>>
>>>> +{
>>>>
>>>> + GHCB_EVENT_INJECTION Event;
>>>>
>>>> +
>>>>
>>>> + Event.Uint64 = 0;
>>>>
>>>> + Event.Elements.Vector = GP_EXCEPTION;
>>>>
>>>> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
>>>>
>>>> + Event.Elements.Valid = 1;
>>>>
>>>> +
>>>>
>>>> + return Event.Uint64;
>>>>
>>>> +}
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + Perform pre-VMGEXIT initialization/preparation.
>>>>
>>>> +
>>>>
>>>> + Performs the necessary steps in preparation for invoking VMGEXIT.
>>>> + Must
>>>> be
>>>>
>>>> + called before setting any fields within the GHCB.
>>>>
>>>> +
>>>>
>>>> + The base library function does nothing.
>>>>
>>>> +
>>>>
>>>> + @param[in, out] Ghcb A pointer to the GHCB
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +VOID
>>>>
>>>> +EFIAPI
>>>>
>>>> +VmgInit (
>>>>
>>>> + IN OUT GHCB *Ghcb
>>>>
>>>> + )
>>>>
>>>> +{
>>>>
>>>> +}
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + Perform post-VMGEXIT cleanup.
>>>>
>>>> +
>>>>
>>>> + Performs the necessary steps to cleanup after invoking VMGEXIT.
>>>> + Must be
>>>>
>>>> + called after obtaining needed fields within the GHCB.
>>>>
>>>> +
>>>>
>>>> + The base library function does nothing.
>>>>
>>>> +
>>>>
>>>> + @param[in, out] Ghcb A pointer to the GHCB
>>>>
>>>> +
>>>>
>>>> +**/
>>>>
>>>> +VOID
>>>>
>>>> +EFIAPI
>>>>
>>>> +VmgDone (
>>>>
>>>> + IN OUT GHCB *Ghcb
>>>>
>>>> + )
>>>>
>>>> +{
>>>>
>>>> +}
>>>>
>>>> +
>>>>
>>>> +/**
>>>>
>>>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
>>>>
>>>> +
>>>>
>>>> + @retval EFI_SUCCESS Exception 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
>>>>
>>>> + )
>>>>
>>>> +{
>>>>
>>>> + *ExceptionType = VC_EXCEPTION;
>>>>
>>>> +
>>>>
>>>> + return EFI_UNSUPPORTED;
>>>>
>>>> +}
>>>>
>>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>>>> new file mode 100644
>>>> index 000000000000..8639bc0e8ce9
>>>> --- /dev/null
>>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
>>>> @@ -0,0 +1,15 @@
>>>> +// /** @file
>>>>
>>>> +// VMGEXIT support library instance.
>>>>
>>>> +//
>>>>
>>>> +// VMGEXIT support library instance.
>>>>
>>>> +//
>>>>
>>>> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
>>>> +reserved.<BR>
>>>>
>>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>
>>>> +//
>>>>
>>>> +// **/
>>>>
>>>> +
>>>>
>>>> +
>>>>
>>>> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT
>> support
>>>> NULL library instance"
>>>>
>>>> +
>>>>
>>>> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
>>>> support NULL library instance."
>>>>
>>>> +
>>>>
>>>> --
>>>> 2.27.0
>>>
>>
>>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61518): https://edk2.groups.io/g/devel/message/61518
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> Lendacky, Thomas
> Sent: Friday, June 19, 2020 9:51 PM
> To: devel@edk2.groups.io; Dong, Eric <eric.dong@intel.com>
> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>;
> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
> support for VMGEXIT
>
> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
> >
> >
> >> -----Original Message-----
> >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> >> Lendacky, Thomas
> >> Sent: Thursday, June 18, 2020 10:09 PM
> >> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io
> >> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> >> <ard.biesheuvel@arm.com>; Justen, Jordan L
> >> <jordan.l.justen@intel.com>; Laszlo Ersek <lersek@redhat.com>; Gao,
> >> Liming <liming.gao@intel.com>; Kinney, Michael D
> >> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement
> >> library support for VMGEXIT
> >>
> >> On 6/18/20 2:23 AM, Dong, Eric wrote:
> >>> Hi Tom,
> >>>
> >>> When use VS2015 to build this code, it reports below error. Please
> >>> help to
> >> fix it.
> >>>
> >>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220:
> >>> warning treated as error - no 'object' file generated
> >>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
> >>> file format detected: please convert the source file to either DOS
> >>> or UNIX format
> >>
> >> That is strange... I didn't see this when I ran through the CI. When
> >> I do a file command against the file it reports:
> >>
> >> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with
> >> CRLF line terminators
> >>
> >> I'll investigate this and try and figure out what's going on, but if
> >> anyone else has some ideas, please let me know.
> >
> > Hi Tom,
> >
> > I met this error again when I trig below patch from AMD again for CPU
> change.
> > "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"
>
> Hmmm... I think we could be running into issues with sending patches
> through our mail servers. Let me send you the patch series directly using
> some changes I made to my git config file to see if that helps. Would that be
> ok?
Yes, please do it.
Thanks,
Eric
>
> Thanks,
> Tom
>
> >
> > I'm not sure whether this is patch issue, or our internal test sever issue. I
> have reported this error to our internal team to check also.
> > Please check it from your side and make sure no error from your side. I will
> update the status from my side when I get the update.
> >
> > Thanks,
> > Eric
> >
> >>
> >> Thanks,
> >> Tom
> >>
> >>>
> >>> Thanks,
> >>> Eric
> >>>
> >>>> -----Original Message-----
> >>>> From: Tom Lendacky <thomas.lendacky@amd.com>
> >>>> Sent: Friday, June 5, 2020 9:27 PM
> >>>> To: devel@edk2.groups.io
> >>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
> >>>> <ard.biesheuvel@arm.com>; Dong, Eric <eric.dong@intel.com>; Justen,
> >>>> Jordan L <jordan.l.justen@intel.com>; Laszlo Ersek
> >>>> <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; Kinney,
> >>>> Michael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
> >>>> Subject: [PATCH v9 08/46] UefiCpuPkg: Implement library support for
> >>>> VMGEXIT
> >>>>
> >>>> BZ:
> >>>>
> >>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbug
> >>>>
> >>
> zilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Ct
> >> ho
> >>>>
> >>
> mas.lendacky%40amd.com%7Cd75554da4959407c967608d8135877be%7C3dd
> >> 8961fe
> >>>>
> >>
> 4884e608e11a82d994e183d%7C0%7C0%7C637280617975250842&sdata=
> >> fBlK2B
> >>>>
> FkRdAS5EWcM8YShf1ZswfRN%2F41L7XeUsb4ZCs%3D&reserved=0
> >>>>
> >>>> To support handling #VC exceptions and issuing VMGEXIT
> >>>> instructions, create a library with functions that can be used to
> >>>> perform these #VC/VMGEXIT related operations. This includes
> functions for:
> >>>> - Handling #VC exceptions
> >>>> - Preparing for and issuing a VMGEXIT
> >>>> - Performing MMIO-related write operations to support flash
> emulation
> >>>> - Performing AP related boot opeations
> >>>>
> >>>> The base functions in this driver will not do anything and will
> >>>> return an error if a return value is required. It is expected that
> >>>> other packages (like OvmfPkg) will create a version of the library
> >>>> to fully support an SEV-ES guest.
> >>>>
> >>>> Cc: Eric Dong <eric.dong@intel.com>
> >>>> Cc: Ray Ni <ray.ni@intel.com>
> >>>> Cc: Laszlo Ersek <lersek@redhat.com>
> >>>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> >>>> ---
> >>>> UefiCpuPkg/UefiCpuPkg.dec | 3 +
> >>>> UefiCpuPkg/UefiCpuPkg.dsc | 2 +
> >>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf | 27 +++++
> >>>> UefiCpuPkg/Include/Library/VmgExitLib.h | 103
> >> +++++++++++++++++
> >>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c | 121
> >>>> ++++++++++++++++++++
> >>>> UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++
> >>>> 6 files changed, 271 insertions(+)
> >>>>
> >>>> diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
> >>>> index df5d02bae6b4..cb92f34b6f55 100644
> >>>> --- a/UefiCpuPkg/UefiCpuPkg.dec
> >>>> +++ b/UefiCpuPkg/UefiCpuPkg.dec
> >>>> @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
> >>>> ##
> >>>>
> >>>> MpInitLib|Include/Library/MpInitLib.h
> >>>>
> >>>>
> >>>>
> >>>> + ## @libraryclass Provides function to support VMGEXIT processing.
> >>>>
> >>>> + VmgExitLib|Include/Library/VmgExitLib.h
> >>>>
> >>>> +
> >>>>
> >>>> [Guids]
> >>>>
> >>>> gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4,
> { 0xaa,
> >>>> 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
> >>>>
> >>>> gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,
> 0x30,
> >>>> 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
> >>>>
> >>>> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> >>>> index afa304128221..f0e58b90ff0a 100644
> >>>> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> >>>> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> >>>> @@ -56,6 +56,7 @@ [LibraryClasses]
> >>>>
> >>>>
> >>
> PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/Base
> >>>> PeCoffGetEntryPointLib.inf
> >>>>
> >>>>
> >>>>
> >>
> PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/Base
> >>>> PeCoffExtraActionLib|P
> >>>> eCoffExtraActionLibNull.inf
> >>>>
> >>>>
> >>>>
> >>
> TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/Tp
> >>>> mMeasurementLibNull.inf
> >>>>
> >>>> + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>>>
> >>>>
> >>>>
> >>>> [LibraryClasses.common.SEC]
> >>>>
> >>>>
> >>>>
> >>
> PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNu
> >>>> PlatformSecLib|ll.i
> >>>> nf
> >>>>
> >>>> @@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
> >>>>
> >>>>
> >>
> UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLib
> >>>> Null.inf
> >>>>
> >>>> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
> >>>>
> >>>>
> UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> >>>>
> >>>> + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>>>
> >>>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
> >>>>
> >>>> UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
> >>>>
> >>>> UefiCpuPkg/SecCore/SecCore.inf
> >>>>
> >>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>>> new file mode 100644
> >>>> index 000000000000..d8770a21c355
> >>>> --- /dev/null
> >>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
> >>>> @@ -0,0 +1,27 @@
> >>>> +## @file
> >>>>
> >>>> +# VMGEXIT Support Library.
> >>>>
> >>>> +#
> >>>>
> >>>> +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >>>> +reserved.<BR>
> >>>>
> >>>> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>
> >>>> +#
> >>>>
> >>>> +##
> >>>>
> >>>> +
> >>>>
> >>>> +[Defines]
> >>>>
> >>>> + INF_VERSION = 0x00010005
> >>>>
> >>>> + BASE_NAME = VmgExitLibNull
> >>>>
> >>>> + MODULE_UNI_FILE = VmgExitLibNull.uni
> >>>>
> >>>> + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
> >>>>
> >>>> + MODULE_TYPE = BASE
> >>>>
> >>>> + VERSION_STRING = 1.0
> >>>>
> >>>> + LIBRARY_CLASS = VmgExitLib
> >>>>
> >>>> +
> >>>>
> >>>> +[Sources.common]
> >>>>
> >>>> + VmgExitLibNull.c
> >>>>
> >>>> +
> >>>>
> >>>> +[Packages]
> >>>>
> >>>> + MdePkg/MdePkg.dec
> >>>>
> >>>> + UefiCpuPkg/UefiCpuPkg.dec
> >>>>
> >>>> +
> >>>>
> >>>> +[LibraryClasses]
> >>>>
> >>>> + BaseLib
> >>>>
> >>>> +
> >>>>
> >>>> diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h
> >>>> b/UefiCpuPkg/Include/Library/VmgExitLib.h
> >>>> new file mode 100644
> >>>> index 000000000000..0b2f39026a4a
> >>>> --- /dev/null
> >>>> +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
> >>>> @@ -0,0 +1,103 @@
> >>>> +/** @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.<BR>
> >>>>
> >>>> + SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +
> >>>>
> >>>> +#ifndef __VMG_EXIT_LIB_H__
> >>>>
> >>>> +#define __VMG_EXIT_LIB_H__
> >>>>
> >>>> +
> >>>>
> >>>> +#include <Protocol/DebugSupport.h>
> >>>>
> >>>> +#include <Register/Amd/Ghcb.h>
> >>>>
> >>>> +
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + 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.
> >>>>
> >>>> +
> >>>>
> >>>> + @return 0 VMGEXIT succeeded.
> >>>>
> >>>> + @return Others VMGEXIT processing did not succeed.
> Exception
> >>>>
> >>>> + number to be propagated.
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +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] Ghcb A pointer to the GHCB
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +VOID
> >>>>
> >>>> +EFIAPI
> >>>>
> >>>> +VmgInit (
> >>>>
> >>>> + IN OUT GHCB *Ghcb
> >>>>
> >>>> + );
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + 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] Ghcb A pointer to the GHCB
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +VOID
> >>>>
> >>>> +EFIAPI
> >>>>
> >>>> +VmgDone (
> >>>>
> >>>> + IN OUT GHCB *Ghcb
> >>>>
> >>>> + );
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
> >>>>
> >>>> +
> >>>>
> >>>> + @retval EFI_SUCCESS Exception 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
> >>>>
> >>>> + );
> >>>>
> >>>> +
> >>>>
> >>>> +#endif
> >>>>
> >>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >>>> new file mode 100644
> >>>> index 000000000000..30a239df298e
> >>>> --- /dev/null
> >>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
> >>>> @@ -0,0 +1,121 @@
> >>>> +/** @file
> >>>>
> >>>> + VMGEXIT Base Support Library.
> >>>>
> >>>> +
> >>>>
> >>>> + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >>>> + reserved.<BR>
> >>>>
> >>>> + SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +
> >>>>
> >>>> +#include <Base.h>
> >>>>
> >>>> +#include <Uefi.h>
> >>>>
> >>>> +#include <Library/VmgExitLib.h>
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + Perform VMGEXIT.
> >>>>
> >>>> +
> >>>>
> >>>> + Sets the necessary fields of the GHCB, invokes the VMGEXIT
> >>>> + instruction
> >>>> and
> >>>>
> >>>> + then handles the return actions.
> >>>>
> >>>> +
> >>>>
> >>>> + The base library function returns an error in the form of a
> >>>>
> >>>> + GHCB_EVENT_INJECTION representing a GP_EXCEPTION.
> >>>>
> >>>> +
> >>>>
> >>>> + @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.
> >>>>
> >>>> +
> >>>>
> >>>> + @return 0 VMGEXIT succeeded.
> >>>>
> >>>> + @return Others VMGEXIT processing did not succeed.
> Exception
> >>>>
> >>>> + event to be propagated.
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +UINT64
> >>>>
> >>>> +EFIAPI
> >>>>
> >>>> +VmgExit (
> >>>>
> >>>> + IN OUT GHCB *Ghcb,
> >>>>
> >>>> + IN UINT64 ExitCode,
> >>>>
> >>>> + IN UINT64 ExitInfo1,
> >>>>
> >>>> + IN UINT64 ExitInfo2
> >>>>
> >>>> + )
> >>>>
> >>>> +{
> >>>>
> >>>> + GHCB_EVENT_INJECTION Event;
> >>>>
> >>>> +
> >>>>
> >>>> + Event.Uint64 = 0;
> >>>>
> >>>> + Event.Elements.Vector = GP_EXCEPTION;
> >>>>
> >>>> + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
> >>>>
> >>>> + Event.Elements.Valid = 1;
> >>>>
> >>>> +
> >>>>
> >>>> + return Event.Uint64;
> >>>>
> >>>> +}
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + Perform pre-VMGEXIT initialization/preparation.
> >>>>
> >>>> +
> >>>>
> >>>> + Performs the necessary steps in preparation for invoking VMGEXIT.
> >>>> + Must
> >>>> be
> >>>>
> >>>> + called before setting any fields within the GHCB.
> >>>>
> >>>> +
> >>>>
> >>>> + The base library function does nothing.
> >>>>
> >>>> +
> >>>>
> >>>> + @param[in, out] Ghcb A pointer to the GHCB
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +VOID
> >>>>
> >>>> +EFIAPI
> >>>>
> >>>> +VmgInit (
> >>>>
> >>>> + IN OUT GHCB *Ghcb
> >>>>
> >>>> + )
> >>>>
> >>>> +{
> >>>>
> >>>> +}
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + Perform post-VMGEXIT cleanup.
> >>>>
> >>>> +
> >>>>
> >>>> + Performs the necessary steps to cleanup after invoking VMGEXIT.
> >>>> + Must be
> >>>>
> >>>> + called after obtaining needed fields within the GHCB.
> >>>>
> >>>> +
> >>>>
> >>>> + The base library function does nothing.
> >>>>
> >>>> +
> >>>>
> >>>> + @param[in, out] Ghcb A pointer to the GHCB
> >>>>
> >>>> +
> >>>>
> >>>> +**/
> >>>>
> >>>> +VOID
> >>>>
> >>>> +EFIAPI
> >>>>
> >>>> +VmgDone (
> >>>>
> >>>> + IN OUT GHCB *Ghcb
> >>>>
> >>>> + )
> >>>>
> >>>> +{
> >>>>
> >>>> +}
> >>>>
> >>>> +
> >>>>
> >>>> +/**
> >>>>
> >>>> + 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] SystemContext Pointer to EFI_SYSTEM_CONTEXT
> >>>>
> >>>> +
> >>>>
> >>>> + @retval EFI_SUCCESS Exception 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
> >>>>
> >>>> + )
> >>>>
> >>>> +{
> >>>>
> >>>> + *ExceptionType = VC_EXCEPTION;
> >>>>
> >>>> +
> >>>>
> >>>> + return EFI_UNSUPPORTED;
> >>>>
> >>>> +}
> >>>>
> >>>> diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >>>> b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >>>> new file mode 100644
> >>>> index 000000000000..8639bc0e8ce9
> >>>> --- /dev/null
> >>>> +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni
> >>>> @@ -0,0 +1,15 @@
> >>>> +// /** @file
> >>>>
> >>>> +// VMGEXIT support library instance.
> >>>>
> >>>> +//
> >>>>
> >>>> +// VMGEXIT support library instance.
> >>>>
> >>>> +//
> >>>>
> >>>> +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights
> >>>> +reserved.<BR>
> >>>>
> >>>> +// SPDX-License-Identifier: BSD-2-Clause-Patent
> >>>>
> >>>> +//
> >>>>
> >>>> +// **/
> >>>>
> >>>> +
> >>>>
> >>>> +
> >>>>
> >>>> +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT
> >> support
> >>>> NULL library instance"
> >>>>
> >>>> +
> >>>>
> >>>> +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT
> >>>> support NULL library instance."
> >>>>
> >>>> +
> >>>>
> >>>> --
> >>>> 2.27.0
> >>>
> >>
> >>
> >
> >
> >
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61524): https://edk2.groups.io/g/devel/message/61524
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 06/19/20 15:50, Tom Lendacky wrote:
> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote:
>>
>>
>>> -----Original Message-----
>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
>>> Lendacky, Thomas
>>> Sent: Thursday, June 18, 2020 10:09 PM
>>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io
>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel
>>> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
>>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>;
>>> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray
>>> <ray.ni@intel.com>
>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library
>>> support for VMGEXIT
>>>
>>> On 6/18/20 2:23 AM, Dong, Eric wrote:
>>>> Hi Tom,
>>>>
>>>> When use VS2015 to build this code, it reports below error. Please
>>>> help to
>>> fix it.
>>>>
>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: warning
>>>> treated as error - no 'object' file generated
>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: Mac
>>>> file format detected: please convert the source file to either DOS or
>>>> UNIX format
>>>
>>> That is strange... I didn't see this when I ran through the CI. When
>>> I do a file
>>> command against the file it reports:
>>>
>>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with CRLF
>>> line terminators
>>>
>>> I'll investigate this and try and figure out what's going on, but if
>>> anyone else
>>> has some ideas, please let me know.
>>
>> Hi Tom,
>>
>> I met this error again when I trig below patch from AMD again for CPU
>> change.
>> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib"
>
> Hmmm... I think we could be running into issues with sending patches
> through our mail servers. Let me send you the patch series directly
> using some changes I made to my git config file to see if that helps.
> Would that be ok?
both sender and recipient git clones should have
[core]
whitespace = cr-at-eol
and the recipient clone should have
[am]
keepcr = true
https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers#contrib-05
These are also set by "BaseTools/Scripts/SetupGit.py".
Thanks
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#61527): https://edk2.groups.io/g/devel/message/61527
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
> -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Laszlo > Ersek > Sent: Friday, June 19, 2020 11:39 PM > To: Tom Lendacky <thomas.lendacky@amd.com>; devel@edk2.groups.io; > Dong, Eric <eric.dong@intel.com> > Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel > <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>; > Gao, Liming <liming.gao@intel.com>; Kinney, Michael D > <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> > Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library > support for VMGEXIT > > On 06/19/20 15:50, Tom Lendacky wrote: > > On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote: > >> > >> > >>> -----Original Message----- > >>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > >>> Lendacky, Thomas > >>> Sent: Thursday, June 18, 2020 10:09 PM > >>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io > >>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel > >>> <ard.biesheuvel@arm.com>; Justen, Jordan L > <jordan.l.justen@intel.com>; > >>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; > >>> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray > >>> <ray.ni@intel.com> > >>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement > library > >>> support for VMGEXIT > >>> > >>> On 6/18/20 2:23 AM, Dong, Eric wrote: > >>>> Hi Tom, > >>>> > >>>> When use VS2015 to build this code, it reports below error. Please > >>>> help to > >>> fix it. > >>>> > >>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: > warning > >>>> treated as error - no 'object' file generated > >>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: > Mac > >>>> file format detected: please convert the source file to either DOS or > >>>> UNIX format > >>> > >>> That is strange... I didn't see this when I ran through the CI. When > >>> I do a file > >>> command against the file it reports: > >>> > >>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with > CRLF > >>> line terminators > >>> > >>> I'll investigate this and try and figure out what's going on, but if > >>> anyone else > >>> has some ideas, please let me know. > >> > >> Hi Tom, > >> > >> I met this error again when I trig below patch from AMD again for CPU > >> change. > >> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to > BaseUefiCpuLib" > > > > Hmmm... I think we could be running into issues with sending patches > > through our mail servers. Let me send you the patch series directly > > using some changes I made to my git config file to see if that helps. > > Would that be ok? > > both sender and recipient git clones should have > > [core] > whitespace = cr-at-eol > > and the recipient clone should have > > [am] > keepcr = true > > https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git- > guide-for-edk2-contributors-and-maintainers#contrib-05 > > These are also set by "BaseTools/Scripts/SetupGit.py". > Hi Tom, I see below context in another mail thread and base on the latest status, this solution works and that patch has fixed the issue. Can you follow below suggest fixing your issue? Hi Garrett, I encounter below error when build UefiCpuPkg\Library\BaseUefiCpuLib\BaseUefiCpuLib.c: warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format' I encounter the issue ever, it result by mail encoding. To resolve this issue, you can run [BaseTools\ Scripts\SetupGit.py] first, and then send the patch again. Could you try it and send the patch again? Thanks, Eric > Thanks > Laszlo > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61572): https://edk2.groups.io/g/devel/message/61572 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 6/22/20 8:16 PM, Dong, Eric via groups.io wrote: > > >> -----Original Message----- >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Laszlo >> Ersek >> Sent: Friday, June 19, 2020 11:39 PM >> To: Tom Lendacky <thomas.lendacky@amd.com>; devel@edk2.groups.io; >> Dong, Eric <eric.dong@intel.com> >> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel >> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>; >> Gao, Liming <liming.gao@intel.com>; Kinney, Michael D >> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library >> support for VMGEXIT >> >> On 06/19/20 15:50, Tom Lendacky wrote: >>> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote: >>>> >>>> >>>>> -----Original Message----- >>>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of >>>>> Lendacky, Thomas >>>>> Sent: Thursday, June 18, 2020 10:09 PM >>>>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io >>>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel >>>>> <ard.biesheuvel@arm.com>; Justen, Jordan L >> <jordan.l.justen@intel.com>; >>>>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; >>>>> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray >>>>> <ray.ni@intel.com> >>>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement >> library >>>>> support for VMGEXIT >>>>> >>>>> On 6/18/20 2:23 AM, Dong, Eric wrote: >>>>>> Hi Tom, >>>>>> >>>>>> When use VS2015 to build this code, it reports below error. Please >>>>>> help to >>>>> fix it. >>>>>> >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: >> warning >>>>>> treated as error - no 'object' file generated >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: >> Mac >>>>>> file format detected: please convert the source file to either DOS or >>>>>> UNIX format >>>>> >>>>> That is strange... I didn't see this when I ran through the CI. When >>>>> I do a file >>>>> command against the file it reports: >>>>> >>>>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, with >> CRLF >>>>> line terminators >>>>> >>>>> I'll investigate this and try and figure out what's going on, but if >>>>> anyone else >>>>> has some ideas, please let me know. >>>> >>>> Hi Tom, >>>> >>>> I met this error again when I trig below patch from AMD again for CPU >>>> change. >>>> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to >> BaseUefiCpuLib" >>> >>> Hmmm... I think we could be running into issues with sending patches >>> through our mail servers. Let me send you the patch series directly >>> using some changes I made to my git config file to see if that helps. >>> Would that be ok? >> >> both sender and recipient git clones should have >> >> [core] >> whitespace = cr-at-eol >> >> and the recipient clone should have >> >> [am] >> keepcr = true >> >> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Ftianocore.github.io%2Fwiki%2FLaszlo%27s-unkempt-git-&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cd461956236264e4a6d3a08d81713205d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637284718210751789&sdata=ftFiRZkC3n2n2MZyL6t9HKnp1fYgzUQV4FRBvVNQ4%2FA%3D&reserved=0 >> guide-for-edk2-contributors-and-maintainers#contrib-05 >> >> These are also set by "BaseTools/Scripts/SetupGit.py". >> > > Hi Tom, > > I see below context in another mail thread and base on the latest status, this solution works and that patch has fixed the issue. Can you follow below suggest fixing your issue? > > Hi Garrett, > > I encounter below error when build > UefiCpuPkg\Library\BaseUefiCpuLib\BaseUefiCpuLib.c: warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format' > > I encounter the issue ever, it result by mail encoding. > To resolve this issue, you can run [BaseTools\ Scripts\SetupGit.py] first, and then send the patch again. > > Could you try it and send the patch again? Hi Eric, I already had those settings in my git config file, so I'm thinking it was still something else. I sent you a direct set of patches with some other setting tweaks. Let me know how those work out for you. Thanks, Tom > > Thanks, > Eric > >> Thanks >> Laszlo >> >> >> > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61599): https://edk2.groups.io/g/devel/message/61599 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Hi Tom, We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case. With that change, now I met below error when use VS2015 tool chain. Can you help to fix it? Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64] PeCoffLoaderEx.c g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2' Thanks, Eric > -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > Lendacky, Thomas > Sent: Tuesday, June 23, 2020 8:58 PM > To: devel@edk2.groups.io; Dong, Eric <eric.dong@intel.com>; > lersek@redhat.com > Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel > <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>; > Gao, Liming <liming.gao@intel.com>; Kinney, Michael D > <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> > Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library > support for VMGEXIT > > On 6/22/20 8:16 PM, Dong, Eric via groups.io wrote: > > > > > >> -----Original Message----- > >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > Laszlo > >> Ersek > >> Sent: Friday, June 19, 2020 11:39 PM > >> To: Tom Lendacky <thomas.lendacky@amd.com>; devel@edk2.groups.io; > >> Dong, Eric <eric.dong@intel.com> > >> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel > >> <ard.biesheuvel@arm.com>; Justen, Jordan L > >> <jordan.l.justen@intel.com>; Gao, Liming <liming.gao@intel.com>; > >> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray > >> <ray.ni@intel.com> > >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement > >> library support for VMGEXIT > >> > >> On 06/19/20 15:50, Tom Lendacky wrote: > >>> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote: > >>>> > >>>> > >>>>> -----Original Message----- > >>>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of > >>>>> Lendacky, Thomas > >>>>> Sent: Thursday, June 18, 2020 10:09 PM > >>>>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io > >>>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel > >>>>> <ard.biesheuvel@arm.com>; Justen, Jordan L > >> <jordan.l.justen@intel.com>; > >>>>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming > >>>>> <liming.gao@intel.com>; Kinney, Michael D > >>>>> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> > >>>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement > >> library > >>>>> support for VMGEXIT > >>>>> > >>>>> On 6/18/20 2:23 AM, Dong, Eric wrote: > >>>>>> Hi Tom, > >>>>>> > >>>>>> When use VS2015 to build this code, it reports below error. > >>>>>> Please help to > >>>>> fix it. > >>>>>> > >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: > >> warning > >>>>>> treated as error - no 'object' file generated > >>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: > >> Mac > >>>>>> file format detected: please convert the source file to either > >>>>>> DOS or UNIX format > >>>>> > >>>>> That is strange... I didn't see this when I ran through the CI. > >>>>> When I do a file command against the file it reports: > >>>>> > >>>>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, > >>>>> with > >> CRLF > >>>>> line terminators > >>>>> > >>>>> I'll investigate this and try and figure out what's going on, but > >>>>> if anyone else has some ideas, please let me know. > >>>> > >>>> Hi Tom, > >>>> > >>>> I met this error again when I trig below patch from AMD again for > >>>> CPU change. > >>>> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to > >> BaseUefiCpuLib" > >>> > >>> Hmmm... I think we could be running into issues with sending patches > >>> through our mail servers. Let me send you the patch series directly > >>> using some changes I made to my git config file to see if that helps. > >>> Would that be ok? > >> > >> both sender and recipient git clones should have > >> > >> [core] > >> whitespace = cr-at-eol > >> > >> and the recipient clone should have > >> > >> [am] > >> keepcr = true > >> > >> > https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit > >> hub.com%2Ftianocore%2Ftianocore.github.io%2Fwiki%2FLaszlo%27s- > unkempt > >> -git- > &data=02%7C01%7Cthomas.lendacky%40amd.com%7Cd461956236264e > 4a > >> > 6d3a08d81713205d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C6 > 372847 > >> > 18210751789&sdata=ftFiRZkC3n2n2MZyL6t9HKnp1fYgzUQV4FRBvVNQ4 > %2FA%3 > >> D&reserved=0 > >> guide-for-edk2-contributors-and-maintainers#contrib-05 > >> > >> These are also set by "BaseTools/Scripts/SetupGit.py". > >> > > > > Hi Tom, > > > > I see below context in another mail thread and base on the latest status, > this solution works and that patch has fixed the issue. Can you follow below > suggest fixing your issue? > > > > Hi Garrett, > > > > I encounter below error when build > > UefiCpuPkg\Library\BaseUefiCpuLib\BaseUefiCpuLib.c: warning C4335: > Mac file format detected: please convert the source file to either DOS or > UNIX format' > > > > I encounter the issue ever, it result by mail encoding. > > To resolve this issue, you can run [BaseTools\ Scripts\SetupGit.py] first, > and then send the patch again. > > > > Could you try it and send the patch again? > > Hi Eric, > > I already had those settings in my git config file, so I'm thinking it was still > something else. I sent you a direct set of patches with some other setting > tweaks. Let me know how those work out for you. > > Thanks, > Tom > > > > > Thanks, > > Eric > > > >> Thanks > >> Laszlo > >> > >> > >> > > > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61960): https://edk2.groups.io/g/devel/message/61960 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 7/2/20 2:04 AM, Dong, Eric wrote: > Hi Tom, Hi Eric, > > We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case. Good to know, thanks! > > With that change, now I met below error when use VS2015 tool chain. Can you help to fix it? > > Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64] > PeCoffLoaderEx.c > g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2' Yup, looks like that needs to be a "1ULL <<" instead of "1 <<". I have verified that fixes the issue. One thing I noticed is that the 32-bit builds (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and Platform_CI OVMF_IA32X64_NOOPT) encounter an error: ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460' Any idea what is causing this error? Thanks, Tom > > Thanks, > Eric >> -----Original Message----- >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of >> Lendacky, Thomas >> Sent: Tuesday, June 23, 2020 8:58 PM >> To: devel@edk2.groups.io; Dong, Eric <eric.dong@intel.com>; >> lersek@redhat.com >> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel >> <ard.biesheuvel@arm.com>; Justen, Jordan L <jordan.l.justen@intel.com>; >> Gao, Liming <liming.gao@intel.com>; Kinney, Michael D >> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> >> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library >> support for VMGEXIT >> >> On 6/22/20 8:16 PM, Dong, Eric via groups.io wrote: >>> >>> >>>> -----Original Message----- >>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of >> Laszlo >>>> Ersek >>>> Sent: Friday, June 19, 2020 11:39 PM >>>> To: Tom Lendacky <thomas.lendacky@amd.com>; devel@edk2.groups.io; >>>> Dong, Eric <eric.dong@intel.com> >>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel >>>> <ard.biesheuvel@arm.com>; Justen, Jordan L >>>> <jordan.l.justen@intel.com>; Gao, Liming <liming.gao@intel.com>; >>>> Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ray >>>> <ray.ni@intel.com> >>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement >>>> library support for VMGEXIT >>>> >>>> On 06/19/20 15:50, Tom Lendacky wrote: >>>>> On 6/19/20 2:47 AM, Dong, Eric via groups.io wrote: >>>>>> >>>>>> >>>>>>> -----Original Message----- >>>>>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of >>>>>>> Lendacky, Thomas >>>>>>> Sent: Thursday, June 18, 2020 10:09 PM >>>>>>> To: Dong, Eric <eric.dong@intel.com>; devel@edk2.groups.io >>>>>>> Cc: Brijesh Singh <brijesh.singh@amd.com>; Ard Biesheuvel >>>>>>> <ard.biesheuvel@arm.com>; Justen, Jordan L >>>> <jordan.l.justen@intel.com>; >>>>>>> Laszlo Ersek <lersek@redhat.com>; Gao, Liming >>>>>>> <liming.gao@intel.com>; Kinney, Michael D >>>>>>> <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com> >>>>>>> Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement >>>> library >>>>>>> support for VMGEXIT >>>>>>> >>>>>>> On 6/18/20 2:23 AM, Dong, Eric wrote: >>>>>>>> Hi Tom, >>>>>>>> >>>>>>>> When use VS2015 to build this code, it reports below error. >>>>>>>> Please help to >>>>>>> fix it. >>>>>>>> >>>>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: error C2220: >>>> warning >>>>>>>> treated as error - no 'object' file generated >>>>>>>> k:\edk2\UefiCpuPkg\Include\Library/VmgExitLib.h: warning C4335: >>>> Mac >>>>>>>> file format detected: please convert the source file to either >>>>>>>> DOS or UNIX format >>>>>>> >>>>>>> That is strange... I didn't see this when I ran through the CI. >>>>>>> When I do a file command against the file it reports: >>>>>>> >>>>>>> UefiCpuPkg/Include/Library/VmgExitLib.h: C source, ASCII text, >>>>>>> with >>>> CRLF >>>>>>> line terminators >>>>>>> >>>>>>> I'll investigate this and try and figure out what's going on, but >>>>>>> if anyone else has some ideas, please let me know. >>>>>> >>>>>> Hi Tom, >>>>>> >>>>>> I met this error again when I trig below patch from AMD again for >>>>>> CPU change. >>>>>> "UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to >>>> BaseUefiCpuLib" >>>>> >>>>> Hmmm... I think we could be running into issues with sending patches >>>>> through our mail servers. Let me send you the patch series directly >>>>> using some changes I made to my git config file to see if that helps. >>>>> Would that be ok? >>>> >>>> both sender and recipient git clones should have >>>> >>>> [core] >>>> whitespace = cr-at-eol >>>> >>>> and the recipient clone should have >>>> >>>> [am] >>>> keepcr = true >>>> >>>> >> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit >>>> hub.com%2Ftianocore%2Ftianocore.github.io%2Fwiki%2FLaszlo%27s- >> unkempt >>>> -git- >> &data=02%7C01%7Cthomas.lendacky%40amd.com%7Cd461956236264e >> 4a >>>> >> 6d3a08d81713205d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C6 >> 372847 >>>> >> 18210751789&sdata=ftFiRZkC3n2n2MZyL6t9HKnp1fYgzUQV4FRBvVNQ4 >> %2FA%3 >>>> D&reserved=0 >>>> guide-for-edk2-contributors-and-maintainers#contrib-05 >>>> >>>> These are also set by "BaseTools/Scripts/SetupGit.py". >>>> >>> >>> Hi Tom, >>> >>> I see below context in another mail thread and base on the latest status, >> this solution works and that patch has fixed the issue. Can you follow below >> suggest fixing your issue? >>> >>> Hi Garrett, >>> >>> I encounter below error when build >>> UefiCpuPkg\Library\BaseUefiCpuLib\BaseUefiCpuLib.c: warning C4335: >> Mac file format detected: please convert the source file to either DOS or >> UNIX format' >>> >>> I encounter the issue ever, it result by mail encoding. >>> To resolve this issue, you can run [BaseTools\ Scripts\SetupGit.py] first, >> and then send the patch again. >>> >>> Could you try it and send the patch again? >> >> Hi Eric, >> >> I already had those settings in my git config file, so I'm thinking it was still >> something else. I sent you a direct set of patches with some other setting >> tweaks. Let me know how those work out for you. >> >> Thanks, >> Tom >> >>> >>> Thanks, >>> Eric >>> >>>> Thanks >>>> Laszlo >>>> >>>> >>>> >>> >>> >>> >> >> -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62102): https://edk2.groups.io/g/devel/message/62102 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 07/06/20 22:03, Tom Lendacky wrote:
> On 7/2/20 2:04 AM, Dong, Eric wrote:
>> Hi Tom,
>
> Hi Eric,
>
>>
>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case.
>
> Good to know, thanks!
>
>>
>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it?
>>
>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64]
>> PeCoffLoaderEx.c
>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2'
This is for the line
Displacement *= (1 << Ext->Sib.Scale);
from
[edk2-devel] [PATCH v9 17/46]
OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO)
>
> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<".
> I have verified that fixes the issue.
I disagree.
At that point, Displacement is of type INT64, and it may well be a
negative value. We definitely want to multiply it by a signed int
(values 1, 2, 4, 8).
I commented on this before. Please see:
(i) my comment block (10) here -- especially comment (10c):
https://edk2.groups.io/g/devel/message/60144
(alternative link:
<http://mid.mail-archive.com/169e44cb-2c1c-6d9a-342a-2a1f618e3753@redhat.com>)
(ii) and my comment here:
https://edk2.groups.io/g/devel/message/60146
(alternative link:
<http://mid.mail-archive.com/139ce789-b938-c8b9-030e-c1b6c67e47ea@redhat.com>).
The compiler warning is well-meaning, but unnecessary. A 64-bit shift is
*NOT* intended. We want to end up with one of the signed int (aka INT32)
values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that
value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be
implicitly converted to INT64. That's entirely intentional.
If we want to suppress the warning, while keeping the logic intact, we
should employ an explicit cast:
Displacement *= (INT64)(1 << Ext->Sib.Scale);
>
> One thing I noticed is that the 32-bit builds
> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and
> Platform_CI OVMF_IA32X64_NOOPT) encounter an error:
>
> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl
> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals
> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460'
>
> Any idea what is causing this error?
A left-shift operator (<<) applied to a 64-bit operand is somehow
finding its way into the 32-bit SEC build.
That is indeed wrong (for such cases, we're supposed to use LShiftU64()
from BaseLib).
What I don't understand however is that all of the "<<" operator uses,
on 64-bit operands, should already be limited to code that is *only*
built for X64!
For example, with this series applied, SecMain in OVMF consumes
"UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf".
And the latter consumes VmgExitLib.
But VmgExitLib is resolved to
"UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and
IA32X64 DSC files. This Null instance contains no left-shifts.
Therefore any << operators, applied to 64-bit operands, present in
"OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64.
So I don't know where the problematic "<<" comes from. It does not come
from VmgExitLib, as far as I can tell.
Thanks,
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#62166): https://edk2.groups.io/g/devel/message/62166
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 7/7/20 10:36 AM, Laszlo Ersek wrote: > On 07/06/20 22:03, Tom Lendacky wrote: >> On 7/2/20 2:04 AM, Dong, Eric wrote: >>> Hi Tom, >> >> Hi Eric, >> >>> >>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case. >> >> Good to know, thanks! >> >>> >>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it? >>> >>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64] >>> PeCoffLoaderEx.c >>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) >>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2' > > This is for the line > > Displacement *= (1 << Ext->Sib.Scale); > > from > > [edk2-devel] [PATCH v9 17/46] > OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) > >> >> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<". >> I have verified that fixes the issue. > > I disagree. > > At that point, Displacement is of type INT64, and it may well be a > negative value. We definitely want to multiply it by a signed int > (values 1, 2, 4, 8). > > I commented on this before. Please see: > > (i) my comment block (10) here -- especially comment (10c): > > https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60144&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=g%2BGooY1Sv0G7ydr11Jh%2BTXxo4Wy6ZWcT5Mq9VmWddi8%3D&reserved=0 > > (alternative link: > <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F169e44cb-2c1c-6d9a-342a-2a1f618e3753%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=6p91db%2F6oz%2FHc65Sq4fvH%2FcPmiAfdS8MImsaznaoaXA%3D&reserved=0>) > > (ii) and my comment here: > > https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60146&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=iNIBJCIlfEEsY37cdwUbH27tx5HvXVs3PZiOQfaGeLQ%3D&reserved=0 > > (alternative link: > <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F139ce789-b938-c8b9-030e-c1b6c67e47ea%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=mWCAHqTOpp7B9nWUJjTRJ9VZ74iwdElRTOoNhEpFs%2Bc%3D&reserved=0>). > > > The compiler warning is well-meaning, but unnecessary. A 64-bit shift is > *NOT* intended. We want to end up with one of the signed int (aka INT32) > values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that > value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be > implicitly converted to INT64. That's entirely intentional. > > If we want to suppress the warning, while keeping the logic intact, we > should employ an explicit cast: > > Displacement *= (INT64)(1 << Ext->Sib.Scale); Ok, that makes sense. I'll use the explicit cast. > >> >> One thing I noticed is that the 32-bit builds >> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and >> Platform_CI OVMF_IA32X64_NOOPT) encounter an error: >> >> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl >> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals >> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460' >> >> Any idea what is causing this error? > > A left-shift operator (<<) applied to a 64-bit operand is somehow > finding its way into the 32-bit SEC build. > > That is indeed wrong (for such cases, we're supposed to use LShiftU64() > from BaseLib). > > What I don't understand however is that all of the "<<" operator uses, > on 64-bit operands, should already be limited to code that is *only* > built for X64! > > For example, with this series applied, SecMain in OVMF consumes > "UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf". > And the latter consumes VmgExitLib. > > But VmgExitLib is resolved to > "UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and > IA32X64 DSC files. This Null instance contains no left-shifts. > > Therefore any << operators, applied to 64-bit operands, present in > "OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64. > > So I don't know where the problematic "<<" comes from. It does not come > from VmgExitLib, as far as I can tell. Yes, I don't think it's coming from VmgExitLib, either. I wonder if it somehow might be coming from the MSR_SEV_ES_GHCB_REGISTER struct and the bit fields that are used within it? That code, while not executed in non-X64 builds because SEV-ES is not active, is still built and maybe the bit fields result in implicit shifts occurring, specifically in SevEsProtocolFailure()? I'll experiment with some things and see if that is the issue. Thanks, Tom > > Thanks, > Laszlo > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62168): https://edk2.groups.io/g/devel/message/62168 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 7/7/20 10:50 AM, Tom Lendacky wrote: > On 7/7/20 10:36 AM, Laszlo Ersek wrote: >> On 07/06/20 22:03, Tom Lendacky wrote: >>> On 7/2/20 2:04 AM, Dong, Eric wrote: >>>> Hi Tom, >>> >>> Hi Eric, >>> >>>> >>>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case. >>> >>> Good to know, thanks! >>> >>>> >>>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it? >>>> >>>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64] >>>> PeCoffLoaderEx.c >>>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) >>>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2' >> >> This is for the line >> >> Displacement *= (1 << Ext->Sib.Scale); >> >> from >> >> [edk2-devel] [PATCH v9 17/46] >> OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) >> >>> >>> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<". >>> I have verified that fixes the issue. >> >> I disagree. >> >> At that point, Displacement is of type INT64, and it may well be a >> negative value. We definitely want to multiply it by a signed int >> (values 1, 2, 4, 8). >> >> I commented on this before. Please see: >> >> (i) my comment block (10) here -- especially comment (10c): >> >> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60144&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=g%2BGooY1Sv0G7ydr11Jh%2BTXxo4Wy6ZWcT5Mq9VmWddi8%3D&reserved=0 >> >> (alternative link: >> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F169e44cb-2c1c-6d9a-342a-2a1f618e3753%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=6p91db%2F6oz%2FHc65Sq4fvH%2FcPmiAfdS8MImsaznaoaXA%3D&reserved=0>) >> >> (ii) and my comment here: >> >> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60146&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=iNIBJCIlfEEsY37cdwUbH27tx5HvXVs3PZiOQfaGeLQ%3D&reserved=0 >> >> (alternative link: >> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F139ce789-b938-c8b9-030e-c1b6c67e47ea%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=mWCAHqTOpp7B9nWUJjTRJ9VZ74iwdElRTOoNhEpFs%2Bc%3D&reserved=0>). >> >> >> The compiler warning is well-meaning, but unnecessary. A 64-bit shift is >> *NOT* intended. We want to end up with one of the signed int (aka INT32) >> values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that >> value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be >> implicitly converted to INT64. That's entirely intentional. >> >> If we want to suppress the warning, while keeping the logic intact, we >> should employ an explicit cast: >> >> Displacement *= (INT64)(1 << Ext->Sib.Scale); > > Ok, that makes sense. I'll use the explicit cast. > >> >>> >>> One thing I noticed is that the 32-bit builds >>> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and >>> Platform_CI OVMF_IA32X64_NOOPT) encounter an error: >>> >>> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl >>> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals >>> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460' >>> >>> Any idea what is causing this error? >> >> A left-shift operator (<<) applied to a 64-bit operand is somehow >> finding its way into the 32-bit SEC build. >> >> That is indeed wrong (for such cases, we're supposed to use LShiftU64() >> from BaseLib). >> >> What I don't understand however is that all of the "<<" operator uses, >> on 64-bit operands, should already be limited to code that is *only* >> built for X64! >> >> For example, with this series applied, SecMain in OVMF consumes >> "UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf". >> And the latter consumes VmgExitLib. >> >> But VmgExitLib is resolved to >> "UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and >> IA32X64 DSC files. This Null instance contains no left-shifts. >> >> Therefore any << operators, applied to 64-bit operands, present in >> "OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64. >> >> So I don't know where the problematic "<<" comes from. It does not come >> from VmgExitLib, as far as I can tell. > > Yes, I don't think it's coming from VmgExitLib, either. > > I wonder if it somehow might be coming from the MSR_SEV_ES_GHCB_REGISTER > struct and the bit fields that are used within it? That code, while not > executed in non-X64 builds because SEV-ES is not active, is still built > and maybe the bit fields result in implicit shifts occurring, specifically > in SevEsProtocolFailure()? > > I'll experiment with some things and see if that is the issue. I commented out the setting of the GhcbTerminate fields in the SevEsProtocolFailure() routine of OvmfPkg/Sec/SecMain.c and the error disappeared. I'll see if changing from using UINT64 to multiple UINT32 entries fixes the problem, but I wouldn't think that the bit fields would/should cause an issue here with 32-bit builds. Thanks, Tom > > Thanks, > Tom > >> >> Thanks, >> Laszlo >> -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62170): https://edk2.groups.io/g/devel/message/62170 Mute This Topic: https://groups.io/mt/74692413/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 7/7/20 12:11 PM, Tom Lendacky wrote:
> On 7/7/20 10:50 AM, Tom Lendacky wrote:
>> On 7/7/20 10:36 AM, Laszlo Ersek wrote:
>>> On 07/06/20 22:03, Tom Lendacky wrote:
>>>> On 7/2/20 2:04 AM, Dong, Eric wrote:
>>>>> Hi Tom,
>>>>
>>>> Hi Eric,
>>>>
>>>>>
>>>>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case.
>>>>
>>>> Good to know, thanks!
>>>>
>>>>>
>>>>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it?
>>>>>
>>>>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64]
>>>>> PeCoffLoaderEx.c
>>>>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
>>>>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2'
>>>
>>> This is for the line
>>>
>>> Displacement *= (1 << Ext->Sib.Scale);
>>>
>>> from
>>>
>>> [edk2-devel] [PATCH v9 17/46]
>>> OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO)
>>>
>>>>
>>>> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<".
>>>> I have verified that fixes the issue.
>>>
>>> I disagree.
>>>
>>> At that point, Displacement is of type INT64, and it may well be a
>>> negative value. We definitely want to multiply it by a signed int
>>> (values 1, 2, 4, 8).
>>>
>>> I commented on this before. Please see:
>>>
>>> (i) my comment block (10) here -- especially comment (10c):
>>>
>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60144&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=g%2BGooY1Sv0G7ydr11Jh%2BTXxo4Wy6ZWcT5Mq9VmWddi8%3D&reserved=0
>>>
>>> (alternative link:
>>> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F169e44cb-2c1c-6d9a-342a-2a1f618e3753%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=6p91db%2F6oz%2FHc65Sq4fvH%2FcPmiAfdS8MImsaznaoaXA%3D&reserved=0>)
>>>
>>> (ii) and my comment here:
>>>
>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60146&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=iNIBJCIlfEEsY37cdwUbH27tx5HvXVs3PZiOQfaGeLQ%3D&reserved=0
>>>
>>> (alternative link:
>>> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F139ce789-b938-c8b9-030e-c1b6c67e47ea%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=mWCAHqTOpp7B9nWUJjTRJ9VZ74iwdElRTOoNhEpFs%2Bc%3D&reserved=0>).
>>>
>>>
>>> The compiler warning is well-meaning, but unnecessary. A 64-bit shift is
>>> *NOT* intended. We want to end up with one of the signed int (aka INT32)
>>> values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that
>>> value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be
>>> implicitly converted to INT64. That's entirely intentional.
>>>
>>> If we want to suppress the warning, while keeping the logic intact, we
>>> should employ an explicit cast:
>>>
>>> Displacement *= (INT64)(1 << Ext->Sib.Scale);
>>
>> Ok, that makes sense. I'll use the explicit cast.
>>
>>>
>>>>
>>>> One thing I noticed is that the 32-bit builds
>>>> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and
>>>> Platform_CI OVMF_IA32X64_NOOPT) encounter an error:
>>>>
>>>> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl
>>>> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals
>>>> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460'
>>>>
>>>> Any idea what is causing this error?
>>>
>>> A left-shift operator (<<) applied to a 64-bit operand is somehow
>>> finding its way into the 32-bit SEC build.
>>>
>>> That is indeed wrong (for such cases, we're supposed to use LShiftU64()
>>> from BaseLib).
>>>
>>> What I don't understand however is that all of the "<<" operator uses,
>>> on 64-bit operands, should already be limited to code that is *only*
>>> built for X64!
>>>
>>> For example, with this series applied, SecMain in OVMF consumes
>>> "UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf".
>>> And the latter consumes VmgExitLib.
>>>
>>> But VmgExitLib is resolved to
>>> "UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and
>>> IA32X64 DSC files. This Null instance contains no left-shifts.
>>>
>>> Therefore any << operators, applied to 64-bit operands, present in
>>> "OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64.
>>>
>>> So I don't know where the problematic "<<" comes from. It does not come
>>> from VmgExitLib, as far as I can tell.
>>
>> Yes, I don't think it's coming from VmgExitLib, either.
>>
>> I wonder if it somehow might be coming from the MSR_SEV_ES_GHCB_REGISTER
>> struct and the bit fields that are used within it? That code, while not
>> executed in non-X64 builds because SEV-ES is not active, is still built
>> and maybe the bit fields result in implicit shifts occurring, specifically
>> in SevEsProtocolFailure()?
>>
>> I'll experiment with some things and see if that is the issue.
>
> I commented out the setting of the GhcbTerminate fields in the
> SevEsProtocolFailure() routine of OvmfPkg/Sec/SecMain.c and the error
> disappeared. I'll see if changing from using UINT64 to multiple UINT32
> entries fixes the problem, but I wouldn't think that the bit fields
> would/should cause an issue here with 32-bit builds.
Changing the bit fields from UINT64 to UINT32 fixed the error and SEV-ES
support continues to function properly. Since the architecture is little
endian, there was no need to pad out to the full UINT64 size for the
structs (the union takes care of that in general). The change looks like
this:
diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Register/Amd/Fam17Msr.h
index 466a3143599c..3cbe593868d4 100644
--- a/MdePkg/Include/Register/Amd/Fam17Msr.h
+++ b/MdePkg/Include/Register/Amd/Fam17Msr.h
@@ -28,7 +28,7 @@
**/
typedef union {
struct {
- UINT64 Function:12;
+ UINT32 Function:12;
} GhcbInfo;
struct {
@@ -39,9 +39,9 @@ typedef union {
} GhcbProtocol;
struct {
- UINT64 Function:12;
- UINT64 ReasonCodeSet:4;
- UINT64 ReasonCode:8;
+ UINT32 Function:12;
+ UINT32 ReasonCodeSet:4;
+ UINT32 ReasonCode:8;
} GhcbTerminate;
VOID *Ghcb;
Unless there are any concerns, I'll incorporate this change.
Thanks,
Tom
>
> Thanks,
> Tom
>
>>
>> Thanks,
>> Tom
>>
>>>
>>> Thanks,
>>> Laszlo
>>>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#62230): https://edk2.groups.io/g/devel/message/62230
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 07/08/20 15:07, Tom Lendacky wrote:
> On 7/7/20 12:11 PM, Tom Lendacky wrote:
>> On 7/7/20 10:50 AM, Tom Lendacky wrote:
>>> On 7/7/20 10:36 AM, Laszlo Ersek wrote:
>>>> On 07/06/20 22:03, Tom Lendacky wrote:
>>>>> On 7/2/20 2:04 AM, Dong, Eric wrote:
>>>>>> Hi Tom,
>>>>>
>>>>> Hi Eric,
>>>>>
>>>>>>
>>>>>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case.
>>>>>
>>>>> Good to know, thanks!
>>>>>
>>>>>>
>>>>>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it?
>>>>>>
>>>>>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64]
>>>>>> PeCoffLoaderEx.c
>>>>>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
>>>>>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2'
>>>>
>>>> This is for the line
>>>>
>>>> Displacement *= (1 << Ext->Sib.Scale);
>>>>
>>>> from
>>>>
>>>> [edk2-devel] [PATCH v9 17/46]
>>>> OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO)
>>>>
>>>>>
>>>>> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<".
>>>>> I have verified that fixes the issue.
>>>>
>>>> I disagree.
>>>>
>>>> At that point, Displacement is of type INT64, and it may well be a
>>>> negative value. We definitely want to multiply it by a signed int
>>>> (values 1, 2, 4, 8).
>>>>
>>>> I commented on this before. Please see:
>>>>
>>>> (i) my comment block (10) here -- especially comment (10c):
>>>>
>>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60144&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=g%2BGooY1Sv0G7ydr11Jh%2BTXxo4Wy6ZWcT5Mq9VmWddi8%3D&reserved=0
>>>>
>>>> (alternative link:
>>>> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F169e44cb-2c1c-6d9a-342a-2a1f618e3753%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=6p91db%2F6oz%2FHc65Sq4fvH%2FcPmiAfdS8MImsaznaoaXA%3D&reserved=0>)
>>>>
>>>> (ii) and my comment here:
>>>>
>>>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60146&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=iNIBJCIlfEEsY37cdwUbH27tx5HvXVs3PZiOQfaGeLQ%3D&reserved=0
>>>>
>>>> (alternative link:
>>>> <https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F139ce789-b938-c8b9-030e-c1b6c67e47ea%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=mWCAHqTOpp7B9nWUJjTRJ9VZ74iwdElRTOoNhEpFs%2Bc%3D&reserved=0>).
>>>>
>>>>
>>>> The compiler warning is well-meaning, but unnecessary. A 64-bit shift is
>>>> *NOT* intended. We want to end up with one of the signed int (aka INT32)
>>>> values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that
>>>> value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be
>>>> implicitly converted to INT64. That's entirely intentional.
>>>>
>>>> If we want to suppress the warning, while keeping the logic intact, we
>>>> should employ an explicit cast:
>>>>
>>>> Displacement *= (INT64)(1 << Ext->Sib.Scale);
>>>
>>> Ok, that makes sense. I'll use the explicit cast.
>>>
>>>>
>>>>>
>>>>> One thing I noticed is that the 32-bit builds
>>>>> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and
>>>>> Platform_CI OVMF_IA32X64_NOOPT) encounter an error:
>>>>>
>>>>> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl
>>>>> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals
>>>>> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460'
>>>>>
>>>>> Any idea what is causing this error?
>>>>
>>>> A left-shift operator (<<) applied to a 64-bit operand is somehow
>>>> finding its way into the 32-bit SEC build.
>>>>
>>>> That is indeed wrong (for such cases, we're supposed to use LShiftU64()
>>>> from BaseLib).
>>>>
>>>> What I don't understand however is that all of the "<<" operator uses,
>>>> on 64-bit operands, should already be limited to code that is *only*
>>>> built for X64!
>>>>
>>>> For example, with this series applied, SecMain in OVMF consumes
>>>> "UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf".
>>>> And the latter consumes VmgExitLib.
>>>>
>>>> But VmgExitLib is resolved to
>>>> "UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and
>>>> IA32X64 DSC files. This Null instance contains no left-shifts.
>>>>
>>>> Therefore any << operators, applied to 64-bit operands, present in
>>>> "OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64.
>>>>
>>>> So I don't know where the problematic "<<" comes from. It does not come
>>>> from VmgExitLib, as far as I can tell.
>>>
>>> Yes, I don't think it's coming from VmgExitLib, either.
>>>
>>> I wonder if it somehow might be coming from the MSR_SEV_ES_GHCB_REGISTER
>>> struct and the bit fields that are used within it? That code, while not
>>> executed in non-X64 builds because SEV-ES is not active, is still built
>>> and maybe the bit fields result in implicit shifts occurring, specifically
>>> in SevEsProtocolFailure()?
>>>
>>> I'll experiment with some things and see if that is the issue.
>>
>> I commented out the setting of the GhcbTerminate fields in the
>> SevEsProtocolFailure() routine of OvmfPkg/Sec/SecMain.c and the error
>> disappeared. I'll see if changing from using UINT64 to multiple UINT32
>> entries fixes the problem, but I wouldn't think that the bit fields
>> would/should cause an issue here with 32-bit builds.
>
> Changing the bit fields from UINT64 to UINT32 fixed the error and SEV-ES
> support continues to function properly. Since the architecture is little
> endian, there was no need to pad out to the full UINT64 size for the
> structs (the union takes care of that in general). The change looks like
> this:
>
> diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Register/Amd/Fam17Msr.h
> index 466a3143599c..3cbe593868d4 100644
> --- a/MdePkg/Include/Register/Amd/Fam17Msr.h
> +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h
> @@ -28,7 +28,7 @@
> **/
> typedef union {
> struct {
> - UINT64 Function:12;
> + UINT32 Function:12;
> } GhcbInfo;
>
> struct {
> @@ -39,9 +39,9 @@ typedef union {
> } GhcbProtocol;
>
> struct {
> - UINT64 Function:12;
> - UINT64 ReasonCodeSet:4;
> - UINT64 ReasonCode:8;
> + UINT32 Function:12;
> + UINT32 ReasonCodeSet:4;
> + UINT32 ReasonCode:8;
> } GhcbTerminate;
>
> VOID *Ghcb;
>
> Unless there are any concerns, I'll incorporate this change.
Right, my general disapproval of bit-fields notwithstanding, this looks
consistent with most of the bit-fields under MdePkg!
Thanks
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#62248): https://edk2.groups.io/g/devel/message/62248
Mute This Topic: https://groups.io/mt/74692413/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 07/07/20 19:11, Tom Lendacky wrote:
> I commented out the setting of the GhcbTerminate fields in the
> SevEsProtocolFailure() routine of OvmfPkg/Sec/SecMain.c and the error
> disappeared. I'll see if changing from using UINT64 to multiple UINT32
> entries fixes the problem, but I wouldn't think that the bit fields
> would/should cause an issue here with 32-bit builds.
For two examples from
"MdePkg/Include/Register/Intel/ArchitecturalMsr.h": the
- MSR_IA32_FEATURE_CONTROL_REGISTER
- MSR_IA32_EFER_REGISTER
types use UINT32 bit-field members.
--*--
I've always disliked bit-fields. Consider:
C99 "6.7.2 Type specifiers"
5 [...] for bit-fields, it is implementation-defined whether the
specifier int designates the same type as signed int or the same
type as unsigned int.
C99 "6.7.2.1 Structure and union specifiers":
4 A bit-field shall have a type that is a qualified or unqualified
version of _Bool, signed int, unsigned int, or some other
implementation-defined type.
10 An implementation may allocate any addressable storage unit large
enough to hold a bit-field. If enough space remains, a bit-field
that immediately follows another bit-field in a structure shall be
packed into adjacent bits of the same unit. If insufficient space
remains, whether a bit-field that does not fit is put into the next
unit or overlaps adjacent units is implementation-defined. The
order of allocation of bit-fields within a unit (high-order to
low-order or low-order to high-order) is implementation-defined.
The alignment of the addressable storage unit is unspecified.
The C99 *Rationale* says under "6.7.2.1. Structure and union
specifiers",
Three types of bit-fields are now defined: plain int calls for
implementation-defined signedness (as in K&R), signed int calls for
assuredly signed fields, and unsigned int calls for unsigned fields.
The old constraints on bit-fields crossing word boundaries have been
relaxed, since so many properties of bit-fields are implementation
dependent anyway.
This means that bit-fields are entirely non-portable.
--*--
The UEFI spec only says, in "Table 5. Common UEFI Data Types":
Bitfields are ordered such that bit 0 is the least significant bit.
So that removes only one variable (order of allocation of bit-fields).
Consider the following type:
typedef struct {
UINT16 Hello;
UINT16 Foo:15;
UINT32 Bar:27;
} FOOBAR;
Even considering the UEFI spec rules that structure members are
"naturally alined", plus the above order of allocation of bit-fields, we
still can't tell whether Bar starts at:
(a) bit 31,
(b) bit 32,
(c) bit 47,
(d) bit 64,
(e) bit 79.
- In case (a), the structure consists of the following units:
- UINT16 (Hello),
- UINT16 (Foo, plus one bit of Bar),
- UINT32 (all bits of Bar except the least significant one).
The implementation chooses to overlap adjacent units, for storing Bar.
Bar starts at bit 31.
- In case (b), the structure consists of the following units:
- UINT16 (Hello),
- UINT16 (Foo),
- UINT32 (Bar).
The imlementation chooses not to overlap adjacent units, for storing
Bar. Bar starts at bit 32.
- In case (c), the structure consists of the following units:
- UINT16 (Hello),
- UINT16 (padding),
- UINT32 (Foo, plus 17 low order bits of Bar),
- UINT32 (10 high order bits of Bar).
The padding is inserted because the implementation chooses UINT32 for
storing Foo, and said UINT32 has to be naturally aligned (per UEFI
spec). Furthermore, the implementation chooses to overlap adjacent
UINT32 units, for storing Bar. Bar starts at bit 47.
- In case (d), the structure consists of the following units:
- UINT16 (Hello),
- UINT16 (padding),
- UINT32 (Foo),
- UINT32 (Bar).
The padding is inserted because the implementation chooses UINT32 for
storing Foo, and said UINT32 has to be naturally aligned (per UEFI
spec). Furthermore, the implementation chooses not to overlap adjacent
UINT32 units, for storing Bar. Bar starts at bit 64.
- In case (e), the structure consists of the following units:
- UINT16 (Hello),
- UINT16[3] (padding),
- UINT64 (Foo and Bar).
The padding is inserted because the implementation chooses UINT64 for
storing Foo, and said UINT64 has to be naturally aligned (per UEFI
spec). And because 15+27=42, both Foo and Bar fit into UINT64, and so
the implementation must pack them both into that unit. Bar starts at
bit 79.
--*--
The edk2 C Coding Standards have a section on bit-fields:
https://edk2-docs.gitbook.io/edk-ii-c-coding-standards-specification/5_source_files/56_declarations_and_types#5-6-3-4-bit-fields
Some part of that section are worth quoting:
> - Bit fields may only be of type INT32, signed INT32, UINT32, or a
> typedef name defined as one of the three INT32 variants.
Unfortunately, the edk2 codebase readily violates this; the following
"grep" confirms there are many UINT64 bit-fields:
$ git grep -E 'UINT64 *[A-Za-z0-9_]+ *: *[0-9]+ *;'
> - The order of allocation of bit-fields within a storage unit is
> compiler defined.
This conflicts with the UEFI spec, as the UEFI spec does define the
order of allocation.
> - A bit-field may not extend from one storage unit into another.
Overlapping adjacent units is up to the implementation, according to the
C standard.
So, is the programmer supposed to prevent that, by using unnamed ":0"
bitfields (per C99 6.7.2.1 p11)?
Then, further CCS sections:
https://edk2-docs.gitbook.io/edk-ii-c-coding-standards-specification/5_source_files/56_declarations_and_types#5-6-3-4-1-visual-c-specific
https://edk2-docs.gitbook.io/edk-ii-c-coding-standards-specification/5_source_files/56_declarations_and_types#5-6-3-4-2-gcc-specific
make toolchain / ABI specific notes. But I think ABI quirks and versions
are not what we should be thinking about when writing C source code. :(
I'm quite unhappy that bit-fields are so widely used in edk2. We should
always use unsigned integers and bitmask macros instead. That way at
least we're honest about the accesses. The bit-field types seem to work
mainly through sheer luck. (If there are ABI assumptions, they don't
seem to be clearly documented, anyway.)
Thanks
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#62236): https://edk2.groups.io/g/devel/message/62236
Mute This Topic: https://groups.io/mt/75378498/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.