From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.5924.1648430414825617825 for ; Sun, 27 Mar 2022 18:20:15 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=X/E6tIET; spf=pass (domain: intel.com, ip: 192.55.52.151, 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=1648430414; x=1679966414; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Rh9OFZ7yEAbh5oOdNHWEraGbgO5IynMQ1OHgtTYptIs=; b=X/E6tIETKMYn5n6p9xIIs9ljisD10uwz2X0OG+85tZmfnOYgF9WpFOGb MWLXjSL06Kkm7CXifiZs/jUVkf4FvDiVz7mJ11L4ykChvkZZhvl5qmejn pjgdkJPmTk3LtHaKMv3opvNkkkcOf45rePTpIvgevwALWDvulUysxLv+G NDvTB+Eqm3n0OM/nGG1wdc05HVdc18ggj719DK5z+VKakC0Hogazpb6Fd mGyRgxHk1LqAiYeMc71Em6+pKApTFtlmeW2GkeyTRDH5/WDNEw0Fo2v8+ 2ArsWk+leaY1sXZ9+4nnNX2Oi1g8AojxVGbDhNub7YOUIG6bDMd92i8nS g==; X-IronPort-AV: E=McAfee;i="6200,9189,10299"; a="239486169" X-IronPort-AV: E=Sophos;i="5.90,216,1643702400"; d="scan'208";a="239486169" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2022 18:20:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,216,1643702400"; d="scan'208";a="787055199" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga006.fm.intel.com with ESMTP; 27 Mar 2022 18:20:13 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Sun, 27 Mar 2022 18:20:13 -0700 Received: from orsmsx604.amr.corp.intel.com (10.22.229.17) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Sun, 27 Mar 2022 18:20:12 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Sun, 27 Mar 2022 18:20:12 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.108) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Sun, 27 Mar 2022 18:20:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OcfgMFVOTxxoZBfN5OuRdZASZejpvCJBUR/r480JXQsLMPHaQC2fg4Bcw6NSrbGlaSYrrOu/bWdoqJOe+/HlLdXH3p4jP7eIje6jvx4eT/xZXI6eoLGFmkqd0kMQwPwsy0CXp3oja4BUot3CCINY5Teen+Uy59YuclHaaIoQmsWNEKQoKLsCYj799qC/6dKMvU97D5VB4pkpW+osNQrrloHmbeb6JaLNh7BD+/9Bfkkc5FB7JVu4b8g9uEdn5rAeHiE1u9Kvzcjd8VmWmJlZknPwZzUM32vvs1rfBSgTO92herhC1yo8rUrN345X1+uwOzhoxSR9XpawgVibjhel9g== 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=Zu6w/fpNZ6XCY/PmXdtpxJRttd29p2iTwbwQHmgIyew=; b=mgKQTL5AwDmHf8tkV0heUA/Ba6iYTVVTKoD7J2oOlY39XGChiWnKotXGMlH25Q9zjbau2px+bSRXHshd0IH0ETPII9HlBF70XLgyVMzsYAu8r69KutHMgIEV6N5Z/t7pXeQhQKeGqVyprmB2AYhSunjP0SBpOH+UlONZU/n6f12HraK++ycXtoKX9WG/qLT0KDCDnnQ2/96sU8E4jwg6oEk257JJTkREi423p2ph4l1UoHYPPujHphnJgGd5LzZHdxK9YUQ5UQs0tCz8VCxdWqxD3QUzEWLJMufo/Twz7g9et+AqqxCRwqZTmuUP92EJLHjRac1ytQyn8D6oOOqMCg== 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 MW4PR11MB5912.namprd11.prod.outlook.com (2603:10b6:303:18a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18; Mon, 28 Mar 2022 01:20:10 +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.5102.022; Mon, 28 Mar 2022 01:20:10 +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 V10 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib Thread-Topic: [PATCH V10 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib Thread-Index: AQHYPxO9YINCWnY4Hku6OXCLzhjBk6zUAlAA Date: Mon, 28 Mar 2022 01:20:10 +0000 Message-ID: References: <20220324001033.1169-1-min.m.xu@intel.com> <20220324001033.1169-15-min.m.xu@intel.com> In-Reply-To: <20220324001033.1169-15-min.m.xu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: 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: a2504762-662f-45d3-e711-08da10591a46 x-ms-traffictypediagnostic: MW4PR11MB5912: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: Pd1Kr+8sev5oFndV9Fse2bP6wE/vvmCBnQi/z6HnWqdhDZBimQ7Jo33aqmBCb6MWVauI645TY6V8JOM1jpty8+I066HDGivbLDI8wRB+M4EAwIF8/kGecyPVpQX0EA2P1yqGdPjasz3J26fNy990sc+nsf/D+SXlGQTzJQuP6iDhol5OjKKGRmE4fYBX6rSjjhnNCjHq4blLVFroAc4yNWM6GrubHzBYRKeCiAIb6R19Nndj06xna+BKbrAcdH7r+loa7+88K4polTxYuNn+cHdWvWM4IslW5fyhc2xubXUL4TEoaGBhTIDxHDX0HV5Jre7oLmHQVK5+D4vUOBazGi+wFz9DO27MtdwG9lkbxhkmA8VZpr9tBOoN9AG/jlVDqEJNnCqytav2XX+cu2oHp/X96Tea6+6+9oymix+SkBVtJeJu58v1LfjrUTWSOvCtEeiIZnhxxceEMgNmiaQiw+0TRVyY0a+gHPmZ56pWVeKqF8fZoqSeNcKbkGfN2vgy95K3hWxmjXwHq6MylAEAlqEs6nSMIk1T90/7KHvkuCTBlZJ8oIQhb1BHJG00X16n10zvxsQGqr6J3nDzoXiqHJOtK8tUDqXrjHcuWSDDnlelgS8lLBK0P+xuWoNJIWA3zHI3e2u7E0Yer78aE6aYBZUKf9F437KHsL5GrYyUfFLVgnF4FMgIxJN0k0Q60FVLxJd+IVABAvDjhz6QCi/a/vKtZrQoGpFdWl9q0C9o72EaY/V1WCofcCmeKAJeZsd5JUkPabo53L1fpuUJzK9AfxXa6U6HmNl2XCdxTUu0zm4= 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)(66476007)(82960400001)(110136005)(54906003)(9686003)(8936002)(52536014)(966005)(7696005)(8676002)(86362001)(122000001)(71200400001)(33656002)(6506007)(76116006)(66446008)(508600001)(4326008)(64756008)(66946007)(5660300002)(53546011)(2906002)(83380400001)(38100700002)(38070700005)(55016003)(30864003)(186003)(316002)(26005)(66556008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?jkZ9mpTJDvsVeelJyxXZm3hYS9PdNUO00c0TF8VNiti+aAmcsk3b0SKC4FKf?= =?us-ascii?Q?OurMBo3q2yOvGd/bd9EhMbr7gGXZsPjP9uvpO4NCT5mbt5ZNWhgzvP4B/eC+?= =?us-ascii?Q?X34KqXsANFJKaaaQ8rTr7V01AlDpAyMlYqWHCsDtvYTQpP34btX0ElV02CIC?= =?us-ascii?Q?dz2afSMyH3EIAqqiprAJ3bz1f5/M01jczL/nE/jIv/qaDZnD0pZV9clW4sZ3?= =?us-ascii?Q?eysJnkEjebN4Bkv4AHsb5Sv2Q5lGHEnbqTskbHKpdt2LdBbDgb/R9XO/Lg5M?= =?us-ascii?Q?nREb6mP60nOMSElanm3k4U1i1IG1myeJXvd4E3jX3/wsGNNWYdYaWeFUG8um?= =?us-ascii?Q?TaKT0ApX/Mu1yGhQIIxyjKxFlQh8RMy2dtjPlHsjIQcWnEbuhbxaNioUganT?= =?us-ascii?Q?ODYl69aIeVhLfl0367cyIT5IRumj133DiAJl2YUoIaJZXKma2eWwC1SFi0Ph?= =?us-ascii?Q?tjBrq0B6bVwbtCEve2u1e5hyL/5lQcSuhb1ea0/xN+v40Yxw4OZkaIE4oMX0?= =?us-ascii?Q?1yzih5YiD4FTvad3H88DPR7F7Ityrnc7IZwFJVDijAbfokLzgHw2qB5aHr+d?= =?us-ascii?Q?1q1t64dqWnGjzfDW37+WjeZBdjRpHCA/HCDNZSgv/QpoqHP8o0gfqbgSsxyj?= =?us-ascii?Q?CbfWPDGUXYWclRfNICp1gSHamhulgKLKkXYxwsSj7dN5u7auK4YGBZBKgvy5?= =?us-ascii?Q?69lvxVreorofqWDJlgk3NkzWOvZ/jxJTS6D5JBdllL7rrXU5dN22NXC6oYoV?= =?us-ascii?Q?Ktw4ZkrwI46xl3YbADKjtrWl16u7zonBAYqLXh3gSkEOprz7CNnNKjdgJicG?= =?us-ascii?Q?fstpcBm+nG2ckXuFlFWf0nhXQ8k2CiHBYu8z2+MdfGrx8h/Nt9Fh13NGrTFF?= =?us-ascii?Q?10fuAXRYUqxxWycmG81g3nrxOfRXq/ZmXBDPoFQe7PkHshzzdrkOc5KFpMhU?= =?us-ascii?Q?AyBcqsjCPePscOpozEBCUKUuLYVfTky6AjT2nWqHM4kXMVfrLkYVNqJ77knk?= =?us-ascii?Q?7cLHVmOMVH5hKH+IVto9Ubq1PgXm6N6CA0UTlYYLXX+dIhf7lW2d3d36hb5E?= =?us-ascii?Q?rQD0HzF7/aKQWNG4+Of7HT9fSlZnnI3GBPtDBjI8nYkdlIVTIE5TSc0fO81Y?= =?us-ascii?Q?oHcuYOBxaI3rWVJk/FhTvX+9rq21/t5gdX57ettR8xhvSNwjoorO2iyxelzy?= =?us-ascii?Q?ZCFjdTs+tPVDD6ZQJtyQyuhsLfHufvkblaKMhSkMGjCJfWW+XG8gqY+mCpW9?= =?us-ascii?Q?qDnf12kRk4nVTuEs2VI7GLojrLuqJy36Tyi+fEXsnDNiKPNKuNhfQdJu482d?= =?us-ascii?Q?9UgFZXeDTA8ALMjBGYQO7yvM22wMrC00L51IRSazvbwLShXiHIiDKTbzEGOT?= =?us-ascii?Q?z69kJJpB4UedzKYn9JxrkGnu1z994SatArFGcTzVQZXXpoaPKwzjR7+NIhzs?= =?us-ascii?Q?WJDWWL7OjLev9G7npMuwj846iC4xYY9WQj6GQqHS0E/pFkrGRoOSl1DCJ/4k?= =?us-ascii?Q?Bxo7ULEkrTgVMz3Z5cNw8HuY9/sPkT/9qRqQQ9DEN5wSIWTX2lIvitRSH449?= =?us-ascii?Q?vLyQWhe3nT2+6xH+5Tfulbo/aRYv3P9xAuqzrGW60y8/Ux6GtL541GZ/pPYU?= =?us-ascii?Q?pVrQFGg/gcCNe06DBDXyHBztIQpNJZ+MsvYwAQFaaTgnAbB+o0EmZqHHqk/y?= =?us-ascii?Q?r/HUNzPFxuWlrSY6CxLXSVPB25PyV/ztHdy6182GjyRX+5km?= 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: a2504762-662f-45d3-e711-08da10591a46 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2022 01:20:10.3772 (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: 8mzPXlRrXl/HxEXRoELh6QzOcd9f7Dg7h9Iw2iM8oT8c30W+CLt9sfoub5FHttFol83XajJzXmrP+Nyr6c1W4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5912 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 All look good! 3 minor comments: 1. DxeMpLib.c may not need to include MpIntelTdx.h 2. You may use "ASSERT (!ExcludeBsp)" in below code. Otherwise, it may conf= use reader that when ExcludeBsp is TRUE, SUCCESS is returned when Processor= Count is 1 which is not right. if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { if (!ExcludeBsp) { // // Start BSP. // Procedure (ProcedureArgument); } return EFI_SUCCESS; } 3. TdxMpInitLibGetProcessorInfo may not need to call GetProcessorLocationBy= ApicId. You can directly set Package/Core/Thread to 0. -----Original Message----- From: Xu, Min M =20 Sent: Thursday, March 24, 2022 8:10 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 V10 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 | 2 +- UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h | 71 ++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 60 ++++++++- UefiCpuPkg/Library/MpInitLib/MpLibTdx.c | 125 ++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c | 73 ++++++++++ UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + 7 files changed, 331 insertions(+), 6 deletions(-) create mode 100644 Uef= iCpuPkg/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..1b2b937e1c8e 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,7 +16,6 @@ #include #include #include - #include =20 #define AP_SAFE_STACK_SIZE 128 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..469dda256b8b 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 @@ -2167,6 +2177,10 @@ SwitchBSPWorker ( BOOLEAN OldInterruptState; BOOLEAN OldTimerInterruptState; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + // // Save and Disable Local APIC timer interrupt // @@ -2307,6 +2321,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 +2385,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,12 +242= 8,16 @@ MpInitLibGetNumberOfProcessors ( UINTN EnabledProcessorNumber; UINTN Index; =20 - CpuMpData =3D GetCpuMpData (); - if ((NumberOfProcessors =3D=3D NULL) && (NumberOfEnabledProcessors =3D= =3D NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return TdxMpInitLibGetNumberOfProcessors (NumberOfProcessors,=20 + NumberOfEnabledProcessors); } + + CpuMpData =3D GetCpuMpData (); + // // Check whether caller processor is BSP // @@ -2490,13 +2517,16 @@ StartupAllCPUsWorker ( BOOLEAN HasEnabledAp; CPU_STATE ApState; =20 - CpuMpData =3D GetCpuMpData (); - if (FailedCpuList !=3D NULL) { *FailedCpuList =3D NULL; } =20 - if ((CpuMpData->CpuCount =3D=3D 1) && ExcludeBsp) { + Status =3D MpInitLibGetNumberOfProcessors (&ProcessorCount, NULL); if=20 + (EFI_ERROR (Status)) { + return Status; + } + + if ((ProcessorCount =3D=3D 1) && ExcludeBsp) { return EFI_NOT_STARTED; } =20 @@ -2504,6 +2534,19 @@ StartupAllCPUsWorker ( return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + if (!ExcludeBsp) { + // + // Start BSP. + // + Procedure (ProcedureArgument); + } + + return EFI_SUCCESS; + } + + CpuMpData =3D GetCpuMpData (); + // // Check whether caller processor is BSP // @@ -2643,6 +2686,13 @@ StartupThisAPWorker ( CPU_AP_DATA *CpuData; UINTN CallerNumber; =20 + // + // In Td guest, startup of AP is not supported in current stage. + // + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + CpuMpData =3D GetCpuMpData (); =20 if (Finished !=3D NULL) { diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c b/UefiCpuPkg/Library/M= pInitLib/MpLibTdx.c new file mode 100644 index 000000000000..1a8d7d6dab64 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c @@ -0,0 +1,125 @@ +/** @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 + ) +{ + ASSERT (NumberOfProcessors !=3D NULL || NumberOfEnabledProcessors !=3D=20 +NULL); + // + // In current stage only the BSP is workable. So NumberOfProcessors + // & 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