From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 57391740035 for ; Wed, 3 Apr 2024 07:06:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=NPGpM7YwsDR8bdC8ACscaAxTkUytndHnhZvxIeRB9mA=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1712127993; v=1; b=bb/YPHJAhK1oZFraSo2pni5UouqVfp6B3cb6zE6oXtjkN0zhBKCecZ+JvI3h43mqliohhJEO uKCgXYhIGcXeS6oXkit0AlOKlnSiMCOPaB9MXGDTU+z5yZNWm8uIdWGN1Di6Io4iIAHR1bv3+UL n7mNoawbKkNy/yMBFtcylP3IdmDA0JVJ5Dw8fj8yeFN0CqqwkwzAy0cR08PqyWXFkZJyjKPZYtU RLQQWRIBJXCdg5cZNG46yJZ2A0PayU9d3fd6Vb9wg8cTjuejFqj1ITsTbvY4ZWOymUmpP+6TQW9 yALbK8honxn78RdKMIiYoNA0UJBSbV77wqNANaitjpW2Q== X-Received: by 127.0.0.2 with SMTP id obmlYY7687511xxX9NriwhsJ; Wed, 03 Apr 2024 00:06:33 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by mx.groups.io with SMTP id smtpd.web11.5388.1712127993186297100 for ; Wed, 03 Apr 2024 00:06:33 -0700 X-CSE-ConnectionGUID: uPF8hX7DQASlr8AiCrX7uQ== X-CSE-MsgGUID: ieRCsiXoQeKaJF9msz049Q== X-IronPort-AV: E=McAfee;i="6600,9927,11032"; a="7464487" X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208,217";a="7464487" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2024 00:06:32 -0700 X-CSE-ConnectionGUID: UCt69sxETGy69Mxri7rz0w== X-CSE-MsgGUID: PGUSJxEdRbmy82+D+m6nHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,176,1708416000"; d="scan'208,217";a="23040180" X-Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orviesa003.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 03 Apr 2024 00:06:33 -0700 X-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.2507.35; Wed, 3 Apr 2024 00:06:32 -0700 X-Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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.2507.35 via Frontend Transport; Wed, 3 Apr 2024 00:06:32 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.169) 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.2507.35; Wed, 3 Apr 2024 00:06:31 -0700 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by PH7PR11MB6401.namprd11.prod.outlook.com (2603:10b6:510:1fb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.23; Wed, 3 Apr 2024 07:06:23 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::2c31:82b7:9f26:5817]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::2c31:82b7:9f26:5817%5]) with mapi id 15.20.7409.031; Wed, 3 Apr 2024 07:06:23 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "thomas.lendacky@amd.com" CC: Ard Biesheuvel , "Aktas, Erdem" , Gerd Hoffmann , "Yao, Jiewen" , Laszlo Ersek , Liming Gao , "Kinney, Michael D" , "Xu, Min M" , "Liu, Zhiguang" , "Kumar, Rahul R" , Michael Roth Subject: Re: [edk2-devel] [PATCH v3 12/24] UefiCpuPkg/AmdSvsmLib: Create the AmdSvsmLib library to support an SVSM Thread-Topic: [edk2-devel] [PATCH v3 12/24] UefiCpuPkg/AmdSvsmLib: Create the AmdSvsmLib library to support an SVSM Thread-Index: AQHacW3FXtSsm9yY0kiQafTI+zh5ArFWzgib Date: Wed, 3 Apr 2024 07:06:23 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|PH7PR11MB6401:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: KZx+SsLVTMyw4bx75lFu42iYCQvQZzYT9yxxg7xtsG6r+mvwsNmSOe7CnJTfIaXpQZZ1ZjjGPGFQglt+I+YNa0UEkjxqNcHRu1ywD40Tur2cUT9pSH05y7f51hWtfyMPguuR+L5IjHX5ziNvRrx44V+adxNsms1CgU2qfmkElBOYlp1UEbG7NwV2M95X7pHLNfZpijwdEifgU9O2Wz7jvYN9Vwu7PiViW9A2A7ugbJCVTEH+Cz6kuIlYFc64Q4srIDagenPkaKRrALuvn98caGkeFuiYvTnYdL7MgdghQMTQ32OMOeNX8XJgnpBfsBOaHY/6OrcesEzX6Mu7CSoA9onC1UdriaCn947u/smCgPEFH9r+pv242EDfgZTT5NUt9wUva6KlWD8+23w1TazztFciot1GPRCXAWD0XjMtOTZooJygfiZ5nZh8Pfr9HHSES7X3kzAG+RT450ts0q3LK+mfMliIY0Q3r59uX3RIqJN3Tf1532+nKiPhRevfpyHhmyopwdT8e+vTosXpJKq5dydv9Ri5JOMH4S5rPrxlgMSM/Fuu12mqmNiieiVZVlpE7TOt9k66DTGd1FFbdizbUFle8VpIsjK/zGC90o+2iHT6BqEQU3A0owkmf1USsDFq x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?mmgiHmjavVrCAdcnjaQ/eGr8NhTcefAlZa9ug1c6GqgHurwelh5edIB5H0hG?= =?us-ascii?Q?+rlL6WBxdqAukPZHYSYvbvmN8zf+HtoPoyt8gKlRHSzeTEZg2DX2AXZURYd2?= =?us-ascii?Q?LWoYT1zFVNooWbjCKzMMaEIrdRa5oSAIcd1DD+pVmeK4TmTX4qIOV/qSz8EN?= =?us-ascii?Q?BZzQHNd7RHCwz8BOqpspJjSMziMepjFlIhIlkrJT0cRDQDRvqG/hGgkEFWGd?= =?us-ascii?Q?2kw03KojABJmfpgNSLau1OF7IYK0V5QH9olXIQufoF9hfLftTHrCdxSNvVJh?= =?us-ascii?Q?B6+lnLCmLv7RVJXg25futA9GqReQ1sfMSlxwbqtMzVzrMvmiV5zxR35YThVP?= =?us-ascii?Q?RP1H3prCQIeSZEKdOVMdV+JVL0ULAakWRU5TiGF9B6UnULt5W4ajybb2jlER?= =?us-ascii?Q?/YFbxbPrPfxjnS+lCehJCc8mY17YCcvRw6lzkIdwRhYG202rRj1/AzDgHr5u?= =?us-ascii?Q?CM0IFqOmLp7pVkwVgERzUuXTwX6rDEo2Sy+cCFDy5th9F/cLyXVm0aK8kxXV?= =?us-ascii?Q?3hQvlYXq2N74emUQmYpKbwhgRvTHRP3GIN6itx1/q7b0P8AhjFcb/YD9XA/Q?= =?us-ascii?Q?4pDLTSCV29YvwdkWXkt5NLEZHIRwlpHhyVi1j1B7Ruf1I4j1O+CdIIh9hnQh?= =?us-ascii?Q?zh90tSzmFVgn+TnnmOXM1yZu/UtjHUpBjeiRhlsukCfX8c9sjAq/iDpeZK+8?= =?us-ascii?Q?NVsTq6xDaPdUglv4KCU0eVbL76uBpQedDH+tHGoI8c1JMwsKo7CCuxwx7peg?= =?us-ascii?Q?8eooqRy6qFNwI18ro6RtEcZGgrP1DHR8mpLJFNEXEqrakE14o9vhh5TttiGY?= =?us-ascii?Q?B5sjc5HmK/qZxbfjWnkhAVO+K7Wj3SWtIvxuO1xh14raMVRJTbCSCLyftGHC?= =?us-ascii?Q?1pfFcy1eMx3YHahgzd+QI2tX7c0o4fXZgMoH45vMDmSUPOelyeOLbQwtEHXP?= =?us-ascii?Q?NweLNCwSfPpBgVw550empMnMz8pFoa/kkKbXmn/odFage4kH41S2M4pj1rEI?= =?us-ascii?Q?+AqEE7MNZaAcSefIhO9smi8NpFSimanLg2wP1tf+VJIgYlvAHrHf/qZutUzN?= =?us-ascii?Q?6sD3TGsm0aA5l58VK7IlGLNZ0ncm6rgZ+vcZILQkrb3Fv1fGpym7/prX8b45?= =?us-ascii?Q?lDRBt3n0fII0f5eBXOG4Yggt5tDrRRxsc9AdNRhn+gDv6Dh0wKBnnEtc1VSn?= =?us-ascii?Q?SuZxgCdWHFohcpWeOQc9+pGxIAOLr9dW0SHSl13rStD/Kovs9dXqVjaXzwFb?= =?us-ascii?Q?s7uGnKoJPiRSbd6j5zPMP8q1ZZAv4auymPF/EDeQmSgJi3dm1LfGajMziBwN?= =?us-ascii?Q?n0SkHA62ZiOC/RzUmbzSzmm7xeWi0xfE0LRHQrucrpHDiXOLO18pDsa2YufY?= =?us-ascii?Q?g8qowvsHIiB9xxjhuXiLTrGsVtf/+Dry4uqlL1eB3hNzMqFZb/f822PUK44H?= =?us-ascii?Q?Tvmqro4kbu0LMucfEzo6AYecC3a7cvXdB38Y6xRsjYyjRJ5jb0B519TLBXZ7?= =?us-ascii?Q?jUlWcdK9H/TVDWNApTATXeuqC+lOT6tH+sK1vu1T/N4GtERkIcLoFkyXj97i?= =?us-ascii?Q?UvC9RKljYEXPZD02q3A=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98ef5d16-e8ff-44ab-e7d0-08dc53ac9262 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Apr 2024 07:06:23.4962 (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: 8cJ5SIpj3Nj5zVMf20Kx8xR7thLLTvuI27PjT2v/6t7TfQiWyPYxZ3p1ZnOFiHL0OS3PXi1jfYzglTOSdzFGjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6401 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Wed, 03 Apr 2024 00:06:33 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DFp06sONsSgq2aLyTqpsaYFdx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB824413CC6AE8A8A637BE42728C3D2MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b="bb/YPHJA"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB824413CC6AE8A8A637BE42728C3D2MN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Acked-by: Ray Ni Thanks, Ray ________________________________ From: devel@edk2.groups.io on behalf of Lendacky, Th= omas via groups.io Sent: Friday, March 8, 2024 23:31 To: devel@edk2.groups.io Cc: Ard Biesheuvel ; Aktas, Erdem ; Gerd Hoffmann ; Yao, Jiewen ; Laszlo Ersek ; Liming Gao ; Kinney, Michael D ; Xu, Min M ; Liu, Zhiguang ; Kumar, Rahul R ; Ni, Ray ; Michael Roth Subject: [edk2-devel] [PATCH v3 12/24] UefiCpuPkg/AmdSvsmLib: Create the Am= dSvsmLib library to support an SVSM BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654 In order to support an SEV-SNP guest running under an SVSM at VMPL1 or lower, a new library must be created. This library includes an interface to detect if running under an SVSM, an interface to return the current VMPL, an interface to perform memory validation and an interface to set or clear the attribute that allows a page to be used as a VMSA. Cc: Gerd Hoffmann Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Ray Ni Acked-by: Gerd Hoffmann Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 4 +- UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf | 27 +++++ UefiCpuPkg/Include/Library/AmdSvsmLib.h | 101 +++++++++++++++= +++ UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c | 108 +++++++++++++++= +++++ UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni | 13 +++ 6 files changed, 255 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index c31d8b6736cf..d1bff93ae2e0 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -52,6 +52,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides function to support CcExit processing. CcExitLib|Include/Library/CcExitLib.h + ## @libraryclass Provides function to support AmdSvsm processing. + AmdSvsmLib|Include/Library/AmdSvsmLib.h + ## @libraryclass Provides function to get CPU cache information. CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 10b33594e586..422e50c92b48 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -2,7 +2,7 @@ # UefiCpuPkg Package # # Copyright (c) 2007 - 2023, Intel Corporation. All rights reserved.
-# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights rese= rved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -61,6 +61,7 @@ [LibraryClasses] PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezv= ousLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf @@ -159,6 +160,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf b/UefiCpu= Pkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf new file mode 100644 index 000000000000..45a189540941 --- /dev/null +++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf @@ -0,0 +1,27 @@ +## @file +# AmdSvsm Base Support Library. +# +# Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D AmdSvsmLibNull + MODULE_UNI_FILE =3D AmdSvsmLibNull.uni + FILE_GUID =3D 62b45e0f-c9b4-45ce-a5b3-41762709b3d9 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D AmdSvsmLib + +[Sources.common] + AmdSvsmLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/UefiCpuPkg/Include/Library/AmdSvsmLib.h b/UefiCpuPkg/Include/L= ibrary/AmdSvsmLib.h new file mode 100644 index 000000000000..40e0e5bd4259 --- /dev/null +++ b/UefiCpuPkg/Include/Library/AmdSvsmLib.h @@ -0,0 +1,101 @@ +/** @file + Public header file for the AmdSvsmLib. + + This library class defines some routines used for invoking an SVSM when = the + guest is not running at VMPL0. + + Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef AMD_SVSM_LIB_H_ +#define AMD_SVSM_LIB_H_ + +#include +#include + +/** + Report the presence of an Secure Virtual Services Module (SVSM). + + Determines the presence of an SVSM. + + @retval TRUE An SVSM is present + @retval FALSE An SVSM is not present + +**/ +BOOLEAN +EFIAPI +AmdSvsmIsSvsmPresent ( + VOID + ); + +/** + Report the VMPL level at which the SEV-SNP guest is running. + + Determines the VMPL level at which the guest is running. If an SVSM is + not present, then it must be VMPL0, otherwise return what is reported + by the SVSM. + + @return The VMPL level + +**/ +UINT8 +EFIAPI +AmdSvsmSnpGetVmpl ( + VOID + ); + +/** + Report the Calling Area address (CAA) for the BSP of the SEV-SNP guest. + + If an SVSM is present, the CAA for the BSP is returned. + + @return The CAA + +**/ +UINT64 +EFIAPI +AmdSvsmSnpGetCaa ( + VOID + ); + +/** + Perform a PVALIDATE operation for the page ranges specified. + + Validate or rescind the validation of the specified pages. + + @param[in] Info Pointer to a page state change structure + +**/ +VOID +EFIAPI +AmdSvsmSnpPvalidate ( + IN SNP_PAGE_STATE_CHANGE_INFO *Info + ); + +/** + Perform an RMPADJUST operation to alter the VMSA setting of a page. + + Add or remove the VMSA attribute for a page. + + @param[in] Vmsa Pointer to an SEV-ES save area page + @param[in] ApicId APIC ID associated with the VMSA + @param[in] SetVmsa Boolean indicator as to whether to set o= r + or clear the VMSA setting for the page + + @retval EFI_SUCCESS RMPADJUST operation successful + @retval EFI_UNSUPPORTED Operation is not supported + @retval EFI_INVALID_PARAMETER RMPADJUST operation failed, an invalid + parameter was supplied + +**/ +EFI_STATUS +EFIAPI +AmdSvsmSnpVmsaRmpAdjust ( + IN SEV_ES_SAVE_AREA *Vmsa, + IN UINT32 ApicId, + IN BOOLEAN SetVmsa + ); + +#endif diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c b/UefiCpuPk= g/Library/AmdSvsmLibNull/AmdSvsmLibNull.c new file mode 100644 index 000000000000..a83fcbd6ce7b --- /dev/null +++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c @@ -0,0 +1,108 @@ +/** @file + AmdSvsm Base Support Library. + + Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Report the presence of an Secure Virtual Services Module (SVSM). + + Determines the presence of an SVSM. + + @retval TRUE An SVSM is present + @retval FALSE An SVSM is not present + +**/ +BOOLEAN +EFIAPI +AmdSvsmIsSvsmPresent ( + VOID + ) +{ + return FALSE; +} + +/** + Report the VMPL level at which the SEV-SNP guest is running. + + Determines the VMPL level at which the guest is running. If an SVSM is + not present, then it must be VMPL0, otherwise return what is reported + by the SVSM. + + @return The VMPL level + +**/ +UINT8 +EFIAPI +AmdSvsmSnpGetVmpl ( + VOID + ) +{ + return 0; +} + +/** + Report the Calling Area address (CAA) for the BSP of the SEV-SNP guest. + + If an SVSM is present, the CAA for the BSP is returned. + + @return The CAA + +**/ +UINT64 +EFIAPI +AmdSvsmSnpGetCaa ( + VOID + ) +{ + return 0; +} + +/** + Perform a PVALIDATE operation for the page ranges specified. + + Validate or rescind the validation of the specified pages. + + @param[in] Info Pointer to a page state change structure + +**/ +VOID +EFIAPI +AmdSvsmSnpPvalidate ( + IN SNP_PAGE_STATE_CHANGE_INFO *Info + ) +{ +} + +/** + Perform an RMPADJUST operation to alter the VMSA setting of a page. + + Add or remove the VMSA attribute for a page. + + @param[in] Vmsa Pointer to an SEV-ES save area page + @param[in] ApicId APIC ID associated with the VMSA + @param[in] SetVmsa Boolean indicator as to whether to set o= r + or clear the VMSA setting for the page + + @retval EFI_SUCCESS RMPADJUST operation successful + @retval EFI_UNSUPPORTED Operation is not supported + @retval EFI_INVALID_PARAMETER RMPADJUST operation failed, an invalid + parameter was supplied + +**/ +EFI_STATUS +EFIAPI +AmdSvsmSnpVmsaRmpAdjust ( + IN SEV_ES_SAVE_AREA *Vmsa, + IN UINT32 ApicId, + IN BOOLEAN SetVmsa + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni b/UefiCpu= Pkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni new file mode 100644 index 000000000000..5e998030de5b --- /dev/null +++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni @@ -0,0 +1,13 @@ +// /** @file +// AmdSvsmLib instance. +// +// Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "AmdSvsmLib NULL i= nstance" + +#string STR_MODULE_DESCRIPTION #language en-US "AmdSvsmLib NULL i= nstance." + -- 2.43.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 (#117344): https://edk2.groups.io/g/devel/message/117344 Mute This Topic: https://groups.io/mt/104810717/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB824413CC6AE8A8A637BE42728C3D2MN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Acked-by: Ray Ni <ray.ni@intel.com>

Thanks,
Ray

From: devel@edk2.groups.io = <devel@edk2.groups.io> on behalf of Lendacky, Thomas via groups.io &l= t;thomas.lendacky=3Damd.com@groups.io>
Sent: Friday, March 8, 2024 23:31
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Aktas, Erdem &= lt;erdemaktas@google.com>; Gerd Hoffmann <kraxel@redhat.com>; Yao,= Jiewen <jiewen.yao@intel.com>; Laszlo Ersek <lersek@redhat.com>= ;; Liming Gao <gaoliming@byosoft.com.cn>; Kinney, Michael D <micha= el.d.kinney@intel.com>; Xu, Min M <min.m.xu@intel.com>; Liu, Zhiguang <zhiguang.liu@intel= .com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Ni, Ray <ray.n= i@intel.com>; Michael Roth <michael.roth@amd.com>
Subject: [edk2-devel] [PATCH v3 12/24] UefiCpuPkg/AmdSvsmLib: Create= the AmdSvsmLib library to support an SVSM
 
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654

In order to support an SEV-SNP guest running under an SVSM at VMPL1 or
lower, a new library must be created.

This library includes an interface to detect if running under an SVSM, an interface to return the current VMPL, an interface to perform memory
validation and an interface to set or clear the attribute that allows a
page to be used as a VMSA.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 UefiCpuPkg/UefiCpuPkg.dec       &n= bsp;            = ;        |   3 +
 UefiCpuPkg/UefiCpuPkg.dsc       &n= bsp;            = ;        |   4 +-
 UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf |  27 +++++=
 UefiCpuPkg/Include/Library/AmdSvsmLib.h     =          | 101 ++++++++++++++++++  UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c   | 108 = ++++++++++++++++++++
 UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni |  13 +++  6 files changed, 255 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index c31d8b6736cf..d1bff93ae2e0 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -52,6 +52,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   ##  @libraryclass  Provides function to support CcEx= it processing.
   CcExitLib|Include/Library/CcExitLib.h
 
+  ##  @libraryclass  Provides function to support AmdSvsm p= rocessing.
+  AmdSvsmLib|Include/Library/AmdSvsmLib.h
+
   ##  @libraryclass  Provides function to get CPU cach= e information.
   CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h
 
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 10b33594e586..422e50c92b48 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -2,7 +2,7 @@
 #  UefiCpuPkg Package
 #
 #  Copyright (c) 2007 - 2023, Intel Corporation. All rights rese= rved.<BR>
-#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserve= d.<BR>
+#  Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights= reserved.<BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -61,6 +61,7 @@ [LibraryClasses]
   PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNu= ll/BasePeCoffExtraActionLibNull.inf
   TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/T= pmMeasurementLibNull.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf +  AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf
   MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf<= br>    SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/Smm= CpuRendezvousLib.inf
   CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTabl= eLib.inf
@@ -159,6 +160,7 @@ [Components.IA32, Components.X64]
   UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLi= b.inf
   UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf
   UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
   UefiCpuPkg/SecCore/SecCore.inf
diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf b/UefiCpu= Pkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf
new file mode 100644
index 000000000000..45a189540941
--- /dev/null
+++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf
@@ -0,0 +1,27 @@
+## @file
+#  AmdSvsm Base Support Library.
+#
+#  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserv= ed.<BR>
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION         &n= bsp;          =3D 1.29
+  BASE_NAME         &nbs= p;            =3D Am= dSvsmLibNull
+  MODULE_UNI_FILE        &nbs= p;       =3D AmdSvsmLibNull.uni
+  FILE_GUID         &nbs= p;            =3D 62= b45e0f-c9b4-45ce-a5b3-41762709b3d9
+  MODULE_TYPE         &n= bsp;          =3D BASE
+  VERSION_STRING         = ;        =3D 1.0
+  LIBRARY_CLASS         =          =3D AmdSvsmLib
+
+[Sources.common]
+  AmdSvsmLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+
diff --git a/UefiCpuPkg/Include/Library/AmdSvsmLib.h b/UefiCpuPkg/Include/L= ibrary/AmdSvsmLib.h
new file mode 100644
index 000000000000..40e0e5bd4259
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/AmdSvsmLib.h
@@ -0,0 +1,101 @@
+/** @file
+  Public header file for the AmdSvsmLib.
+
+  This library class defines some routines used for invoking an SVSM = when the
+  guest is not running at VMPL0.
+
+  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserve= d.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef AMD_SVSM_LIB_H_
+#define AMD_SVSM_LIB_H_
+
+#include <Protocol/DebugSupport.h>
+#include <Register/Amd/Ghcb.h>
+
+/**
+  Report the presence of an Secure Virtual Services Module (SVSM). +
+  Determines the presence of an SVSM.
+
+  @retval  TRUE        &= nbsp;          An SVSM is pres= ent
+  @retval  FALSE        =           An SVSM is not prese= nt
+
+**/
+BOOLEAN
+EFIAPI
+AmdSvsmIsSvsmPresent (
+  VOID
+  );
+
+/**
+  Report the VMPL level at which the SEV-SNP guest is running.
+
+  Determines the VMPL level at which the guest is running. If an SVSM= is
+  not present, then it must be VMPL0, otherwise return what is report= ed
+  by the SVSM.
+
+  @return          =             &nb= sp;  The VMPL level
+
+**/
+UINT8
+EFIAPI
+AmdSvsmSnpGetVmpl (
+  VOID
+  );
+
+/**
+  Report the Calling Area address (CAA) for the BSP of the SEV-SNP gu= est.
+
+  If an SVSM is present, the CAA for the BSP is returned.
+
+  @return          =             &nb= sp;  The CAA
+
+**/
+UINT64
+EFIAPI
+AmdSvsmSnpGetCaa (
+  VOID
+  );
+
+/**
+  Perform a PVALIDATE operation for the page ranges specified.
+
+  Validate or rescind the validation of the specified pages.
+
+  @param[in]       Info  &nbs= p;        Pointer to a page state change= structure
+
+**/
+VOID
+EFIAPI
+AmdSvsmSnpPvalidate (
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  );
+
+/**
+  Perform an RMPADJUST operation to alter the VMSA setting of a page.=
+
+  Add or remove the VMSA attribute for a page.
+
+  @param[in]       Vmsa  &nbs= p;        Pointer to an SEV-ES save area= page
+  @param[in]       ApicId  &n= bsp;      APIC ID associated with the VMSA
+  @param[in]       SetVmsa  &= nbsp;     Boolean indicator as to whether to set or
+            &n= bsp;            = ;         or clear the VMSA setting= for the page
+
+  @retval  EFI_SUCCESS       =      RMPADJUST operation successful
+  @retval  EFI_UNSUPPORTED      &n= bsp; Operation is not supported
+  @retval  EFI_INVALID_PARAMETER  RMPADJUST operation faile= d, an invalid
+            &n= bsp;            = ;         parameter was supplied +
+**/
+EFI_STATUS
+EFIAPI
+AmdSvsmSnpVmsaRmpAdjust (
+  IN SEV_ES_SAVE_AREA  *Vmsa,
+  IN UINT32         &nbs= p;  ApicId,
+  IN BOOLEAN         &nb= sp; SetVmsa
+  );
+
+#endif
diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c b/UefiCpuPk= g/Library/AmdSvsmLibNull/AmdSvsmLibNull.c
new file mode 100644
index 000000000000..a83fcbd6ce7b
--- /dev/null
+++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c
@@ -0,0 +1,108 @@
+/** @file
+  AmdSvsm Base Support Library.
+
+  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserve= d.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/AmdSvsmLib.h>
+
+/**
+  Report the presence of an Secure Virtual Services Module (SVSM). +
+  Determines the presence of an SVSM.
+
+  @retval  TRUE        &= nbsp;          An SVSM is pres= ent
+  @retval  FALSE        =           An SVSM is not prese= nt
+
+**/
+BOOLEAN
+EFIAPI
+AmdSvsmIsSvsmPresent (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Report the VMPL level at which the SEV-SNP guest is running.
+
+  Determines the VMPL level at which the guest is running. If an SVSM= is
+  not present, then it must be VMPL0, otherwise return what is report= ed
+  by the SVSM.
+
+  @return          =             &nb= sp;  The VMPL level
+
+**/
+UINT8
+EFIAPI
+AmdSvsmSnpGetVmpl (
+  VOID
+  )
+{
+  return 0;
+}
+
+/**
+  Report the Calling Area address (CAA) for the BSP of the SEV-SNP gu= est.
+
+  If an SVSM is present, the CAA for the BSP is returned.
+
+  @return          =             &nb= sp;  The CAA
+
+**/
+UINT64
+EFIAPI
+AmdSvsmSnpGetCaa (
+  VOID
+  )
+{
+  return 0;
+}
+
+/**
+  Perform a PVALIDATE operation for the page ranges specified.
+
+  Validate or rescind the validation of the specified pages.
+
+  @param[in]       Info  &nbs= p;        Pointer to a page state change= structure
+
+**/
+VOID
+EFIAPI
+AmdSvsmSnpPvalidate (
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  )
+{
+}
+
+/**
+  Perform an RMPADJUST operation to alter the VMSA setting of a page.=
+
+  Add or remove the VMSA attribute for a page.
+
+  @param[in]       Vmsa  &nbs= p;        Pointer to an SEV-ES save area= page
+  @param[in]       ApicId  &n= bsp;      APIC ID associated with the VMSA
+  @param[in]       SetVmsa  &= nbsp;     Boolean indicator as to whether to set or
+            &n= bsp;            = ;         or clear the VMSA setting= for the page
+
+  @retval  EFI_SUCCESS       =      RMPADJUST operation successful
+  @retval  EFI_UNSUPPORTED      &n= bsp; Operation is not supported
+  @retval  EFI_INVALID_PARAMETER  RMPADJUST operation faile= d, an invalid
+            &n= bsp;            = ;         parameter was supplied +
+**/
+EFI_STATUS
+EFIAPI
+AmdSvsmSnpVmsaRmpAdjust (
+  IN SEV_ES_SAVE_AREA  *Vmsa,
+  IN UINT32         &nbs= p;  ApicId,
+  IN BOOLEAN         &nb= sp; SetVmsa
+  )
+{
+  return EFI_UNSUPPORTED;
+}
diff --git a/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni b/UefiCpu= Pkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni
new file mode 100644
index 000000000000..5e998030de5b
--- /dev/null
+++ b/UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni
@@ -0,0 +1,13 @@
+// /** @file
+// AmdSvsmLib instance.
+//
+// Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.&l= t;BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT        = ;     #language en-US "AmdSvsmLib NULL instance&qu= ot;
+
+#string STR_MODULE_DESCRIPTION       &n= bsp;  #language en-US "AmdSvsmLib NULL instance."
+
--
2.43.2






_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#117344) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB824413CC6AE8A8A637BE42728C3D2MN6PR11MB8244namp_--