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 8659FAC13CB for ; Fri, 8 Mar 2024 15:32:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JdBxFez0F1Xqog7fUbm7daMCCsFGtk9NIC0vludTnJc=; 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=1709911931; v=1; b=YVzbRC8UAX2NYOxuJ09kLoDiXmajPPyrhQOfqcQy/1X0IVOk9VZzB/1lnBWuEbyXWvINB2A5 UF4/wIcy9t83hBhWA23dGa/jUjvIpazvhN3Fua0jYhuto0ga7+R7Vafri9Cg4vvv3mwcyhRGbDW a6693Q884gUM3B0yz5kvNH/29K5KFrKwLfhwFwe5GdvbYDJADIoDaq/zufOdU4woB7XGrstPC/P UK12AP4LiQVcjMTAUDVkp9KvNqdgWFerS8f2p5ws4hLWSshOYRDUYuWJW54/CVPKfaDNnaXJ2/N 3yLGm/IRZCeGqraaY16VjHL/WnMcwF9YyJhBHaMwlg1bQ== X-Received: by 127.0.0.2 with SMTP id oYIfYY7687511x0toXlrT1OL; Fri, 08 Mar 2024 07:32:11 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.53]) by mx.groups.io with SMTP id smtpd.web10.24823.1709911930687091163 for ; Fri, 08 Mar 2024 07:32:10 -0800 X-Received: from CYXPR02CA0013.namprd02.prod.outlook.com (2603:10b6:930:cf::24) by DM4PR12MB6469.namprd12.prod.outlook.com (2603:10b6:8:b6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26; Fri, 8 Mar 2024 15:32:08 +0000 X-Received: from CY4PEPF0000E9D5.namprd05.prod.outlook.com (2603:10b6:930:cf:cafe::56) by CYXPR02CA0013.outlook.office365.com (2603:10b6:930:cf::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.29 via Frontend Transport; Fri, 8 Mar 2024 15:32:07 +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 CY4PEPF0000E9D5.mail.protection.outlook.com (10.167.241.76) 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:32:07 +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:32:04 -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 17/24] OvmfPkg/BaseMemEncryptSevLib: Use AmdSvsmSnpPvalidate() to validate pages Date: Fri, 08 Mar 2024 07:32:10 -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: CY4PEPF0000E9D5:EE_|DM4PR12MB6469:EE_ X-MS-Office365-Filtering-Correlation-Id: a914f54c-c570-4525-5187-08dc3f84ea30 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: eeh6InMLi9bzOYjLrDXxawEYPZ7qBYar9CJpuHTNu6rsaNAtHCIlIkto4lWGLjjVj5BW447JXw374xvkLumuWpeOWXNEkXLXKTDhwpaT0srLJ9lTLyIqXg9OWWuNE0i1QYHqfmcET7siBxSV7HFzi7DHWcB86TsV1I9vY8QYMNdSjwvGZsaW2LDSp1kD1SZFtiCzK7gJ5fxKstbDUzhG2w/FFPi/B3WDRhVyKq/+fRJK7OLbEHRZnW/AxHAU5+0DZNXMNyqEWluLVF+r2YK7srf+ZR2/9v1B8EZOdMKC+/DkzBLOE7cwibZfFrY43B1Hp06P54Lx6gqE7ZasjSOwCC+Bgm5xhFgJ2358Kru+agTqBiTUqnLpnLV0N4e0NXaVvEdxOfwTh2pvyNhDEiPE6DTHm6Wtn0gvV+Ppxiu16NqNcbeJii0/CJ846bmlQPT5AKRWZA+vLpolg7fMXu2MWcpMkqJILkUN8P6JeDgR/28yEk5tUlqJD6Zzz1FqMdeo5JLLcMmhN94M/ZwCIJaTvARahEl1XVi4s+o0sfSK9mN5snZr/C80cDoM1UtBTGmFAfCUjW65W010ptmapqDUIiO3mf3hX6oSX1vvMEgBelkNwSouc410n1UGgDGf9jk4C1CraHDtQbfRQ6OJ0jKvmIQd9NNyaDq45YKl/t5OaLGVvggkxjUAxiybQzS9wO+4kSiDNcknCPQ2gDhy82GQ2A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:32:07.6098 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a914f54c-c570-4525-5187-08dc3f84ea30 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: CY4PEPF0000E9D5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6469 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: CIJQXBecxt61BknUAao8p5WRx7686176AA= 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=YVzbRC8U; 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 The PVALIDATE instruction is used to change the SNP validation of a page, but that can only be done when running at VMPL0. To prepare for running at a less priviledged VMPL, use the AmdSvsmLib library API to perform the PVALIDATE. The AmdSvsmLib library will perform the proper operation on behalf of the caller. Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Laszlo Ersek Cc: Michael Roth Cc: Min Xu Signed-off-by: Tom Lendacky --- OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf | 3= +- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf | 3= +- OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf | 3= +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 74= +------------------- 4 files changed, 9 insertions(+), 74 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index cc24961c9265..312ee73e5474 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -1,7 +1,7 @@ ## @file # Library provides the helper functions for SEV guest # -# Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> +# Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.<= BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -52,6 +52,7 @@ [LibraryClasses] MemoryAllocationLib PcdLib CcExitLib + AmdSvsmLib =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 8f56783da55e..1e0b5600eb1d 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -1,7 +1,7 @@ ## @file # Library provides the helper functions for SEV guest # -# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2020 - 2024, Advanced Micro Devices. All rights reserved.<= BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -52,6 +52,7 @@ [LibraryClasses] MemoryAllocationLib PcdLib CcExitLib + AmdSvsmLib =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf index b6d76e7e630f..a06ea6188eab 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf @@ -1,7 +1,7 @@ ## @file # Library provides the helper functions for SEV guest # -# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2020 - 2024, Advanced Micro Devices. All rights reserved.<= BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -49,6 +49,7 @@ [LibraryClasses] DebugLib PcdLib CcExitLib + AmdSvsmLib =20 [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c index f1883239a661..c8c0c4ef0e95 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -14,14 +14,13 @@ #include #include #include +#include =20 #include #include =20 #include "SnpPageStateChange.h" =20 -#define PAGES_PER_LARGE_ENTRY 512 - STATIC UINTN MemoryStateToGhcbOp ( @@ -63,73 +62,6 @@ SnpPageStateFailureTerminate ( CpuDeadLoop (); } =20 -/** - This function issues the PVALIDATE instruction to validate or invalidate = the memory - range specified. If PVALIDATE returns size mismatch then it retry validat= ing with - smaller page size. - - */ -STATIC -VOID -PvalidateRange ( - IN SNP_PAGE_STATE_CHANGE_INFO *Info - ) -{ - UINTN RmpPageSize; - UINTN StartIndex; - UINTN EndIndex; - UINTN Index; - UINTN Ret; - EFI_PHYSICAL_ADDRESS Address; - BOOLEAN Validate; - - StartIndex =3D Info->Header.CurrentEntry; - EndIndex =3D Info->Header.EndEntry; - - for ( ; StartIndex <=3D EndIndex; StartIndex++) { - // - // Get the address and the page size from the Info. - // - Address =3D ((EFI_PHYSICAL_ADDRESS)Info->Entry[StartIndex].GuestFr= ameNumber) << EFI_PAGE_SHIFT; - RmpPageSize =3D Info->Entry[StartIndex].PageSize; - Validate =3D Info->Entry[StartIndex].Operation =3D=3D SNP_PAGE_STAT= E_PRIVATE; - - Ret =3D AsmPvalidate (RmpPageSize, Validate, Address); - - // - // If we fail to validate due to size mismatch then try with the - // smaller page size. This senario will occur if the backing page in - // the RMP entry is 4K and we are validating it as a 2MB. - // - if ((Ret =3D=3D PVALIDATE_RET_SIZE_MISMATCH) && (RmpPageSize =3D=3D Pv= alidatePageSize2MB)) { - for (Index =3D 0; Index < PAGES_PER_LARGE_ENTRY; Index++) { - Ret =3D AsmPvalidate (PvalidatePageSize4K, Validate, Address); - if (Ret) { - break; - } - - Address =3D Address + EFI_PAGE_SIZE; - } - } - - // - // If validation failed then do not continue. - // - if (Ret) { - DEBUG (( - DEBUG_ERROR, - "%a:%a: Failed to %a address 0x%Lx Error code %d\n", - gEfiCallerBaseName, - __func__, - Validate ? "Validate" : "Invalidate", - Address, - Ret - )); - SnpPageStateFailureTerminate (); - } - } -} - STATIC EFI_PHYSICAL_ADDRESS BuildPageStateBuffer ( @@ -328,7 +260,7 @@ InternalSetPageState ( // invalidate the pages before making the page shared in the RMP table= . // if (State =3D=3D SevSnpPageShared) { - PvalidateRange (Info); + AmdSvsmSnpPvalidate (Info); } =20 // @@ -341,7 +273,7 @@ InternalSetPageState ( // validate the pages after it has been added in the RMP table. // if (State =3D=3D SevSnpPagePrivate) { - PvalidateRange (Info); + AmdSvsmSnpPvalidate (Info); } } } --=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 (#116542): https://edk2.groups.io/g/devel/message/116542 Mute This Topic: https://groups.io/mt/104810729/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-