From nobody Fri May 17 07:47:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+91133+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91133+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1657174777; cv=none; d=zohomail.com; s=zohoarc; b=YjmXCzbcIf0GdculxFWWk1/pnsLL/ldMfo6pxur1Rqw7wA8330yR53s8D81EOQ4OX3MdDUkbtpyszexFy6yRSb2qaO12s35vjSMa8KVEEi0XVFkXZF9pqjTIEpeLnpKPd39oIxpdZCq+ZHqO0Zr04ebMhUDtDIih0cBv9Es4Qgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657174777; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=f5Po1Tucnl36dAX8/Ku0XruZNDf9fwFu0T5lzqVa1T4=; b=BB5PKxNnsBPKSeMlnHFh+FRfNcutpqoOUATF/Sn+pm//NCLF0QH5WKFKTNvfiDxZxOYT/VhmHmF1ebH15Lw57hYW3x4nv/W/qMZyrVETLaGAYv5UMAzMzIAY8OIPLnJpAvGIBEieAyvQjIHywrLjCNYwMJ9YDMWOP5z7fCwAh14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91133+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1657174777715340.7614401892556; Wed, 6 Jul 2022 23:19:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2JJxYY1788612xeAncgic1wD; Wed, 06 Jul 2022 23:19:37 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.2468.1657174776261985407 for ; Wed, 06 Jul 2022 23:19:36 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10400"; a="264358761" X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="264358761" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 23:19:11 -0700 X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="620653851" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.30.203]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 23:19:09 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky , Yuan Yu Subject: [edk2-devel] [PATCH 1/2] OvmfPkg: Add SecPeiCcProbeLib Date: Thu, 7 Jul 2022 14:17:45 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: 5wdLM1ZFCiksTvhVuydBqW5fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1657174777; bh=6DT+Wf5ir7Yivw7r2EySMcAhvj4zNUo+zbsVBfVsBaY=; h=Cc:Date:From:Reply-To:Subject:To; b=vRwv+jyR+GmUIf3oC2Vvdk6v5ixe99lzJED/pdVcl8MuIWNq559sQetbJqahxNSaxXT jzhvhBmDQCB/WBVuuRHXKp30bMhEwDqltwTZCccxY5wdkXZEczviMh3ZCXWyYB0abwnEx sXy9R3UH0cA0Y/z5HW+uJxk+I8zRMxORckI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1657174779803100005 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3974 SecPeiCcProbeLib is designed to probe the Confidential Computing guest type in SEC/PEI phase. The CC guest type was set by each CC guest at the beginning of boot up and saved in PcdOvmfWorkArea. Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Cc: Yuan Yu Signed-off-by: Min Xu --- OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.c | 31 +++++++++++++++++++ .../Library/CcProbeLib/SecPeiCcProbeLib.inf | 25 +++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.c create mode 100644 OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf diff --git a/OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.c b/OvmfPkg/Librar= y/CcProbeLib/SecPeiCcProbeLib.c new file mode 100644 index 000000000000..d698e5c8d7f8 --- /dev/null +++ b/OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.c @@ -0,0 +1,31 @@ +/** @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 =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + + return WorkArea !=3D NULL ? WorkArea->Header.GuestType : CcGuestTypeNonE= ncrypted; +} diff --git a/OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf b/OvmfPkg/Libr= ary/CcProbeLib/SecPeiCcProbeLib.inf new file mode 100644 index 000000000000..f63ed71e7c28 --- /dev/null +++ b/OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf @@ -0,0 +1,25 @@ +## @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 =3D 0x00010005 + BASE_NAME =3D SecPeiCcProbeLib + FILE_GUID =3D 78eb7f2a-a42a-4b01-b160-5a05a0a52bac + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D CcProbeLib|SEC PEIM PEI_CORE + +[Sources] + SecPeiCcProbeLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91133): https://edk2.groups.io/g/devel/message/91133 Mute This Topic: https://groups.io/mt/92223434/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 07:47:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+91134+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91134+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1657174778; cv=none; d=zohomail.com; s=zohoarc; b=TZtuna/HiphjNx4xfSzspSTwI+Gs+IYIFtQzz4ftdd+SiVQ8fVVYaV8MzxA5rlXmy6tXNHNO9bVm26DoIT4KkhGkVFJhpxlYbEYFIMWF3lRTf7TP2DOluBbzCEdfZqZ2HA0TGE/nmWbg3q5wNM6e6dYA8UJc9JeIMVqdd//k7cI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657174778; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=n/COHPnCdkJexxjNIKEZdsPuVzyUlCsK01npyBWYefE=; b=AGQNP6rQZR/T5H32uvQYIwXwhAE33tA4SMtDEpmD3fKqLI0Dx8Vy5i4VCfEyazeuBzPZZ8crOx9ekc3TKchDpWB8a7NgE53eOX8D44Rp2j37dn9/XVM9up/TgfD/JRjoKAUOWI/wBqY0gDs4g9mzVXKKvYJdEbNtwxFf2AufTr4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91134+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16571747788161007.7313971979547; Wed, 6 Jul 2022 23:19:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OXDmYY1788612xuOYHQLqHTR; Wed, 06 Jul 2022 23:19:37 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.2468.1657174776261985407 for ; Wed, 06 Jul 2022 23:19:37 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10400"; a="264358773" X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="264358773" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 23:19:14 -0700 X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="620653873" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.30.203]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 23:19:12 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Gerd Hoffmann , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Yuan Yu Subject: [edk2-devel] [PATCH 2/2] OvmfPkg: Update CcProbeLib Date: Thu, 7 Jul 2022 14:17:46 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: sGrDQhj4tFSQsofj6iymetkIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1657174777; bh=5B441tLINk5YKaiYvCuqx0/RZ7QCTFRUJ3tTUaxl2pY=; h=Cc:Date:From:Reply-To:Subject:To; b=xGm5tPcZLnpEdxX4BM3E0RwN5EhD5XYBGWrKXeiyNLr+mOnxa+8umej6WiHeLN4gO1N LQ+FBF5zO6bKdSaaT7w/irwP7zU9rsEv2b4SU5HYBaUXbFXyMbox5BNuPv7LNZAaHjGgh /I1YeNo6UPDQWRWyFZAT3YgJattNWqRW97A= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1657174779814100006 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3974 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 - CcProbeLib In SecPeiCcProbeLib we still 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 CcProbeLib we call TdIsEnabled() to check if it is of Tdx guest. To improve the efficiency the result is cached in a global variable. In current stage only the Tdx related code is added in CcProbeLib. SEV code may be added in the future. 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 Cc: Yuan Yu Signed-off-by: Min Xu --- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/Library/CcProbeLib/CcProbeLib.c | 24 +++++++++++++++++++---- OvmfPkg/Library/CcProbeLib/CcProbeLib.inf | 5 +---- OvmfPkg/OvmfPkgX64.dsc | 3 +++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 144d50aa9dba..ca41d9d13e7a 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -234,6 +234,7 @@ HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf PeilessStartupLib|OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf diff --git a/OvmfPkg/Library/CcProbeLib/CcProbeLib.c b/OvmfPkg/Library/CcPr= obeLib/CcProbeLib.c index d698e5c8d7f8..efb929ef8b21 100644 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.c +++ b/OvmfPkg/Library/CcProbeLib/CcProbeLib.c @@ -7,8 +7,12 @@ =20 **/ =20 +#include +#include #include -#include + +STATIC UINT8 CcProbeGuestType =3D 0; +STATIC BOOLEAN CcProbed =3D FALSE; =20 /** Probe the ConfidentialComputing Guest type. See defition of @@ -23,9 +27,21 @@ CcProbe ( VOID ) { - OVMF_WORK_AREA *WorkArea; + if (CcProbed) { + return CcProbeGuestType; + } =20 - WorkArea =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + if (TdIsEnabled ()) { + CcProbeGuestType =3D CcGuestTypeIntelTdx; + } else { + // + // SEV code should be added here to determine if it is CcGuestTypeAmdS= ev. + // Now we set CcProbeGuestType to CcGuestTypeNonEncrypted. + // + CcProbeGuestType =3D CcGuestTypeNonEncrypted; + } =20 - return WorkArea !=3D NULL ? WorkArea->Header.GuestType : CcGuestTypeNonE= ncrypted; + CcProbed =3D TRUE; + + return CcProbeGuestType; } diff --git a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf b/OvmfPkg/Library/Cc= ProbeLib/CcProbeLib.inf index 5300c9ba2644..99b7434d6180 100644 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf +++ b/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf @@ -12,7 +12,7 @@ FILE_GUID =3D 05184ec9-abb0-4491-8584-e388639a7c48 MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D CcProbeLib + LIBRARY_CLASS =3D CcProbeLib|DXE_CORE DXE_DRIVER DXE_RU= NTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION =20 [Sources] CcProbeLib.c @@ -20,6 +20,3 @@ [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec - -[Pcd] - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 8ad04b50f74f..59d47ae272bb 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -287,6 +287,7 @@ !endif VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLi= b.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -303,6 +304,7 @@ DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.i= nf !endif PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf =20 [LibraryClasses.common.PEIM] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf @@ -332,6 +334,7 @@ PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf =20 MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91134): https://edk2.groups.io/g/devel/message/91134 Mute This Topic: https://groups.io/mt/92223435/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-