From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.6337.1648019996982030424 for ; Wed, 23 Mar 2022 00:19:57 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=OK1Q9zXN; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648019997; x=1679555997; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=y4JvOnNX4BFfnF8WHgx8vwMlFuHZE2j329grBHFqeYQ=; b=OK1Q9zXNt8Cw2wz8iNEeHseXA4o3iJ+jNRQOY0qrJpHPl8PjeDTAZIn1 MStMnq9UrqMfG4JfRgg2LkFbx46zSEC0Y7RYsN26PdXP/by8lNYSKu/yc VxJaC8UkSYMRGiFA+WBV+WDdpZbFRV1A6Li0gP5kcxcl44ANzWeOKwHvZ mIl5KFxvBUwtGFLfpkMPcc/W/QXtY0l0vWhYhdPfjrBy+ziLTZo7m1vGT RxLmMc+XxR8syqgn68XtNJYQW/FcEdQoUeiAQuQZLl/mXW7D5rxC4IEha eNGRfZdBEbtJIyhsh0OT2I7ydA6cMRjfScl9S/1hvXJ0oqk4PQPBk4nxA A==; X-IronPort-AV: E=McAfee;i="6200,9189,10294"; a="318752154" X-IronPort-AV: E=Sophos;i="5.90,203,1643702400"; d="scan'208";a="318752154" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 00:19:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,203,1643702400"; d="scan'208";a="692854716" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by fmsmga001.fm.intel.com with ESMTP; 23 Mar 2022 00:19:54 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 23 Mar 2022 00:19:54 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Wed, 23 Mar 2022 00:19:54 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.175) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Wed, 23 Mar 2022 00:19:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TIN5C8QASl+2zKZb4CUfUgD27kGQ+RCDfJkU+pwSkYA/Ze3dvyypwHXM5grf7VOqHl1nmsCKlWRXj4rymSoETg+3FDALQZ6yycJCJ9uxe38ciuMBNJqfZfW6HIouM84OK4JhhLLnZnYz6oSIdDv3e3lGaFApzJ5ag9TdKkD8Qbh2Q4m5ZZnLfz9EMSfwaWCpoTwCjXcTo9J/q9fGQjr6RQxmioBU9EdmprhSivgwtXcpFrdz/me4GtXEGxchFPA2p9cz2blIkXi4UaDOUD6YZ7gRYswGqtkOdSoJ4XicmZo9WgnMoN/D3QpHVysN1C8dwQqc3rmLnrJ7foq+Lr6ffA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LpNZJNUkjUD7uaeXmu6fZOSHNg7KkH7/WXDY7nd1PoI=; b=AmACppaOzl+rK+UnpF3YaXCo+tUKOoEqXfmGM9xhC3Lm8UgN+FvFO2bcZw8W/UTu9Lv3Nu4JyFevVwmTSFb6v8xWdAi09AKtbqMjsmMHlrjT6A0ZSumhtapQJ+JH916vnQ9lEyBykIaxBdTz5qXDE7x/GznZ4us2XfK4ePntzjuCT2DA2+dTEFxOKoUAqL8v4nfb4GbG9xKZOu6FSG/rZbGC0YMs938i6Vtcp6qEWrHAate7AZFKA3SY0sKntCyjWhVWPTmB/B9GzuGHRPHZCRgGNi4o2NvRDJU5aUMja+oeSIqH6xJhqU8hd3OI5W61U9wW3LUdeC1xVt5u48N9UQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MWHPR11MB1631.namprd11.prod.outlook.com (2603:10b6:301:10::10) by MWHPR11MB1982.namprd11.prod.outlook.com (2603:10b6:300:10f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.19; Wed, 23 Mar 2022 07:19:50 +0000 Received: from MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::30a3:3926:64ca:50d5]) by MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::30a3:3926:64ca:50d5%8]) with mapi id 15.20.5081.023; Wed, 23 Mar 2022 07:19:50 +0000 From: "Ni, Ray" To: "Xu, Min M" , "devel@edk2.groups.io" CC: Brijesh Singh , "Aktas, Erdem" , James Bottomley , "Yao, Jiewen" , Tom Lendacky , "Dong, Eric" , "Kumar, Rahul1" , "Gerd Hoffmann" Subject: Re: [PATCH V9 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib Thread-Topic: [PATCH V9 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib Thread-Index: AQHYOmG2LT2Ua0qepUyPdxYqHpEx6qzMfHYw Date: Wed, 23 Mar 2022 07:19:50 +0000 Message-ID: References: <2b5c26f8bbc272abfa39521175c85cf46b0fbeda.1647523953.git.min.m.xu@intel.com> In-Reply-To: <2b5c26f8bbc272abfa39521175c85cf46b0fbeda.1647523953.git.min.m.xu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.200.16 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 19c49ab7-660b-4aea-fb8b-08da0c9d852a x-ms-traffictypediagnostic: MWHPR11MB1982:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3VVdS42RD+USNuy5iSaMVQR947ICn9C67OfmttTdAFkZXMVWrE0i+6Nbm1rUynxMUxM2KffIZP7iGXuRmw0S7oQL+6n1zojSf6A+Ut3RyqlqAMOuBDlIfsKRDp117w6m8+U/4Ds22q2TX0MGHmzIpLMPJAqrGdKR//GHInOO0p8rPWNaK/bBWJOtnw0AGDtprTj49hVYXiX5uN02Wrjz/5b6AcQuIMZg/ml1ranITOyb8EFCGcmvDDYAjJ/2f2gAiX0XkhyROOtMfSMcxZ3gZ+KfAlKxtiEGNpLOspQwrLxyUoNKD4SeJnREuqCW3o2lIPGY9F0f1m55VYW9YLiY/d5ecW91c2MAIFr28XYr36ucR9F19cq7hepGr528DmAVke3iTXtOznQKT2/oHWXD7C4qtqZGNg9aXjB5r5/k88XKWPF7cNkYgGIFWexwhIG8vTtzDgqBU2egXb81luSsw8g7aNC/MdRHT3cXzQItc6+bM9vpJolcetsppo63+w+BhsimstiMI65Ps8ZJXmEjrIR1pJCw9oNk7qrLAUGo4Pbe3jO6HbmYbwgIh2iF8o0K/nkZYRZT49LhBcAYIiQK21wUHlVu7rQEuWQaXCbs3EiowI/OkxHDntQQ6DCE6fYWCBOM8rR7kwV8VHtq0Qd2LXlPYW+dGCCo60Nmv+qy+p6JntZ9OQfF2xY1oCVEzjQ6xjUhXs8T5ef4lmGsf4kT9JksKZP9ss4kB+JrSr8XG+WKv+vUz7gB8eEwI888IBnMhhDEHGv/lfjfogNdm5nRkjKVMxc4T2QaIjzegQs2Gok= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1631.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(6029001)(366004)(83380400001)(508600001)(2906002)(966005)(64756008)(66446008)(9686003)(76116006)(66556008)(66946007)(66476007)(4326008)(52536014)(8676002)(33656002)(5660300002)(53546011)(26005)(8936002)(7696005)(186003)(86362001)(30864003)(71200400001)(6506007)(54906003)(316002)(82960400001)(38070700005)(38100700002)(122000001)(55016003)(110136005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?GVaRrALssZAS8cY9oHpuue5Dorxq+2zRWKs8rS1Kz7BL4Lpekt62N8ifEkpA?= =?us-ascii?Q?V+tFInKHNRZLDrdz9sUva0G4NveLiIrJTFXgWaBwh3fXl1Lbd8W/waZecgVz?= =?us-ascii?Q?AyTQq5AOQ8Lnw4sb1vWiyfaHiEymIXkpoA3pnL+wDVq2aWisuXNBEv39PqT4?= =?us-ascii?Q?yhgsn8CJmttF0NyLL301f9aZGevGIXsnCH0Y9vwDjC8ivaSSpITkbIB7ZCVR?= =?us-ascii?Q?4Ki5cohJ4z9muNo4ntYmyNw0ViwdXzXuuG6ZaNUjB0Ke6d2b1MyEWjgQnqm5?= =?us-ascii?Q?ZXlWDkRddDUHjRwqlPBcmzRy+hVkUBrOtIgZkSbp3B1tOdcO7oWiJ5zFPKYT?= =?us-ascii?Q?N/r+uAe2mMBFUWmhHmk5fv8fqZzDgtUof/pVtSG+dPiwqfBQuX8ftvu88aOt?= =?us-ascii?Q?y+z8s2CWRF+LKu2NS00KOjndgbjrw+VMcY+GgY6hEEQ+jZZOP9q54hUWPNad?= =?us-ascii?Q?xd1guTFrS96AaJ09M2AA5/4zJbhCmNKa9uYV6q+38+k8M9A0u+PwYc3DKsmV?= =?us-ascii?Q?WV3jov5SHkYieAGQvohrL0OgYIDbsRvsXPpOblkV6U5DY4IwLhkeDO3miaqg?= =?us-ascii?Q?PmRf61Y+BCqmzy92Dw1Mrr6f0aviEaqgVX1ZLOrFefYybv3S2c0lTv/Me89y?= =?us-ascii?Q?LQZe/Bqywm9dFms3NWhiuH8wnpkAsJYMEMmQxHuFjwrjGrPcJ3poSftr+mG/?= =?us-ascii?Q?Snh7E9YVC+l/UCw6MytqDXXvuXkIK4oEwVvokDP5gsZdLmGlIQOtH29SxrSB?= =?us-ascii?Q?m696YX9TprmGC9m4G3wcHQtj/5V38mpY3+4clhB6eeisDWzOimrcp7B//DAP?= =?us-ascii?Q?DIdWz9gpdGAzoINaSBf4COPjzbLwHgjiCKpyDbwNBz+L6a6dDGnElhmnbBZb?= =?us-ascii?Q?qSQy6xvmOw0L+dNifXOkItGHoueX1+ZxoeigUlzF4WtrtOuqMghYpu0qcLCT?= =?us-ascii?Q?lHNddW2apHkLEO5T5O0cy+r1/whQfnE/gQ3tS8XOhIox551mHT38qbQ8olR3?= =?us-ascii?Q?+StElmjbh23HplzsX5Au27hPu8OBpp3wmi29CgZCozY5HqZbE41VFLC3k+gV?= =?us-ascii?Q?BaJpFWywte8seZitfhpZs5Zw/PEiTi80paqTVqlkvybDe6RZ+k6hfpRw9mWe?= =?us-ascii?Q?BY1BWYl0eITgrKiKotdawpxQ6dcE72GLfOoohB3MNhsgodcBPzhBPNCy99o0?= =?us-ascii?Q?EMLIMywW3KUHeo4lxPoRUUYB2WN4sqFECkWlLmTRjvXCIGyOmQhm7ZK+1mq5?= =?us-ascii?Q?/dSbJMiO5bzw5uqQMeRZGkThyRot8elXdVQTob24fbKaYutkORvbJOPtfPsj?= =?us-ascii?Q?JB2S8d3BzoEOhL/davv9cNbBvGmeOBKA/qWFu8XCyU4qnPCucooLU9W3ph0C?= =?us-ascii?Q?q4Y1UW+5aCjX6edSGgV/N1Ku1Tw/VoXXQgJMp4cwJV1AOjunBDEmaOlSXZDO?= =?us-ascii?Q?QufOzfETiZ8=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1631.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19c49ab7-660b-4aea-fb8b-08da0c9d852a X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Mar 2022 07:19:50.8525 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: RrOZd3cTbufy7PRci01UyoUcqtfUCjZAEAz8vLkxG6jAIcfKJ5Us61OUF8at5QpsvKqJwdrM53BW7jxZYn7rKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1982 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Min, MpInitLib contains following APIs. Let's discuss one by one. MpInitLibInitialize: Directly return. Looks good to me. MpInitLibGetNumberOfProcessors : Call TdxMpInitLibGetNumberOfProcessors(). = Why call a subfunction here but directly return in above API? Not quite con= sistent to me. By the way, can you re-use the parameter check logic? MpInitLibGetProcessorInfo : Call TdxMpInitLibGetProcessorInfo (). Consisten= cy concern. MpInitLibStartupAllAPs : Directly return in DXE version. But StartupAllCPUs= Worker() directly returns AGAIN! My guess that's for PEI version. Can you r= emove the changes in DXE version? MpInitLibStartupThisAP : Directly return in DXE version. How is the PEI ver= sion handled? MpInitLibSwitchBSP : Directly return in DXE version. How is the PEI version= handled? MpInitLibEnableDisableAP : Directly return in DXE version. But EnableDisabl= eApWorker () directly returns AGAIN! My guess that's for PEI version. Can y= ou remove the changes in DXE version? MpInitLibWhoAmI : Directly return. Looks good to me. MpInitLibStartupAllCPUs : Not handled. Missed? Thanks Ray -----Original Message----- From: Xu, Min M =20 Sent: Friday, March 18, 2022 8:46 AM To: devel@edk2.groups.io Cc: Xu, Min M ; Brijesh Singh ; = Aktas, Erdem ; James Bottomley ;= Yao, Jiewen ; Tom Lendacky = ; Dong, Eric ; Ni, Ray ; Kumar, Rahu= l1 ; Gerd Hoffmann Subject: [PATCH V9 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3429 In TDVF BSP and APs are simplified. BSP is the vCPU-0, while the others are= treated as APs. So MP intialization is rather simple. The processor info is retrieved by TD= CALL, ApWorker is not supported, BSP is always the working processor, while= the APs are just in a wait-for-precedure state. Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 15 +- UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h | 71 ++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 27 ++++ UefiCpuPkg/Library/MpInitLib/MpLibTdx.c | 128 ++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c | 73 ++++++++++ UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + 7 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 Uefi= CpuPkg/Library/MpInitLib/MpIntelTdx.h create mode 100644 UefiCpuPkg/Library/MpInitLib/MpLibTdx.c create mode 100644 UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index e1cd0b350008..159b4d16ed0e 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -24,10 +24,12 @@ [Sources.IA32] Ia32/AmdSev.c Ia32/MpFuncs.nasm + MpLibTdxNull.c =20 [Sources.X64] X64/AmdSev.c X64/MpFuncs.nasm + MpLibTdx.c =20 [Sources.common] AmdSev.c @@ -36,6 +38,7 @@ MpLib.c MpLib.h Microcode.c + MpIntelTdx.h =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 60d14a5a0e10..237cad8c5fd6 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -7,6 +7,7 @@ **/ =20 #include "MpLib.h" +#include "MpIntelTdx.h" =20 #include #include @@ -15,8 +16,8 @@ #include #include #include - #include +#include =20 #define AP_SAFE_STACK_SIZE 128 =20 @@ -824,6 +825,10 @@ MpInitLibStartupThisAP ( { EFI_STATUS Status; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + // // temporarily stop checkAllApsStatus for avoid resource dead-lock. // @@ -880,6 +885,10 @@ MpInitLibSwitchBSP ( EFI_TIMER_ARCH_PROTOCOL *Timer; UINT64 TimerPeriod; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + TimerPeriod =3D 0; // // Locate Timer Arch Protocol @@ -953,6 +962,10 @@ MpInitLibEnableDisableAP ( EFI_STATUS Status; BOOLEAN TempStopCheckState; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + TempStopCheckState =3D FALSE; // // temporarily stop checkAllAPsStatus for initialize parameters. diff --git a/UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h b/UefiCpuPkg/Library= /MpInitLib/MpIntelTdx.h new file mode 100644 index 000000000000..b2136f466ce6 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h @@ -0,0 +1,71 @@ +/** @file + Intel Tdx header file. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MP_INTEL_TDX_H_ +#define MP_INTEL_TDX_H_ + +#include +#include +#include +#include +#include + +/** + Gets detailed MP-related information on the requested processor at=20 +the + instant this call is made. This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ); + +/** + Retrieves the number of logical processor in the platform and the=20 +number of + those logical processors that are enabled on this boot. This service=20 +may only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ); + +#endif diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 4a73787ee43a..de2ed8e6c294 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,9 +9,11 @@ **/ =20 #include "MpLib.h" +#include "MpIntelTdx.h" #include #include #include +#include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; =20 @@ -1803,6 +1805,10 @@ MpInitLibInitialize ( UINTN BackupBufferAddr; UINTN ApIdtBase; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_SUCCESS; + } + OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); if (OldCpuMpData =3D=3D NULL) { MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); @@ -2073,6 +2079,10 @@ MpInitLibGetProcessorInfo ( CPU_INFO_IN_HOB *CpuInfoInHob; UINTN OriginalProcessorNumber; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return TdxMpInitLibGetProcessorInfo (ProcessorNumber,=20 + ProcessorInfoBuffer, HealthData); } + CpuMpData =3D GetCpuMpData (); CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; =20 @@ -2307,6 +2317,10 @@ EnableDisableApWorker ( CPU_MP_DATA *CpuMpData; UINTN CallerNumber; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + CpuMpData =3D GetCpuMpData (); =20 // @@ -2367,6 +2381,11 @@ MpInitLibWhoAmI ( return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + *ProcessorNumber =3D 0; + return EFI_SUCCESS; + } + CpuMpData =3D GetCpuMpData (); =20 return GetProcessorNumber (CpuMpData, ProcessorNumber); @@ -2405,6 +2424= ,10 @@ MpInitLibGetNumberOfProcessors ( UINTN EnabledProcessorNumber; UINTN Index; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return TdxMpInitLibGetNumberOfProcessors (NumberOfProcessors,=20 + NumberOfEnabledProcessors); } + CpuMpData =3D GetCpuMpData (); =20 if ((NumberOfProcessors =3D=3D NULL) && (NumberOfEnabledProcessors =3D= =3D NULL)) { @@ -2490,6 +2513,10 @@ StartupAllCPUsWorker ( BOOLEAN HasEnabledAp; CPU_STATE ApState; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_SUCCESS; + } + CpuMpData =3D GetCpuMpData (); =20 if (FailedCpuList !=3D NULL) { diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c b/UefiCpuPkg/Library/M= pInitLib/MpLibTdx.c new file mode 100644 index 000000000000..175dfd9a6d32 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c @@ -0,0 +1,128 @@ +/** @file + CPU MP Initialize Library common functions. + + Copyright (c) 2016 - 2020, Intel Corporation. All rights=20 + reserved.
Copyright (c) 2020, AMD Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include "MpIntelTdx.h" +#include +#include +#include +#include + +/** + Gets detailed MP-related information on the requested processor at=20 +the + instant this call is made. This service may only be called from the BSP. + + In current stage only the BSP is workable. So ProcessorNumber should be = 0. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL or Processor= Number is not 0. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ) +{ + EFI_STATUS Status; + TD_RETURN_DATA TdReturnData; + + if ((ProcessorInfoBuffer =3D=3D NULL) || (ProcessorNumber !=3D 0)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData); ASSERT=20 + (Status =3D=3D EFI_SUCCESS); + + if (ProcessorNumber >=3D TdReturnData.TdInfo.NumVcpus) { + return EFI_NOT_FOUND; + } + + ProcessorInfoBuffer->ProcessorId =3D ProcessorNumber; =20 + ProcessorInfoBuffer->StatusFlag =3D 0; if (ProcessorNumber =3D=3D 0) { + ProcessorInfoBuffer->StatusFlag |=3D PROCESSOR_AS_BSP_BIT; } + + ProcessorInfoBuffer->StatusFlag |=3D PROCESSOR_ENABLED_BIT; + + // + // Get processor location information // =20 + GetProcessorLocationByApicId ( + (UINT32)ProcessorNumber, + &ProcessorInfoBuffer->Location.Package, + &ProcessorInfoBuffer->Location.Core, + &ProcessorInfoBuffer->Location.Thread + ); + + if (HealthData !=3D NULL) { + HealthData->Uint32 =3D 0; + } + + return Status; +} + +/** + Retrieves the number of logical processor in the platform and the=20 +number of + those logical processors that are enabled on this boot. This service=20 +may only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ) +{ + if ((NumberOfProcessors =3D=3D NULL) && (NumberOfEnabledProcessors =3D= =3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + // + // In current stage only the BSP is workable. So NumberOfProcessors =20 + // & NumberOfEnableddProcessors are both 1. + // + if (NumberOfProcessors !=3D NULL) { + *NumberOfProcessors =3D 1; + } + + if (NumberOfEnabledProcessors !=3D NULL) { + *NumberOfEnabledProcessors =3D 1; + } + + return EFI_SUCCESS; +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c b/UefiCpuPkg/Libra= ry/MpInitLib/MpLibTdxNull.c new file mode 100644 index 000000000000..2849e13f2aaa --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c @@ -0,0 +1,73 @@ +/** @file + CPU MP Initialize Library common functions. + + Copyright (c) 2016 - 2020, Intel Corporation. All rights=20 + reserved.
Copyright (c) 2020, AMD Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include "MpIntelTdx.h" +#include + +/** + Gets detailed MP-related information on the requested processor at=20 +the + instant this call is made. This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + +/** + Retrieves the number of logical processor in the platform and the=20 +number of + those logical processors that are enabled on this boot. This service=20 +may only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized= . + +**/ +EFI_STATUS +EFIAPI +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 5facf4db9499..894be0f8daab 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -24,10 +24,12 @@ [Sources.IA32] Ia32/AmdSev.c Ia32/MpFuncs.nasm + MpLibTdxNull.c =20 [Sources.X64] X64/AmdSev.c X64/MpFuncs.nasm + MpLibTdx.c =20 [Sources.common] AmdSev.c @@ -36,6 +38,7 @@ MpLib.c MpLib.h Microcode.c + MpIntelTdx.h =20 [Packages] MdePkg/MdePkg.dec -- 2.29.2.windows.2