From 1b1c58ab32c30d32ba7d037c0ea1da198c1b372b Mon Sep 17 00:00:00 2001 From: Min M Xu Date: Thu, 7 Jul 2022 10:51:20 +0800 Subject: OvmfPkg: Update CcProbeLib to DxeCcProbeLib BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3974 CcProbeLib once was designed to probe the Confidential Computing guest type by checking the PcdOvmfWorkArea. But this memory is allocated with either EfiACPIMemoryNVS or EfiBootServicesData. It cannot be accessed after ExitBootService. Please see the detailed analysis in BZ#3974. To fix this issue, CcProbeLib is redesigned as 2 implementation: - SecPeiCcProbeLib - DxeCcProbeLib In SecPeiCcProbeLib we check the CC guest type by reading the PcdOvmfWorkArea. Because it is used in SEC / PEI and we don't worry about the issues in BZ#3974. In DxeCcProbeLib we cache the GuestType in Ovmf work area in a variable. After that the Guest type is returned with the cached value. So that we don't need to worry about the access to Ovmf work area after ExitBootService. The reason why we probe CC guest type in 2 different ways is the global varialbe. Global variable cannot be used in SEC/PEI and CcProbe is called very frequently. Cc: Gerd Hoffmann Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Acked-by: Gerd Hoffmann Reviewed-by: Jiewen Yao --- OvmfPkg/Library/CcProbeLib/CcProbeLib.c | 31 ------------- OvmfPkg/Library/CcProbeLib/CcProbeLib.inf | 25 ---------- OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c | 68 ++++++++++++++++++++++++++++ OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf | 26 +++++++++++ 4 files changed, 94 insertions(+), 56 deletions(-) delete mode 100644 OvmfPkg/Library/CcProbeLib/CcProbeLib.c delete mode 100644 OvmfPkg/Library/CcProbeLib/CcProbeLib.inf create mode 100644 OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c create mode 100644 OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf (limited to 'OvmfPkg/Library') diff --git a/OvmfPkg/Library/CcProbeLib/CcProbeLib.c b/OvmfPkg/Library/CcProbeLib/CcProbeLib.c deleted file mode 100644 index d698e5c8d7..0000000000 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.c +++ /dev/null @@ -1,31 +0,0 @@ -/** @file - - CcProbeLib is used to probe the Confidential computing guest type. - - Copyright (c) 2022, Intel Corporation. All rights reserved.
- SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include -#include - -/** - Probe the ConfidentialComputing Guest type. See defition of - CC_GUEST_TYPE in . - - @return The guest type - -**/ -UINT8 -EFIAPI -CcProbe ( - VOID - ) -{ - OVMF_WORK_AREA *WorkArea; - - WorkArea = (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); - - return WorkArea != NULL ? WorkArea->Header.GuestType : CcGuestTypeNonEncrypted; -} diff --git a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf b/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf deleted file mode 100644 index 5300c9ba26..0000000000 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf +++ /dev/null @@ -1,25 +0,0 @@ -## @file -# CcProbeLib is used to probe Confidential Computing guest type. -# -# Copyright (c) 2022, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = CcProbeLib - FILE_GUID = 05184ec9-abb0-4491-8584-e388639a7c48 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = CcProbeLib - -[Sources] - CcProbeLib.c - -[Packages] - MdePkg/MdePkg.dec - OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase diff --git a/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c new file mode 100644 index 0000000000..868e32bf7f --- /dev/null +++ b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c @@ -0,0 +1,68 @@ +/** @file + + CcProbeLib is used to probe the Confidential computing guest type. + + Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +STATIC UINT8 mCcProbeGuestType = 0; +STATIC BOOLEAN mCcProbed = FALSE; + +/** + * Read the the ConfidentialComputing Guest type from Ovmf work-area. + * + * @return The ConfidentialComputing Guest type + */ +STATIC +UINT8 +ReadCcGuestType ( + VOID + ) +{ + OVMF_WORK_AREA *WorkArea; + + if (!mCcProbed) { + WorkArea = (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + mCcProbeGuestType = WorkArea != NULL ? WorkArea->Header.GuestType : CcGuestTypeNonEncrypted; + mCcProbed = TRUE; + } + + return mCcProbeGuestType; +} + +/** + Probe the ConfidentialComputing Guest type. See defition of + CC_GUEST_TYPE in . + + @return The guest type + +**/ +UINT8 +EFIAPI +CcProbe ( + VOID + ) +{ + return ReadCcGuestType (); +} + +/** + * Constructor of DxeCcProbeLib + * + * @return EFI_SUCCESS Successfully called of constructor + */ +EFI_STATUS +EFIAPI +DxeCcProbeLibConstructor ( + VOID + ) +{ + ReadCcGuestType (); + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf new file mode 100644 index 0000000000..2fd0b4d46d --- /dev/null +++ b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf @@ -0,0 +1,26 @@ +## @file +# CcProbeLib is used to probe Confidential Computing guest type. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeCcProbeLib + FILE_GUID = 05184ec9-abb0-4491-8584-e388639a7c48 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = CcProbeLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION + CONSTRUCTOR = DxeCcProbeLibConstructor + +[Sources] + DxeCcProbeLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase -- cgit v1.2.3