Skip to content

Commit 1b1c58a

Browse files
mxu9mergify[bot]
authored andcommitted
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 <kraxel@redhat.com> Cc: Erdem Aktas <erdemaktas@google.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Min Xu <min.m.xu@intel.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
1 parent c4bc1a9 commit 1b1c58a

File tree

5 files changed

+78
-36
lines changed

5 files changed

+78
-36
lines changed

OvmfPkg/IntelTdx/IntelTdxX64.dsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
PciCapLib|OvmfPkg/Library/BasePciCapLib/BasePciCapLib.inf
141141
PciCapPciSegmentLib|OvmfPkg/Library/BasePciCapPciSegmentLib/BasePciCapPciSegmentLib.inf
142142
PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf
143-
CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf
143+
CcProbeLib|OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf
144144
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
145145
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
146146
SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf
@@ -234,6 +234,7 @@
234234
HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
235235
PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
236236
PeilessStartupLib|OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
237+
CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf
237238

238239
[LibraryClasses.common.DXE_CORE]
239240
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

OvmfPkg/Library/CcProbeLib/CcProbeLib.c

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/** @file
2+
3+
CcProbeLib is used to probe the Confidential computing guest type.
4+
5+
Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#include <Uefi/UefiBaseType.h>
11+
#include <Library/CcProbeLib.h>
12+
#include <WorkArea.h>
13+
14+
STATIC UINT8 mCcProbeGuestType = 0;
15+
STATIC BOOLEAN mCcProbed = FALSE;
16+
17+
/**
18+
* Read the the ConfidentialComputing Guest type from Ovmf work-area.
19+
*
20+
* @return The ConfidentialComputing Guest type
21+
*/
22+
STATIC
23+
UINT8
24+
ReadCcGuestType (
25+
VOID
26+
)
27+
{
28+
OVMF_WORK_AREA *WorkArea;
29+
30+
if (!mCcProbed) {
31+
WorkArea = (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
32+
mCcProbeGuestType = WorkArea != NULL ? WorkArea->Header.GuestType : CcGuestTypeNonEncrypted;
33+
mCcProbed = TRUE;
34+
}
35+
36+
return mCcProbeGuestType;
37+
}
38+
39+
/**
40+
Probe the ConfidentialComputing Guest type. See defition of
41+
CC_GUEST_TYPE in <ConfidentialComputingGuestAttr.h>.
42+
43+
@return The guest type
44+
45+
**/
46+
UINT8
47+
EFIAPI
48+
CcProbe (
49+
VOID
50+
)
51+
{
52+
return ReadCcGuestType ();
53+
}
54+
55+
/**
56+
* Constructor of DxeCcProbeLib
57+
*
58+
* @return EFI_SUCCESS Successfully called of constructor
59+
*/
60+
EFI_STATUS
61+
EFIAPI
62+
DxeCcProbeLibConstructor (
63+
VOID
64+
)
65+
{
66+
ReadCcGuestType ();
67+
return EFI_SUCCESS;
68+
}

OvmfPkg/Library/CcProbeLib/CcProbeLib.inf renamed to OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
[Defines]
1010
INF_VERSION = 0x00010005
11-
BASE_NAME = CcProbeLib
11+
BASE_NAME = DxeCcProbeLib
1212
FILE_GUID = 05184ec9-abb0-4491-8584-e388639a7c48
1313
MODULE_TYPE = BASE
1414
VERSION_STRING = 1.0
15-
LIBRARY_CLASS = CcProbeLib
15+
LIBRARY_CLASS = CcProbeLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION
16+
CONSTRUCTOR = DxeCcProbeLibConstructor
1617

1718
[Sources]
18-
CcProbeLib.c
19+
DxeCcProbeLib.c
1920

2021
[Packages]
2122
MdePkg/MdePkg.dec

OvmfPkg/OvmfPkgX64.dsc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204

205205
!if $(SMM_REQUIRE) == FALSE
206206
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
207-
CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf
207+
CcProbeLib|OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf
208208
!else
209209
CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
210210
!endif
@@ -295,6 +295,7 @@
295295
!endif
296296
VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf
297297
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
298+
CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf
298299

299300
[LibraryClasses.common.PEI_CORE]
300301
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -311,6 +312,7 @@
311312
DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
312313
!endif
313314
PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
315+
CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf
314316

315317
[LibraryClasses.common.PEIM]
316318
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -340,6 +342,7 @@
340342
PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
341343

342344
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
345+
CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf
343346

344347
[LibraryClasses.common.DXE_CORE]
345348
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf

0 commit comments

Comments
 (0)