From nobody Mon Apr 29 02:30:53 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+97619+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+97619+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525779; cv=none; d=zohomail.com; s=zohoarc; b=GmUtCLPdm46aPgU9+9dWmZqmGXm/mxCgoQqr2k+M06/lfvnUh5qZArl+A6tqbZnwMnDy/to1lR2+jP21CCwBi1lKTvfCfmp+F/4YG2NQ7MqTqBPA7ZnmJOU9GVizZvV6dDYhEUm/50098qxqZ7cfr1rQNROuXvZhkG5gb80BW2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525779; 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=KwVRYGS8vMcl0M/5BXjzEk7TjMvL1YR/Q8wQbQoIo2A=; b=V774s+bYKWIupKO8o9ojp13X6hE/KOWOGU5MNHbD4PxNxs6wInO1Y7ncbcucLcOr7wL4Sb3Ra5fbl5kBIccfBcQMYWqijUAO0d+uszVnACTFUIQl5CLh49esHpw4ftPwIjIdOwPYZsnZda1WZtADSC6LEdIO+DJuEXAizlGLUSI= 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+97619+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 1671525779603960.0392953109856; Tue, 20 Dec 2022 00:42:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id VTQmYY1788612xTph422IKJG; Tue, 20 Dec 2022 00:42:59 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46058.1671525777169185136 for ; Tue, 20 Dec 2022 00:42:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908214" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="383908214" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:42:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644646" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644646" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:42:56 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 1/6] OvmfPkg/TdxMailboxLib: Delete global variables Date: Tue, 20 Dec 2022 16:42:35 +0800 Message-Id: <20221220084240.1922-2-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: EJQvwx3bCxFLOcbn2mig6Obax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525779; bh=x7bj3ujWk2FmkCS75GyoL7MmXTkwTQKaMfy7qJGCO2c=; h=Cc:Date:From:Reply-To:Subject:To; b=rU+8/5YemaNKy4Bs3lDjvE2XW696gzHoPjQpDGbCs8RJe/zuBxAzId3zqCF8WiX6ZsT Mge6++Z5RAkPqaYKUiuCpXcM2pNs9uyqkbhz+wLjLLu6G21ez6mKNwouyCzd0Ye7VX4Bq 1JqAd1GYzO5QvqW/i3Lq+mjrjD5mJhEU1Y0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525780767100002 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 TdxMailboxLib once was designed to be used in DXE phase. But now it is going to be used in SEC/PEI phase (in the following patches). Global variables are not allowed. The library is refactored after those global variables are deleted. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c b/OvmfPkg/Library/T= dxMailboxLib/TdxMailbox.c index 74cb55611fe3..c580a2885603 100644 --- a/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c +++ b/OvmfPkg/Library/TdxMailboxLib/TdxMailbox.c @@ -13,14 +13,10 @@ #include #include #include -#include #include #include #include =20 -volatile VOID *mMailBox =3D NULL; -UINT32 mNumOfCpus =3D 0; - /** This function will be called by BSP to get the CPU number. =20 @@ -32,11 +28,17 @@ GetCpusNum ( VOID ) { - if (mNumOfCpus =3D=3D 0) { - mNumOfCpus =3D TdVCpuNum (); + UINT64 Status; + TD_RETURN_DATA TdReturnData; + + Status =3D TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData); + if (Status =3D=3D TDX_EXIT_REASON_SUCCESS) { + return TdReturnData.TdInfo.NumVcpus; + } else { + DEBUG ((DEBUG_ERROR, "Failed call TDCALL_TDINFO. %llx\n", Status)); } =20 - return mNumOfCpus; + return 0; } =20 /** @@ -48,11 +50,7 @@ GetTdxMailBox ( VOID ) { - if (mMailBox =3D=3D NULL) { - mMailBox =3D (VOID *)(UINTN)PcdGet32 (PcdOvmfSecGhcbBackupBase); - } - - return mMailBox; + return (VOID *)(UINTN)PcdGet32 (PcdOvmfSecGhcbBackupBase); } =20 /** --=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 (#97619): https://edk2.groups.io/g/devel/message/97619 Mute This Topic: https://groups.io/mt/95782427/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 Mon Apr 29 02:30:53 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+97620+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+97620+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525781; cv=none; d=zohomail.com; s=zohoarc; b=Nx3DZGXRWzNSXaWnDL99auIC7XzTu+B1pCvzDAfM1aCMEUyo8+EyPDnVPW9QZqnejmjDE0e8zDW7wueLJaiy9qyoqVRwMduwlODDAeqSbGz7JZOl0hkY0R5T6eSlcgX8TqmYUdRen/15CVdNVnkBq63gYgJPVa4dbs0Axp64Dh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525781; 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=jyyVh5aUUpddmAxxbxywhVPqi0hOBHGjLaECNQchpeY=; b=esnDneTBEDXTR7HHjpFTfqAf7prTfJ7tS5MP3LWXKMyaAsDbjjwCjFwELbLXEp+EFGKe9IDZMO3YH9v02XMxJq7fnvkvGVkCNSo4k6HhEmFejvNuJfEq7ekjqTLqJSz56vK06opjmkd0q89z7zlXao2Y15rTWcp3ucl0hXpeMgw= 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+97620+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 1671525781954139.90404285528336; Tue, 20 Dec 2022 00:43:01 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id FgcHYY1788612x0j2U2Ztzxm; Tue, 20 Dec 2022 00:43:01 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46058.1671525777169185136 for ; Tue, 20 Dec 2022 00:43:01 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908249" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="383908249" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:00 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644649" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644649" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:42:58 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 2/6] OvmfPkg/TdxMailboxLib: Add NULL instance of TdxMailboxLib Date: Tue, 20 Dec 2022 16:42:36 +0800 Message-Id: <20221220084240.1922-3-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: UcmNRZmUsyZHsAdinVTgxV8Gx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525781; bh=qxbuTYqMrwXpMZC8awYYIGdwXgLH2lIDWLw9LE6MH8k=; h=Cc:Date:From:Reply-To:Subject:To; b=LbDoyudc27cD2AYnSEUf1xYinVsp7W2cziyceWxqHTGJGz+lyXVkm2zBthZwv7OQTRq V7AAUIKWxD2JYy1k0bb06nVLWU3Xs2zYeGXc3NP8Py4F98XEw34KOUYpOGYfmQOlrXUzg F/E66xHqzq/FbVBNOMC9HNsCpbu1LumSujU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525782619100009 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 TdxMailboxLib is designed only for TDX guest which arch is X64. This patch set the VALID_ARCHITECTURES of TdxMailboxLib as X64. Because in the following patches TdxMailboxLib will be included in PlatformInitLib. While PlatformInitLib is imported by some X64 platforms (for example AmdSevX64.dsc). So we need a NULL instance of TdxMailboxLib which VALID_ARCHITECTURES is X64 as well. Based on this consideration we design TdxMailboxLibNull. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- .../Library/TdxMailboxLib/TdxMailboxLib.inf | 7 ++-- .../TdxMailboxLib/TdxMailboxLibNull.inf | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf diff --git a/OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf b/OvmfPkg/Libr= ary/TdxMailboxLib/TdxMailboxLib.inf index 3cf3690a16c7..e504bda0dd90 100644 --- a/OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf +++ b/OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf @@ -1,6 +1,6 @@ #/** @file # -# TBD +# TdxMailbox Library # # Copyright (c) 2018, Intel Corporation. All rights reserved.
# Copyright (c) 2008, Apple Inc. All rights reserved.
@@ -19,12 +19,9 @@ LIBRARY_CLASS =3D TdxMailboxLib =20 # -# VALID_ARCHITECTURES =3D X64 IA32 +# VALID_ARCHITECTURES =3D X64 # =20 -[Sources.IA32] - TdxMailboxNull.c - [Sources.X64] TdxMailbox.c =20 diff --git a/OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf b/OvmfPkg/= Library/TdxMailboxLib/TdxMailboxLibNull.inf new file mode 100644 index 000000000000..8380d9f4f6d8 --- /dev/null +++ b/OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf @@ -0,0 +1,34 @@ +#/** @file +# +# Null instance of TdxMailboxLib +# +# Copyright (c) 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2008, Apple Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +#**/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D TdxMailboxLibNull + FILE_GUID =3D 002a1265-a1a0-47cd-bc69-4342b147f57d + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TdxMailboxLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + TdxMailboxNull.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib --=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 (#97620): https://edk2.groups.io/g/devel/message/97620 Mute This Topic: https://groups.io/mt/95782428/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 Mon Apr 29 02:30:53 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+97621+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+97621+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525784; cv=none; d=zohomail.com; s=zohoarc; b=OHh0flKIzxnNhKb0JlWOfC6h/Tato+SJafmJycLG3hQyDcvWDWcqmKS2mkFyhdXrOZql592vvq9ieG++3TY66QwE6h3O6nIZxF/7jyKQZ2sfOgAD99nCnx3KpC4tUL+5QPycMSAeGZfP6WJdDRNbwwSl1M1v+xZ0kk2pbGtkPJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525784; 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=CversB1uOWhmgAQfJeOZH59o/pKRvgoj9vi9Eax3se4=; b=Uh9FPaEBPv7L1IUFjGEsZSsve1A75lW2UdMjjfYPPo6kqCWRj76pNZW/AdSTqlnPFDZ0IZ4U3u+x4cVua/GHHPpUFL54Qnq5pDl5Hq/WCQkErF95sf3dMln7PrKd//x1zEe6GLUm3tgzlf3yFHsDr+g/mPvtsyXWqFeMZEoQa9I= 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+97621+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 1671525784144972.7495885217634; Tue, 20 Dec 2022 00:43:04 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id TBUtYY1788612xK8SFrMMaVq; Tue, 20 Dec 2022 00:43:03 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46058.1671525777169185136 for ; Tue, 20 Dec 2022 00:43:03 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908272" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="383908272" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:02 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644653" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644653" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:00 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 3/6] OvmfPkg: Add TdxMailboxLibNull in some platform dsc Date: Tue, 20 Dec 2022 16:42:37 +0800 Message-Id: <20221220084240.1922-4-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: KAAjbSOAAum42Sg8Aotx9mS3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525783; bh=jyJYPn5wmBql51/81gj91WZZd4pB06GPpSsOFZ8PeJQ=; h=Cc:Date:From:Reply-To:Subject:To; b=Y5ldLqTeA3Ve7yN8DJvKUsfMwwWSCdYo15VkSGp5ggYNKRoUwbdrYZKCY7P6dKftxgq UZ0AyEiRZZThhOLc3GtyXEwD6ZCVUjleDrTerrLLDn3QPaVXe1Nkmse3YBX4UYp0BEG/u zvUB6Cz6+DRdb51CQp9wLAgpZ9mZ+8gdSzU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525784630100014 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 In the following patches TdxMailboxLib will be included in PlatformInitLib. While PlatformInitLib is imported by some IA32/X64 platforms (for example AmdSevX64.dsc). So TdxMailboxLibNull is added in those platforms which don't support TDX feature. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index d51c913a0890..ece4cfa89a86 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -206,6 +206,7 @@ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf TdxLib|MdePkg/Library/TdxLib/TdxLib.inf + TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 4fe7cb5f1b68..6d76e524167e 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -253,6 +253,7 @@ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf TdxLib|MdePkg/Library/TdxLib/TdxLib.inf + TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index bcca3afbf666..47df222cf6e7 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -255,6 +255,7 @@ FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf TdxLib|MdePkg/Library/TdxLib/TdxLib.inf + TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf =20 [LibraryClasses.common.SEC] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index dcf46d207d3d..f617aa60ca43 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -257,6 +257,7 @@ [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index bc0036eda0d3..49c71cd00f35 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -262,7 +262,7 @@ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf TdxLib|MdePkg/Library/TdxLib/TdxLib.inf - TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf + TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.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 (#97621): https://edk2.groups.io/g/devel/message/97621 Mute This Topic: https://groups.io/mt/95782429/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 Mon Apr 29 02:30:53 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+97622+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+97622+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525786; cv=none; d=zohomail.com; s=zohoarc; b=FbCAXlQCnQ9flxKbDr3gNh73F/QtbT3iK9n+vY/6kmkrATAEmiBPlB6yDpqN1nEkEk+MTFYXAMY1E1FzLkqtyOfpXscqLiuzjpCedzfp9eiX6DYQSW5u+RPjR50ltfFCsjwmT+WCj4wgc6QSyihOy1eCx51MfPYnB2JhvU2zfFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525786; 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=1M/kpxqRQZOZ9nSsj20zmnFEvb+f0FlPTSyJQMqOXnU=; b=TFGq4BMG/J3BP7o2UdYRooWCbujvWtbJW0Hj1ndc76kO5rd5p2vxtrMeEGoFyE3Mt+OIEWZ/BJNbbRvkKqQBDAbVe+io0j/CZw6oHpoDZFp1Y4FrJzo1cwlaE2eRs2KPydyyAN3y1ju/0UgFC9QcfMCO7mQ/qTysCQ3WaqATwqc= 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+97622+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 1671525786870263.7653006292958; Tue, 20 Dec 2022 00:43:06 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id mQ8aYY1788612xwvrA38gzTm; Tue, 20 Dec 2022 00:43:06 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46058.1671525777169185136 for ; Tue, 20 Dec 2022 00:43:05 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908291" X-IronPort-AV: E=Sophos;i="5.96,258,1665471600"; d="scan'208";a="383908291" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:05 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644656" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644656" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:02 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 4/6] OvmfPkg/Sec: Move TDX APs related nasm code to IntelTdxAPs.nasm Date: Tue, 20 Dec 2022 16:42:38 +0800 Message-Id: <20221220084240.1922-5-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: EJXF8lxmzLwrBxeBBRSoGgsPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525786; bh=iMHBsX5521gZslHYo+5wK1t9fhTXCTkYm2qCquPOmPk=; h=Cc:Date:From:Reply-To:Subject:To; b=A2JNu/OF9qcitKLeOSGoM4gTiu/vdA3WVDKnHE8004urBmG2wKjtlueHUOS1rccryKw xHYVG0uWjOfjeVIQuYS0uXmQRbVGiJdjoTItPx+bt2SiWstdAu+L1XtnH2Tp94ZxTvzgP yjTaQw+8NuD+GFHgRLA8B7X05lWQJag3xKs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525788640100001 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 This patch moves the TDX APs nasm code from SecEntry.nasm to IntelTdxAPs.nasm. IntelTdxX64 and OvmfPkgX64 use the same nasm so that it can be easier to be managed. In the following patch there will be AcceptMemory related changes in IntelTdxAPs.nasm. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm | 58 +++++++++++++++++++++++ OvmfPkg/IntelTdx/Sec/X64/SecEntry.nasm | 58 ++--------------------- OvmfPkg/Sec/X64/SecEntry.nasm | 58 ++--------------------- 3 files changed, 68 insertions(+), 106 deletions(-) create mode 100644 OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm diff --git a/OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm b/OvmfPkg/IntelTdx/S= ec/X64/IntelTdxAPs.nasm new file mode 100644 index 000000000000..034ac0ee9421 --- /dev/null +++ b/OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm @@ -0,0 +1,58 @@ +;-------------------------------------------------------------------------= ----- +; @file +; Intel TDX APs +; +; Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + +%include "TdxCommondefs.inc" + + ; + ; Note: BSP never gets here. APs will be unblocked by DXE + ; + ; R8 [31:0] NUM_VCPUS + ; [63:32] MAX_VCPUS + ; R9 [31:0] VCPU_INDEX + ; +ParkAp: + +do_wait_loop: + ; + ; register itself in [rsp + CpuArrivalOffset] + ; + mov rax, 1 + lock xadd dword [rsp + CpuArrivalOffset], eax + inc eax + +.check_arrival_cnt: + cmp eax, r8d + je .check_command + mov eax, dword[rsp + CpuArrivalOffset] + jmp .check_arrival_cnt + +.check_command: + mov eax, dword[rsp + CommandOffset] + cmp eax, MpProtectedModeWakeupCommandNoop + je .check_command + + cmp eax, MpProtectedModeWakeupCommandWakeup + je .do_wakeup + + ; Don't support this command, so ignore + jmp .check_command + +.do_wakeup: + ; + ; BSP sets these variables before unblocking APs + ; RAX: WakeupVectorOffset + ; RBX: Relocated mailbox address + ; RBP: vCpuId + ; + mov rax, 0 + mov eax, dword[rsp + WakeupVectorOffset] + mov rbx, [rsp + WakeupArgsRelocatedMailBox] + nop + jmp rax + jmp $ diff --git a/OvmfPkg/IntelTdx/Sec/X64/SecEntry.nasm b/OvmfPkg/IntelTdx/Sec/= X64/SecEntry.nasm index 4528fec309a0..5a38c4213916 100644 --- a/OvmfPkg/IntelTdx/Sec/X64/SecEntry.nasm +++ b/OvmfPkg/IntelTdx/Sec/X64/SecEntry.nasm @@ -10,7 +10,6 @@ ;-------------------------------------------------------------------------= ----- =20 #include -%include "TdxCommondefs.inc" =20 DEFAULT REL SECTION .text @@ -49,6 +48,7 @@ ASM_PFX(_ModuleEntryPoint): cmp byte[eax], VM_GUEST_TYPE_TDX jne InitStack =20 + %define TDCALL_TDINFO 1 mov rax, TDCALL_TDINFO tdcall =20 @@ -62,7 +62,9 @@ ASM_PFX(_ModuleEntryPoint): mov rax, r9 and rax, 0xffff test rax, rax - jne ParkAp + jz InitStack + mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase) + jmp ParkAp =20 InitStack: =20 @@ -98,54 +100,4 @@ InitStack: sub rsp, 0x20 call ASM_PFX(SecCoreStartupWithStack) =20 - ; - ; Note: BSP never gets here. APs will be unblocked by DXE - ; - ; R8 [31:0] NUM_VCPUS - ; [63:32] MAX_VCPUS - ; R9 [31:0] VCPU_INDEX - ; -ParkAp: - - mov rbp, r9 - -.do_wait_loop: - mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase) - - ; - ; register itself in [rsp + CpuArrivalOffset] - ; - mov rax, 1 - lock xadd dword [rsp + CpuArrivalOffset], eax - inc eax - -.check_arrival_cnt: - cmp eax, r8d - je .check_command - mov eax, dword[rsp + CpuArrivalOffset] - jmp .check_arrival_cnt - -.check_command: - mov eax, dword[rsp + CommandOffset] - cmp eax, MpProtectedModeWakeupCommandNoop - je .check_command - - cmp eax, MpProtectedModeWakeupCommandWakeup - je .do_wakeup - - ; Don't support this command, so ignore - jmp .check_command - -.do_wakeup: - ; - ; BSP sets these variables before unblocking APs - ; RAX: WakeupVectorOffset - ; RBX: Relocated mailbox address - ; RBP: vCpuId - ; - mov rax, 0 - mov eax, dword[rsp + WakeupVectorOffset] - mov rbx, [rsp + WakeupArgsRelocatedMailBox] - nop - jmp rax - jmp $ +%include "IntelTdxAPs.nasm" diff --git a/OvmfPkg/Sec/X64/SecEntry.nasm b/OvmfPkg/Sec/X64/SecEntry.nasm index 4528fec309a0..0f82051720da 100644 --- a/OvmfPkg/Sec/X64/SecEntry.nasm +++ b/OvmfPkg/Sec/X64/SecEntry.nasm @@ -10,7 +10,6 @@ ;-------------------------------------------------------------------------= ----- =20 #include -%include "TdxCommondefs.inc" =20 DEFAULT REL SECTION .text @@ -49,6 +48,7 @@ ASM_PFX(_ModuleEntryPoint): cmp byte[eax], VM_GUEST_TYPE_TDX jne InitStack =20 + %define TDCALL_TDINFO 1 mov rax, TDCALL_TDINFO tdcall =20 @@ -62,7 +62,9 @@ ASM_PFX(_ModuleEntryPoint): mov rax, r9 and rax, 0xffff test rax, rax - jne ParkAp + jz InitStack + mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase) + jmp ParkAp =20 InitStack: =20 @@ -98,54 +100,4 @@ InitStack: sub rsp, 0x20 call ASM_PFX(SecCoreStartupWithStack) =20 - ; - ; Note: BSP never gets here. APs will be unblocked by DXE - ; - ; R8 [31:0] NUM_VCPUS - ; [63:32] MAX_VCPUS - ; R9 [31:0] VCPU_INDEX - ; -ParkAp: - - mov rbp, r9 - -.do_wait_loop: - mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase) - - ; - ; register itself in [rsp + CpuArrivalOffset] - ; - mov rax, 1 - lock xadd dword [rsp + CpuArrivalOffset], eax - inc eax - -.check_arrival_cnt: - cmp eax, r8d - je .check_command - mov eax, dword[rsp + CpuArrivalOffset] - jmp .check_arrival_cnt - -.check_command: - mov eax, dword[rsp + CommandOffset] - cmp eax, MpProtectedModeWakeupCommandNoop - je .check_command - - cmp eax, MpProtectedModeWakeupCommandWakeup - je .do_wakeup - - ; Don't support this command, so ignore - jmp .check_command - -.do_wakeup: - ; - ; BSP sets these variables before unblocking APs - ; RAX: WakeupVectorOffset - ; RBX: Relocated mailbox address - ; RBP: vCpuId - ; - mov rax, 0 - mov eax, dword[rsp + WakeupVectorOffset] - mov rbx, [rsp + WakeupArgsRelocatedMailBox] - nop - jmp rax - jmp $ +%include "../../IntelTdx/Sec/X64/IntelTdxAPs.nasm" --=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 (#97622): https://edk2.groups.io/g/devel/message/97622 Mute This Topic: https://groups.io/mt/95782430/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 Mon Apr 29 02:30:53 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+97623+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+97623+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525817; cv=none; d=zohomail.com; s=zohoarc; b=jML6ZFlE7FW0l0A1+VRYdSBN35kXSxU6EhJ6afclJTgyuNxUmXWX4MNPjJvBAzuJ1BzovJDOtGxk5t4UMkXHfox7HQmT+U+akfVl0f5UjYI2JUz36IXH69/nmrPCDIbclpXcnRtqdpz3c8HjY2SNNZ8LyjhW8cxriAZ8ZeXO6A8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525817; 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=ZpnAptUQeUt4F5xjS1J51Di563zVxO/DpzCqboqm3Ko=; b=lccO5pEx2vepx27kkhmTu3G8FXV9RvTWfb8M/8y/lDQhmvi9ImGXlHmqCjPqMKbAzlxrdkyr/7IGpj2VGfVK+fajBhCRIUK32TlcSw1EFPipzKbmblVu3UGENauX5XyYm3Ri3nofkWwPbG9sHL9VMbv0Y/Soox/dmPkeC/DLKu0= 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+97623+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 1671525817112705.3298687277155; Tue, 20 Dec 2022 00:43:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id zygPYY1788612xqUnkhQvOmd; Tue, 20 Dec 2022 00:43:36 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46066.1671525816147549841 for ; Tue, 20 Dec 2022 00:43:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908312" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="383908312" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:07 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644659" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644659" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:04 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 5/6] OvmfPkg: Enable APs to accept memory for TDVF Date: Tue, 20 Dec 2022 16:42:39 +0800 Message-Id: <20221220084240.1922-6-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: B5YretK97iqu7KQLk9yhJpF8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525816; bh=eAfvdP0YZtXZj/NGFmgFc6y2sCmUNpPt1tDgtZFf2ZQ=; h=Cc:Date:From:Reply-To:Subject:To; b=aZGcA/VbpHqexWpb++IgzM9wWomP4Ft1JiHjFIVL0AJZ7vfGSSpGTwMVGaLz17cDJyf /j1/3ew6sn1Z3kziYTGEWBWOJqBNK5K69wnauiCFqquVtoybVk3S6payzDoIpkJNtlEVF cYVXWGMUFLLTnEi1JX7uJme9rgdV1pZXtno= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525818940100001 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 TDVF APs once did nothing but spin around to wait for the Wakeup command. This patch enables APs to handle the AcceptPages command. Once APs find the AcceptPages command, it set its stack and jump to the function of ApAcceptMemoryResourceRange (which will be introduced in the following patch). Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- OvmfPkg/Include/TdxCommondefs.inc | 4 +- OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm | 61 +++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Include/TdxCommondefs.inc b/OvmfPkg/Include/TdxCommond= efs.inc index 970eac96592a..a29d2fad4233 100644 --- a/OvmfPkg/Include/TdxCommondefs.inc +++ b/OvmfPkg/Include/TdxCommondefs.inc @@ -15,8 +15,8 @@ FirmwareArgsOffset equ 800h WakeupArgsRelocatedMailBox equ 800h AcceptPageArgsPhysicalStart equ 800h AcceptPageArgsPhysicalEnd equ 808h -AcceptPageArgsChunkSize equ 810h -AcceptPageArgsPageSize equ 818h +AcceptPageArgsTopStackAddress equ 810h +AcceptPageArgsApStackSize equ 818h CpuArrivalOffset equ 900h CpusExitingOffset equ 0a00h TalliesOffset equ 0a08h diff --git a/OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm b/OvmfPkg/IntelTdx/S= ec/X64/IntelTdxAPs.nasm index 034ac0ee9421..4a984ecc1058 100644 --- a/OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm +++ b/OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm @@ -40,9 +40,70 @@ do_wait_loop: cmp eax, MpProtectedModeWakeupCommandWakeup je .do_wakeup =20 + cmp eax, MpProtectedModeWakeupCommandAcceptPages + je .do_accept_pages + ; Don't support this command, so ignore jmp .check_command =20 +.do_accept_pages: + ; + ; Read the top stack address from arguments + mov rsi, [rsp + AcceptPageArgsTopStackAddress] + + ; + ; Calculate the top stack address of the AP. + ; ApStackAddr =3D BaseStackAddr + (vCpuIndex) * ApStackSize + xor rdx, rdx + xor rbx, rbx + xor rax, rax + mov eax, [rsp + AcceptPageArgsApStackSize] + mov ebx, r9d ; vCpuIndex + mul ebx + add rsi, rax ; now rsi is ApStackAddr + +.start_accept_pages: + ; + ; Read the function address which will be called + mov rax, [rsp + WakeupVectorOffset] + + ; + ; vCPU index as the first argument + mov ecx, r9d + mov rdx, [rsp + AcceptPageArgsPhysicalStart] + mov r8, [rsp + AcceptPageArgsPhysicalEnd] + + ; save the Mailbox address to rbx + mov rbx, rsp + + ; + ; set AP Stack + mov rsp, rsi + nop + + ; save rax (the Mailbox address) + push rbx + + call rax + + ; recove rsp + pop rbx + mov rsp, rbx + ; + ; recover r8, r9 + mov rax, 1 + tdcall + + mov eax, 0FFFFFFFFh + lock xadd dword [rsp + CpusExitingOffset], eax + dec eax + +.check_exiting_cnt: + cmp eax, 0 + je do_wait_loop + mov eax, dword[rsp + CpusExitingOffset] + jmp .check_exiting_cnt + .do_wakeup: ; ; BSP sets these variables before unblocking APs --=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 (#97623): https://edk2.groups.io/g/devel/message/97623 Mute This Topic: https://groups.io/mt/95782437/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 Mon Apr 29 02:30:53 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+97624+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+97624+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671525817; cv=none; d=zohomail.com; s=zohoarc; b=L6UhkYovdbhHWP1pvczxU5dpaeBlbANCtMKBl3KIztUrbJWJ2IFiaBQR1nZfBHjsnCCLjCpA+TN/lZMAUryQDJfvc1tKhth54CsPqHARDiateH93AUHeuDTp8MTbhIOHY9VMIw5g/iAUK9yEW1VibljtOiyE3QT3sDNQadMNl8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671525817; 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=JFuGOYRlu1S+tDp15VNPDF//GesnuC47ERdJSCAbIVY=; b=Csvo1C0waQdWUBrbWzKy9ax0OqB3g+BswLT0CLZaypDSIoq9IEp7IpL4WZUK91Mk2Z7FcJCn82NC5QoP+DCt+Nl59s7WJRMdMEdE2m2JBKD02tFh8uPmYR5rMIawwg9TJIisCzT6Nv7xUpb9CqbwC5ny7ce1kySfbnBrHmIvE3w= 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+97624+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 1671525817544234.80373404061504; Tue, 20 Dec 2022 00:43:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XUHZYY1788612xWdUW5BpZ1U; Tue, 20 Dec 2022 00:43:37 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.46066.1671525816147549841 for ; Tue, 20 Dec 2022 00:43:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="383908321" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="383908321" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10566"; a="628644663" X-IronPort-AV: E=Sophos;i="5.96,259,1665471600"; d="scan'208";a="628644663" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.12]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2022 00:43:06 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V2 6/6] OvmfPkg/PlatformInitLib: Implement multi-core accept memory for TDVF Date: Tue, 20 Dec 2022 16:42:40 +0800 Message-Id: <20221220084240.1922-7-min.m.xu@intel.com> In-Reply-To: <20221220084240.1922-1-min.m.xu@intel.com> References: <20221220084240.1922-1-min.m.xu@intel.com> 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: dP2oGpGmK8mnzsrabsk0wWUfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671525817; bh=rf4rBEHyGY/efyoYLYk4g2lQpYmBkfoOxKNNJzLsZvY=; h=Cc:Date:From:Reply-To:Subject:To; b=sLIEj43pCf8j2/L6jbulg1IJX3OgqsExDO4RMwXwudIjwcuGyw1eRwZoDGjzq+YfCYY VXJxYPkgPAwZk58R9wIMqTcnzbyJoQ8IpgaWTCtM+ar/SLqPj4CUby9RHsJ3+fFj3ZC51 frU3bKrP3XrVeUD6o+e0C/qZR6v/7zUmvUE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671525818964100003 Content-Type: text/plain; charset="utf-8" From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4172 TDVF once accepts memory only by BSP. To improve the boot performance this patch introduce the multi-core accpet memory. Multi-core means BSP and APs work together to accept memory. TDVF leverages mailbox to wake up APs. It is not enabled in MpInitLib (Which requires SIPI). So multi-core accept memory cannot leverages MpInitLib to coordinate BSP and APs to work together. So TDVF split the accept memory into 2 phases. - AcceptMemoryForAPsStack: BSP accepts a small piece of memory which is then used by APs to setup stack. We assign a 16KB stack for each AP. So a td-guest with 256 vCPU requires 255*16KB =3D 4080KB. - AcceptMemory: After above small piece of memory is accepted, BSP commands APs to accept memory by sending AcceptPages command in td-mailbox. Together with the command and accpet-function, the APsStack address is send as well. APs then set the stack and jump to accept-function to accept memory. AcceptMemoryForAPsStack accepts as small memory as possible and then jump to AcceptMemory. It fully takes advantage of BSP/APs to work together. After accept memory is done, the memory region for APsStack is not used anymore. It can be used as other private memory. Because accept-memory is in the very beginning of boot process and it will not impact other phases. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu Reviewed-by: Jiewen Yao --- OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 411 +++++++++++++++--- .../PlatformInitLib/PlatformInitLib.inf | 1 + 2 files changed, 363 insertions(+), 49 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/P= latformInitLib/IntelTdx.c index 55ca3ecaa13d..6cb63139cba0 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,10 @@ #define ALIGNED_2MB_MASK 0x1fffff #define MEGABYTE_SHIFT 20 =20 +#define ACCEPT_CHUNK_SIZE SIZE_32MB +#define AP_STACK_SIZE SIZE_16KB +#define APS_STACK_SIZE(CpusNum) (ALIGN_VALUE(CpusNum*AP_STACK_SIZE, SIZE_= 2MB)) + /** This function will be called to accept pages. Only BSP accepts pages. =20 @@ -81,8 +86,6 @@ BspAcceptMemoryResourceRange ( return EFI_SUCCESS; } =20 - DEBUG ((DEBUG_INFO, "TdAccept: 0x%llx - 0x%llx\n", PhysicalAddress, Tota= lLength)); - if (ALIGN_VALUE (PhysicalAddress, SIZE_2MB) !=3D PhysicalAddress) { StartAddress1 =3D PhysicalAddress; Length1 =3D ALIGN_VALUE (PhysicalAddress, SIZE_2MB) - PhysicalAd= dress; @@ -106,11 +109,6 @@ BspAcceptMemoryResourceRange ( Length3 =3D TotalLength; } =20 - DEBUG ((DEBUG_INFO, " Part1: 0x%llx - 0x%llx\n", StartAddress1, Length= 1)); - DEBUG ((DEBUG_INFO, " Part2: 0x%llx - 0x%llx\n", StartAddress2, Length= 2)); - DEBUG ((DEBUG_INFO, " Part3: 0x%llx - 0x%llx\n", StartAddress3, Length= 3)); - DEBUG ((DEBUG_INFO, " Page : 0x%x\n", AcceptPageSize)); - Status =3D EFI_SUCCESS; if (Length1 > 0) { Pages =3D Length1 / SIZE_4KB; @@ -140,6 +138,342 @@ BspAcceptMemoryResourceRange ( return Status; } =20 +/** + * This function is called by BSP and APs to accept memory. + * Note: + * The input PhysicalStart/PhysicalEnd indicates the whole memory region + * to be accepted. BSP or AP only accepts one piece in the whole memory re= gion. + * + * @param CpuIndex vCPU index + * @param CpusNum Total vCPU number of a Tdx guest + * @param PhysicalStart Start address of a memory region which is to be = accepted + * @param PhysicalEnd End address of a memory region which is to be ac= cepted + * + * @retval EFI_SUCCESS Successfully accept the memory + * @retval Other Other errors as indicated + */ +STATIC +EFI_STATUS +EFIAPI +BspApAcceptMemoryResourceRange ( + UINT32 CpuIndex, + UINT32 CpusNum, + EFI_PHYSICAL_ADDRESS PhysicalStart, + EFI_PHYSICAL_ADDRESS PhysicalEnd + ) +{ + UINT64 Status; + UINT64 Pages; + UINT64 Stride; + UINT64 AcceptPageSize; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + + AcceptPageSize =3D (UINT64)(UINTN)FixedPcdGet32 (PcdTdxAcceptPageSize); + + Status =3D EFI_SUCCESS; + Stride =3D (UINTN)CpusNum * ACCEPT_CHUNK_SIZE; + PhysicalAddress =3D PhysicalStart + ACCEPT_CHUNK_SIZE * (UINTN)CpuIndex; + + while (!EFI_ERROR (Status) && PhysicalAddress < PhysicalEnd) { + Pages =3D MIN (ACCEPT_CHUNK_SIZE, PhysicalEnd - PhysicalAddress) / Ac= ceptPageSize; + Status =3D TdAcceptPages (PhysicalAddress, Pages, (UINT32)(UINTN)Accep= tPageSize); + ASSERT (!EFI_ERROR (Status)); + PhysicalAddress +=3D Stride; + } + + return EFI_SUCCESS; +} + +/** + * This function is called by APs to accept memory. + * + * @param CpuIndex vCPU index of an AP + * @param PhysicalStart Start address of a memory region which is to be = accepted + * @param PhysicalEnd End address of a memory region which is to be ac= cepted + * + * @retval EFI_SUCCESS Successfully accept the memory + * @retval Others Other errors as indicated + */ +STATIC +EFI_STATUS +EFIAPI +ApAcceptMemoryResourceRange ( + UINT32 CpuIndex, + EFI_PHYSICAL_ADDRESS PhysicalStart, + EFI_PHYSICAL_ADDRESS PhysicalEnd + ) +{ + UINT64 Status; + TD_RETURN_DATA TdReturnData; + + Status =3D TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData); + if (Status !=3D TDX_EXIT_REASON_SUCCESS) { + ASSERT (FALSE); + return EFI_ABORTED; + } + + if ((CpuIndex =3D=3D 0) || (CpuIndex >=3D TdReturnData.TdInfo.NumVcpus))= { + ASSERT (FALSE); + return EFI_ABORTED; + } + + return BspApAcceptMemoryResourceRange (CpuIndex, TdReturnData.TdInfo.Num= Vcpus, PhysicalStart, PhysicalEnd); +} + +/** + * This function is called by BSP. It coordinates BSP/APs to accept memory= together. + * + * @param PhysicalStart Start address of a memory region which is to b= e accepted + * @param PhysicalEnd End address of a memory region which is to be = accepted + * @param APsStackAddress APs stack address + * @param CpusNum Total vCPU number of the Tdx guest + * + * @retval EFI_SUCCESS Successfully accept the memory + * @retval Others Other errors as indicated + */ +EFI_STATUS +EFIAPI +MpAcceptMemoryResourceRange ( + IN EFI_PHYSICAL_ADDRESS PhysicalStart, + IN EFI_PHYSICAL_ADDRESS PhysicalEnd, + IN OUT EFI_PHYSICAL_ADDRESS APsStackAddress, + IN UINT32 CpusNum + ) +{ + UINT64 Length; + EFI_STATUS Status; + + Length =3D PhysicalEnd - PhysicalStart; + + DEBUG ((DEBUG_INFO, "MpAccept : 0x%llx - 0x%llx (0x%llx)\n", PhysicalSta= rt, PhysicalEnd, Length)); + + if (Length =3D=3D 0) { + return EFI_SUCCESS; + } + + // + // The start address is not 2M aligned. BSP first accept the part which = is not 2M aligned. + // + if (ALIGN_VALUE (PhysicalStart, SIZE_2MB) !=3D PhysicalStart) { + Length =3D MIN (ALIGN_VALUE (PhysicalStart, SIZE_2MB) - PhysicalStart,= Length); + Status =3D BspAcceptMemoryResourceRange (PhysicalStart, PhysicalStart = + Length); + ASSERT (Status =3D=3D EFI_SUCCESS); + + PhysicalStart +=3D Length; + Length =3D PhysicalEnd - PhysicalStart; + } + + if (Length =3D=3D 0) { + return EFI_SUCCESS; + } + + // + // BSP will accept the memory by itself if the memory is not big enough = compared with a chunk. + // + if (Length <=3D ACCEPT_CHUNK_SIZE) { + return BspAcceptMemoryResourceRange (PhysicalStart, PhysicalEnd); + } + + // + // Now APs are asked to accept the memory together. + // + MpSerializeStart (); + + MpSendWakeupCommand ( + MpProtectedModeWakeupCommandAcceptPages, + (UINT64)(UINTN)ApAcceptMemoryResourceRange, + PhysicalStart, + PhysicalEnd, + APsStackAddress, + AP_STACK_SIZE + ); + + // + // Now BSP does its job. + // + BspApAcceptMemoryResourceRange (0, CpusNum, PhysicalStart, PhysicalEnd); + + MpSerializeEnd (); + + return EFI_SUCCESS; +} + +/** + BSP accept a small piece of memory which will be used as APs stack. + + @param[in] VmmHobList The Hoblist pass the firmware + @param[in] APsStackSize APs stack size + @param[out] PhysicalAddressEnd The physical end address of accepted m= emory in phase-1 + + @retval EFI_SUCCESS Process the HobList successfully + @retval Others Other errors as indicated +**/ +EFI_STATUS +EFIAPI +AcceptMemoryForAPsStack ( + IN CONST VOID *VmmHobList, + IN UINT32 APsStackSize, + OUT EFI_PHYSICAL_ADDRESS *PhysicalAddressEnd + ) +{ + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS Hob; + EFI_PHYSICAL_ADDRESS PhysicalEnd; + EFI_PHYSICAL_ADDRESS PhysicalStart; + UINT64 ResourceLength; + BOOLEAN MemoryRegionFound; + + ASSERT (VmmHobList !=3D NULL); + + Status =3D EFI_SUCCESS; + Hob.Raw =3D (UINT8 *)VmmHobList; + MemoryRegionFound =3D FALSE; + + DEBUG ((DEBUG_INFO, "AcceptMemoryForAPsStack with APsStackSize=3D0x%x\n"= , APsStackSize)); + + // + // Parse the HOB list until end of list or matching type is found. + // + while (!END_OF_HOB_LIST (Hob) && !MemoryRegionFound) { + if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + DEBUG ((DEBUG_INFO, "\nResourceType: 0x%x\n", Hob.ResourceDescriptor= ->ResourceType)); + + if (Hob.ResourceDescriptor->ResourceType =3D=3D BZ3937_EFI_RESOURCE_= MEMORY_UNACCEPTED) { + ResourceLength =3D Hob.ResourceDescriptor->ResourceLength; + PhysicalStart =3D Hob.ResourceDescriptor->PhysicalStart; + PhysicalEnd =3D PhysicalStart + ResourceLength; + + DEBUG ((DEBUG_INFO, "ResourceAttribute: 0x%x\n", Hob.ResourceDescr= iptor->ResourceAttribute)); + DEBUG ((DEBUG_INFO, "PhysicalStart: 0x%llx\n", PhysicalStart)); + DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", ResourceLength)); + DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owne= r)); + + if (ResourceLength >=3D APsStackSize) { + MemoryRegionFound =3D TRUE; + if (ResourceLength > ACCEPT_CHUNK_SIZE) { + PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + APsSta= ckSize; + } + } + + Status =3D BspAcceptMemoryResourceRange ( + Hob.ResourceDescriptor->PhysicalStart, + PhysicalEnd + ); + if (EFI_ERROR (Status)) { + break; + } + } + } + + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + + ASSERT (MemoryRegionFound); + *PhysicalAddressEnd =3D PhysicalEnd; + + return Status; +} + +/** + BSP and APs work togeter to accept memory which is under the address of = 4G. + + @param[in] VmmHobList The Hoblist pass the firmware + @param[in] CpusNum Number of vCPUs + @param[in] APsStackStartAddres Start address of APs stack + @param[in] PhysicalAddressStart Start physical address which to be accep= ted + + @retval EFI_SUCCESS Process the HobList successfully + @retval Others Other errors as indicated +**/ +EFI_STATUS +EFIAPI +AcceptMemory ( + IN CONST VOID *VmmHobList, + IN UINT32 CpusNum, + IN EFI_PHYSICAL_ADDRESS APsStackStartAddress, + IN EFI_PHYSICAL_ADDRESS PhysicalAddressStart + ) +{ + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS Hob; + EFI_PHYSICAL_ADDRESS PhysicalStart; + EFI_PHYSICAL_ADDRESS PhysicalEnd; + EFI_PHYSICAL_ADDRESS AcceptMemoryEndAddress; + + Status =3D EFI_SUCCESS; + AcceptMemoryEndAddress =3D BASE_4GB; + + ASSERT (VmmHobList !=3D NULL); + Hob.Raw =3D (UINT8 *)VmmHobList; + + DEBUG ((DEBUG_INFO, "AcceptMemory under address of 4G\n")); + + // + // Parse the HOB list until end of list or matching type is found. + // + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + if (Hob.ResourceDescriptor->ResourceType =3D=3D BZ3937_EFI_RESOURCE_= MEMORY_UNACCEPTED) { + PhysicalStart =3D Hob.ResourceDescriptor->PhysicalStart; + PhysicalEnd =3D PhysicalStart + Hob.ResourceDescriptor->Resource= Length; + + if (PhysicalEnd <=3D PhysicalAddressStart) { + // this memory region has been accepted. Skipped it. + Hob.Raw =3D GET_NEXT_HOB (Hob); + continue; + } + + if (PhysicalStart >=3D AcceptMemoryEndAddress) { + // this memory region is not to be accepted. And we're done. + break; + } + + if (PhysicalStart >=3D PhysicalAddressStart) { + // this memory region has not been acceted. + } else if ((PhysicalStart < PhysicalAddressStart) && (PhysicalEnd = > PhysicalAddressStart)) { + // part of the memory region has been accepted. + PhysicalStart =3D PhysicalAddressStart; + } + + // then compare the PhysicalEnd with AcceptMemoryEndAddress + if (PhysicalEnd >=3D AcceptMemoryEndAddress) { + PhysicalEnd =3D AcceptMemoryEndAddress; + } + + DEBUG ((DEBUG_INFO, "ResourceAttribute: 0x%x\n", Hob.ResourceDescr= iptor->ResourceAttribute)); + DEBUG ((DEBUG_INFO, "PhysicalStart: 0x%llx\n", Hob.ResourceDescrip= tor->PhysicalStart)); + DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescri= ptor->ResourceLength)); + DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owne= r)); + + // Now we're ready to accept memory [PhysicalStart, PhysicalEnd) + if (CpusNum =3D=3D 1) { + Status =3D BspAcceptMemoryResourceRange (PhysicalStart, Physical= End); + } else { + Status =3D MpAcceptMemoryResourceRange ( + PhysicalStart, + PhysicalEnd, + APsStackStartAddress, + CpusNum + ); + } + + if (EFI_ERROR (Status)) { + ASSERT (FALSE); + break; + } + + if (PhysicalEnd =3D=3D AcceptMemoryEndAddress) { + break; + } + } + } + + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + + return Status; +} + /** Check the value whether in the valid list. =20 @@ -375,55 +709,34 @@ ProcessHobList ( ) { EFI_STATUS Status; - EFI_PEI_HOB_POINTERS Hob; + UINT32 CpusNum; EFI_PHYSICAL_ADDRESS PhysicalEnd; - UINT64 ResourceLength; - UINT64 AccumulateAcceptedMemory; + EFI_PHYSICAL_ADDRESS APsStackStartAddress; =20 - Status =3D EFI_SUCCESS; - ASSERT (VmmHobList !=3D NULL); - Hob.Raw =3D (UINT8 *)VmmHobList; - - AccumulateAcceptedMemory =3D 0; + CpusNum =3D GetCpusNum (); =20 // - // Parse the HOB list until end of list or matching type is found. + // If there are mutli-vCPU in a TDX guest, accept memory is split into 2= phases. + // Phase-1 accepts a small piece of memory by BSP. This piece of memory + // is used to setup AP's stack. + // After that phase-2 accepts a big piece of memory by BSP/APs. // - while (!END_OF_HOB_LIST (Hob)) { - if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { - DEBUG ((DEBUG_INFO, "\nResourceType: 0x%x\n", Hob.ResourceDescriptor= ->ResourceType)); - - if (Hob.ResourceDescriptor->ResourceType =3D=3D BZ3937_EFI_RESOURCE_= MEMORY_UNACCEPTED) { - DEBUG ((DEBUG_INFO, "ResourceAttribute: 0x%x\n", Hob.ResourceDescr= iptor->ResourceAttribute)); - DEBUG ((DEBUG_INFO, "PhysicalStart: 0x%llx\n", Hob.ResourceDescrip= tor->PhysicalStart)); - DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescri= ptor->ResourceLength)); - DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owne= r)); - - PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Res= ourceDescriptor->ResourceLength; - ResourceLength =3D Hob.ResourceDescriptor->ResourceLength; - - if (Hob.ResourceDescriptor->PhysicalStart >=3D BASE_4GB) { - // - // In current stage, we only accept the memory under 4G - // - break; - } - - Status =3D BspAcceptMemoryResourceRange ( - Hob.ResourceDescriptor->PhysicalStart, - PhysicalEnd - ); - if (EFI_ERROR (Status)) { - break; - } - - AccumulateAcceptedMemory +=3D ResourceLength; - } - } - - Hob.Raw =3D GET_NEXT_HOB (Hob); + // TDVF supports 4K and 2M accept-page-size. The memory which can be acc= peted + // in 2M accept-page-size must be 2M aligned and multiple 2M. So we align + // APsStackSize to 2M size aligned. + // + if (CpusNum > 1) { + Status =3D AcceptMemoryForAPsStack (VmmHobList, APS_STACK_SIZE (CpusNu= m), &PhysicalEnd); + ASSERT (Status =3D=3D EFI_SUCCESS); + APsStackStartAddress =3D PhysicalEnd - APS_STACK_SIZE (CpusNum); + } else { + PhysicalEnd =3D 0; + APsStackStartAddress =3D 0; } =20 + Status =3D AcceptMemory (VmmHobList, CpusNum, APsStackStartAddress, Phys= icalEnd); + ASSERT (Status =3D=3D EFI_SUCCESS); + return Status; } =20 diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index 86a82ad3e084..140216979a54 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -52,6 +52,7 @@ PcdLib PciLib PeiHardwareInfoLib + TdxMailboxLib =20 [LibraryClasses.X64] TdxLib --=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 (#97624): https://edk2.groups.io/g/devel/message/97624 Mute This Topic: https://groups.io/mt/95782438/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-