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 02E607803D7 for ; Fri, 8 Mar 2024 15:31:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=15Er6vxaJtpA9dmY2aurnIUq07P73SpuXzFOemgMB5c=; c=relaxed/simple; d=groups.io; h=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=20240206; t=1709911892; v=1; b=yRyden1nKyQPRFM0PEMbxS54YFm2cZcqAEe73Z8qDZzmu1yGtloTWj5WzA/ArA03AtjftnTE nfksPl/ZLEG4JebROtZ/bv+bF+iIfgFudokra2wb8z1rQ4HOdEsh6NoPeE5MZZUqPxUW+lBF4Xy fciYMxkHaKgSoiYCKIMMDuG2+AjHOz8e1wCYE6jp14/XNFPVbCHJyQ1YD7svBS1N0tB54jZ0haE lMTgC70mlmPHNWIpzepqZj6+Tiwb/5TX8Ajk8R8oQf6WCxjOD+QGtGtrxrcc6KespfYMGS9rxT3 MdusyDCOUvvMdnOZlv8t18UhxRnSE7GQdLgChAJzA5GBw== X-Received: by 127.0.0.2 with SMTP id mfBwYY7687511xTOaAL7u9jH; Fri, 08 Mar 2024 07:31:32 -0800 X-Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.43]) by mx.groups.io with SMTP id smtpd.web10.24798.1709911892008050034 for ; Fri, 08 Mar 2024 07:31:32 -0800 X-Received: from DM6PR08CA0062.namprd08.prod.outlook.com (2603:10b6:5:1e0::36) by LV2PR12MB5920.namprd12.prod.outlook.com (2603:10b6:408:172::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.29; Fri, 8 Mar 2024 15:31:29 +0000 X-Received: from CY4PEPF0000E9DC.namprd05.prod.outlook.com (2603:10b6:5:1e0:cafe::4f) by DM6PR08CA0062.outlook.office365.com (2603:10b6:5:1e0::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 15:31:29 +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 CY4PEPF0000E9DC.mail.protection.outlook.com (10.167.241.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 15:31:29 +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; Fri, 8 Mar 2024 09:31:28 -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 v3 12/24] UefiCpuPkg/AmdSvsmLib: Create the AmdSvsmLib library to support an SVSM Date: Fri, 08 Mar 2024 07:31:32 -0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DC:EE_|LV2PR12MB5920:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c61fa97-186f-4819-dff4-08dc3f84d343 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: KUkFQr7CoNec145T1EI1wc/PRTaODezBOZp6xA7AC6ZRCuSmyLOjH2SSSg/nU/upX0DfQTGEkI7jxAnuCbsD8MovIYmeCgNaLQRyACvQWsfGbzdhzG/oXnL/MPoO5Rmw2DRwxOFFcrKoCyROhcIK3UQFLuximVBIhg5kX7F4TXTVjMaUOGDlZ/FZUw7iUinsr6wAH8IyWQf1KgSVA4Q8/3zXBSUhSfvf328DhQ8TdAyForBR0PMW9pafvK4puR8aDg2Sf5pUq1qpSIjceKR6Lz5xWmEq8MlhE2Fhf1JT/P/VdUBvcBcchOb0YNs5TKiXL3FIuoA75/H8O/mQ1ZpMXFku6ppxpaPFzq4fxzH5OUSxyobFqw7Ely8GMY90axfyjCPV9iuk+JgSYaUYk7fHeGDax5LznCsvSW23nBXVEwVck5J/WMmUQxTaQNBrYGq0XhkWsjJcw9VFdpVU5OdtDfab+gSwEJl+8MXkgqukaJ50BJdE5i4IA9ShhOc5oqqGw49eI3mcINQPqq/m2nsgB9Psr6zDFhD+g36THiMQecaC1m7hxqke2ZSyQ3s4OSQ4dFdq90PUCKfoczO7+Yb2S6th/ltlxptrYhuAXJMPMXfqZsJuF/8vAQp1zt8QK1eEHIeC538Wg8rnBetz0CeLFpcomLegNyRbo9mPzJuP3RIwYI5U8Qa7L3FMb0FpE1KQ3eA9h+viYblCWkWrEl+CIg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:31:29.1504 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c61fa97-186f-4819-dff4-08dc3f84d343 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: CY4PEPF0000E9DC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5920 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: wi7BpNWGY0UXLJZaxnDCagGkx7686176AA= 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=20240206 header.b=yRyden1n; 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 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 =20 + ## @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 =20 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." + --=20 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 (#116537): https://edk2.groups.io/g/devel/message/116537 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-