From nobody Mon May 6 12:11:19 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+97427+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+97427+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093897; cv=none; d=zohomail.com; s=zohoarc; b=a+O724BKI8yl9OM1Kt4Wd2OMtaQpDPjrK8V5Qc49u2SHX2/m6n8oX5U2l5ioufC7RNevITgzGaYDzWGTwF5aCtYSZdXEZCxfLlcjXZ5X4+wc33zAHMTABopJC9S/qBzG6UPNmbboVcc7E8f6G8KDzD4Izu776l7+anFHSn1dESc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093897; 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=a6nS/M4fX8PEB2c/VbOoznuoXnJbeEYL/LL0prSl0To=; b=Ez5ES2KClngH10lMnTOF2XtwPU27PsdwXCXbQ8VFRSlPDU3tD8Fu4tBgbpo3P9VY6a1BB7GB38Ifdv93zb+aHhwIhSW6M/Hu90Vnu9COIour16wcs8bgCS1z0I9ShF06Hky9ySF3C2FJQN+uM5XI/35MdHTPvMawD4qs9dFdMrA= 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+97427+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 1671093897235379.02519310071625; Thu, 15 Dec 2022 00:44:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uQdpYY1788612xiuMJtq7fxi; Thu, 15 Dec 2022 00:44:56 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.128317.1671093895214005705 for ; Thu, 15 Dec 2022 00:44:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967864" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967864" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:44:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464804" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464804" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:44:54 -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 V1 1/6] OvmfPkg/TdxMailboxLib: Delete global variables Date: Thu, 15 Dec 2022 16:44:35 +0800 Message-Id: <20221215084440.481-2-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: et1Hj6UgOueKxwsCp43DSzuZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093896; bh=UddIfeUwbIBVTZ+emykHpZAaTMz/ceNX2saoueKQnQM=; h=Cc:Date:From:Reply-To:Subject:To; b=d+3YZK9uoaVpZACbxfU0fDJEoeDtAeluVVodNa2AVKeGFpNiIudBlNRJXA/heTVVmzT pZmpVvgSB92W33CtaTb3Puw0Ry/H8KAc7EHEXZD1Y9DXIodC74J4vDvyOVhLVWHHKBkG3 WxisBJ9oL5EeIYFjL2Dyz/oqq/jGXPU36kM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093898314100002 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 --- 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 (#97427): https://edk2.groups.io/g/devel/message/97427 Mute This Topic: https://groups.io/mt/95684987/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 May 6 12:11:19 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+97428+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+97428+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093921; cv=none; d=zohomail.com; s=zohoarc; b=lg2li2McMeWfJTooOFL4tYiGXi42nnw46CzjEQKpthhXLxsrTwV8GPucNYnk9UFxD7AIzL7OaHOrznJLUm+/b0nRUQqggwFrH26ObVOkNL5Dc+aaxS0xm51Vs+rHczqd7+grI/EDm3Xa16Www9Pm1C+wDpsOZQWjPk+OmLcZelQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093921; 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=CT/5fqSegCqmJt7v21TZ5V5MbNdlIrlNf1Tsvm16xec=; b=eh5H1OWCqIF/GCabM9F8xV+g1MRjlFTodgJhDUrnrmHEOhuloE443SGbZbEeB5QJnKajGhW/ZEPiRYScSaYYXW9RVzpmeFXOEfpNnsOB8ture+KYLU+rO+sNhhosEwTOnbfojrIuRDgoDAxEOd212v3mfFBw6lB1rI6M5CBWtYQ= 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+97428+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 1671093921099573.8205423255661; Thu, 15 Dec 2022 00:45:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6tJzYY1788612xwTi1tqYW29; Thu, 15 Dec 2022 00:45:20 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.128323.1671093920118855250 for ; Thu, 15 Dec 2022 00:45:20 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967896" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967896" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:14 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464822" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464822" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:44: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 V1 2/6] OvmfPkg/TdxMailboxLib: Add NULL instance of TdxMailboxLib Date: Thu, 15 Dec 2022 16:44:36 +0800 Message-Id: <20221215084440.481-3-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: O8985dQ62zF5hbwvow3RmQfvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093920; bh=ozVgXTTIpJX+KLplJw1UnrvnXT9F3aizThafE8Z8XGI=; h=Cc:Date:From:Reply-To:Subject:To; b=aqbwg00BpUeWGkf1eDHHqSBJvHdqguH6iKP4z41sI3hY/qxoIYrRQww4LwmESIYFANE 404BX1E8tNqtRhlAk6PSWFLoBJk7aT0tR8L/r1149OT0bO83cpUUDgTBWBILlVkD2ukO7 FYi2CVl7aR25+c3Cg8Ye3ziKpaBgRVC6OHs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093923553100001 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 --- .../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 (#97428): https://edk2.groups.io/g/devel/message/97428 Mute This Topic: https://groups.io/mt/95684993/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 May 6 12:11:19 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+97429+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+97429+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093937; cv=none; d=zohomail.com; s=zohoarc; b=FuD9xPeM2hdFDUHNYofSDEgoiP1rbkJl2VfxN1HJXw/EF1jFj25u1UlEFDOZB9kFX6N6LqLekqobt8vnLnzPnxxX+bMCfup1hRysSv1HJBufsAZG4rlne9cbIDen8isoESE2cdI8OJgiPuHdTixXeEo9BEOv1pLsQz732jJRq7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093937; 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=qnJ0s3rKAnBxJoDisNVO1bllJTS6p2OyCWf6cw5dVnE=; b=f2msjbYhqgL1EYb6i1tKauKrmXsHEVsvuCqVDnZ7odOorhE15uJn3tNtavec/p0ubXyznj1s+OS8Ss4ibjj/WcO5EwatyvteQiDpderh93BaxxynXqb689mWODrPd7eS9O7ZW+KJctvd3/V8AaZblXRTpdG7m2WpaxwPK3nrLDY= 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+97429+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 1671093937915567.8231541850857; Thu, 15 Dec 2022 00:45:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kkLcYY1788612x2ILFrRSqvH; Thu, 15 Dec 2022 00:45:36 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.129128.1671093936170705767 for ; Thu, 15 Dec 2022 00:45:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967905" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967905" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464888" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464888" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45: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 V1 3/6] OvmfPkg: Add TdxMailboxLibNull in some platform dsc Date: Thu, 15 Dec 2022 16:44:37 +0800 Message-Id: <20221215084440.481-4-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: 9Y9Hp4YpvLXUugObecIM0yaNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093936; bh=cF3+pp/SkE8dXbo1DCfEv00osmDHsFgMl9L7H4x+Xmg=; h=Cc:Date:From:Reply-To:Subject:To; b=a+ZSaK3ee+5hUdF6g6YBA7MCMA/0QqBoytt4besSD9QpH3zx74YrCPaACcV7cA5QzMU zBb2VK8VI+1qspdikJxH6Dx9b1n6MSMvkV7NOt/PHIfZPW5DWfTRiFibqDe+RbVZGOrvx VesZmEV3nY5LCk3DPVjqjvWlgRwGMK5FvlM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093939614100007 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 --- 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 8f7cae787e97..706d00707715 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 ce277cb2398b..867a1e1e9378 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 994a02d30107..33f7cd7d6342 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 6f774baf90f5..56c5fd873444 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 c851764dec05..9a8045ffc406 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 (#97429): https://edk2.groups.io/g/devel/message/97429 Mute This Topic: https://groups.io/mt/95684996/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 May 6 12:11:19 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+97430+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+97430+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093937; cv=none; d=zohomail.com; s=zohoarc; b=YZU0RZqo024zVb8PxDPxDtucJbCCFVTisLBJrXiIy88kQIzusLqyy21gr6lwOjC38gBd0YDQMXrh2cfN/MC36211Ak7c9wepWUFnLHbsrfEa4JkWgO7VrxLWwn9SQ571f0jh5jzuljkO9onXV3uNgDJyxD3rLMXfZHodw5FuCf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093937; 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=rRfCro3fMRa3Wi9OPBbUdBJso5wsUBjYup4CW8+MGy4=; b=Ei7mR4igvbN5s9EQ/UM8Si27p8+Em5fmHaLfVNBk8QOnYBrBg/3EW/gAJtdmR/sJikhpza2EGlpkEPNOACDxQeYXCf/ia+2njwlGsnfJ0ZcP+l4ZIK7FEOVbLnqBMdVwo/tdcfEqm6JN/ZrK/MYvzkB/eQO3gS87KVCzL0ERsV0= 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+97430+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 1671093937258272.4300227171327; Thu, 15 Dec 2022 00:45:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id CeOlYY1788612xFMoJ0Q9GtS; Thu, 15 Dec 2022 00:45:36 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.128326.1671093936329116914 for ; Thu, 15 Dec 2022 00:45:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967911" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967911" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464910" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464910" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45: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 V1 4/6] OvmfPkg/Sec: Move TDX APs related nasm code to IntelTdxAPs.nasm Date: Thu, 15 Dec 2022 16:44:38 +0800 Message-Id: <20221215084440.481-5-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: ATj3fkxwInSc7qo87cXeldsox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093936; bh=kno0q00flupiZvOmCqMtZXqMGFvSllbzEucJ/i/pURs=; h=Cc:Date:From:Reply-To:Subject:To; b=DCi+6cbdEkH+TG1Qxqc97x3AcvsKK4bRVa+RQwvJ6zWZBUGSzuTf7cf6VjyIEPSPCv9 Zg8VXwIeGZP/cOaYQUf46vNo1DSOGUE6+5uu/l871HUhWaCaCk4xCADrUkiQ383arNzQR 99itlwtD0YuhW8bugLYbjdkxGYR+8JDIzKk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093937657100001 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 --- 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 (#97430): https://edk2.groups.io/g/devel/message/97430 Mute This Topic: https://groups.io/mt/95684997/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 May 6 12:11:19 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+97431+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+97431+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093938; cv=none; d=zohomail.com; s=zohoarc; b=hRxuxsKYszJyidWbCPQpzdn3Gd4h1NbRu9ofo8Ychm/fmUhg5+o2qnsVHOKjvBCPoPsIURHeoD7QZk2OSivDLvw7cdYh/pOV8NYUR5aQbT2S/NyyniYWz92nLGQVDVtfS/DYmvpN5lia0A6JavhsvRjNHvTB+J54MngGpiNnW7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093938; 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=PA+ZfQleu+y4JsCT04YQcxT26RKu2/HSs9rcutRIjgY=; b=ShdzmEHMWqRw7FKzpQw1qYVL9BbhOHRrfKORQsscY8WcikCL9s0eh2NFfCDYOiCu+QvIODkyR6rUBxo8E7g2chAV380xbxEEUrMG/L3FHET2A7+ur0zZee5StjOMsQLv87ru7dqnIOhFd2buXSuPx6TU4UNmnmyexr7Mil62Al0= 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+97431+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 1671093938133770.5453140527759; Thu, 15 Dec 2022 00:45:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id oXk5YY1788612xZoWSibktAO; Thu, 15 Dec 2022 00:45:37 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.129128.1671093936170705767 for ; Thu, 15 Dec 2022 00:45:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967925" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967925" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464939" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464939" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45: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 V1 5/6] OvmfPkg: Enable APs to accept memory for TDVF Date: Thu, 15 Dec 2022 16:44:39 +0800 Message-Id: <20221215084440.481-6-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: vhunxVSUJr0vBDw3OVCm5inmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093937; bh=OmwfPiwXG98giaBRnHmmBCUZ1XdBK++53VA1LcGPAVQ=; h=Cc:Date:From:Reply-To:Subject:To; b=xPQRYBqi4K9HmqRGs0ZFFbkoz62iAqfvdIlbpBeh75ZIJ4BvCx+6pzRyDn6BkcjANJq Unr+qY9ScUyz8SJUCBl4KW5L6ilPyxL4AKBT1zMqk5UMIzIe3a9ugaX+oraeVptbnABYi HffuU41LHQcPxztqMuqGWyzvVr915STtLTs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093939606100006 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 --- 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 (#97431): https://edk2.groups.io/g/devel/message/97431 Mute This Topic: https://groups.io/mt/95684998/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 May 6 12:11:19 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+97432+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+97432+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1671093938; cv=none; d=zohomail.com; s=zohoarc; b=j5o+xc3BNPNkE0kDWOkAlKYdkGSkqdifFpEN+dEfL0B/dDTspAWvRR/+a3EsGvHa5ZjVGvf/vCiJ0Ng5EnLi0xaMAPRmzg1SArk1BEZpHmbMFE6Ka0hitIca+7JisBo1n7Efx5sMU0oLAFTG/S8nBNPEF20IhZPbSztNQjde4CU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671093938; 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=FeDWrWBbhhkAaGJg3XOwdASPbZl4iLflBlxRYxAQ8eE=; b=HF22YoRTBpqR9iB5Z/sJkzIZ8AmL8AYBwvlceV55t6b4d2PL/4qt3/CGndnedwn1/rLMiOvzOW/Un71AmYqrGWS+//8+O7oBJa16INzW66SAbT46/0LOn5NzugXXRY5sQGtZ8MgHzKjYmzsYtZpu0uPFKyrH2VKgg/RoqJhqbFM= 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+97432+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 1671093938640513.3311396428002; Thu, 15 Dec 2022 00:45:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uv49YY1788612xOerhVh9XFr; Thu, 15 Dec 2022 00:45:38 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.129128.1671093936170705767 for ; Thu, 15 Dec 2022 00:45:37 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="298967934" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="298967934" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="651464952" X-IronPort-AV: E=Sophos;i="5.96,246,1665471600"; d="scan'208";a="651464952" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.170.19]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 00:45:08 -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 V1 6/6] OvmfPkg/PlatformInitLib: Implement multi-core accept memory for TDVF Date: Thu, 15 Dec 2022 16:44:40 +0800 Message-Id: <20221215084440.481-7-min.m.xu@intel.com> In-Reply-To: <20221215084440.481-1-min.m.xu@intel.com> References: <20221215084440.481-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: MyATRzCDaQrgvB0AaM1YYn9Lx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1671093938; bh=gspXmeBmbEnv/R32avPF0npvdbU+GFGLH0IVG3/YvAQ=; h=Cc:Date:From:Reply-To:Subject:To; b=FntbCmtFhCVPF0WapWs96Jnko/06fxDzMrhdwyQ+Ym9ElyK88Xokro9FT21h8+/sZ2l +XRogGwH89mUwckPgqFvU0b3uikvaoVrn2aUw7rqW12W3pwUWYq0U/SqNPmOHD1/tSlmZ GSJ8UdPLveTIhpn1/i1hL4VL1Gew3Z7ba1E= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1671093939642100009 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 --- 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 acd114e38e46..91a8aaf244a4 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 CpusNum * ACCEPT_CHUNK_SIZE; + PhysicalAddress =3D PhysicalStart + ACCEPT_CHUNK_SIZE * 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 (#97432): https://edk2.groups.io/g/devel/message/97432 Mute This Topic: https://groups.io/mt/95684999/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-