OvmfPkg: Call CcProbe in SecMain.c instead of TsIsEnabled

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

TdIsEnabled() uses the CPUID instruction. At this point, exception
handling is not established and a CPUID instruction will generate
a #VC and cause the booting guest to crash.

CcProbe() checks Ovmf work area to return the guest type. So call
of CcProbe() instead of TdIsEnabled() to fix the above issue.

Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
This commit is contained in:
Min Xu 2022-04-19 08:26:28 +08:00 committed by mergify[bot]
parent 7012cb73c4
commit 76fda1def3
4 changed files with 8 additions and 5 deletions

View File

@ -25,7 +25,7 @@
#include <Library/CpuExceptionHandlerLib.h> #include <Library/CpuExceptionHandlerLib.h>
#include <IndustryStandard/Tdx.h> #include <IndustryStandard/Tdx.h>
#include <Library/PlatformInitLib.h> #include <Library/PlatformInitLib.h>
#include <Library/CcProbeLib.h>
#include <Library/PeilessStartupLib.h> #include <Library/PeilessStartupLib.h>
#define SEC_IDT_ENTRY_COUNT 34 #define SEC_IDT_ENTRY_COUNT 34
@ -61,7 +61,7 @@ SecCoreStartupWithStack (
UINT32 Index; UINT32 Index;
volatile UINT8 *Table; volatile UINT8 *Table;
if (TdIsEnabled ()) { if (CcProbe () == CcGuestTypeIntelTdx) {
// //
// For Td guests, the memory map info is in TdHobLib. It should be processed // For Td guests, the memory map info is in TdHobLib. It should be processed
// first so that the memory is accepted. Otherwise access to the unaccepted // first so that the memory is accepted. Otherwise access to the unaccepted
@ -119,7 +119,7 @@ SecCoreStartupWithStack (
// //
AsmWriteIdtr (&IdtDescriptor); AsmWriteIdtr (&IdtDescriptor);
if (TdIsEnabled ()) { if (CcProbe () == CcGuestTypeIntelTdx) {
// //
// InitializeCpuExceptionHandlers () should be called in Td guests so that // InitializeCpuExceptionHandlers () should be called in Td guests so that
// #VE exceptions can be handled correctly. // #VE exceptions can be handled correctly.

View File

@ -49,6 +49,7 @@
CpuExceptionHandlerLib CpuExceptionHandlerLib
PeilessStartupLib PeilessStartupLib
PlatformInitLib PlatformInitLib
CcProbeLib
[Pcd] [Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase

View File

@ -28,6 +28,7 @@
#include <Library/CpuExceptionHandlerLib.h> #include <Library/CpuExceptionHandlerLib.h>
#include <Ppi/TemporaryRamSupport.h> #include <Ppi/TemporaryRamSupport.h>
#include <Library/PlatformInitLib.h> #include <Library/PlatformInitLib.h>
#include <Library/CcProbeLib.h>
#include "AmdSev.h" #include "AmdSev.h"
#define SEC_IDT_ENTRY_COUNT 34 #define SEC_IDT_ENTRY_COUNT 34
@ -738,7 +739,7 @@ SecCoreStartupWithStack (
volatile UINT8 *Table; volatile UINT8 *Table;
#if defined (TDX_GUEST_SUPPORTED) #if defined (TDX_GUEST_SUPPORTED)
if (TdIsEnabled ()) { if (CcProbe () == CcGuestTypeIntelTdx) {
// //
// For Td guests, the memory map info is in TdHobLib. It should be processed // For Td guests, the memory map info is in TdHobLib. It should be processed
// first so that the memory is accepted. Otherwise access to the unaccepted // first so that the memory is accepted. Otherwise access to the unaccepted
@ -828,7 +829,7 @@ SecCoreStartupWithStack (
} }
#if defined (TDX_GUEST_SUPPORTED) #if defined (TDX_GUEST_SUPPORTED)
if (TdIsEnabled ()) { if (CcProbe () == CcGuestTypeIntelTdx) {
// //
// InitializeCpuExceptionHandlers () should be called in Td guests so that // InitializeCpuExceptionHandlers () should be called in Td guests so that
// #VE exceptions can be handled correctly. // #VE exceptions can be handled correctly.

View File

@ -54,6 +54,7 @@
LocalApicLib LocalApicLib
MemEncryptSevLib MemEncryptSevLib
CpuExceptionHandlerLib CpuExceptionHandlerLib
CcProbeLib
[Ppis] [Ppis]
gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED