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 3192D7803DA for ; Thu, 22 Feb 2024 17:31:46 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=8UShA4pyyJtN6MhUEb4SN1Ty1rJlmwqGhX5BsX7Gqp4=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1708623104; v=1; b=dy2X/KXMQ3spmzvMM0/pBidDkEkCFBczemoPV/qljUnzevnMzKhZsVhMgE4TH2k4Kb3OYRTZ 7RS/PwRCdxLCO8fU9rNLt3ttRHdqCyeNufiZeb/KZeYP1RqHkI4dxrnKQK6BUgdirGU2SBg3cu5 1Ti75VO3q0S8LA2MV5kG5sUQ= X-Received: by 127.0.0.2 with SMTP id TPeYYY7687511xz1jzJH2mCR; Thu, 22 Feb 2024 09:31:44 -0800 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.43]) by mx.groups.io with SMTP id smtpd.web10.19120.1708623104246382399 for ; Thu, 22 Feb 2024 09:31:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NTWf4RkSe8dZkWPjDAsRrulKtxwpNZXalb/CgtyLr5DYhtRNb+BrtNve8XVudUY0u9D+uYNdlKf42KKg0aCDsJ/QZpg8/2KDv2lKkLuT9j0Nd9XEl+hIst/ZOyLQ2bJMMeEg5/gZL+lvuEjNrTI929MXqBBYaVrr1AQZU1humENWxpQLYPJFkKZEpzIcKJiusYN60ZUCwzs4yhhhDKDATlrldkAJ0XNPuHFGfguU2LFR3mGVJKiSAcVrJ9slEeEP67hHYDcxzlXRQVcZpUHiz4Afqs2bzAqLgGGfK4ld0M/+ABQXUEan4RdgGXE/rlwLYFE+5KiL1w8/R0aDDACj7w== 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=4xxG7q1KGOK3d+q0j06lXBQ/4K/NViIp0fEqMEbtrkI=; b=HF/lo+GSiMD5lPj8nGfFOO1oORjv4uOI0aRPV2oXCamt0BtalWUG/GQ+s/1VOKDzg/Pg7bN2jZRDn2xH67d0nNcC/WHrxpbyFOUSrOZLnIXbpd/ahDzCdL/Vh6maI3TCp7GovwH3L1JbZYikm/U8pf4eTGa6c6zwwMA57NkvXw3OfRfefqz4+BFAvq+a+xeVBRjiZ0vEnPb2Ja9/MDq60B+tyX9e2n7n/wj0Gwa2/gfJSpSef75/EzV+sEkSU0gDTNl/08AzS6Sm8opWtuaJ4rbo/8mkGB8c+WdD/AQxWsAOZrlw/4q6qT/rSgtNmZNfbvrM3zVpFwI2SMcyJNYc6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from BN9PR03CA0662.namprd03.prod.outlook.com (2603:10b6:408:10e::7) by MN6PR12MB8470.namprd12.prod.outlook.com (2603:10b6:208:46d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.20; Thu, 22 Feb 2024 17:31:38 +0000 X-Received: from BN2PEPF000044AB.namprd04.prod.outlook.com (2603:10b6:408:10e:cafe::12) by BN9PR03CA0662.outlook.office365.com (2603:10b6:408:10e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.42 via Frontend Transport; Thu, 22 Feb 2024 17:31:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF000044AB.mail.protection.outlook.com (10.167.243.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Thu, 22 Feb 2024 17:31:38 +0000 X-Received: from tlendack-t1.amdoffice.net (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 22 Feb 2024 11:31:37 -0600 From: "Lendacky, Thomas via groups.io" To: CC: Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann , Jiewen Yao , Laszlo Ersek , Liming Gao , Michael D Kinney , Min Xu , Zhiguang Liu , "Rahul Kumar" , Ray Ni , Michael Roth Subject: [edk2-devel] [PATCH v2 12/23] UefiCpuPkg/CcSvsmLib: Create the CcSvsmLib library to support an SVSM Date: Thu, 22 Feb 2024 11:29:51 -0600 Message-ID: <2bba1fe3921bab6830cfebd405ce166a337276b9.1708623001.git.thomas.lendacky@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044AB:EE_|MN6PR12MB8470:EE_ X-MS-Office365-Filtering-Correlation-Id: 05a8f0d1-5902-4e64-bf25-08dc33cc1fed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 3LQbPLW4ROgKaXm54m71qWNtmC8P55hyniwsOaAqrb85fqbgXYmre1NM5jkbHkFI4vplk8r2vbi8sGxwIey8WsYM6onigE1CfZTeAo7/mOFW1c96azkAT8aNQ5mtFJSd0Jxsxp0LhDAifF4Pu3/igzViGiMDC4CMrYfSp8RKa6QIrDNsFbJJYEBm+qCjCLkKRDqW6F3ZEBuhxjFLmNGnL2MeFNd0vDDFcmircLC0BMWS5OqvkgHLDGZD1uJThjEXj5HWbUHsiYSIJzwVRLmIlQNgtevgdPBlIdVrp52BO81w16Db7k2ZwbMvX2rV2Mo1YsXzJ4in9ysYpxJJWvxKhGVsDScz6aTlBv44RMEChgCzQMGksd5v0rDZGLMfeF3M6rJGBCiqv17u5I6h7d2ICyVXszTKeuDYGs5DaZ/bp/48VSx2C1Ib7k28eQFn3k2FMlqUd1yn+qWZWCa5t6LNxepCK/x63+FRJGjvz6PyaPNTJCPP9ZokGlK2hMqZBtvZ3pYLm8Eui2DxyKQwngEq7oMzxnLCLM5LxsrW6wQKQwp+it7kM6uZpZa+oXn4KCY45v32qNDS6RxEHMbIKo4Hs1xkuUZgzxtCGk8zFTW8C2vQRIwhstdBIt3xVHnm++/MtgnPOEtYBSzcKKE4ltFvVQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2024 17:31:38.1474 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05a8f0d1-5902-4e64-bf25-08dc33cc1fed X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044AB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8470 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 Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 9zeKZ3H4sPdNCGENuK8qoc2Cx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="dy2X/KXM"; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 CcSvsmLib 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. Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 5 +- UefiCpuPkg/UefiCpuPkg.dsc | 4 +- UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf | 27 +++++ UefiCpuPkg/Include/Library/CcSvsmLib.h | 101 +++++++++++++++++= + UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.c | 108 +++++++++++++++++= +++ UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.uni | 13 +++ 6 files changed, 256 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 571b59b36f0a..4a383c6d1d4d 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -2,7 +2,7 @@ # This Package provides UEFI compatible CPU modules and libraries. # # 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 reser= ved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -52,6 +52,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides function to support CcExit processing. CcExitLib|Include/Library/CcExitLib.h =20 + ## @libraryclass Provides function to support CcSvsm processing. + CcSvsmLib|Include/Library/CcSvsmLib.h + ## @libraryclass Provides function to get CPU cache information. CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h =20 diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 10b33594e586..1ee726e6c6b5 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 + CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.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/CcSvsmLibNull/CcSvsmLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf b/UefiCpuPk= g/Library/CcSvsmLibNull/CcSvsmLibNull.inf new file mode 100644 index 000000000000..b45a75941a8a --- /dev/null +++ b/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf @@ -0,0 +1,27 @@ +## @file +# CcSvsm 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 CcSvsmLibNull + MODULE_UNI_FILE =3D CcSvsmLibNull.uni + FILE_GUID =3D 62b45e0f-c9b4-45ce-a5b3-41762709b3d9 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D CcSvsmLib + +[Sources.common] + CcSvsmLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/UefiCpuPkg/Include/Library/CcSvsmLib.h b/UefiCpuPkg/Include/Li= brary/CcSvsmLib.h new file mode 100644 index 000000000000..4715f4db3bd1 --- /dev/null +++ b/UefiCpuPkg/Include/Library/CcSvsmLib.h @@ -0,0 +1,101 @@ +/** @file + Public header file for the CcSvsmLib. + + 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 CC_SVSM_LIB_H_ +#define CC_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 +CcSvsmIsSvsmPresent ( + 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 +CcSvsmSnpGetVmpl ( + 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 +CcSvsmSnpGetCaa ( + 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 +CcSvsmSnpPvalidate ( + 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 +CcSvsmSnpVmsaRmpAdjust ( + IN SEV_ES_SAVE_AREA *Vmsa, + IN UINT32 ApicId, + IN BOOLEAN SetVmsa + ); + +#endif diff --git a/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.c b/UefiCpuPkg/= Library/CcSvsmLibNull/CcSvsmLibNull.c new file mode 100644 index 000000000000..268bd9a7ca54 --- /dev/null +++ b/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.c @@ -0,0 +1,108 @@ +/** @file + CcSvsm 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 +CcSvsmIsSvsmPresent ( + 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 +CcSvsmSnpGetVmpl ( + 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 +CcSvsmSnpGetCaa ( + 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 +CcSvsmSnpPvalidate ( + 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 +CcSvsmSnpVmsaRmpAdjust ( + IN SEV_ES_SAVE_AREA *Vmsa, + IN UINT32 ApicId, + IN BOOLEAN SetVmsa + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.uni b/UefiCpuPk= g/Library/CcSvsmLibNull/CcSvsmLibNull.uni new file mode 100644 index 000000000000..c80c0a5656dd --- /dev/null +++ b/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.uni @@ -0,0 +1,13 @@ +// /** @file +// CcSvsmLib 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 "CcSvsmLib NULL in= stance" + +#string STR_MODULE_DESCRIPTION #language en-US "CcSvsmLib NULL in= stance." + --=20 2.42.0 -=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 (#115847): https://edk2.groups.io/g/devel/message/115847 Mute This Topic: https://groups.io/mt/104512960/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-