From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.25369.1650164497717213024 for ; Sat, 16 Apr 2022 20:01:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=RAwSmnQW; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650164513; x=1681700513; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Euxa37q+3XHWOQ5cm2t+dHsuB5l7F6StZW78kCp+BFw=; b=RAwSmnQWA6DCA7P8T5sY9zeIeYNsI+pCB4x/tUeiEOba/HvUbn0FdGlw T0KMTTl92Yo7ixoz2NyF32JLr1OKbXmznseCTFN7xRTM0A6kD1bEfcFZa aiN12pRo2cJxHKe7iGKRknY6kCzPW8jKcHIpzlR9dbAXJaLtnGY5UdxwG O1bOVw9H9MPE+OBrBv81U5TOIFv725WFEG04zuvJvj1jVqsPROg+s0INy SAGISfuBf7tgneoWTzoYPKCbnkpjnWr2nqZcT5tbGeWVi6bF6rev2REps U6ixiAXTpqyuvmNkqi1u/Ci+sGxbXqfcDHOVzrzb7SAbOTueRKKAryT9J Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10318"; a="349806299" X-IronPort-AV: E=Sophos;i="5.90,266,1643702400"; d="scan'208";a="349806299" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2022 20:01:53 -0700 X-IronPort-AV: E=Sophos;i="5.90,266,1643702400"; d="scan'208";a="575044389" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.191]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2022 20:01:50 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , James Bottomley , Jiewen Yao , Gerd Hoffmann , Brijesh Singh , Erdem Aktas , Tom Lendacky Subject: [PATCH V3 7/7] OvmfPkg: Call CcProbe in SecMain.c instead of TsIsEnabled Date: Sun, 17 Apr 2022 11:01:13 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Brijesh Singh Cc: Erdem Aktas Cc: Tom Lendacky Signed-off-by: Min Xu --- OvmfPkg/IntelTdx/Sec/SecMain.c | 6 +++--- OvmfPkg/IntelTdx/Sec/SecMain.inf | 1 + OvmfPkg/Sec/SecMain.c | 5 +++-- OvmfPkg/Sec/SecMain.inf | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/IntelTdx/Sec/SecMain.c b/OvmfPkg/IntelTdx/Sec/SecMain.c index 26d56be335e1..160e56071103 100644 --- a/OvmfPkg/IntelTdx/Sec/SecMain.c +++ b/OvmfPkg/IntelTdx/Sec/SecMain.c @@ -25,7 +25,7 @@ #include #include #include - +#include #include #define SEC_IDT_ENTRY_COUNT 34 @@ -61,7 +61,7 @@ SecCoreStartupWithStack ( UINT32 Index; volatile UINT8 *Table; - if (TdIsEnabled ()) { + if (CcProbe () == CCGuestTypeIntelTdx) { // // 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 @@ -119,7 +119,7 @@ SecCoreStartupWithStack ( // AsmWriteIdtr (&IdtDescriptor); - if (TdIsEnabled ()) { + if (CcProbe () == CCGuestTypeIntelTdx) { // // InitializeCpuExceptionHandlers () should be called in Td guests so that // #VE exceptions can be handled correctly. diff --git a/OvmfPkg/IntelTdx/Sec/SecMain.inf b/OvmfPkg/IntelTdx/Sec/SecMain.inf index df2e749c3505..9cf1249d02e5 100644 --- a/OvmfPkg/IntelTdx/Sec/SecMain.inf +++ b/OvmfPkg/IntelTdx/Sec/SecMain.inf @@ -49,6 +49,7 @@ CpuExceptionHandlerLib PeilessStartupLib PlatformInitLib + CcProbeLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index ca9717a7b526..25da91b37577 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "AmdSev.h" #define SEC_IDT_ENTRY_COUNT 34 @@ -738,7 +739,7 @@ SecCoreStartupWithStack ( volatile UINT8 *Table; #if defined (TDX_GUEST_SUPPORTED) - if (TdIsEnabled ()) { + if (CcProbe () == CCGuestTypeIntelTdx) { // // 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 @@ -828,7 +829,7 @@ SecCoreStartupWithStack ( } #if defined (TDX_GUEST_SUPPORTED) - if (TdIsEnabled ()) { + if (CcProbe () == CCGuestTypeIntelTdx) { // // InitializeCpuExceptionHandlers () should be called in Td guests so that // #VE exceptions can be handled correctly. diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 4b5b089ccd69..27100595aeca 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -54,6 +54,7 @@ LocalApicLib MemEncryptSevLib CpuExceptionHandlerLib + CcProbeLib [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED -- 2.29.2.windows.2