From nobody Sun May 19 16:31:36 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+92815+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+92815+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661437530; cv=none; d=zohomail.com; s=zohoarc; b=K6+vQ/bikpHPkUckLO17qypfmfUb8jQhl+nAq/PqcTjhTxBKOnfjadNiLideXnYgMpWaE9gRFwkiolqwgl37qaT+5lru+ftjH5fbDDV7HZwEozySvD2FW1NTW17K0z4UDupXv5wbwWL6YNK1rj+CIuc9n9wz7SIYKBfPzbcwKb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661437530; 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=JuBAHaYAiwbA1lFcQp0g7iqSXiXGwaIQnKaBv8Po568=; b=C+/atbUgtHj+AS1Wmu7HEbCgLFDD+Hf1wh6J4qQCcptdxrGXTUBq/XOdOZr+sX49UQmc4Zpyt0vBCGREuDOmqJYuymLH8X/zfVHgk5lGPhuko1b4wKRbm9JUx3qlXPxU52VUVffhGtbvAwWsXo4RM1p29tNHIWMniUu8w1JW7vI= 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+92815+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 1661437530441836.2720663393432; Thu, 25 Aug 2022 07:25:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id oWNCYY1788612xDKzSPlXOtX; Thu, 25 Aug 2022 07:25:30 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.24626.1661437527602551781 for ; Thu, 25 Aug 2022 07:25:29 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="380542360" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="380542360" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:25:29 -0700 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="671004787" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.31.22]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:25:27 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [edk2-devel] [PATCH V3 1/2] OvmfPkg: Add SecPeiCcProbeLib Date: Thu, 25 Aug 2022 22:24:25 +0800 Message-Id: <0d7122ff72be071e9bf6ce4f4abc870a61ffd341.1661432416.git.min.m.xu@intel.com> 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: 0K6akCyZJZkYCtoRVTyHnOcVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661437530; bh=hUS7wzYZWPnNLH20oLixreugGmQxYh1kO7pdsK4TnZ4=; h=Cc:Date:From:Reply-To:Subject:To; b=ADe6kwa/9XOrukFk516GpAQ4ckGfX+TRepCA7MNwnO+4LttcTJYRL64NRuKGVwRCHnf 87BPyx9HR6uNuDFX94lBjnfvy0+hBER9cdCMsvFS3EJxolN8Q5EnlwyUEMg3x+09MVnQT zd0dCdwISbs6/0/p6eDszfweB6h8rLIySwo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661437531774100005 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 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 (#92815): https://edk2.groups.io/g/devel/message/92815 Mute This Topic: https://groups.io/mt/93249192/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 Sun May 19 16:31:36 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+92816+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+92816+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1661437532; cv=none; d=zohomail.com; s=zohoarc; b=n75jg0xdG9+wtIuLnjhINs8aqciiYSkwTVrIvne4wlMw18C0FjbahB6YrQez4dMry0RewMY0x63JFpp18FMPcihbCRA5erGrw4nBVxbho7BNpdYlWpdoiuKcIQBWodUuPAXNfnslXwCR0BhGTzg6wtS1MwErWa0czkHgAdhAWGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661437532; 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=0r0TAmLj7LyQ/jj095PraBlbo+o5i4Gyfw5Rc3IbBEM=; b=HtyyY0ye4qJZKAVOXIO00mmpwtrHVmD+1EvKtKR8tG8RnGD7xQr+fW9vZj2pQUpPHZqbIbd9gUPhSXyF7GYOOdGovGLdlTPmehtCQab3A/3C78STlZbIup/RNl+0sbEGvlauMjjL3M9Ia60mdQML9H+VgnAuLis5pN+le6+FtMY= 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+92816+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 1661437532097882.520026356049; Thu, 25 Aug 2022 07:25:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xw8KYY1788612xVU0UbpYkpC; Thu, 25 Aug 2022 07:25:31 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.24626.1661437527602551781 for ; Thu, 25 Aug 2022 07:25:31 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="380542373" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="380542373" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:25:30 -0700 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="671004823" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.31.22]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:25:29 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Gerd Hoffmann , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V3 2/2] OvmfPkg: Update CcProbeLib to DxeCcProbeLib Date: Thu, 25 Aug 2022 22:24:26 +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: W2MKq22S0MM5k1h6Nx36Pfw2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1661437531; bh=z/TdYAPIczH90O9jW6jPEB76XTMLN6uxeanDIDfY5JY=; h=Cc:Date:From:Reply-To:Subject:To; b=OG4CkAO99eG6f/ximRXUir172wQ0SRtnTPBg1Rm5bQ7+4HW7CpAqB10vizRWtNJBc4Q 0zJd5TyQoRCP51uL1524uERVSUj0BQ3u2euZOZ86SnjG3+Tn0bQuczvNabtXwX5YcXKQI /P+acNTt7dFLT/j7dTh3QdROXjVlKEWW7NA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1661437533819100011 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 - 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 first-call. 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 --- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 3 ++- .../CcProbeLib/{CcProbeLib.c =3D> DxeCcProbeLib.c} | 11 +++++++++-- .../CcProbeLib/{CcProbeLib.inf =3D> DxeCcProbeLib.inf} | 6 +++--- OvmfPkg/OvmfPkgX64.dsc | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) rename OvmfPkg/Library/CcProbeLib/{CcProbeLib.c =3D> DxeCcProbeLib.c} (55%) rename OvmfPkg/Library/CcProbeLib/{CcProbeLib.inf =3D> DxeCcProbeLib.inf} = (70%) diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 71b1cf8e7090..1a7ecd503e50 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -140,7 +140,7 @@ PciCapLib|OvmfPkg/Library/BasePciCapLib/BasePciCapLib.inf PciCapPciSegmentLib|OvmfPkg/Library/BasePciCapPciSegmentLib/BasePciCapPc= iSegmentLib.inf PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf - CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHo= okStatusCodeLibNull.inf SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf @@ -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/DxeCcProbeLib.c similarity index 55% rename from OvmfPkg/Library/CcProbeLib/CcProbeLib.c rename to OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c index d698e5c8d7f8..11b2eef390cf 100644 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.c +++ b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.c @@ -10,6 +10,9 @@ #include #include =20 +STATIC UINT8 mCcProbeGuestType =3D 0; +STATIC BOOLEAN mCcProbed =3D FALSE; + /** Probe the ConfidentialComputing Guest type. See defition of CC_GUEST_TYPE in . @@ -25,7 +28,11 @@ CcProbe ( { OVMF_WORK_AREA *WorkArea; =20 - WorkArea =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + if (!mCcProbed) { + WorkArea =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkArea= Base); + mCcProbeGuestType =3D WorkArea !=3D NULL ? WorkArea->Header.GuestType = : CcGuestTypeNonEncrypted; + mCcProbed =3D TRUE; + } =20 - return WorkArea !=3D NULL ? WorkArea->Header.GuestType : CcGuestTypeNonE= ncrypted; + return mCcProbeGuestType; } diff --git a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf b/OvmfPkg/Library/Cc= ProbeLib/DxeCcProbeLib.inf similarity index 70% rename from OvmfPkg/Library/CcProbeLib/CcProbeLib.inf rename to OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf index 5300c9ba2644..9bdba4312755 100644 --- a/OvmfPkg/Library/CcProbeLib/CcProbeLib.inf +++ b/OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf @@ -8,14 +8,14 @@ =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D CcProbeLib + BASE_NAME =3D DxeCcProbeLib 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 + DxeCcProbeLib.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 6e68f60dc90f..2741f4d988b7 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -199,7 +199,7 @@ =20 !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf - CcProbeLib|OvmfPkg/Library/CcProbeLib/CcProbeLib.inf + CcProbeLib|OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf !else CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf !endif @@ -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 (#92816): https://edk2.groups.io/g/devel/message/92816 Mute This Topic: https://groups.io/mt/93249194/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-