From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69859+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69859+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968148510285.29143919062005; Wed, 6 Jan 2021 13:22:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6oVQYY1788612x64ZE0v3NGn; Wed, 06 Jan 2021 13:22:27 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.59]) by mx.groups.io with SMTP id smtpd.web11.475.1609968146591364881 for ; Wed, 06 Jan 2021 13:22:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dn7u4vvoGRyybvi1LTlVjOdPS4sAlNHdphz77fGbiUjDM3fVSMvXwyRwNaYO+fZc+47F7RgHZAsiXbVEcqq+nWUV1tSSiwe+TMB4vQ5wjeNItA5+amoHplsbL604Z9H33ACi0EzBm3CqxP+nE7pr5n4fjglnyiVIGaCEMtP6Z0dWc0HD4xpRT5iRnL6m9mlMAp2+cB2dX9UbzNdqol5/cxbudiMdhlAlRmUbjYUjON0c8nhovKhfGbglUNnZRndwyaLnwGBZEn3VNniAWkmFpHByu6unhVKWk/7hE9RMRW75I2MVIg1wF6oJy2HxilGbBc889m+VRlhnI0Q8R6xF8Q== 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-SenderADCheck; bh=oO1K9D4ut2PUpPlrsE3RGduw7Jd3LKdGpZ8TKzmjinY=; b=GiTM0CawC/+2QsGuJRk9Q8vA15ls2nBu2tpalQRvbzXcC4QVwI1WOV269zdRG1A3va1nPm26it/Lb0XrpM2bSBb/Pvv3p4Z4OIOQJEmbYSuxh3iYiZg822i2iM6ax8yUv0Cgoc/xMgnHNp3ZzF2Fkapz0jmIWmdmh2F5n8hvE2K5krX0w5jjrYWlEvwc8uJuOYr2FHiKu6VOhXZbC5Uf885mGMsFWeA+R/8ECIWOceLHgeTYDr/ri2pZmD7O84TcAMcX/NmDVxWuxJgZAaDtZiW4KX2vwsQYJwbndLNLgLfLu4h7dwEC/xvgdPtP+yG89Dx8tu0t+oUnGqnWiYmX9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3578.namprd12.prod.outlook.com (2603:10b6:5:3c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.24; Wed, 6 Jan 2021 21:22:23 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:22:23 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 01/15] Ovmf/ResetVector: Simplify and consolidate the SEV features checks Date: Wed, 6 Jan 2021 15:21:27 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0044.namprd11.prod.outlook.com (2603:10b6:806:d0::19) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0044.namprd11.prod.outlook.com (2603:10b6:806:d0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:22:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4f45d95e-24f9-4cda-dc48-08d8b28928e5 X-MS-TrafficTypeDiagnostic: DM6PR12MB3578: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: z87qoONju9RmFXqSlL90YXdpGdbNdpZdN6Kn9TFSM8vplAPsS8dCIQuzWoglG/CmiMfLjuW5DuOUuYAaqCnJ4TXiKhPD5xxm/kQ6ASclyhmReUNqf6NVPFHtnTtNW7KFn3UZFpiOns1l1MBfqeor5cWE/XRzxKiLwkFVv3qFBHK6phwuo2DhftyCNjcQP9CsxGmiwpjNVoAQ5WniqQd6pkZhMTgcDkUAIHHIylrV8VyhdgjeUQLsl9vi4kKWI1pGpR3vf2M+4IwRrc3oiE4Hqxq/TXbtfV2zgWhiK9frP7YpnV+ihCEihePHdH7OAS/X3k7md+nyhWOOwXktK4Y8aBmXKHBCYdy+7k23ZWHDBNPjTEbYd/AsEBjOaXPfIzEuudGVxrs4V8nulE/2Jq2ftyZcWhfSfhPfJ1TTAi0VahKvhdgxO0M/rbgvlq/oNUAi45o6WgoH3cXWfETZBq1eUg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?+qLStPx5JFsO7DE26BhDJJ4YwsekNQoQl2PZrHW77nHnapWfv+RJeJF2C7Gj?= =?us-ascii?Q?TzY3cLAtxn4iQFZwsTBkn5xTHsmiswygZIBEd20Jp9ORBOCQLkXOj+FWh4WU?= =?us-ascii?Q?17PThoyhi9s217BcW+jlPnLZXlWqBAC+LFrsr/kTGp7HPOfdrSIwWP956Q29?= =?us-ascii?Q?+mOPHk0ZZ5J0eW0JR7qLxbcOBhlB6muP3BIQtncJSKa30vqgh0iB7XCYz7Wu?= =?us-ascii?Q?cPJdnFdJFMS+s+QdUFKN4VtdosOh4aFN6jZdY0zjIi6iG/wHJHkVHVhWExoW?= =?us-ascii?Q?IawjJTUhaQXAr1NhxvSY9RTEqk1vNLRfnxB6oYZb9MncUOcWLCKkKba2FWX2?= =?us-ascii?Q?Nxzin+b3P6Ja2h9U+xsgBFDdF/FuWvauLZ71UL8dD8isDOTpv6j/sRYWuKwW?= =?us-ascii?Q?7TZ0rKCLCMzSoefCZtQvuRccInl/0sXl9+xikPzwxvDxfZHHmbnLxJ6y7dKl?= =?us-ascii?Q?ADCheMjotyqXD3k6qpTPhLC/hM2R1O7EwVorIp3wEmoS+TUlId0OIUN6mjCO?= =?us-ascii?Q?rQ4bR7XmYvyqU7OppLNIW4aIjs1MugxOlma3z7V7h3FfLA0zaQ26yAWIVqNA?= =?us-ascii?Q?QmD4MIIiNBfg0PJ7r0JRC1vMivSQC90P0Nq3wm5QQJBADOiWhGhM9ePu/mQ1?= =?us-ascii?Q?oVVGQuwALjNUCqK6bzeMKY+Bru/K0XrIQLhoNnJY1NnjeZb5cc471g4+OFD4?= =?us-ascii?Q?BV2NO5A3t+OUESxApyRxLtln8dYMTzULyCkRqIetl/YJrutl+8pPp/w/weRA?= =?us-ascii?Q?QRh+SOLzUh+JCDlKvdcqn91aBfjIFmPuk721NxgkW04abbfA+c3ssbKSE92v?= =?us-ascii?Q?6lBVrFn8thWzm0xrnvYj2LDG4B6OzVJW+YirFWvcOr08kRHX/Iayht/AuBAT?= =?us-ascii?Q?0XLl2mdHT/kLhEy411YNvLY2YktYuIGWN2dVkchlQTQ5P5q4aWEn051xjGas?= =?us-ascii?Q?PUeTgUeQSW3bGIca4MBdrCp5Hl8qkrhcsdmQ3olgztAYKF+Or5o9ajzZydER?= =?us-ascii?Q?WC6o?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:22:23.7932 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 4f45d95e-24f9-4cda-dc48-08d8b28928e5 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PCZHO5zjtCoS64xX3OgAQovtFtrvBt6dbPN0JMYeq+ZEHaMn/oQg0eudswcE9b4w8gPijYNqhnq9y8b+UstR7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3578 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: klIXoNu6d6ccPNXMslaz7OVWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968147; bh=Qg1hp0DFPUT8YcWt2QyDVUIXRDMw2RqXwKk1ID6Nd4Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=n1R7BnHnGofBFutC2ngvTnU/zm8YphOn1JwJnc/RT99IuGIf/kh1121JoXyQVpKpaFu n6bzWXw5mQCX3lpxiGSKq7ro/ayyvDn5/9fb6dYSXF4CLvKnpObv9xeS4sxlsm36dk+jV uuXb1rV2C5fnpy2roFZLnRllZqA7Ht0j4tI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Simplify and consolidate the SEV and SEV-ES checks into a single routine. This new routine will use CPUID to check for the appropriate CPUID leaves and the required values, as well as read the non-interceptable SEV status MSR (0xc0010131) to check SEV and SEV-ES enablement. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/Ia32/PageTables64.asm | 75 ++++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index 7c72128a84d6..4032719c3075 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -3,6 +3,7 @@ ; Sets the CR3 register for 64-bit paging ; ; Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
+; Copyright (c) 2017 - 2020, Advanced Micro Devices, Inc. All rights reser= ved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ;-------------------------------------------------------------------------= ----- @@ -62,18 +63,22 @@ BITS 32 %define CPUID_INSN_LEN 2 =20 =20 -; Check if Secure Encrypted Virtualization (SEV) feature is enabled +; Check if Secure Encrypted Virtualization (SEV) features are enabled. +; +; Register usage is tight in this routine, so multiple calls for the +; same CPUID and MSR data are performed to keep things simple. ; ; Modified: EAX, EBX, ECX, EDX, ESP ; ; If SEV is enabled then EAX will be at least 32. ; If SEV is disabled then EAX will be zero. ; -CheckSevFeature: +CheckSevFeatures: ; Set the first byte of the workarea to zero to communicate to the SEC ; phase that SEV-ES is not enabled. If SEV-ES is enabled, the CPUID ; instruction will trigger a #VC exception where the first byte of the - ; workarea will be set to one. + ; workarea will be set to one or, if CPUID is not being intercepted, + ; the MSR check below will set the first byte of the workarea to one. mov byte[SEV_ES_WORK_AREA], 0 =20 ; @@ -97,21 +102,41 @@ CheckSevFeature: cmp eax, 0x8000001f jl NoSev =20 - ; Check for memory encryption feature: + ; Check for SEV memory encryption feature: ; CPUID Fn8000_001F[EAX] - Bit 1 ; CPUID raises a #VC exception if running as an SEV-ES guest - mov eax, 0x8000001f + mov eax, 0x8000001f cpuid bt eax, 1 jnc NoSev =20 - ; Check if memory encryption is enabled + ; Check if SEV memory encryption is enabled ; MSR_0xC0010131 - Bit 0 (SEV enabled) mov ecx, 0xc0010131 rdmsr bt eax, 0 jnc NoSev =20 + ; Check for SEV-ES memory encryption feature: + ; CPUID Fn8000_001F[EAX] - Bit 3 + ; CPUID raises a #VC exception if running as an SEV-ES guest + mov eax, 0x8000001f + cpuid + bt eax, 3 + jnc GetSevEncBit + + ; Check if SEV-ES is enabled + ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) + mov ecx, 0xc0010131 + rdmsr + bt eax, 1 + jnc GetSevEncBit + + ; Set the first byte of the workarea to one to communicate to the SEC + ; phase that SEV-ES is enabled. + mov byte[SEV_ES_WORK_AREA], 1 + +GetSevEncBit: ; Get pte bit position to enable memory encryption ; CPUID Fn8000_001F[EBX] - Bits 5:0 ; @@ -132,45 +157,35 @@ SevExit: pop eax mov esp, 0 =20 - OneTimeCallRet CheckSevFeature + OneTimeCallRet CheckSevFeatures =20 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure ; is enabled. ; -; Modified: EAX, EBX, ECX +; Modified: EAX ; ; If SEV-ES is enabled then EAX will be non-zero. ; If SEV-ES is disabled then EAX will be zero. ; -CheckSevEsFeature: +IsSevEsEnabled: xor eax, eax =20 - ; SEV-ES can't be enabled if SEV isn't, so first check the encryption - ; mask. - test edx, edx - jz NoSevEs + ; During CheckSevFeatures, the SEV_ES_WORK_AREA was set to 1 if + ; SEV-ES is enabled. + cmp byte[SEV_ES_WORK_AREA], 1 + jne SevEsDisabled =20 - ; Save current value of encryption mask - mov ebx, edx + mov eax, 1 =20 - ; Check if SEV-ES is enabled - ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) - mov ecx, 0xc0010131 - rdmsr - and eax, 2 - - ; Restore encryption mask - mov edx, ebx - -NoSevEs: - OneTimeCallRet CheckSevEsFeature +SevEsDisabled: + OneTimeCallRet IsSevEsEnabled =20 ; ; Modified: EAX, EBX, ECX, EDX ; SetCr3ForPageTables64: =20 - OneTimeCall CheckSevFeature + OneTimeCall CheckSevFeatures xor edx, edx test eax, eax jz SevNotActive @@ -229,7 +244,7 @@ pageTableEntriesLoop: mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop =20 - OneTimeCall CheckSevEsFeature + OneTimeCall IsSevEsEnabled test eax, eax jz SetCr3 =20 @@ -336,8 +351,8 @@ SevEsIdtVmmComm: ; If we're here, then we are an SEV-ES guest and this ; was triggered by a CPUID instruction ; - ; Set the first byte of the workarea to one to communicate to the SEC - ; phase that SEV-ES is enabled. + ; Set the first byte of the workarea to one to communicate that + ; a #VC was taken. mov byte[SEV_ES_WORK_AREA], 1 =20 pop ecx ; Error code --=20 2.30.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 (#69859): https://edk2.groups.io/g/devel/message/69859 Mute This Topic: https://groups.io/mt/79485040/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69860+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69860+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968159827622.9296784266314; Wed, 6 Jan 2021 13:22:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ofr2YY1788612xubdvNJFpES; Wed, 06 Jan 2021 13:22:39 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.66]) by mx.groups.io with SMTP id smtpd.web09.446.1609968153990841320 for ; Wed, 06 Jan 2021 13:22:34 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oYABHiCTZMooVUiCNQ9YESC4gJmOMBsO0fDls3M3BqNdBR3bs83+GXTX/kHsUoDwLNno1mD0vrMGLS4Q9oxUf+NM87eN2K4zHJH28KFph0MzkR8+nfCEksH9Rr0tlJB+sf+4zZYOT+bJfUBtcKq6HoFF1SJpy0e328Z9ZUL9MOGKmuA7VIgAWV2g7bSwWc673NvYmK4PGJf2GEOCDLlx4Ee9qQ0ZV3QdCX/8LHsNyKBGfqXwcmyb6rvnfD2uU1S7dh6/eFMJpPcrJlzSLqW1vONTjoiVVZJEs7LhAGNHPTtf787jWTKBYkA8Ydkw8rePFfmpysCBfPkM6/SbEjvKNw== 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-SenderADCheck; bh=HGEREPRNXQk83pP8EiRBPA2oNXtsGdt9PxMVo5ZUkg0=; b=d8McZGFSwjEky7N5kAHlJlpxS1Lg4oB6RVQXHDzPRJzV3XqZLDqRCG+htGm7DRjBA13yy0Z6RKR5E3v8FTyFwDSx2/SXsoot80+lDL/bWardRfMdRvlpeltoUsVK+85vsjWtQIxzTdgqzNfGSLLUqtO5XsCZ4JKm5ct6Bfo+rO6aBn9b11u2hj2rUqDruaHM0aE1FBfJYpSvcAGP7MD3bPkgKfDDpwlO76RDvzoumM6+W3akBEP3Mi7f9Jb/OXV3cyOwxn9zPJwi7Vv8rXqWKOoeG98oEehB5pC7zILGCH7uvxX6qEbJxvbde7ipfctB3OTfTd3jpcQKX30n96fNjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3578.namprd12.prod.outlook.com (2603:10b6:5:3c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.24; Wed, 6 Jan 2021 21:22:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:22:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 02/15] OvmfPkg/Sec: Move SEV-ES SEC workarea definition to common header file Date: Wed, 6 Jan 2021 15:21:28 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:22:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fc5440c7-90d3-4d15-2514-08d8b2892d6f X-MS-TrafficTypeDiagnostic: DM6PR12MB3578: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Zu1a03u+knwUWEyTJW1AS0MUN6aqCEN0lFLR5Bm27jAsI+XCMKZtji5rQUZIPsweUdxMpp6GVlwZo3NSoLqGa6mQTAZfDRySbNCKWLJyIeBNXHcMSCU7aUwi7xlLgBWnOSjqG+1Jkpxem7wwMbCpQw59CvzE/vW/5Mxo0fPR6YuZINGxQ2sjVvs8kZP3fLW+HwCLgywVgnZ2R/K60veXvBF7T0ze1lPHIiFaAGncNHAg2T/aY+DxlZWjDEEH+/cXqs62Izk+ay10ywWbRquw2uHY5tLB62ffK8EVnh+S+XuVuCFbTc9kUQLRKvcFNob3utva1+kS26lruCiEv36ZWhUFAmhbl/1pchVYsQn/Rjs4soGaSXBBx1kyA9ridnec56Vm5etLcDOK2mO33EEfqiLIs914ySAgIRmD89BtKqWsapMGK0xVmLR2Y7NwRc41wXpd6D4lpBFJ34hDa7Rccg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?1S9rT0HlzG8rm0+hUQCgUPW9d8plfgQRWsw/QZQ2YQ85AZ2Qde/hVfJrHWdu?= =?us-ascii?Q?bYzrv+2vEYyfrNDlaCpb2gmpWFbqviYo5Cuq6P9Depjwgqs8auzo3C5Y6Q2r?= =?us-ascii?Q?UR/lePBBnVW9fKxF2cDFVA6G+ClPZldZ1g4gn6BNcSZjrQKifVVCM4+1C+xO?= =?us-ascii?Q?J4pQs9OXFDyQbDlyvZ+iDr8L5zlF5Sw8/ZSQujPorMCbd+/CJKU5kElOimvt?= =?us-ascii?Q?aQODR3r5TTuun4OPaBfXTgrP/50in6wvR2Ct2XmZ2KdlwzpHI0f8rJgDDxNh?= =?us-ascii?Q?BJNm4yRdt1qraigesa876SphWmg98tjrCuv0lPbCYGLAgHZPs19MBYtWIWL1?= =?us-ascii?Q?jw9F8pctoWIfWbYXnTkIYLnuJp1jiYozC4avCCDjQ/RJVJR70FZtE3yMAocu?= =?us-ascii?Q?6D/D6KioeJ0euNpmr+Yq+bNCTqxAdy0QBXDTVTXBdbO8jDMnGaOeZRyzeSFe?= =?us-ascii?Q?7Ch3yNtnkmM86mti2d46BpqYuRbZyupzUJi1BaJHeg5a2hpO8DrR9qfNtR5G?= =?us-ascii?Q?DugpwtXY77pgB3tAtCbInnZm3JbKh5Du0PaI9gSXCSpy8vsDbB1kixjDFyQY?= =?us-ascii?Q?mmYbgSkhWpDS9mJ2GNH+Sfr1sDEcOXP9z56tDJASUM8UY9H9gi/dWK80leoy?= =?us-ascii?Q?2/zkHYo6BqYNkwhkbGQ28SPZtMURMz8VIez1GvHNzOfoiL0SUga9YuKweiR3?= =?us-ascii?Q?D6dshYrhOgi/q+7xcQKv/D9D5jRDq9Yq3e+esptKy8T6ATRKHg6Cj1xgcbQe?= =?us-ascii?Q?knSVOIDfhU0BIXEDtDjCtF5mEpbIJI1Q4kACvKI72829MgZGjVyT/n+NvWg+?= =?us-ascii?Q?nik8i8mts2q27JErRkYDNxVOGSffN1HVlRyxviokBy4K4IO/Qv/rctaA8wA9?= =?us-ascii?Q?kLeEq5V/walrEnjWAAR0l00Uik0q0v/dD7vklDvF3e2lzFVnC6BrXO2AHPbN?= =?us-ascii?Q?3/L2Zo4XPHpY0FGCW5z1YnK6xKjeOqodtD2m/wd+00BAjn1ZoWnHHKAjwxvW?= =?us-ascii?Q?9ksg?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:22:31.4527 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: fc5440c7-90d3-4d15-2514-08d8b2892d6f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IcikafUAEX9QN/wKcXnIyf6c90LwastmvWvg1yfDMt9qiJT2qlc/GUh+tKmyogwGWwK2Lf7kkhaZkhQjc1DJ9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3578 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: FYSQu5yuueOqLuYiYId4nJ5sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968159; bh=A7e+XA2j5qdG36EM82GrcKmDkskTo8f/h6UHk4UT0bg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q1LNhUY8AZqO19rdu8hcLaT4sxn4nbAcKVSi9wv8RTxAo/fCUauCthcchM4bfqCp8L+ TFnNoCbMZDq7n9MVAB3rC2rvbfildCdjW0UokChrDMbPNpW5M5lYeK6KocHmXw87rEgR+ CDGwuYebnrbOOnUNcsuuI6HZVI5iW9AEM+s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 In order to allow for the SEV-ES workarea to be used for other purposes and by other files, move the definition into the BaseMemEncryptSevLib header file, MemEncryptSevLib.h. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 16 +++++++++++++++- OvmfPkg/Sec/SecMain.c | 6 ++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index fc70b0114354..a6d82dac7fac 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -2,7 +2,7 @@ =20 Define Secure Encrypted Virtualization (SEV) base library helper function =20 - Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -13,6 +13,20 @@ =20 #include =20 +// +// Internal structure for holding SEV-ES information needed during SEC pha= se +// and valid only during SEC phase and early PEI during platform +// initialization. +// +// This structure is also used by assembler files: +// OvmfPkg/ResetVector/ResetVector.nasmb +// OvmfPkg/ResetVector/Ia32/PageTables64.asm +// any changes must stay in sync with its usage. +// +typedef struct _SEC_SEV_ES_WORK_AREA { + UINT8 SevEsEnabled; +} SEC_SEV_ES_WORK_AREA; + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 63aca7020727..9db67e17b2aa 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -3,6 +3,7 @@ =20 Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -25,6 +26,7 @@ #include #include #include +#include #include #include =20 @@ -37,10 +39,6 @@ typedef struct _SEC_IDT_TABLE { IA32_IDT_GATE_DESCRIPTOR IdtTable[SEC_IDT_ENTRY_COUNT]; } SEC_IDT_TABLE; =20 -typedef struct _SEC_SEV_ES_WORK_AREA { - UINT8 SevEsEnabled; -} SEC_SEV_ES_WORK_AREA; - VOID EFIAPI SecStartupPhase2 ( --=20 2.30.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 (#69860): https://edk2.groups.io/g/devel/message/69860 Mute This Topic: https://groups.io/mt/79485043/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69861+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69861+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968162907804.99222188246; Wed, 6 Jan 2021 13:22:42 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id iNubYY1788612x5Sna33knge; Wed, 06 Jan 2021 13:22:42 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.82]) by mx.groups.io with SMTP id smtpd.web12.488.1609968162089265518 for ; Wed, 06 Jan 2021 13:22:42 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RXB1jThLtGYoSZyA6lqOzdC+yTcIwDwdNUWFuk+J1QfWa9qbErUV9cTqNQKHKL5sQLZ0xL/x8OD4vDvUZG6kixK9nIAdZo/OfGySPccWayDhJxDd5zPoFRgTyBpJC0viYF1A9YKJfoab0VQyHOLbFaF04dibFHsFZUli4IkRt271nIWddUMOWsuFBH29fIUDZIidDfb8RLC//6HWWJU0IAwJpvUo/PosW1tVwM2j3f3rIsm1j02tF9NYrybgNabc6yvWvlMJA4d20pwmzkcNJBwByHiDRBjiHdrNwDiW9siH89fnHEUP6LRO8d26BR298PV03z70uBkF28iHK2OLIA== 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-SenderADCheck; bh=Uy4MNSu+RZ4EyvSqVuS56xXhFd+OKhnER+BJ1Mwx7vs=; b=aSqPxPBjsWLwkZBAV3hZP+btbHA3ZGPMhhABblAm0ivw/w2iSMBIaFyy+wdQrMnHXIYyZWzgwB4d9Xk5hc5R6VXdofBzj8/EqjaL3cPrp21nTgu+FtNMYhoT7/t8Hnf0YOAZ6lWqHqDHgXloX2tpgup6Uc+fxYMAEM/z+bTwdGtRHiwcdDpMyW2oCLrJ9lm60CU05yN6m/VoBzS1kuLjxLPINcY5KOlCbFAFtkRBBCEsCzeerAIQ11qUkRFC3vjZVB+GFPyPaeilZoQz3QPf2nq35/aOaqJ1DaXfQGqQO3U3duhpttFL/rzNTwwd5k2WMWP404y67wm+8lWyg07PNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3578.namprd12.prod.outlook.com (2603:10b6:5:3c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.24; Wed, 6 Jan 2021 21:22:39 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:22:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 03/15] OvmfPkg/ResetVector: Validate the encryption bit position for SEV/SEV-ES Date: Wed, 6 Jan 2021 15:21:29 -0600 Message-ID: <1bc8d8d9f1d6ad1e3640ae0df955087f073dbec2.1609968101.git.thomas.lendacky@amd.com> In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0055.namprd11.prod.outlook.com (2603:10b6:806:d0::30) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0055.namprd11.prod.outlook.com (2603:10b6:806:d0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:22:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cc078590-a182-4644-dc81-08d8b2893230 X-MS-TrafficTypeDiagnostic: DM6PR12MB3578: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 24rojy+ux8WzxtKM2VjrV6Mz7+nLn2h08tCXtON+gd11ISkKwnqERQ92uLGgAzTZvOI14og34uQ5h1QjFoSyTGsq5fhpfAnSKUm8c8MmVYUOxuwfOk4kXE8kweARdSaVvZiV1gSLI81U0Z5JeNOzAHrIpefQj1Obj9KZLTou3zCIU3deFr0TsGuccgo/A4fibFIt2dK1TWOC8kAX8Bv0gauIzg8DzPGF5Ig1FFgrL5AZdmZi8rxzWyoopcUfSSNunZ0CQtSN/n4oMm25CKYxbB/OsyJfXrDQiimuk3MhlGqFreBsf4pJyY+uFakdmDLg6dmZD6W/QLPNW7nGx8PgjtSDFEc9y8m2XjeMyMnEO9jsfvBwlgA+nQnSWEc2lYUQGuZzK4iegijQr2YJ7K1mv1GTHnxXOo+B+J72Xq4CD+5LUJ5XL+FKwYDnF0A/DxLVeKzFkasRc/cotiq63Kn7iA== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?+U6TRKB2uRzwSS+fdwypW+Zh3HpV64qgy1ExLS4X2YAtRAENcRzUFM3HFIHy?= =?us-ascii?Q?7GFz0Ji9Ur2QuvYBEX1ixblPq5SCHaPSEd4nQ8ZOM3MhLR7XZ5Ycuh0PnMZ+?= =?us-ascii?Q?RLUKFUqBewBCLKPdUfUy+Y5ogpqpharTxHj5PyKWZhaHpq5hJSWw2CpEsA9z?= =?us-ascii?Q?lCt7pCrsoHQpp4fyHO4t/JeYsgIm4SZcL/y+/rDOnolZB+0+Gk4GQeExdhol?= =?us-ascii?Q?2yK62SXgaT+/toeVxvGl6qacLCMgjCaLgWYLiSt7QjTRQqJlTyr24O3SkkOf?= =?us-ascii?Q?AgbRHtqEwsCMGoBMFxaM/wailA8EQs/tp5xIzRA6EB38AzMZjMZAgUZ3jE3v?= =?us-ascii?Q?mXu7H1fCf0go4pEh//0sLfk5h0I6YPGqUJcSTVvnN0+MZcH4HCsYkanfi91M?= =?us-ascii?Q?+NnpxvGZrfYq6DlhA7ApoN27DC/gOmJLqRyVKsxz/Bht1VuQ1JZQVU6RogBm?= =?us-ascii?Q?ccuaXuGv+TdRZPHgKBLirMxIZt6xfOXsucx3ay7WYV69Sh/NF237R7lXGdUm?= =?us-ascii?Q?SLFfyMascz276IsJEXJVMjJWDhdMukrycfRFc+QgwHOd1l5IJUwkxDwdaFDx?= =?us-ascii?Q?/xpoIVR8ajEK/19bsfzClBJ2nq/lkDiVHtkP6oAVmIBp9XOHmvbw8mCaru2+?= =?us-ascii?Q?DGJWI3LMAQtCm2z6mkHtGVlNP4GsRWmer3mh1K/2t8HEcz38Jm5BxOt1HNS+?= =?us-ascii?Q?ufafjY4tNpg8Lg9slN8rbkkT30nGir5JnHKHkEfMugvLFERSEDIWjQzZ+Iro?= =?us-ascii?Q?xJAbDMpEqwQbVCct4T40/CqXmFg+nzFDzx+90NuLbh2EiWsJ/Qc+XwMWDkKB?= =?us-ascii?Q?tFckvz07qgCSF7v4aUct5Hs7cRxCyMIAptLAscnTfq7/vSVPEutJ4lv7vQ9c?= =?us-ascii?Q?x2QZSpTCB6sQsK3Sz9b/XYfFtHlDdvIWPhWRrwlMdOu5mUWNDgZCoCcpuAxY?= =?us-ascii?Q?yLL9okQmAUYoC4B+cAt+TlkFqn/bFnRtVuDvQXE2jyGDgRvX91XOCEqykS+x?= =?us-ascii?Q?GVSP?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:22:39.3602 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: cc078590-a182-4644-dc81-08d8b2893230 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DHcy0ui8yrUU/RTEoQDG/ysL9wY8RQHYlNGKfD+wbB9vgEq7+vuA5PXtWA0Folg8QmI+16BTere4Mp5o/NOc4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3578 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: YGfJNPhMzBVHSuRBGmsFMLqnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968162; bh=li6Jfdgr3z1OFZv0OsGbOVS4sUsw3nCp40pm0ydJtJ4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=bQb/cFCSSKiHdTk0owAG+B38QsJwI1I8gxYoCZbcj/MYDosW55cTEmWOiqRPx6wP3BE TSP4uhj/kkkJg+XLmfvTj4ANzo8ikzW2ja6ewBR8XSm76TgZaNEuIn1837aMKA/EYk/mX mGM3iFufhwL2BLkrr4NZMHpRGm5YlvL8quw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 To help mitigate against ROP attacks, add some checks to validate the encryption bit position that is reported by the hypervisor. The first check is to ensure that the hypervisor reports a bit position above bit 31. After extracting the encryption bit position from the CPUID information, the code checks that the value is above 31. If the value is not above 31, then the bit position is not valid, so the code enters a HLT loop. The second check is specific to SEV-ES guests and is a two step process. The first step will obtain random data using RDRAND and store that data to memory before paging is enabled. When paging is not enabled, all writes to memory are encrypted. The random data is maintained in registers, which are protected. The second step is that, after enabling paging, the random data in memory is compared to the register contents. If they don't match, then the reported bit position is not valid, so the code enters a HLT loop. The third check is after switching to 64-bit long mode. Use the fact that instruction fetches are automatically decrypted, while a memory fetch is decrypted only if the encryption bit is set in the page table. By comparing the bytes of an instruction fetch against a memory read of that same instruction, the encryption bit position can be validated. If the compare is not equal, then SEV/SEV-ES is active but the reported bit position is not valid, so the code enters a HLT loop. To keep the changes local to the OvmfPkg, an OvmfPkg version of the Flat32ToFlat64.asm file has been created based on the UefiCpuPkg file UefiCpuPkg/ResetVector/Vtf0/Ia32/Flat32ToFlat64.asm. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 4 + OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm | 118 ++++++++++++++++++++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 13 ++- OvmfPkg/ResetVector/ResetVector.nasmb | 4 +- 4 files changed, 136 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index a6d82dac7fac..dc09c61e58bb 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -21,10 +21,14 @@ // This structure is also used by assembler files: // OvmfPkg/ResetVector/ResetVector.nasmb // OvmfPkg/ResetVector/Ia32/PageTables64.asm +// OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm // any changes must stay in sync with its usage. // typedef struct _SEC_SEV_ES_WORK_AREA { UINT8 SevEsEnabled; + UINT8 Reserved1[7]; + + UINT64 RandomData; } SEC_SEV_ES_WORK_AREA; =20 /** diff --git a/OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm b/OvmfPkg/ResetVec= tor/Ia32/Flat32ToFlat64.asm new file mode 100644 index 000000000000..c6d0d898bcd1 --- /dev/null +++ b/OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm @@ -0,0 +1,118 @@ +;-------------------------------------------------------------------------= ----- +; @file +; Transition from 32 bit flat protected mode into 64 bit flat protected mo= de +; +; Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+; Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + +BITS 32 + +; +; Modified: EAX, ECX, EDX +; +Transition32FlatTo64Flat: + + OneTimeCall SetCr3ForPageTables64 + + mov eax, cr4 + bts eax, 5 ; enable PAE + mov cr4, eax + + mov ecx, 0xc0000080 + rdmsr + bts eax, 8 ; set LME + wrmsr + + ; + ; SEV-ES mitigation check support + ; + xor ebx, ebx + + cmp byte[SEV_ES_WORK_AREA], 0 + jz EnablePaging + + ; + ; SEV-ES is active, perform a quick sanity check against the reported + ; encryption bit position. This is to help mitigate against attacks wh= ere + ; the hypervisor reports an incorrect encryption bit position. + ; + ; This is the first step in a two step process. Before paging is enabl= ed + ; writes to memory are encrypted. Using the RDRAND instruction (availa= ble + ; on all SEV capable processors), write 64-bits of random data to the + ; SEV_ES_WORK_AREA and maintain the random data in registers (register + ; state is protected under SEV-ES). This will be used in the second st= ep. + ; +RdRand1: + rdrand ecx + jnc RdRand1 + mov dword[SEV_ES_WORK_AREA_RDRAND], ecx +RdRand2: + rdrand edx + jnc RdRand2 + mov dword[SEV_ES_WORK_AREA_RDRAND + 4], edx + + ; + ; Use EBX instead of the SEV_ES_WORK_AREA memory to determine whether = to + ; perform the second step. + ; + mov ebx, 1 + +EnablePaging: + mov eax, cr0 + bts eax, 31 ; set PG + mov cr0, eax ; enable paging + + jmp LINEAR_CODE64_SEL:ADDR_OF(jumpTo64BitAndLandHere) +BITS 64 +jumpTo64BitAndLandHere: + + ; + ; Check if the second step of the SEV-ES mitigation is to be performed. + ; + test ebx, ebx + jz InsnCompare + + ; + ; SEV-ES is active, perform the second step of the encryption bit post= ion + ; mitigation check. The ECX and EDX register contain data from RDRAND = that + ; was stored to memory in encrypted form. If the encryption bit positi= on is + ; valid, the contents of ECX and EDX will match the memory location. + ; + cmp dword[SEV_ES_WORK_AREA_RDRAND], ecx + jne SevEncBitHlt + cmp dword[SEV_ES_WORK_AREA_RDRAND + 4], edx + jne SevEncBitHlt + + ; + ; If SEV or SEV-ES is active, perform a quick sanity check against + ; the reported encryption bit position. This is to help mitigate + ; against attacks where the hypervisor reports an incorrect encryption + ; bit position. If SEV is not active, this check will always succeed. + ; + ; The cmp instruction compares the first four bytes of the cmp instruc= tion + ; itself (which will be read decrypted if SEV or SEV-ES is active and = the + ; encryption bit position is valid) against the immediate within the + ; instruction (an instruction fetch is always decrypted correctly by + ; hardware) based on RIP relative addressing. + ; +InsnCompare: + cmp dword[rel InsnCompare], 0xFFF63D81 + je GoodCompare + + ; + ; The hypervisor provided an incorrect encryption bit position, do not + ; proceed. + ; +SevEncBitHlt: + cli + hlt + jmp SevEncBitHlt + +GoodCompare: + debugShowPostCode POSTCODE_64BIT_MODE + + OneTimeCallRet Transition32FlatTo64Flat + diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index 4032719c3075..ccc95ad4715d 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -140,9 +140,18 @@ GetSevEncBit: ; Get pte bit position to enable memory encryption ; CPUID Fn8000_001F[EBX] - Bits 5:0 ; + and ebx, 0x3f mov eax, ebx - and eax, 0x3f - jmp SevExit + + ; The encryption bit position is always above 31 + sub ebx, 32 + jns SevExit + + ; Encryption bit was reported as 31 or below, enter a HLT loop +SevEncBitLowHlt: + cli + hlt + jmp SevEncBitLowHlt =20 NoSev: xor eax, eax diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index c5e0fe93abf4..d3aa87982959 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -3,6 +3,7 @@ ; This file includes all other code files to assemble the reset vector code ; ; Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.
+; Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ;-------------------------------------------------------------------------= ----- @@ -67,13 +68,14 @@ %endif =20 %define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Off= set)) -%include "Ia32/Flat32ToFlat64.asm" =20 %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) + %define SEV_ES_WORK_AREA_RDRAND (FixedPcdGet32 (PcdSevEsWorkAreaBase) + = 8) %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) +%include "Ia32/Flat32ToFlat64.asm" %include "Ia32/PageTables64.asm" %endif =20 --=20 2.30.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 (#69861): https://edk2.groups.io/g/devel/message/69861 Mute This Topic: https://groups.io/mt/79485048/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69862+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69862+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968170383112.95510244637114; Wed, 6 Jan 2021 13:22:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PpW2YY1788612xr6r9aqgXgB; Wed, 06 Jan 2021 13:22:50 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.49]) by mx.groups.io with SMTP id smtpd.web09.451.1609968169509812234 for ; Wed, 06 Jan 2021 13:22:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QR8jqMO3YDiwIc1vaDHHQC3ZReetAZNv7nZZ1ftEgNqIYMKGbBB8bTCdFkh6ZWQJTpAAxcZ8GXCFdb7t53rIRMCryoJGhdYqvBaAJoQICwy/925Ce3g1S6eWNDVNh1UzpQof90L4HL/v+YfsSnOrQlO03ClpCWJ2VWHwt27nnbkBzRWfQ4rJzE5S0iPA3u1/I1edfmjbWUKKDYftG/52bjxKoXIsRNDoO7Af1ViSUQcqGlS/sgl8MTuYpgd3n0KLhE2PW9yx9mddk5WALS6GS3OzGNYPd2tU2/ck3qpG8GTVR/OIvlz/zfkCvebZLfkvQpx4EAdyKdO1Gy3HL4/X4g== 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-SenderADCheck; bh=Fl5c+WUyti+6Z3EUPP8krTRnKF8JE7UIwuZUxS7tsxY=; b=M0i56wh0iZC1+1UcWEEFZrxlZ3J2vSR0WxkR0X1D9neJZKWFMtgU7JYst1HNB+uDgbQCKG+1FCfnvGasQLh6M4QHTM37eF4M3QmEm1xQE6E5gtF8ok6G7EQkLICfOeNyBaP/fQL/ZAchcVkohCpnO/JCmhIlMCfB3ocmLMjcF80e178Y4LY3jL2IR9nk9X5LVLIjly7KhflyX1XzY6ckIWbz8QdCVxAlfESQIJRePHgycGiZZMZqDAPk6AY1Iu6QFZM8sPVeJvFp4cizoqG6uZFUCp/UJDmnHE/b766k/uDTV3Zee0KPmPJl7zTF0o0tSG3LoCSU6OE/a/eQWDziWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3578.namprd12.prod.outlook.com (2603:10b6:5:3c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.24; Wed, 6 Jan 2021 21:22:47 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:22:47 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 04/15] OvmfPkg/ResetVector: Perform a simple SEV-ES sanity check Date: Wed, 6 Jan 2021 15:21:30 -0600 Message-ID: <1c6e5ce7612f64fb1e4aea5f642d01572c063850.1609968101.git.thomas.lendacky@amd.com> In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0059.namprd11.prod.outlook.com (2603:10b6:806:d0::34) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0059.namprd11.prod.outlook.com (2603:10b6:806:d0::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:22:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b193ce88-47cb-4b2e-cabe-08d8b28936ad X-MS-TrafficTypeDiagnostic: DM6PR12MB3578: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1247; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 0WmjLRlyAlePsGgwScnz6oAI904X4m5WRnqc4nOYI84gHguFV8NcoU1VqUHy/gbGxKA7FYw4wufo4ZQsw2KBqbBa9grNuCJOsG6Wq1/E/nXH8kdIde4ff0iRETDpjvasxFM5CmHlXFbFOsmd7PUX9RqoO5sLTIUODmWRO+Tyh7oubY1pmLy/q9GF8Ovr/Ue9gPDJxv4hLA7MexkO28WXIDuVbb7jEwAcoy8yu2fV9Je4wBx91yloAN/vnOpEhOnZOguv3jNVpLDLa47L3+md7umu/T/k4JOSafJynK2EeJUh9h0n7RdQ4fyVInoE8MsUEPIevFSG59tTymAK/xM7n32GkSiEi5Cbv2kJm/XdHw4TVW6Ir4UxGIduqPO0H+5Sz+khReJp9wzM+DZM/C4BRG42PKkHG3fFZ1bNUtd8UVUh5qDcUrk03o/B3SBK7WYndM21dJB6QoK1fXr+HNLctg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?xBVCivC0AxuTqNtu4FRHulCFTvkQ/+8XBImkH6rG7kWdFdcKePCJlh1ptf8I?= =?us-ascii?Q?hpOszjhHoQnKVPUSFCNNg+dtOqNLKXcbuyJJyB+cg28UsZU+RgVcH7Zp2I3Q?= =?us-ascii?Q?83By3e0OktDctpF5mT5FLaQtmbn1Y1tslK0vljofWlNEf07pnWEo/uvYUEyv?= =?us-ascii?Q?udxHV256oRRld8VYlBjwtOD7LUTUxtagdzRSInYbqjRikDT9BwveBYEmJ/bC?= =?us-ascii?Q?onE+TPcB0qgisVbrSTF30WO8OBlWf8vTedbArsQCJTEYLk4j8dJ6vh3Oa5zl?= =?us-ascii?Q?q3IqvYv8m+rZZuydSYmkxL+tzKDsH2mTCCK+WLxnpBuGtKlTBUFTW0p3ih44?= =?us-ascii?Q?li/vLIZbGnoBTtaP/XPMXa3akKpEHdvNOSktE77TddIQ52aDBhNk91zMKrLb?= =?us-ascii?Q?CC5S5r1/6CMhOJn3VRINnXJ0cX7A3D+PTqr0lXxvDLBWEqrw/qQlrmSY3Cxt?= =?us-ascii?Q?aQ8YNHfEWqeuKL+n8RKG1gcc6q000NFHW04KcLenKINtjroRY5hYggETGn5Q?= =?us-ascii?Q?DvSZ1BpsHCYez5FIJrx4TvHxeiHellpfvwnLLJYG+ZTj5VdfiTBroU7NFIIw?= =?us-ascii?Q?aIqrDcpj/uW4gghQnO6EFwKfiuzavzMTGI/0J9uh0VEODyZNmJWVVwbkV3u+?= =?us-ascii?Q?/2j+dWOcQa5Vl7O+RMkKsi4W0gcuO7UPS8szpViFd2xTNMP9H4up/MHbeFdV?= =?us-ascii?Q?/4EvSZlDqtZlmNTrBJlVsc7frmSg9jmYH4Q0k+x+1tI7T68k8/gDi14yeAin?= =?us-ascii?Q?D+h+6Ch4vAr2e9Gkvhdo7izdjScV4HGaqiwHp6m8Wnm+c18kIHeUCZWL0H4v?= =?us-ascii?Q?ji43KwrHbNTUjkxsgkK8ZVoPF/yWw6JuBOOlOjmITT6sikvGLlxBzpzpB8EG?= =?us-ascii?Q?4Sdb44kjB1NwRruJfEpL1294V2XTXpyVQfqTX7fjMUHTuSIRyZlNO8Lk6Io2?= =?us-ascii?Q?nWy96/BGGFC9bZsoCckMApj9po3B9rk5imn/XQ9YT2jLV7lk58GSm+pzYFov?= =?us-ascii?Q?Mxh+?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:22:46.9398 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: b193ce88-47cb-4b2e-cabe-08d8b28936ad X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: F6k5S/vhC3NMgS5Q1keoCGWERBw7MiuKuOI5FRjDqgqOsSMD1bL1rKY4UxCVQmT9RF9biFOVvnTYC4uH9+oi3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3578 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: lKic4TNxEez99wafu7cCi8bvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968170; bh=/jEYs7SeNFdLkrNjK8xHr3RkIqEx+oFAyHGSCXRUaw0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LjtEUxXj35diL81f/l5Enxcq2++CxQ3IvRF9KoDwYAB3DOBjj70pWh4S7GecplWeXQC LFJmk7O5cDSSoo5YpjlodQ+PHDdDROqHaqIy3S0uthAUU0Q3mORplVam/nIqGRqGE9nWm t23afoAHb3yDn430Gq/0hLuJsQcLBI5X+6E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 If a hypervisor incorrectly reports through CPUID that SEV-ES is not active, ensure that a #VC exception was not taken. If it is found that a #VC was taken, then the code enters a HLT loop. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/Ia32/PageTables64.asm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index ccc95ad4715d..a1771dfdec23 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -154,6 +154,22 @@ SevEncBitLowHlt: jmp SevEncBitLowHlt =20 NoSev: + ; + ; Perform an SEV-ES sanity check by seeing if a #VC exception occurred. + ; + cmp byte[SEV_ES_WORK_AREA], 0 + jz NoSevPass + + ; + ; A #VC was received, yet CPUID indicates no SEV-ES support, something + ; isn't right. + ; +NoSevEsVcHlt: + cli + hlt + jmp NoSevEsVcHlt + +NoSevPass: xor eax, eax =20 SevExit: --=20 2.30.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 (#69862): https://edk2.groups.io/g/devel/message/69862 Mute This Topic: https://groups.io/mt/79485050/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69863+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69863+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968177739577.3527506649143; Wed, 6 Jan 2021 13:22:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EgQzYY1788612xqeoG3o6tHU; Wed, 06 Jan 2021 13:22:57 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.70]) by mx.groups.io with SMTP id smtpd.web10.454.1609968176840929669 for ; Wed, 06 Jan 2021 13:22:57 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cpz5DSFhfVUiQw8bPGB8C0CRTfWZiLq2qWH4O/sxNfv3smR8XavzPNRhzSFJhoNkVCz+NbEcanFF0ITxThsLCdJH6FgAmpJnFJn0kc2N4mA6KlpSmJZZwjioC+SDotBRYplFIiUWQu2MuEflWLXX+K9orZ3Se3ZmEiyDgV1FckkQlekKFWlPCXBkh7FAoaSRGgNubUR55cDz46fRJH3Qbembrkgc5gZvshicL5+kgeqAeBSTRMPXK1xrMZQUIOAVWV/2Zst+K+n7ExMiSbUfge2U3WEdl20jnzWjJ/Bye7WtYEUOQKCRrmFDT9wrrK6/MHJzeW38iVlmk7yDFe96xw== 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-SenderADCheck; bh=Hmo+eSlrJkK82pdq5yBd7tBRTqAt1Won0Zzli9IuZSE=; b=Vr18/tvXgZ30vGwGY/C+8pGUcQxlSjEiWE/T3uI+9OEfkSHPC3FPN9dMLAx6uAWN+UadRikOt/rC8eRRFMOzAH2kDXoTtN4HPmgqQMy29vCdMxiVm1KnNfBLgE3F7/647BMEaNPEBNB6w2+UQ77UjQY0wblta7Mgt4aQ1ZeC70ZoC1wENlsQlSv7PPRhsvHV4y/o2hzLW10Cg1EID5AmRu92RNqAsEe/qrbZyty87crFsIpvnfEQ4zC6ljoUdM4J4qrGRxjmEwIE38UfInTsJ6PKfbaCK77TuuWJKlNtpWocpchOzpiKH+jVw1TBXNiojuabBezR2VMlMj7X6O62TQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:22:55 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:22:55 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 05/15] OvmfPkg/MemEncryptSevLib: Save the encryption mask at boot time Date: Wed, 6 Jan 2021 15:21:31 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0035.namprd11.prod.outlook.com (2603:10b6:806:d0::10) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0035.namprd11.prod.outlook.com (2603:10b6:806:d0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:22:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 66597198-34c6-4653-593d-08d8b2893ba5 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Bcb08UqgZTQLcOhbrxQTulpnOZYmDmS0E9vnY9Sa/pLTNvytSAYC9DBwkpAEraX7AEBjelOn1lgqMnqlBGxj849gf5WCchBkI5Se6LQbFD46Gvce26NKkHP64tgTAXorC2dznz4IABRN9pga6nSuuFgKeW+TWLLaacHF455Zfe0k12k73AFFmGoTaIO9MCoXRw+1BcIrnkzuvAXUaqcYVXzVdUvAC2Hp79tBVU+3V2O+atgvzqOiqSd8ZDwvHOLfGHQrzWcTC/q03/0Jfuyy9Qdv0K2mPTrRs+Ab5QfFj6m1dvpz4ERRpmb26flzr6+mKmnBwSqy34kYY2nbaL+Y70wyIpXyd55un42DmJPsngeMPnIvNpUBg5Do1uv1fuaiA7P2lY0uC/txzia5blM7IEbcjuxSxi/d25IqME9N9TrtDpmGSsRFyAkgOJH4zNp98M4NQ7T5M9HbJM6mw7SVWA== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?LpeuWJT3I/g3aC2L8ZRqAFdo1+BwSoIIKjR1mJC7DljDmBv1Ut9T3UjaNx3G?= =?us-ascii?Q?R+lTQwxoHzBxxiHnzQdw318o0pQ55Jnm8SkD7a4ZpfVi7UVKeUB1CgO5RCUC?= =?us-ascii?Q?7HigvC3Of2njvrRKnCF1slMweZnzu5iwRrE3yAc388Imgmio3W60mZUmF3Wb?= =?us-ascii?Q?JeN2cgYeo8heDMGUlBlV0eoQx1KcAHxMW1iMNwhJd6pM3ttw1itPE/m+rS3K?= =?us-ascii?Q?0XfluBpjOoU6ZietJjmpuWqR36IjaJeKhFt/2bRBLgjUhGPkONdT5QxhaQUO?= =?us-ascii?Q?vuzWukfNJN/kxUzEEQmAHlRy1H1VzsMKYI+cikaxqOWCVxh0dpxCi56j8akR?= =?us-ascii?Q?hURtKPG5+he6QTZB9lFBEvNooUd2yfv3Pt7+k0+oxyp3jPSw05ujVeUXT+t6?= =?us-ascii?Q?ROXBFkTgPZlhWRUBJoyPNPnjcuO5N6tdXd7mSaXzYFveL/LWyPUzUzBiSlSU?= =?us-ascii?Q?qSu2P85SwrwHfZHRbBToj9Q99DcqD0aa2zRMBnSsukjf2XKCKjCMn4ousZtg?= =?us-ascii?Q?1+IHPngCahQH1FNHfe1XOeJA5biWePaKXZvR4jHyIcFyaOxn/uzgotC1Xpzv?= =?us-ascii?Q?YzmI9AwtZOxVaiUPjJAj1Fme/GCgtna1iYvcbQx7E35+/mRZllVQlssH6pfk?= =?us-ascii?Q?ULbTvwGU3C0isxi2lMVhui/4S/JI/uKJs1Hxj5/jepcNeHzz4XCIW5ojaNYD?= =?us-ascii?Q?haB2t3UdSWT5SVbco/6OGmvTiwtJiA4z2vGdINZbqPVHWFsT3yn9ufoM/jgd?= =?us-ascii?Q?j5or1dtSyNffqDyPLkC67dj0ajDCNN6PxqsUe548SfvGcMy67KYGRMAH8Mzq?= =?us-ascii?Q?Dbb5nbeJYBdmK9U7ndDU0gh1cdX4glLqQ8rkB//LXguYu9ICksuH4wt8ujZI?= =?us-ascii?Q?Cu9FFueCIQuDvWnkKJ3BO9fXWRAH4Oce1OAN8hm9iO0SV8J4iAKKEooLMO3K?= =?us-ascii?Q?Bx4tKSkd7BRTIGA96RKt8qcw2WOdiQo+ZYpfs/2sSEYRQM+SzLtM3V9ZI7pG?= =?us-ascii?Q?ZGmZ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:22:55.2671 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 66597198-34c6-4653-593d-08d8b2893ba5 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PRL3gimF5cZadXhOjebd0RzcJTDR7RS041sSfCSzvbcugIEMrgQyp1nYSGrB67OF28zFxhCdzEPwrraUkBBG4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: rjkkPCvE1cgmsiOnptqY5LLTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968177; bh=iNgIARkv3BhkEoGy3mdzlXVNWN3CKzpk0yeWgNyQ58E=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q0D8vFq2m91Qu/esxhFXRtNcEMKkVp8dSvT+2/PQRNPkMTcEQ6FExmmtusxL/c1Xi/Y iaG11Tn1eaaiBc4GQ1LADyj7rLPVbLmmtteyY0rWNwbd5xRRN8vzFS3mSMVEwW9BUO3ub YOuJKNWv5v5J+LV/sxPRjZ2vgN13lpSlVL0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 The early assembler code performs validation for some of the SEV-related information, specifically the encryption bit position. To avoid having to re-validate the encryption bit position as the system proceeds through its boot phases, save the validated encryption bit position in the SEV-ES work area for use by later phases. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 2 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 10 +++++++++- OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index dc09c61e58bb..a2c70aa550fe 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -29,6 +29,8 @@ typedef struct _SEC_SEV_ES_WORK_AREA { UINT8 Reserved1[7]; =20 UINT64 RandomData; + + UINT64 EncryptionMask; } SEC_SEV_ES_WORK_AREA; =20 /** diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index a1771dfdec23..5fae8986d9da 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -145,7 +145,7 @@ GetSevEncBit: =20 ; The encryption bit position is always above 31 sub ebx, 32 - jns SevExit + jns SevSaveMask =20 ; Encryption bit was reported as 31 or below, enter a HLT loop SevEncBitLowHlt: @@ -153,6 +153,14 @@ SevEncBitLowHlt: hlt jmp SevEncBitLowHlt =20 +SevSaveMask: + xor edx, edx + bts edx, ebx + + mov dword[SEV_ES_WORK_AREA_ENC_MASK], 0 + mov dword[SEV_ES_WORK_AREA_ENC_MASK + 4], edx + jmp SevExit + NoSev: ; ; Perform an SEV-ES sanity check by seeing if a #VC exception occurred. diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index d3aa87982959..5fbacaed5f9d 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -74,6 +74,7 @@ %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) %define SEV_ES_WORK_AREA_RDRAND (FixedPcdGet32 (PcdSevEsWorkAreaBase) + = 8) + %define SEV_ES_WORK_AREA_ENC_MASK (FixedPcdGet32 (PcdSevEsWorkAreaBase) = + 16) %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/PageTables64.asm" --=20 2.30.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 (#69863): https://edk2.groups.io/g/devel/message/69863 Mute This Topic: https://groups.io/mt/79485051/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69864+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69864+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968187340781.936928490951; Wed, 6 Jan 2021 13:23:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ccW7YY1788612xWjMfGQND69; Wed, 06 Jan 2021 13:23:07 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.44]) by mx.groups.io with SMTP id smtpd.web11.484.1609968186306194133 for ; Wed, 06 Jan 2021 13:23:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTCPjCA5rRnaUk6xcosit2tSUI3EEzbYan+wbgvyvPCiv0OReauQtkS5SCo9IOkHbLLA/cQLQli8qJJV+DePa0w7lWnILafj+CtF6EK/tRTprlEQJlfPtvkwo50nUmbJlz5Y3+jQscctzpeokgj3BSCJyPgcEaTFFk/nUJTgvqxCZQ36/zg9nM72X+Rop18B3yPruG5M+/Oee645Obv9x3Bp/da7CYPN21fV9s24tgKZQFc0gKGlV0zkRPc1sJ8+71M2UGU3xUKDrPSVXvQeUqA9d0GW0NBOpqhWwN79eQHNYSsAiUbdl2pIADY4G6A+b/V9y2Bys3IRWqUzQflV1w== 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-SenderADCheck; bh=7l8Nd60Z0LXaRUDH9ZwcqF3uWycE9AZQtLcTrj/CPD4=; b=QVzHqND0EZt8n1foR+TtrwBYwyC2WbFbQuUzvpkuvAvO+83Rllci9egMmGg3CFiDhRlJsXU9/Zr+JIHw6r4i6OJZoY0bCXwvP73COIo3z4jDdBSU1rA6AIu4XHh1gHVFsucf95/d96n+8HKs1pFqh6X/qlsKFC/w2g6ce8bzEWlxRGy+7evMVIwh63c5G0uxMvIkY29TaIQLSf2lFnZSTBvjR5u/l8OPtFXABsoonfU1QvOgQgJkLiQ+ZqkKjSguODTAjN1fLT1H2pbCZfxB+PL9e0oWRsF86xzkxgwXrnONDhDTN5GR0Ch519yKpinx7wDlzn2VPc3aHHlddaEqEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:03 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:03 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran , Peter Grehan , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v2 06/15] OvmfPkg/MemEncryptSevLib: Add an interface to retrieve the encryption mask Date: Wed, 6 Jan 2021 15:21:32 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0032.namprd11.prod.outlook.com (2603:10b6:806:d0::7) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0032.namprd11.prod.outlook.com (2603:10b6:806:d0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:23:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1f1c0e19-7710-4389-2ec5-08d8b2894074 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: fcn2lMsOHvCvXjbPcMAMc9fW945PeqXfuCwR4Otd1gaI2FzeKDjBPbxsUIinyJ+eExkvm80ImWKcUnknM5z5bjLHU8PVr0tsENouSVYpX+4mWlOT01pOjqjW+VfuY5YbtAzGFcIKjrMUCRRWk4vGGgqWE+ch+z05aWhJQmCbPTiWchTPqeQ3XKaBJmwQhucuXezl0Z0gu+SVxP+0pZX1eG/5GbCvoSfITpwJL+ZLRRPiwMJU4NoZRy+m54g9LYg5EF+I2O5EKB0rMCtqf/atgzKW4hIOkcMmRcYu4l5ir73Vc70zn5JPIKZM9ucCoFv/rxH1k0X6YfZ8w9iYrjEccHCTGOO/YT+AXY+dqo4Q7o2EN4QNzet6V14ZufMIdQx1ijB8E9L4CIxkFzIrHrGk2+Rg9ian+evXGZDQF9SBsrZnOP92HVvcVN90pN2lGu1iBNLPq/tXHGBJMzaNfLdanw== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?yJOdBSJuZV1rLSSV0CxnQUA7PoXtOqj5oi+FOnA3xyGbaCd7wK9oP23sjW45?= =?us-ascii?Q?Fnph+51b2ZIKD+j6Dwl8k2NvFtpn4tZWmW70RBqf7Mqj8+KvQhpRJBrzncnX?= =?us-ascii?Q?rUUTAP+JmRORKdEib9fShf9qRQaOdqX/6oE94iEgSDhpx+nq/567YLj87t3w?= =?us-ascii?Q?EfL59vxCU2NkqPbzxV3+zZu9Amb7qQf1T17v3ffuGXu4PH6WqF3DKrhjVxtp?= =?us-ascii?Q?KfSsHxKaXMp7B8UT5kqq3vmu8bmecQ+k54V1ROOiA6ZFdk9XrFtKbbpmGFIS?= =?us-ascii?Q?Qng60SSPX7NQPzK8BzSwe+UiZJfK2OmjNgE/evkGgilW0NhU5lEKHeCOb3wl?= =?us-ascii?Q?jUFb05K6jFTIarBT6WnpBfi8LVtwiWc8tEigH8ImGRTPUGKmk3SsdBAaQ6N9?= =?us-ascii?Q?ZUNSY8CYSwcDa2IuEhGlI7QO9KZHmPk9xqi8PqnE/js8BLipeKzM100cAf5F?= =?us-ascii?Q?i7sTX3amX5xOy0mo8zJPEr9RbOrBrTlsWtzpPjCPM6lVAAGV5D4nVNd1k6Se?= =?us-ascii?Q?G6D6PDu/IwmJkSpCf7GrilAqkgXcai5AMgA6qubdhFlOGD+DabxYDzvbCwpj?= =?us-ascii?Q?GFEdqc6Czio/7JYrO8GJiP1boE0OW7Qfqfzrt2OsKK7snj8CjnQyoXkKwme/?= =?us-ascii?Q?16yNNq24PExJTsNIs398OXOYxiXLm7hoKWvupOo0l+njd49dFM30pwMZ+Ooj?= =?us-ascii?Q?iX7BZAPfcg/JJq6+GhKc5SIj0AHS0+BlOx6pfLWkvbqdCAu4qqsmgb3DeeaE?= =?us-ascii?Q?VrqCZ4yZDsE17d1EndDiPbw4e/Afa61CRWuE7PJpHo9nlNiDrUn9kjRiCYF1?= =?us-ascii?Q?yeGdb8HO7fFctJzPnH76hfygwjbNwEUEoEVVqVubQVTTkThLdxfqv3Fp8YoD?= =?us-ascii?Q?PlBUQaO0kXjhXyjvxEEHZPff/DcbjZ8iOjup96LtI+agWKiJFnwYQJ3kRwUS?= =?us-ascii?Q?QZHJddRGUEhLTUlZT9aXNYVR4olqvzKmihzcV/ytseSIW3piWd0MHn6Sbl8A?= =?us-ascii?Q?NnM2?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:03.3365 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 1f1c0e19-7710-4389-2ec5-08d8b2894074 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qMqaw5uyVG0nNb45x4mfq98pYcUfBbrQaFhdjnPdQq1ko8DFhxAfrRXzx58ATHlOOVv22gkVMWMs82ssPAu8rw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: EY2Stng3J3O9cyMe1QAvszQEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968187; bh=fkxN5vPh7Mo0wgW9Ic9GoLCwup4RrQYm1Nczpl8Omik=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=XA+/qgiNv3INIVVH1+Iv/VJBvz8cvAVimKfsE4cQk6pTymojASFlZXTThALc7xXKoNh BlBG0U6/XvWcwyiP595W8Isl0MYBIiCA3uneo/oHmWwTjvi1iw2biDPLuiC96BOYG8Ork uDl3DGjR6hL/hVv9TseN3rW2DKbzK/xh5E8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 To ensure that we always use a validated encryption mask for an SEV-ES guest, create a new interface in the MemEncryptSevLib library to return the encryption mask. This can be used in place of the multiple locations where CPUID is used to retrieve the value (which would require validation again) and allows the validated mask to be returned. The PEI phase will use the value from the SEV-ES work area. Since the SEV-ES work area isn't valid in the DXE phase, the DXE phase will use the PcdPteMemoryEncryptionAddressOrMask PCD which is set during PEI. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Rebecca Cran Cc: Peter Grehan Cc: Anthony Perard Cc: Julien Grall Cc: Brijesh Singh Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- OvmfPkg/AmdSev/AmdSevX64.dsc = | 4 +- OvmfPkg/Bhyve/BhyveX64.dsc = | 4 +- OvmfPkg/OvmfPkgIa32.dsc = | 4 +- OvmfPkg/OvmfPkgIa32X64.dsc = | 4 +- OvmfPkg/OvmfPkgX64.dsc = | 4 +- OvmfPkg/OvmfXen.dsc = | 3 +- OvmfPkg/Library/BaseMemEncryptSevLib/{BaseMemEncryptSevLib.inf =3D> DxeMem= EncryptSevLib.inf} | 15 +- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf = | 56 +++++++ OvmfPkg/Include/Library/MemEncryptSevLib.h = | 12 ++ OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c = | 145 ++++++++++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c = | 94 +----------- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c = | 159 ++++++++++++++++++++ 12 files changed, 400 insertions(+), 104 deletions(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index bb7697eb324b..d39436e7afc9 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -164,7 +164,7 @@ [LibraryClasses] QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf @@ -285,6 +285,8 @@ [LibraryClasses.common.PEIM] Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif =20 + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index b93fe30ae4e0..33edf3d2d6b5 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -163,7 +163,7 @@ [LibraryClasses] QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf =20 CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf @@ -292,6 +292,8 @@ [LibraryClasses.common.PEIM] Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif =20 + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 26a013ec353e..75c5f46a7786 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -170,7 +170,7 @@ [LibraryClasses] QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif @@ -310,6 +310,8 @@ [LibraryClasses.common.PEIM] Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif =20 + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 10579fe46c5b..8693248b4ea0 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -174,7 +174,7 @@ [LibraryClasses] QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif @@ -314,6 +314,8 @@ [LibraryClasses.common.PEIM] Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif =20 + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index c9235e48ad62..799468e08e92 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -174,7 +174,7 @@ [LibraryClasses] QemuFwCfgSimpleParserLib|OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFw= CfgSimpleParserLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf !endif @@ -314,6 +314,8 @@ [LibraryClasses.common.PEIM] Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf !endif =20 + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 12b7a87ee877..c13388ba5a05 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -161,7 +161,7 @@ [LibraryClasses] SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVar= iablesLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf - MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLi= b.inf LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf @@ -273,6 +273,7 @@ [LibraryClasses.common.PEIM] QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLi= b.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf = b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf similarity index 68% rename from OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf rename to OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index 7c44d0952815..837db0876184 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -1,7 +1,7 @@ ## @file # Library provides the helper functions for SEV guest # -# Copyright (c) 2017 Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -10,11 +10,11 @@ =20 [Defines] INF_VERSION =3D 1.25 - BASE_NAME =3D MemEncryptSevLib + BASE_NAME =3D DxeMemEncryptSevLib FILE_GUID =3D c1594631-3888-4be4-949f-9c630dbc842b MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D MemEncryptSevLib|PEIM DXE_DRIVER DXE_= RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER + LIBRARY_CLASS =3D MemEncryptSevLib|DXE_DRIVER DXE_RUNTI= ME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER =20 # # The following information is for reference only and not required by the = build @@ -29,15 +29,17 @@ [Packages] OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 +[Sources] + DxeMemEncryptSevLibInternal.c + MemEncryptSevLibInternal.c + [Sources.X64] - MemEncryptSevLibInternal.c X64/MemEncryptSevLib.c X64/VirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] Ia32/MemEncryptSevLib.c - MemEncryptSevLibInternal.c =20 [LibraryClasses] BaseLib @@ -49,3 +51,6 @@ [LibraryClasses] =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf new file mode 100644 index 000000000000..7c29d14039d6 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -0,0 +1,56 @@ +## @file +# Library provides the helper functions for SEV guest +# +# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D PeiMemEncryptSevLib + FILE_GUID =3D 15d9a694-3d2a-4184-9672-ba55c3070e07 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MemEncryptSevLib|PEIM + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + PeiMemEncryptSevLibInternal.c + MemEncryptSevLibInternal.c + +[Sources.X64] + X64/MemEncryptSevLib.c + X64/VirtualMemory.c + X64/VirtualMemory.h + +[Sources.IA32] + Ia32/MemEncryptSevLib.c + +[LibraryClasses] + BaseLib + CacheMaintenanceLib + CpuLib + DebugLib + MemoryAllocationLib + PcdLib + +[FeaturePcd] + gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire + +[FixedPcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index a2c70aa550fe..872abe6725dc 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -135,4 +135,16 @@ MemEncryptSevLocateInitialSmramSaveStateMapPages ( OUT UINTN *BaseAddress, OUT UINTN *NumberOfPages ); + +/** + Returns the SEV encryption mask. + + @return The SEV pagetable encryption mask +**/ +UINT64 +EFIAPI +MemEncryptSevGetEncryptionMask ( + VOID + ); + #endif // _MEM_ENCRYPT_SEV_LIB_H_ diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c new file mode 100644 index 000000000000..2816f859a0c4 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c @@ -0,0 +1,145 @@ +/** @file + + Secure Encrypted Virtualization (SEV) library helper function + + Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevStatusChecked =3D FALSE; + +STATIC UINT64 mSevEncryptionMask =3D 0; +STATIC BOOLEAN mSevEncryptionMaskSaved =3D FALSE; + +/** + Reads and sets the status of SEV features. + + **/ +STATIC +VOID +EFIAPI +InternalMemEncryptSevStatus ( + VOID + ) +{ + UINT32 RegEax; + MSR_SEV_STATUS_REGISTER Msr; + CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax; + BOOLEAN ReadSevMsr; + UINT64 EncryptionMask; + + ReadSevMsr =3D FALSE; + + EncryptionMask =3D PcdGet64 (PcdPteMemoryEncryptionAddressOrMask); + if (EncryptionMask !=3D 0) { + // + // The MSR has been read before, so it is safe to read it again and av= oid + // having to validate the CPUID information. + // + ReadSevMsr =3D TRUE; + } else { + // + // Check if memory encryption leaf exist + // + AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); + if (RegEax >=3D CPUID_MEMORY_ENCRYPTION_INFO) { + // + // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported) + // + AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NUL= L); + + if (Eax.Bits.SevBit) { + ReadSevMsr =3D TRUE; + } + } + } + + if (ReadSevMsr) { + // + // Check MSR_0xC0010131 Bit 0 (Sev Enabled) + // + Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); + if (Msr.Bits.SevBit) { + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; + } + } + + mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevStatus; +} + +/** + Returns the SEV encryption mask. + + @return The SEV pagtable encryption mask +**/ +UINT64 +EFIAPI +MemEncryptSevGetEncryptionMask ( + VOID + ) +{ + if (!mSevEncryptionMaskSaved) { + mSevEncryptionMask =3D PcdGet64 (PcdPteMemoryEncryptionAddressOrMask); + mSevEncryptionMaskSaved =3D TRUE; + } + + return mSevEncryptionMask; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 02b8eb225d81..b4a9f464e268 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -2,7 +2,7 @@ =20 Secure Encrypted Virtualization (SEV) library helper function =20 - Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -12,102 +12,10 @@ #include #include #include -#include -#include -#include #include #include #include =20 -STATIC BOOLEAN mSevStatus =3D FALSE; -STATIC BOOLEAN mSevEsStatus =3D FALSE; -STATIC BOOLEAN mSevStatusChecked =3D FALSE; - -/** - Reads and sets the status of SEV features. - - **/ -STATIC -VOID -EFIAPI -InternalMemEncryptSevStatus ( - VOID - ) -{ - UINT32 RegEax; - MSR_SEV_STATUS_REGISTER Msr; - CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax; - - // - // Check if memory encryption leaf exist - // - AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); - if (RegEax >=3D CPUID_MEMORY_ENCRYPTION_INFO) { - // - // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NULL); - - if (Eax.Bits.SevBit) { - // - // Check MSR_0xC0010131 Bit 0 (Sev Enabled) - // - Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); - if (Msr.Bits.SevBit) { - mSevStatus =3D TRUE; - } - - // - // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) - // - if (Msr.Bits.SevEsBit) { - mSevEsStatus =3D TRUE; - } - } - } - - mSevStatusChecked =3D TRUE; -} - -/** - Returns a boolean to indicate whether SEV-ES is enabled. - - @retval TRUE SEV-ES is enabled - @retval FALSE SEV-ES is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevEsIsEnabled ( - VOID - ) -{ - if (!mSevStatusChecked) { - InternalMemEncryptSevStatus (); - } - - return mSevEsStatus; -} - -/** - Returns a boolean to indicate whether SEV is enabled. - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevIsEnabled ( - VOID - ) -{ - if (!mSevStatusChecked) { - InternalMemEncryptSevStatus (); - } - - return mSevStatus; -} - - /** Locate the page range that covers the initial (pre-SMBASE-relocation) SM= RAM Save State Map. diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c new file mode 100644 index 000000000000..e2fd109d120f --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c @@ -0,0 +1,159 @@ +/** @file + + Secure Encrypted Virtualization (SEV) library helper function + + Copyright (c) 2020, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevStatusChecked =3D FALSE; + +STATIC UINT64 mSevEncryptionMask =3D 0; +STATIC BOOLEAN mSevEncryptionMaskSaved =3D FALSE; + +/** + Reads and sets the status of SEV features. + + **/ +STATIC +VOID +EFIAPI +InternalMemEncryptSevStatus ( + VOID + ) +{ + UINT32 RegEax; + MSR_SEV_STATUS_REGISTER Msr; + CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax; + BOOLEAN ReadSevMsr; + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + ReadSevMsr =3D FALSE; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + if (SevEsWorkArea !=3D NULL && SevEsWorkArea->EncryptionMask !=3D 0) { + // + // The MSR has been read before, so it is safe to read it again and av= oid + // having to validate the CPUID information. + // + ReadSevMsr =3D TRUE; + } else { + // + // Check if memory encryption leaf exist + // + AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); + if (RegEax >=3D CPUID_MEMORY_ENCRYPTION_INFO) { + // + // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported) + // + AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NUL= L); + + if (Eax.Bits.SevBit) { + ReadSevMsr =3D TRUE; + } + } + } + + if (ReadSevMsr) { + // + // Check MSR_0xC0010131 Bit 0 (Sev Enabled) + // + Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); + if (Msr.Bits.SevBit) { + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; + } + } + + mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevStatus; +} + +/** + Returns the SEV encryption mask. + + @return The SEV pagtable encryption mask +**/ +UINT64 +EFIAPI +MemEncryptSevGetEncryptionMask ( + VOID + ) +{ + if (!mSevEncryptionMaskSaved) { + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWork= AreaBase); + if (SevEsWorkArea !=3D NULL) { + mSevEncryptionMask =3D SevEsWorkArea->EncryptionMask; + } else { + CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; + + // + // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) + // + AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NUL= L); + mSevEncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); + } + + mSevEncryptionMaskSaved =3D TRUE; + } + + return mSevEncryptionMask; +} --=20 2.30.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 (#69864): https://edk2.groups.io/g/devel/message/69864 Mute This Topic: https://groups.io/mt/79485055/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69865+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69865+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968197853373.8560401789914; Wed, 6 Jan 2021 13:23:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 03jMYY1788612xVlseUoNrW6; Wed, 06 Jan 2021 13:23:17 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.55]) by mx.groups.io with SMTP id smtpd.web12.495.1609968193589323093 for ; Wed, 06 Jan 2021 13:23:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a/6fosukDC9KwoUSrT1YZ/akfIo0yD8LnyHTP6hm0c9ohRADSXQ2Ai1RycihSnsXUdhm9uC6kpyLYNYiXWEXcuxe524mhstRAwJy6cadXz4yeoclHDEMGTIYhUnbCfqJIO8Ec2CY3flr3s3RiYLRAQFyYjC0DwQG6UlHmtrcm1Dxe+XqVRt1ix4x55AcZkveqmF8sCE/PwqxUnIPkQyomjMz4STl8bl9mE6guWAaOSNRVFqJHAKCKcdRJSDZfiGiSJQetXC2RpCh9EUtuu+WcyHzUrzBOEPywZ8rYCA45Ma1UXfoNt6Fh0IpL0TThUQk2IqHmHHU6hDL9N92dsab0A== 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-SenderADCheck; bh=jeEgzUb8t61v+Ua9D81FBAr9Kebe9Nr/1KOjQARlENE=; b=Ox6HpGQH9+p96K5voApQarW6MpVD0FTjfP3zrz3so0Wwm8Cy9755LxU7O2daH0V/PsyYUblqBj9oN8bbjyMTfWKtbJVGDVb6LbqkgoSbFc9wz8z+nTf+lbHKEIeEcaNcfpIQgqlKhSWC1+7cC8u7XQvfGloBgngDOfA0n5tNoCU39q91F6IalTUdRZjWEPQOL6DPK+MEjj2c9PoPjrNvwip6VsewumlIUX6oH5bC5nmBLKnsEnwMdW3o1oOadlBBOF3cjRr2Ynch5AK/YqL28rLoAR7shbLFbgVMx7zyPH6Bg/5y5no+WqeIWt5dn/bVTst8SWWci3q1MulKdngvwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:12 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:12 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran , Peter Grehan , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v2 07/15] OvmfPkg/MemEncryptSevLib: Obtain encryption mask using the new interface Date: Wed, 6 Jan 2021 15:21:33 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0043.namprd11.prod.outlook.com (2603:10b6:806:d0::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0043.namprd11.prod.outlook.com (2603:10b6:806:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:23:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d666010c-63c6-41e9-c8ed-08d8b2894592 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 2Vcjn8HhfGH32Dni6EUYre+bm1AaISPULxaG+EpuM1Kgyv8q5ACiHrSyqPcrYtZNUoy37IKZRSz1y2NdmuUAToqyr+f8SfXMV6rCuxvMoKG7okO2Rh9sPnxh4JSNBhUsIHdRv44tHvT3sGu3vbXLqF7VOHc/bpuCgG8g0jIutWHRRq7VG5bwZNGlMh8XfaX1C0yI21++VpIzoDoFIQbpLjAFYmA73jL7jvmtHOzp+TFn76ICOJGSGtHTndjHAT6Yy/6Ufj1Wq8pFUPMYDsu99Mltlo+LxgMlZENMOEydIalsuq5iL/I13V8DtfMf0M008paPGiNvyJkDbcDUzASRABqwio6SpDZWL5nKSXGD0n7BnKy5NwUo7QrL8jOwyRC4gKz041se7WmLDP6VvZiKM3RLeitkNr7FEDjRo5IfL38/l4kNYX85u2DNtSwqbOPEEhDi9S66Z1tnPlD4TYnCEg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?I2ppsACoPR/dIOJsnCIhSod1DrA8h3umLzV72f1Hoe/YdovrOh3TFjBAOb+7?= =?us-ascii?Q?vmH8olzcRrjmp8aA2m4pTJ8DGTXg7UFpHZ94IG3JGJ4prYcH6UxWv71oA5j1?= =?us-ascii?Q?wi846Uf2NB0f9tdG1RY359Z9o5YgiArMhan6i6UK/RF7I2dGDz+Wy+/3Stxy?= =?us-ascii?Q?uXllHRYEDoTvvwSw3oJ/Elm+xDErnddkx5hhtVpVmuoqh68jBlxXC0vXPit9?= =?us-ascii?Q?rjuXfzILThLMA/Pa3SBvj2urTCMVGec2QzSLnTE+A7fbsOGmBs9W1knSJuFz?= =?us-ascii?Q?nqHbadMU652h9p75UDly+Nkc92U5rpl30aY8pBZRGNPPGvOBM+QDKut5I7D6?= =?us-ascii?Q?bs/4Ma/RLjNu+m4hX8LepGinSc9whvpUbna7ycOkeje1bmw/RSw+RCvXenTS?= =?us-ascii?Q?AmaZdFOgLxkdCWhD3yb3JQRWIIloRzFSpDBfcUCFBxk6KmcTfxeL/L49umzY?= =?us-ascii?Q?L3JA46Bkqz2aYMW0OGyw83Mc0HcBkjvLmp5i5NogLmj3/4Qwhij+DMjICEjg?= =?us-ascii?Q?TZu7o/h/obwpCxDoOLxl+arPRgT9+LrUphPq9l5K0HNwzCTgPM6bVL4k/l70?= =?us-ascii?Q?U7YzDQPauJ6bi2MFILrct11wD9uBE4lYRmZVfpNCQ+n4KNKwqzCejnTD3sao?= =?us-ascii?Q?ygXypT6vD3/XSxIYnHJdMoO4qypeVW/HGxo8XKnzYO1QpFoNSbVtniv/JwPJ?= =?us-ascii?Q?0PWCvQt40xWxDl+TQSIUQf4voXnBzSkXhlJfOStVumI+1tx7eBW7WADyzqmA?= =?us-ascii?Q?Cmh65i0291zJEeCQO14F4vpQoRNWqzy7bz34kZBBpsuqbjPuzGBOf0KDXYFF?= =?us-ascii?Q?+TT7O+FXS1iOOWOunWmVJ8Qe8kwz38vVX9DDqqnohcMLNSH98QxOSSVIKLjz?= =?us-ascii?Q?NuORHKfY/0IXirpDLok7nYSFkPTfhNoJtNwq7HZaecb/qcS30Yo7VmvZPKLO?= =?us-ascii?Q?fy6Uz1l/x5t4VwnCPmQOYoblgH5Wb456uX+TDLv11trKj5VXVWpqkj6HkfB/?= =?us-ascii?Q?Zr4d?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:11.9047 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: d666010c-63c6-41e9-c8ed-08d8b2894592 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KiVmcUlZE7Gk6+jHk2IhxQaelJExNleQ+LB2Sx0NP8yhEl1yKqbML3lMTZS8StS1+rpiqJoIs7lEZpy2qg001Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: 1DtXxkVCnDZigu0CqIzMLiP4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968197; bh=LKPFdDWDA9qQMYP6OVkmQvw7gOR/tARWzF398XaRsuc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=kdbQeyUkosOshuacnccy/hcdbS/R2BCEIBBMJyrOhFyfmDz+6Lvcf3OztHhM7T2uER8 aez9PD8p+mK4IERFVdSo6RDqiexctUg3CWoi6CBrPdFzk6Y2S7VPPsmzkPfwWBuPKNTbl fxsygLsLtcIugLkHuW09y7BnZUg/UygPrtY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 The early assembler code performs validation for some of the SEV-related information, specifically the encryption bit position. The new MemEncryptSevGetEncryptionMask() interface provides access to this validated value. To ensure that we always use a validated encryption mask for an SEV-ES guest, update all locations that use CPUID to calculate the encryption mask to use the new interface. Also, clean up some call areas where extra masking was being performed and where a function call was being used instead of the local variable that was just set using the function. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Rebecca Cran Cc: Peter Grehan Cc: Brijesh Singh Cc: Anthony Perard Cc: Julien Grall Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- OvmfPkg/Bhyve/PlatformPei/AmdSev.c | 12 ++---------- OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 15 +++++-------= --- OvmfPkg/PlatformPei/AmdSev.c | 12 ++---------- OvmfPkg/XenPlatformPei/AmdSev.c | 12 ++---------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/OvmfPkg/Bhyve/PlatformPei/AmdSev.c b/OvmfPkg/Bhyve/PlatformPei= /AmdSev.c index e484f4b311fe..e3ed78581c1b 100644 --- a/OvmfPkg/Bhyve/PlatformPei/AmdSev.c +++ b/OvmfPkg/Bhyve/PlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -15,8 +15,6 @@ #include #include #include -#include -#include #include =20 #include "Platform.h" @@ -32,7 +30,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -43,15 +40,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c index 5e110c84ff81..6422bc53bd5d 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c @@ -3,7 +3,7 @@ Virtual Memory Management Services to set or clear the memory encryption= bit =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
- Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -12,6 +12,7 @@ **/ =20 #include +#include #include #include =20 @@ -39,17 +40,12 @@ GetMemEncryptionAddressMask ( ) { UINT64 EncryptionMask; - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; =20 if (mAddressEncMaskChecked) { return mAddressEncMask; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); =20 mAddressEncMask =3D EncryptionMask & PAGING_1G_ADDRESS_MASK_64; mAddressEncMaskChecked =3D TRUE; @@ -289,8 +285,7 @@ SetPageTablePoolReadOnly ( LevelSize[3] =3D SIZE_1GB; LevelSize[4] =3D SIZE_512GB; =20 - AddressEncMask =3D GetMemEncryptionAddressMask() & - PAGING_1G_ADDRESS_MASK_64; + AddressEncMask =3D GetMemEncryptionAddressMask(); PageTable =3D (UINT64 *)(UINTN)PageTableBase; PoolUnitSize =3D PAGE_TABLE_POOL_UNIT_SIZE; =20 @@ -437,7 +432,7 @@ Split1GPageTo2M ( =20 AddressEncMask =3D GetMemEncryptionAddressMask (); ASSERT (PageDirectoryEntry !=3D NULL); - ASSERT (*PageEntry1G & GetMemEncryptionAddressMask ()); + ASSERT (*PageEntry1G & AddressEncMask); // // Fill in 1G page entry. // diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4a515a484720..954d53eba4e8 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -17,9 +17,7 @@ #include #include #include -#include #include -#include #include =20 #include "Platform.h" @@ -116,7 +114,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -127,15 +124,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 diff --git a/OvmfPkg/XenPlatformPei/AmdSev.c b/OvmfPkg/XenPlatformPei/AmdSe= v.c index 7ebbb5cc1fd2..4ed448632ae2 100644 --- a/OvmfPkg/XenPlatformPei/AmdSev.c +++ b/OvmfPkg/XenPlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> Copyright (c) 2019, Citrix Systems, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -14,8 +14,6 @@ #include #include #include -#include -#include =20 #include "Platform.h" =20 @@ -30,7 +28,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -41,15 +38,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 --=20 2.30.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 (#69865): https://edk2.groups.io/g/devel/message/69865 Mute This Topic: https://groups.io/mt/79485057/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69866+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69866+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968209304802.5768824568584; Wed, 6 Jan 2021 13:23:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id CF27YY1788612xPmQLxOv0hu; Wed, 06 Jan 2021 13:23:27 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.73]) by mx.groups.io with SMTP id smtpd.web11.489.1609968202441317657 for ; Wed, 06 Jan 2021 13:23:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yf1fctfa766CgRxMkiWYRQzFEbPM9ydaQZvInCp/z18eEjsPCKGVWRVbCnJGnH0B5J3oC/O/4P+uO7bXO4S77V4Hicm14H+wLe4BuVer6a7x2lvFzFiD81zTYYgEmHr2Cbmuv85EEqjtv/osYp89ENDtIVv2X5ZsK/7wierAZdukZqcaWwWiEFpKow8RlNqzBRc8JXa+EWxWJfYW7BqLOhA4gt1qVSgHOvrUElxSpJu87A7Ckx8wkIEkL+aLdDR8gR2+Fe104y+pes2zIa4aMBnn+2+eUIAHVEJWSBk0FOBSbs1jMDh2iMMRxQ20mjKPcGKYlRyKcJAcN214/C7uEg== 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-SenderADCheck; bh=xrWe/lVlufpffDCm+3yDZdIMpp8lRR1l0HrvZ/IqIgI=; b=N/hOWXSLEj3MA50Z2zYyUgY90iY6BykCk80elp2ufaAVV5J8ktslYS8Y2hIZcSfk+6v4qMZdRbGG20j0ufmF6/D3doLEQDAfwzMGayTNy+HrbtmfEuOyqQ41W9pAd7mAWjA2O6d1zFJh4KpM9M9jl73kPLTOBjyYu5qvAGOc6e9sn2JEQgdolA5t/FHBUn/Ls3tvpibxwBQkyuE1t8gaXl2zW3dO13ySD0E1ULuCsmPinMFPvhhDpMN92gawoLtk5u1sdwLezbVZ1sXkY6baz/gF8y7QgNn8R6JCRnbbqfL5m66E5oSqmRqrqxFgLLe+hLEDxCfTnPEBHuuTOWre/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:20 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:20 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 08/15] OvmfPkg/AmdSevDxe: Clear encryption bit on PCIe MMCONFIG range Date: Wed, 6 Jan 2021 15:21:34 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:23:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fdb60507-decb-4245-4b06-08d8b2894a7e X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: k+2H+gUQW4/mmvRf88F5QgV1KIudZXaJTCWSFROdj8wJzC+7hyr5iBRr0Aeqnnk3bv/RxbmxV6UTmQ+nK7NGquA7BKhysxl7JVcWrqWvnVMwwSow96lUwTlxQXFzHPpy1OY/39eYUvjWLv0mP4UY58A+dqIH7pS7Jz2Jaty3rMcc4J8gbCI+NG1cXy49zvY4IfJunnImiV14wuC0iH+1zxoDzRB23gjbhnXz95I/xrR/fMJ+PEIsaxRdeLAt2DcXfUTgF1mf8rfSNk4V2LoP3xMKGDdmtyKrdMLfSS1zKRbrsEH2MEczgmCx+TB1LxuHewTIkmw5/MU5ZQUWm+ZP042+YpVOpvdCgQNJVWZEtjzYAdpl/MKzqiPqRccWr7saciCTCfcleI30/eIOacHFwCpmv/mqiCK2xzYJgrItYtYUBQjcTVhJRvjm8302RKQdRF7O+CAziCV9yPN7QLYycw== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?1A/r129cXAWBE2Hc/Yc+wov8sHdppbyhKxkBGkXlIs+rCV0DlUy58kYWNfwx?= =?us-ascii?Q?dPwlxCbXC1Et3N2eMJhBg20gNnP0/Fxu7GzV9YI9xl5E2+yXSIOvnTmAklwn?= =?us-ascii?Q?8L3SLIoGOrnp9wuYA7y4fqkurjp9aAhjBLrzBUcLU9ue0AFfSykjx+pexEOg?= =?us-ascii?Q?X24qhYVxjXuhq6KZHdHQ1RZxOtReVkEnXVjQzXwV7Oq98fPszarE6PoHlAoU?= =?us-ascii?Q?jrwgtQF/6XhyHh4cr6uxg7x2Q26wbPt3CI9s78jrSqeMkdKlRoU2UGkwD9Ho?= =?us-ascii?Q?wGHwjP8gKrmSXtQ36VHg3qYU6ylZXxNKY2PudUMROsTtzqRK2rzNtYlw/YT2?= =?us-ascii?Q?0BsXRdryRp0RqhVkdZ0AdKvxJVz018Rt5fsHhXc6xIRx+Prm2jlFUUMv7FP2?= =?us-ascii?Q?rZJEwKl4lTAblJ9D0V7F5cx2pw8T5Mz0hQsIE2VswgbQdFJTPtwfT3GSpPSt?= =?us-ascii?Q?tIIW0B+5t5BEre5WxaJjD0p1kkLZPjJnPY/pd5KigBe15dHzmXChd/tS5Uvi?= =?us-ascii?Q?qaBYOqU0AbiByg3i37eO7PoTa1VqzYYoA1x3jKmLTrosvGTDpx6zKsmgicel?= =?us-ascii?Q?DBz8oyrzJI6uqIeW32yujk+/00Q45h31OBcHA4tU514/9YWgTd1uT62ZHPjR?= =?us-ascii?Q?+GHBNlOk2zUdBS9a3OO0isF9CNSDr4LnnM69XfGCFt4GIbKcUqGIl/jxCQSj?= =?us-ascii?Q?hokbAJwVsnytY+fvk9dJKw/i4lmQCgIDqqnSsHq+JdBpUm5QC2Dlfl0BCelD?= =?us-ascii?Q?YohTLOQXuwBKWqdiSd9A8NQ0LBLdImsqYVP66B9oKnyoVmN/lxScgRX+y5Il?= =?us-ascii?Q?7vIj6Rj1W2Uu+75uobAhezC0YedVwj2InlfZqJJbZCpTpvPaDQNY2wRQcLVJ?= =?us-ascii?Q?XeeO0SGNvDfwwjKISJEJEOZjR2z7BWPPIvYdb5T2gCUnbRNE2BW3ytrRmP7R?= =?us-ascii?Q?bRW3i9lcWxCgh3hoVKNm7YpDvfhQVGeSfhmY3e8414o4W36pvp2tw3DA1HCt?= =?us-ascii?Q?+ILQ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:19.6772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: fdb60507-decb-4245-4b06-08d8b2894a7e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HdBAvUlO+08c2ZpcpAzpVzai3VteEC/941qoitNMpf1n1a6SYGheSwAXyfemJCXre3lOQ35fDurjpIUZ7OV8Uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: uKnKXcmR7qTqjOYhLnihNdJox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968207; bh=ujSHZmBGDP2+k1COrMqF7iMaz/2mm1iDrpMVqrMR7lM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=QtGkOCzI+qu1Its40n44EYto03KM2pFR7hZJ6CgTbOsrBK3MI5DZSJUzLEobNJtPSSS GRCR/7UvQEW/WppKRe2Eiw+KtE/x+u6rg40GP4ZhKJirXRw2CQgVOjKFMeGRyZ5YOypDA V6g+4l1sLxgebzsDSA5PNDnsqlnEh3NfdYc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 The PCIe MMCONFIG range should be treated as an MMIO range. However, there is a comment in the code explaining why AddIoMemoryBaseSizeHob() is not called. The AmdSevDxe walks the GCD map looking for MemoryMappedIo or NonExistent type memory and will clear the encryption bit for these ranges. Since the MMCONFIG range does not have one of these types, the encryption bit is not cleared for this range. Add support to detect the presence of the MMCONFIG range and clear the encryption bit. This will be needed for follow-on support that will validate that MMIO is not being performed to an encrypted address range under SEV-ES. Even though the encryption bit was set for this range, this still worked under both SEV and SEV-ES because the address range is marked by the hypervisor as MMIO in the nested page tables: - For SEV, access to this address range triggers a nested page fault (NPF) and the hardware supplies the guest physical address (GPA) in the VMCB's EXITINFO2 field as part of the exit information. However, the encryption bit is not set in the GPA, so the hypervisor can process the request without any issues. - For SEV-ES, access to this address range triggers a #VC. Since OVMF runs identity mapped (VA =3D=3D PA), the virtual address is used to avoid the lookup of the physical address. The virtual address does not have the encryption bit set, so the hypervisor can process the request without any issues. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 8 +++++++- OvmfPkg/AmdSevDxe/AmdSevDxe.c | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.= inf index dd9ecc789a20..0676fcc5b6a4 100644 --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf @@ -2,7 +2,7 @@ # # Driver clears the encryption attribute from MMIO regions when SEV is en= abled # -# Copyright (c) 2017, AMD Inc. All rights reserved.
+# Copyright (c) 2017 - 2020, AMD Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -39,3 +39,9 @@ [Depex] =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c index 595586617882..689bfb376d03 100644 --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c @@ -4,12 +4,13 @@ in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when = SEV is enabled. =20 - Copyright (c) 2017, AMD Inc. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 +#include #include #include #include @@ -65,6 +66,23 @@ AmdSevDxeEntryPoint ( FreePool (AllDescMap); } =20 + // + // If PCI Express is enabled, the MMCONFIG area has been reserved, rather + // than marked as MMIO, and so the C-bit won't be cleared by the above w= alk + // through the GCD map. Check for the MMCONFIG area and clear the C-bit = for + // the range. + // + if (PcdGet16 (PcdOvmfHostBridgePciDevId) =3D=3D INTEL_Q35_MCH_DEVICE_ID)= { + Status =3D MemEncryptSevClearPageEncMask ( + 0, + FixedPcdGet64 (PcdPciExpressBaseAddress), + EFI_SIZE_TO_PAGES (SIZE_256MB), + FALSE + ); + + ASSERT_EFI_ERROR (Status); + } + // // When SMM is enabled, clear the C-bit from SMM Saved State Area // --=20 2.30.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 (#69866): https://edk2.groups.io/g/devel/message/69866 Mute This Topic: https://groups.io/mt/79485062/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69867+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69867+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968210147918.6414188693954; Wed, 6 Jan 2021 13:23:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kJm8YY1788612xAWsnl4RMxy; Wed, 06 Jan 2021 13:23:29 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.68]) by mx.groups.io with SMTP id smtpd.web08.514.1609968209166181402 for ; Wed, 06 Jan 2021 13:23:29 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RWzKQHw1YFS4rKIjBHHsjRXX4yYPrDb+zjtw8KxhEYf6L/uaaFGno/+GK3oOE38UDt2kAbLTLo8XvNGSQAMxjTmAauBRYFUMcM/YUyJWh9P1KmkBbQzDlvj3+6ccpMfTB7pqP6zNehK/ycXkCgjd5GTA6ZOWpGSKsy0kBLdhOWi6WwpZ6BzLtbMPqqOF7cJsEsmdx3V2iQgJd60kxqenQFtwVSf8klCcwA0krUxHr6bJtTiyqN8uKpLFo15bHvVoZLRWUjR7IKts3gKKh5ByMSouW2y49mvg0GRPHQdNULp4SMXvkQ4kTnsKMHrKCnPBwXHZotL8MxY7nJr3spnfag== 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-SenderADCheck; bh=8kFpyzoO8wbsDOFAoVQRLo3+seYYNZM3lE1pSLkD3+8=; b=R6FJsfhrOK6D7xW9lzfaV3HzVyuQXVldlALglgnMqdpkq+P1Ie6+Dm0R+BEVALsQmkpnuPBieeuUKTg8aO72duftx87PlYOLcNDYO8x+8qMSbQl9TmCzA6C/y8EDnuzkZ5ssSs5vcZkTblyoZsN5MhG6xECag0TNIw2zLYnAMNnt9Na5BairVvzvuHc8oxhqddVcAhKgZxW1iFtAMtThQbmgPiTI0AshQWUkGyNSo0Qxcb3liLiMGbAowF8knn2+AtzHtFJh11FPqEwmYenvw8oC6S/UOiiGJKBJXCbmlFroR2/fZRK8GyY5AL/0vcmjlEKPddTlvofQdyNvCTfcyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:27 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:27 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 09/15] OvmfPkg/VmgExitLib: Check for an explicit DR7 cached value Date: Wed, 6 Jan 2021 15:21:35 -0600 Message-ID: <0657a0677b1d39bfa3797c9a5fe098936416ab78.1609968101.git.thomas.lendacky@amd.com> In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.2 via Frontend Transport; Wed, 6 Jan 2021 21:23:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fe3bd03c-fc30-4416-57bf-08d8b2894eff X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: mzSPE7/+ZUvwgPpYJ2XZf0ty8c7iNvIivjge93Ta6lD2VX4kyIFcJ4SBMYy2hIC8Hc+X4BPoGzz1vipyZFqJF83ZexsxUXDuwb6Qy4bz1Hv5Ze+PPhzFUogK1OosurAD/kcnk1crBOwTWhecaHvBcgwLiugrJi+ptJLIjzVqdM2Tv6/cIEMeV0U5eMwNHVyNIIDkJuLOs5cRmN0ATt1B3BuKeijEcRQxi2lBaZMYQkZPcc6kQSKBmULsRrSOnCCFUhdUDFiwEkAL8x9FkvB+30EgzR0PiF0LFLN2oOhLTR5zvzze4wi/gPyYxnSxcBKqkd4d9qGtUPsIA1ULuxC/ur4aZbnD1Dpfwdp5VhpSWHSfqWRFCSl66dJ5+MYU4il1nCkaMVAPs6USfIlTTChF+bdP4+Ib/2rxkQiPRIhN3SmJL5Nx+7RLDyDh/mrFvv8+dQ56SAjbXy0vcJEFdVRxwg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?38qIetP0z3ruzQDQeb3AJa41tFLAF6wCmp0ZBEpAp4FotpZ5qvVQIL8VhrqX?= =?us-ascii?Q?siLVZq5tKmr3xhfU46M/Xcqr/xdshdEkmUU5wRoFEnx0Q4Sd1at1zkVpt6S3?= =?us-ascii?Q?SF8dUMmA2jY9yi4pXQsVBSwX0s+CN5/ajKUADEnoO7dafY+OTS1pkHWkZHrD?= =?us-ascii?Q?JpRH9UicbdeK4UyytUCFKMYlIylNsZs0puH6oC6prrJzA5iXpxfm9A0h4wkn?= =?us-ascii?Q?TF2lobhhafPYtpRq8JGuL6/IIbdGJCtuuC7Nyuqz9dFF3z1DBGN2uvw18bq9?= =?us-ascii?Q?5yhYR0rc5tnHpI0Q91k0R/Ivh7hVNvGaIyCXAWUO0qQ/L+B5aQEtQArAwTcp?= =?us-ascii?Q?NPiMHeS5vdcHQrwFaJUbg6v8axE+d7Mpk/+gKS+IDUw3VHiY40la6lHbk62E?= =?us-ascii?Q?2rydrI2yqBfOE2tgKqTkHD96dIZLmwZ8UlvUmoW0PzdscDgrcUjlK4tx1qTe?= =?us-ascii?Q?2k0Shj3vUDVFP6ktTAlftco27OwgxjMu6aG58hCJ9broPjOjguRzL4cs5jeT?= =?us-ascii?Q?S44CKF9dCaAKiJBukOoDkODEAGxgCFnwK8o3mwxIWFR/Tkq96+Ajx3L5zkRB?= =?us-ascii?Q?2lBnkpO2MPdO5YzgUeH83Duc1ZxIqCQtYt4xYx427Gg2Vj58mgqMk607jX9P?= =?us-ascii?Q?tZhZEQ+CMNrg+9D0UEawpgCxnLb7wybpBYhHTKdRZKRR1HxUpjAdCYAkPS6B?= =?us-ascii?Q?yGWST5jR8XAvHUv1OxCUrd6+MRJO46r9EnJ4w9OOd/iUGN/Jr1NwfT8THZz2?= =?us-ascii?Q?x/26KsGw5UQRhB1VhSeVqPM8FmYNYCNigKGOZ6s1VC+eqmos0ga6UQlwAue7?= =?us-ascii?Q?JfaW1vAv4+RztaM8B5YtWiUiwwts5AP5DkNOYy4kq1JaZeQPRO4HqUFq+5o/?= =?us-ascii?Q?W1Lb6G7RHhvQCyDO400bHyThf+bDwO9AY6aXDKk+ODagr24t6QOO+uepA2bR?= =?us-ascii?Q?8Mgv934IVCYT+qthf0lGga3jh+vvmOtFkQX54q+53yeC3D0RYVNRvCE818/W?= =?us-ascii?Q?s6Qs?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:27.7136 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: fe3bd03c-fc30-4416-57bf-08d8b2894eff X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ytxqWMI8cEXPslVoyZFb9W57jCUcnasgq5gTA2jGY/FxRuaq8Z5l5Pnf7hrntTkEMVd1+4RK+VWeqrqx+Re6sw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: 0vuC9WK2Dv1FG8D1wpZcMPK0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968209; bh=x/rTMYBYjpQKCJ25OYEmlrzyuUjO8pJimYhL+29QDb0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=no8BxP3OYf97cZsWDJ3kOLO6i6q0BIRmmk4CYU2cuEV6/KVwmrj/R5PdmIu89okKML+ m1/sUJP9A/O/oHC5bAf0+NUWWR8gkg+JRUcIQWru1ciTN9kaVrLNJjNjpHDrV3vMuU2qX Q01eWoyxNvPw1NaL83WNwL7m3sKu3iKzfSE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Check the DR7 cached indicator against a specific value. This makes it harder for a hypervisor to just write random data into that field in an attempt to use an invalid DR7 value. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1671db3a01b1..5149ab2bc989 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -128,10 +128,13 @@ UINT64 =20 // // Per-CPU data mapping structure +// Use UINT32 for cached indicators and compare to a specific value +// so that the hypervisor can't indicate a value is cached by just +// writing random data to that area. // typedef struct { - BOOLEAN Dr7Cached; - UINT64 Dr7; + UINT32 Dr7Cached; + UINT64 Dr7; } SEV_ES_PER_CPU_DATA; =20 =20 @@ -1489,7 +1492,7 @@ Dr7WriteExit ( } =20 SevEsData->Dr7 =3D *Register; - SevEsData->Dr7Cached =3D TRUE; + SevEsData->Dr7Cached =3D 1; =20 return 0; } @@ -1533,7 +1536,7 @@ Dr7ReadExit ( // If there is a cached valued for DR7, return that. Otherwise return the // DR7 standard reset value of 0x400 (no debug breakpoints set). // - *Register =3D (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400; + *Register =3D (SevEsData->Dr7Cached =3D=3D 1) ? SevEsData->Dr7 : 0x400; =20 return 0; } --=20 2.30.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 (#69867): https://edk2.groups.io/g/devel/message/69867 Mute This Topic: https://groups.io/mt/79485066/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69868+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69868+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968217766517.49189654344; Wed, 6 Jan 2021 13:23:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kVaHYY1788612xkOulz0KCvi; Wed, 06 Jan 2021 13:23:37 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.76]) by mx.groups.io with SMTP id smtpd.web10.463.1609968216894440102 for ; Wed, 06 Jan 2021 13:23:37 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E6LXg88EviSUwoB/dtWJfInUcnQwwGULdtkjUfIrB6u2TUpoMDiBlLqa1UCfmke396o5jNxLaGWeaAa8y+KZa1PFsSSe3C8ORVgliKc74SUrhn+HKOM3w/WXvdiEAMVp7m8m9SZf8BdUYPB+cwmCdVD+KP8ryhZXAZlnbcyf3eIe3cLN8vIO0dKFi4aX2VoSN3dCDAL8gDWNA3wzcAA0xACVR4w18aLJ544Aug21GAg+7Re9hhpDlxn6qxlt7YgHyjmXtp16oSfJbbXtLhu4C07HGHD8uFrzkdBH5tJ8cfqo6xEMJQh4h51mw/Y+OfYPdAaKC5kfHLlyYDIyVCKxrg== 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-SenderADCheck; bh=D3jFqtVqC8sQxaMIgLJ6Kv4Q2EyY8jCxAdWex4olu1c=; b=jyTY1tTmrdbx3DcA3QylkN6WaCmoMeKfyQvINOyWEgAo0QUVpsfpd4OCBcj3UdePIpP8Fa3v14r22JjWCGFY7HDII7pr+IG0otnJ+wrz9UNU0wDmJ8HWcfZ69A7KuijqXhSrhVp7IfNZ4BFIZF2lKickQHX+Gw08Dc1wnUSjf3y9p8PLMZBGLVP08RlLfNsI1+9fEHZRm34/ATXyjGXWFqxksh2RUzrCuDOz02PCQ4ihFqaPAkLW1aQwuR9ZX2+Wa7S5MqvcR/AvtEZgFsCBrJk54giMWip5od8l/aRejKVB1nZsjBr4iw6aw0ACtYz8zbOITL20/ZdrO61G+T6PzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:35 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:35 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 10/15] OvmfPkg/MemEncryptSevLib: Coding style fixes in prep for SEC library Date: Wed, 6 Jan 2021 15:21:36 -0600 Message-ID: <47e8a4edf59761c1052631487276d4ac04bea561.1609968101.git.thomas.lendacky@amd.com> In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0003.namprd05.prod.outlook.com (2603:10b6:805:de::16) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0003.namprd05.prod.outlook.com (2603:10b6:805:de::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.2 via Frontend Transport; Wed, 6 Jan 2021 21:23:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f0591923-2b44-4802-a3ae-08d8b28953b3 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: egmJmiwzJYFrZ5CcczMU81PQhpbZ18E6JDfL4yoCQCwp6r9AkEAOdwMZDxnwMUrhchTwiBDG9NqF8fVWVOdJYTJqSRfnqzw/UGvrr52pfArRU+BT32kpRlziUqB1X7ey+068vcRsl1no/hmFp0BRwyef/e+RiKse1SBlCHbTqbmrC8E41ANXHz6wmP5ZXoqVWRQUinO1n0eO9HK2CiMRe1nwa4Yo/f8lPH01VrKT4k89oDUpV9Sft1hsAruQ64NvytVNp5B3u3R5wtQAD6SDZTZ2KG49YkpbA0aqkoGAqQSRIWuNttX+NOkHGP01lLejsjqmnMi8ov02/VrivagPiBGcL5XLh96KTquD8kc/VESZUuIGE9CYXipQXKyl5aKlwFNZilPfqI1OjbI8MtXiGUDFTNrqTouyFPRMid8cKVWE3DMiJF7tPoEf67ZQ70GHWsI63EjROOzcggcd723lZw== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?84nIE9o8CiS6X1cUk+UgckQHbem9qlb3dRxcsjTz7X1m+ukP4TxhC8I9HSIT?= =?us-ascii?Q?WE+00wq5asYTnHA5rZ+5yDFzEpvCE55Se8xNq5xK4s6Y9FkxA2+UvptoOuPz?= =?us-ascii?Q?v/Sx67gr+OuDeHRct+ngqYBFp9Vt/BtX74gRMkd06nqJgWdE/DlQ+qss/1he?= =?us-ascii?Q?ox0t2MKsKQWx4VUz/bGaHpEgCm3cbbf8ml33u3u1moV0/JHxu+nVwXKnv3th?= =?us-ascii?Q?fd4conbNmyxMwj6jWKxNIwcw+AX+LPwkpEEnlFbvGFlATt/wkdCfWmc4TDXA?= =?us-ascii?Q?9dKkQlDB8SbCyB7s/ZJyKHiB4YpHpzGkmuTvec09OQecxkZuhCZBO0Tpv6lP?= =?us-ascii?Q?Rf2bnpRl9OqlYuLaQ16/8fma4hvyzmXAGWKfIfqxFI6n3FYLzecfEZcKHCt5?= =?us-ascii?Q?4N0EAj1AJikJxAyWN6foJ1YKznEq4t9igrZxbZH+JCt5sA2BuKdDAbXCUeXo?= =?us-ascii?Q?kmxHCTwKy3X4eQiJ3OEBit33vyDpYb470z6/V04n42IArAcjq3Ynp2GyRvAm?= =?us-ascii?Q?MZUtNAVI5GynDgJnIXF6MWn1wwHH8IDKt4UoVBcC6psvH7n4+thgCvnYa45e?= =?us-ascii?Q?vWPSTZsJIAB2V1uFpznTTJoCcoKYatJr3knOYOG9o/BtS0e+WWHHRsd2zqhy?= =?us-ascii?Q?PKRq/RzzQGsuqfz+63DYcJkm8BnbbrDYT/PHBRTjUFQGxvNflyf8pib8bGbS?= =?us-ascii?Q?v2zz4suC001msDD746ZDv37HuXJQdyr3WBjk8Xh3SfwnJoAD+UfFWDcfqh1L?= =?us-ascii?Q?+4kjUROJQ4WSv0Y11IT1tWk7CXDJ72ewL7OHDF4+Nr0cNsOxU6jb9QpPrcG6?= =?us-ascii?Q?MN6Bg0ss19jdubVR9q0XZYL8DwCOnRUP5a7XrUC2Ax/0blkAgVgoObNpv3xe?= =?us-ascii?Q?PYS1vX5boeamiFjFMuQ5ZUgA7mCNmDIO+FArQlRdCO3puDW5+fyrhBVUQzGn?= =?us-ascii?Q?Et/482ZcjPqsu5/CTJrCunBDTUyfi92Z8ogcQhMBhf/nnhH0i6q2rZC6Fb2e?= =?us-ascii?Q?OXoP?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:35.6720 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: f0591923-2b44-4802-a3ae-08d8b28953b3 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NbAOsOBzb6xMpHBhTLvJ0jrepKcvEt1b5HHpNDGF2gt8FShzNkSEPeVhnkdZiaK8I7EziZvNGq6zNebspZrT1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: WkNKX1ZLmdUHZhYmxImCBq8mx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968217; bh=PrZQZ2EmkmmvjB0ANymyq/QArW/zyjvGt3PK63ea+Ac=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UOt/iUNSi6PiVDNhtdSi6nUNhWf1ik+NLUsMQAOHp6V3E12k/RUUQIqUbtDagZc2qtU UxGNJsrvwrbyfgRzbGRETj5ybrPQFwK2hWeEwuw0djhzoPr/NNmBCZJKG4ckjyDZFWc79 43Jbm+kRhgbDkLv6DdLg1JAcaCtwvEuCn/0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Creating an SEC version of the library requires renaming an existing file which will result in the existing code failing ECC. Prior to renaming the existing file, fix the coding style to avoid the ECC failure. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c index 6422bc53bd5d..3a5bab657bd7 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c @@ -192,7 +192,8 @@ Split2MPageTo4K ( { PHYSICAL_ADDRESS PhysicalAddress4K; UINTN IndexOfPageTableEntries; - PAGE_TABLE_4K_ENTRY *PageTableEntry, *PageTableEntry1; + PAGE_TABLE_4K_ENTRY *PageTableEntry; + PAGE_TABLE_4K_ENTRY *PageTableEntry1; UINT64 AddressEncMask; =20 PageTableEntry =3D AllocatePageTableMemory(1); @@ -472,7 +473,7 @@ Split1GPageTo2M ( /** Set or Clear the memory encryption bit =20 - @param[in] PagetablePoint Page table entry pointer (PTE). + @param[in, out] PageTablePointer Page table entry pointer (PTE). @param[in] Mode Set or Clear encryption bit =20 **/ @@ -562,7 +563,6 @@ EnableReadOnlyPageWriteProtect ( @retval RETURN_UNSUPPORTED Setting the memory encyrption attrib= ute is not supported **/ - STATIC RETURN_STATUS EFIAPI @@ -635,7 +635,7 @@ SetMemoryEncDec ( =20 Status =3D EFI_SUCCESS; =20 - while (Length) + while (Length !=3D 0) { // // If Cr3BaseAddress is not specified then read the current CR3 @@ -683,7 +683,7 @@ SetMemoryEncDec ( // Valid 1GB page // If we have at least 1GB to go, we can just update this entry // - if (!(PhysicalAddress & (BIT30 - 1)) && Length >=3D BIT30) { + if ((PhysicalAddress & (BIT30 - 1)) =3D=3D 0 && Length >=3D BIT30) { SetOrClearCBit(&PageDirectory1GEntry->Uint64, Mode); DEBUG (( DEBUG_VERBOSE, @@ -744,7 +744,7 @@ SetMemoryEncDec ( // Valid 2MB page // If we have at least 2MB left to go, we can just update this ent= ry // - if (!(PhysicalAddress & (BIT21-1)) && Length >=3D BIT21) { + if ((PhysicalAddress & (BIT21-1)) =3D=3D 0 && Length >=3D BIT21) { SetOrClearCBit (&PageDirectory2MEntry->Uint64, Mode); PhysicalAddress +=3D BIT21; Length -=3D BIT21; --=20 2.30.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 (#69868): https://edk2.groups.io/g/devel/message/69868 Mute This Topic: https://groups.io/mt/79485071/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69869+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69869+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968230790733.6413443579961; Wed, 6 Jan 2021 13:23:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 47TrYY1788612xpX2mXSbWFg; Wed, 06 Jan 2021 13:23:50 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.65]) by mx.groups.io with SMTP id smtpd.web12.498.1609968224879271350 for ; Wed, 06 Jan 2021 13:23:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OceLdNeq1K22A7G7ZKAa7gx+6FAAps2aEj99blw0avSaNHWPeE8ooUczYZ3DltHAKmkaKDJrJlGz/AH2IFwTXDZu4Ygcpc8PRlpLP6q4lP/qIhrNQx8agwpPtxv7cifJLxG4UUhTHqDtlk7T1y2g1CDVkL6BCJeGFWTiUq6JaMi4pdgUkQqqlgf0fdtPCX/ykCRatgRwHYRjFipcZqR69piAUy6zADu0SPTfUIQbKEow841GVi/52Yug+wFkk3ApciCA2RRi4V//vr5e3Y/NdgBER4SDy6zRTTWiRNBCVrBh5YG/rXlhMUfp1fvRkqLyaeiDQpqY9XGFNT+b6x2joQ== 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-SenderADCheck; bh=Ua88ieNEocCYGzEcX72OUQe+ZYkxZuUuGVXvp6/VEFc=; b=ZjNqKCNBh7j7bdBXWppPf4RrJzgJTm+eyJprdqL2Fd9xv888+XfxjA5m846VGA8pkOU2BMqFDAx+jEiRfCpM23RKMhviry1lJlEW1p4n7HTX5J6KFcTsZnlDosmkjWT+YdY3YaJ7cbUeIPbKgqRWNcj/aYxVVaeu60nCG/0zNiqakmo7zXYH3xr1ldu3WXVZ4SZGYmYwWZgDk71RqjrUezZbTW/+3vo/c0jUtcIWhwMYyZomYb29nMN8mY7owJyIPHShzJDSJK31zpiZ9dG7Z5QJLOiHBJAEBOm2Bqo4HUCKXgct9DXDfN7Har8YxTWF9bi030m6FvBuakMD8vC+1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:43 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:43 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 11/15] OvmfPkg/MemEncryptSevLib: Make the MemEncryptSevLib available for SEC Date: Wed, 6 Jan 2021 15:21:37 -0600 Message-ID: <5a3cac5933e29eaf3bfdd1e7406335784cbb8d6d.1609968101.git.thomas.lendacky@amd.com> In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0013.namprd05.prod.outlook.com (2603:10b6:805:de::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0013.namprd05.prod.outlook.com (2603:10b6:805:de::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.4 via Frontend Transport; Wed, 6 Jan 2021 21:23:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d57bf650-620f-4769-d2be-08d8b289583f X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: LU/Uz03xV5U4i6C6xbkYamWT+pFobzBwnQFNVvSS7KVjl6tiQtdVdCRf4IaIbbAU/Z6/GWDqMyRQaVoBwmrngd8acoj2NHsqbFYCNCJFH4J/3GssYTryWMm/Qm6pfy3SiuuhGxAH21Oy0UciupZIbPoQFGtYCW3dyWTkw9fgxO4W+34zdfX27vyvSAW90p1N6KyoXSYu7Z6LOqJM9R/0/fqFSpei1Q54oDF8B1SGH5Gbb4KS/4wFB6PMqjoUmLJ3EaGzRXh0jV9Qkm0QESE6wwZw/E1KXCKim+q5hXa/do20cBXFkFoGoluApLWGG8K8KY7rZP2++QfzwHW1GQQT0Kbur/iYpzHH+tYGKUxncyrDNetdVnB1IrHxljqDmTq8mmieYZ3JJjymFYfINss8nFCbljcGgR2ihbNMn/6NURzYGu5A4SuuYuD8+7RRS9GnnMc6kFHE4krvFhsej+5NOg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?gV3VxjsuIyXAWnBT970Zwzik+xF+zkFjl4V1uLqD6hedsey6sPgb58Thar+6?= =?us-ascii?Q?yWQk0aTCX1qdrr5LVC64QuztD5ahe6tXb83T7UjCeEZHbQGhU7amuvewzOFa?= =?us-ascii?Q?DE9v5DPMQul0kvhoOR5y+wWx1swOi0NIkWoMgVVDzhbDDUUfmVVFn2XLiMSQ?= =?us-ascii?Q?+pvHthrZNLS2idOWmvhl/oruvbGh7Y3xTrPdRPIcOyCfv4PMNS2n/BzvWaqv?= =?us-ascii?Q?QI1+2VKpOHcx/J7MnmMVvCCwXQPYhk2LAqQ05uuLqky4jLSvknYo2AIfggjX?= =?us-ascii?Q?zRKGDk3L1A6XmxoRlSqjatTHsQhXny8o+ZUIwktd2om6dnCWnBcVjJ78wiW3?= =?us-ascii?Q?9PpIKSkuVJcnB/1gF1ltkjxpIjUNiAa5wpu2C2iEFOKQ/Q535JXkmGQLFZpY?= =?us-ascii?Q?Z5ueBnzJD1/MrfpzsQ1NZCtzO2A0z5b1RU2t9Kz7JKqK+wtphOtB2AJtONEX?= =?us-ascii?Q?1kjmGfyNFgGMyqmzfhUIf0JDrZUHccKjkth4rhVIMAAfE/FeZ+hLfyaTjF6A?= =?us-ascii?Q?B3YT9eqn/EQ3bKL0naA0IA2UzkozONPQOqHv7FdJr/m7k2TRyfMxX7JiWQ4H?= =?us-ascii?Q?3ylptWu9TF9Nyxx76pbioiVa8w+VsaaER5Zrr7kF8yJp20jk45XwwKnQbBv+?= =?us-ascii?Q?4V2blITicSUZWqQ0biHpZphP7DBhKz5yNofBTTFYGl2mNSOZQPYj/+5HTpF2?= =?us-ascii?Q?KXurBzVSKLhuYv2cTSQTIykg6oG/92gFaDvsFpeydtqRT2O2AkWfpy9HtuOh?= =?us-ascii?Q?eNmvDPxQnhmCul6gs10xf8gS+l9VpLxIQr2+fHpDeTMrYJXID6nKf2g2C9cM?= =?us-ascii?Q?P4VC2lV+R7RHAneZdb/IayeoLVi7u3EiG8flkAPHAY0KZHEE+4l3sISR7fg4?= =?us-ascii?Q?9i98MZk4SvUc2L+nYHmDpjZhRXwRix59kTDRP/ajv3G0JMluk8ZC5Ks5Q97N?= =?us-ascii?Q?3tdiuB5C13f2IVs09cxTFrVbjTn4lQbDmS/wRSFe1JBvjiVwVmw85MacST8A?= =?us-ascii?Q?Wgtq?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:43.2976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: d57bf650-620f-4769-d2be-08d8b289583f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rfmuYv03ejV3vq99xppgiCVTH7oktivDw6inmykaBTvgtrWhIpX7llWPzpKod0FIJuDq+2kvFzzbmQf2JduMdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: U848ewJNz94rYqBLlQG1TRXgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968230; bh=zhGmA1vZwsYHktRHZtVqO9B6jhDKKcQweRhsOx6Edpk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=iH4WRMODDXuyES5g/AyXqykmyBuCbTz58d5oxuB7dEoxpRMOMnKa1DFRqTJbJEMTxle m41vRVJzlLB7ye2xUXAv5/t5m/p2WxSHasxoGWkPTboChNOCWQLox8fGHcQDPIkMj8/dG g+BJmzNHVADP8hSEAthToSY6LuDWVGFUf7s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 In preparation for a new interface to be added to the MemEncryptSevLib library that will be used in SEC, create an SEC version of the library. This requires the creation of SEC specific files. Some of the current MemEncryptSevLib functions perform memory allocations which cannot be performed in SEC, so these interfaces will return an error during SEC. Also, the current MemEncryptSevLib library uses some static variables to optimize access to variables, which cannot be used in SEC. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf = | 4 +- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf = | 4 +- OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf = | 50 +++++++ OvmfPkg/Library/BaseMemEncryptSevLib/{MemEncryptSevLibInternal.c =3D> PeiD= xeMemEncryptSevLibInternal.c} | 0 OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c = | 155 ++++++++++++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/{VirtualMemory.c =3D> PeiDxeVirtu= alMemory.c} | 0 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c = | 80 ++++++++++ 7 files changed, 289 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index 837db0876184..4480e4cc7c89 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -31,11 +31,11 @@ [Packages] =20 [Sources] DxeMemEncryptSevLibInternal.c - MemEncryptSevLibInternal.c + PeiDxeMemEncryptSevLibInternal.c =20 [Sources.X64] X64/MemEncryptSevLib.c - X64/VirtualMemory.c + X64/PeiDxeVirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 7c29d14039d6..faabd234e393 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -31,11 +31,11 @@ [Packages] =20 [Sources] PeiMemEncryptSevLibInternal.c - MemEncryptSevLibInternal.c + PeiDxeMemEncryptSevLibInternal.c =20 [Sources.X64] X64/MemEncryptSevLib.c - X64/VirtualMemory.c + X64/PeiDxeVirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf new file mode 100644 index 000000000000..7cd0111fe47b --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf @@ -0,0 +1,50 @@ +## @file +# Library provides the helper functions for SEV guest +# +# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D SecMemEncryptSevLib + FILE_GUID =3D 046388b4-430e-4e61-88f6-51ea21db2632 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D MemEncryptSevLib|SEC + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + SecMemEncryptSevLibInternal.c + +[Sources.X64] + X64/MemEncryptSevLib.c + X64/SecVirtualMemory.c + X64/VirtualMemory.h + +[Sources.IA32] + Ia32/MemEncryptSevLib.c + +[LibraryClasses] + BaseLib + CpuLib + DebugLib + PcdLib + +[FixedPcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiDxeMemEncryptSevLibInternal.c similarity index 100% rename from OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c rename to OvmfPkg/Library/BaseMemEncryptSevLib/PeiDxeMemEncryptSevLibIntern= al.c diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c new file mode 100644 index 000000000000..56d8f3f3183f --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -0,0 +1,155 @@ +/** @file + + Secure Encrypted Virtualization (SEV) library helper function + + Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + Reads and sets the status of SEV features. + + **/ +STATIC +UINT32 +EFIAPI +InternalMemEncryptSevStatus ( + VOID + ) +{ + UINT32 RegEax; + CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax; + BOOLEAN ReadSevMsr; + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + ReadSevMsr =3D FALSE; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + if (SevEsWorkArea !=3D NULL && SevEsWorkArea->EncryptionMask !=3D 0) { + // + // The MSR has been read before, so it is safe to read it again and av= oid + // having to validate the CPUID information. + // + ReadSevMsr =3D TRUE; + } else { + // + // Check if memory encryption leaf exist + // + AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); + if (RegEax >=3D CPUID_MEMORY_ENCRYPTION_INFO) { + // + // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported) + // + AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NUL= L); + + if (Eax.Bits.SevBit) { + ReadSevMsr =3D TRUE; + } + } + } + + return ReadSevMsr ? AsmReadMsr32 (MSR_SEV_STATUS) : 0; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.SevEsBit ? TRUE : FALSE; +} + +/** + Returns a boolean to indicate whether SEV is enabled. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.SevBit ? TRUE : FALSE; +} + +/** + Returns the SEV encryption mask. + + @return The SEV pagtable encryption mask +**/ +UINT64 +EFIAPI +MemEncryptSevGetEncryptionMask ( + VOID + ) +{ + CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + UINT64 EncryptionMask; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + if (SevEsWorkArea !=3D NULL) { + EncryptionMask =3D SevEsWorkArea->EncryptionMask; + } else { + // + // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) + // + AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); + EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); + } + + return EncryptionMask; +} + +/** + Locate the page range that covers the initial (pre-SMBASE-relocation) SM= RAM + Save State Map. + + @param[out] BaseAddress The base address of the lowest-address page = that + covers the initial SMRAM Save State Map. + + @param[out] NumberOfPages The number of pages in the page range that c= overs + the initial SMRAM Save State Map. + + @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set = on + output. + + @retval RETURN_UNSUPPORTED SMM is unavailable. +**/ +RETURN_STATUS +EFIAPI +MemEncryptSevLocateInitialSmramSaveStateMapPages ( + OUT UINTN *BaseAddress, + OUT UINTN *NumberOfPages + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c similarity index 100% rename from OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c rename to OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c b/= OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c new file mode 100644 index 000000000000..5c337ea0b820 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c @@ -0,0 +1,80 @@ +/** @file + + Virtual Memory Management Services to set or clear the memory encryption= bit + + Copyright (c) 2020, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include "VirtualMemory.h" + +/** + This function clears memory encryption bit for the memory region specifi= ed by + PhysicalAddress and Length from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] PhysicalAddress The physical address that is the sta= rt + address of a memory region. + @param[in] Length The length of memory region + @param[in] Flush Flush the caches before applying the + encryption mask + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encyrption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +InternalMemEncryptSevSetMemoryDecrypted ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length, + IN BOOLEAN Flush + ) +{ + // + // This function is not available during SEC. + // + return RETURN_UNSUPPORTED; +} + +/** + This function sets memory encryption bit for the memory region specified= by + PhysicalAddress and Length from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] PhysicalAddress The physical address that is the sta= rt + address of a memory region. + @param[in] Length The length of memory region + @param[in] Flush Flush the caches before applying the + encryption mask + + @retval RETURN_SUCCESS The attributes were set for the memo= ry + region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Setting the memory encyrption attrib= ute + is not supported +**/ +RETURN_STATUS +EFIAPI +InternalMemEncryptSevSetMemoryEncrypted ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length, + IN BOOLEAN Flush + ) +{ + // + // This function is not available during SEC. + // + return RETURN_UNSUPPORTED; +} --=20 2.30.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 (#69869): https://edk2.groups.io/g/devel/message/69869 Mute This Topic: https://groups.io/mt/79485075/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69870+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69870+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160996823402160.50242105453276; Wed, 6 Jan 2021 13:23:54 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id D4uYYY1788612xpjKvOfsV3a; Wed, 06 Jan 2021 13:23:53 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.61]) by mx.groups.io with SMTP id smtpd.web11.501.1609968233083522825 for ; Wed, 06 Jan 2021 13:23:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=agKf+vVavxQeRayoEYkJq5cLrDFriqNnv6yjyz+eANlrqsslV8wRZqCBhl3S9syXQUEEy1ycjABPiJ+4n43EBv2mXW4CCXHxru9k2bCFEnMDkXcSdqZG70zrkMrPZipntF0Ki6AHb4y6Su+7wrh5F9L3k+8C4ipjaF8TCvxDARkMVBiiY4U0JiDq69bHFX8Dh/j4LRkO9ZFTnX3tMmqzd97xvrbjukyCH0v0EGPtdTvKnfrT3my334fSP/l5DSzUABhMf2eAfiGDCnQC4B3OqB2taJk4jD+ZLsP7llTETjBqlTxYmua5m7isvfUqbP4qgO9rS1w50ZNTX3INke4oUw== 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-SenderADCheck; bh=C79H85DkKHQ8Nv81qry6VCkKz2H8uFDWt4cf/wrE4Qg=; b=LRviL7/lSqOG2WQHSlG9OulV1arCG/IKPdXeJRHEAdOFlQjMxy8yKML79Hnywt4g0q9FQydvOSo+xQezryi8ytDSAhdmf1a6rgrTjU37BYYW0YQGqQfit6yq4tKWyrtMZYIlZQlY9b7yHP0YtzQLiVQslJBuUYZWTSH7qIhbCFBqdlEXcQZ4ZMr/wxwimosX5V4K4TPYv2v09tDesvF3ii7nHdENE4TS5UCrPeJeMxOhqXbfwpxoDg3fy/pBE4ZLYVfqT4us7A5iLGvsMwID+7sNf529BqGs7hvD8HI4P4246QteRZpZj5D4pL2I7nXUBxl5bEX0OEY++DkHtS0TEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 12/15] OvmfPkg/MemEncryptSevLib: Address range encryption state interface Date: Wed, 6 Jan 2021 15:21:38 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0009.namprd05.prod.outlook.com (2603:10b6:805:de::22) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0009.namprd05.prod.outlook.com (2603:10b6:805:de::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.2 via Frontend Transport; Wed, 6 Jan 2021 21:23:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c50fa821-3023-491d-fb19-08d8b2895d0c X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: HeOyNVIpH47ny2nrNLcM9yMWmSE/niHt9ViYNeVT1lLuyl1qQKwUMnnZ5uKzer7uDV2T7ypouUC9BKUR4L1PDtsGF2CM2e3gTUjgu3qtIM7k1hhu1NWx2QbJVkuaLbi0A1S57+4Nbjwycuwoc+iAD3HqHWNBUXRzI0KuzP7yOqwia91uEt3rtKsClGZG+eSmDZvocNhA7bQgKu9cZq70p05byD23va2kYXb02xNUb3LwfdTOnuHzIhaTOzWu8lVmG4cCYmXbalqxcLk2GFfXKfjfUI94zHN2/JPKVr942CKvfvoEeP0y7yN39aSJfy1qphrHjGDzalZhZLhJVaAaWRIQOcMdnlYvIt4+9l0Aum5t7WqYsv5a9UCXvpB8Cd9EpkNduHPKpEEZ2WYdfPHkNDAJE8LXGYD2kjjVwdEq5x4GHlyKs7WjQaDE0z22Acl0kMsx9f+FLgVSj1ngDD8V7A== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ZF0JF7dWWXWGo+z1gzqRboeznTmdR18hcfMedPpSfrMPBUT28IuFcCPIKkwZ?= =?us-ascii?Q?a4Xi/vHTIdECvNlQXBG5jg9tlAmgb5KNUkv/G8ZETSyC/Hj8VzCfdVLQRKvN?= =?us-ascii?Q?Hp90qAbG1N0WxraUcdvzYBhqv3EuT/ghcB9p1sQ/M0c3NRiYdYZKNGB5X4a2?= =?us-ascii?Q?ZPbymO3gqOyuIsy53ePYGFrmZvpzYnf/eKTthscBpnKkUV+IVead3Z/Gy3+i?= =?us-ascii?Q?osB19lUFbU0WHg0I0weFYwr7R7kl5jicTszh8+GOrLQEza/s+GmBIIIRFLgk?= =?us-ascii?Q?sSYSEs0wE1z3qYBwbqyAYKB7GWuWfLiti4FqdHJLT8R6BVnk2FvoqbRhFFHV?= =?us-ascii?Q?E1WER6ZiGIbp9vAUYffCijGxS8tk8eR4E/5vRAVFK0IVc8OVYHln+WKflSXC?= =?us-ascii?Q?RNrhyQtHP6GvHA96xZU1Zu1G0K6OsiUe7rvTWrK7KPaQlbV1zw7DlU8w1xZP?= =?us-ascii?Q?8/ITKzptVF3eMRbWbDNIMHVhXCdTJXooee3kbweriatPFmV3WXvO0D7ddylo?= =?us-ascii?Q?I7l2EY8aUjTpnh51GykhDbJXuPyk0tdZBf1DZES16ltRQuWQdeMB8Lu6tNlN?= =?us-ascii?Q?e/dAWtBoyxwQfn4LsD6vd3y7HUuuCcp/EigK93AxZNTfKvcDgU5xT3tYINy0?= =?us-ascii?Q?z55MXxT+IqbLKHCn3HepS9cf8fqIoL/NdgSPZUE/lRntVu+ESpwxsT1Uu+DT?= =?us-ascii?Q?Ai4cdhAws8fowRdi13RTuflUFo/9I+TKdGvDok2sd5RmXCoZxTPCarGNEIxS?= =?us-ascii?Q?S8TwGN6rw5ZYwBrSZFBnxErVzsXwXWDje4aPdIRL3KPMQztSj+1n5kcBPu5F?= =?us-ascii?Q?o8xqyfG4HghiMMItkEEl6lIHcsYDYNdtj2gsLJObLCoXAY4P/BQwMrNWL7IW?= =?us-ascii?Q?hL3ncxvNcwfAqEZ6bmVD96nQ/O2azuCCg8+0DDVb/tCByvVJD4l7NyxnrP9d?= =?us-ascii?Q?4B3z5B1jYE7E7Suw/UULPTp64dIssKshtgIviL8YGqWvTHNGvzyupAM3jpTA?= =?us-ascii?Q?33v2?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:51.3061 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: c50fa821-3023-491d-fb19-08d8b2895d0c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pbnplpG6t87vBeQLVUDTVL3pBXsx3d+nmIAzcg2P+YYac9KaILLT7YkzYIZvyDsH4ZBNJE4MH3ou3AHx3939eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: R2rPGPedUpCL6FijeTJO458Ux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968233; bh=fp9BJ2F5fxQiCrQFrm257Z3V6u5w0Oo97dK/ir7LlvA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CsD/484MDyvuw1/OrhQn6Y0lNDjgMukb+D7nagWY1kE1ffRxJNy2iJb6O79179dXBs3 aZcCo+JPJD3Hfwm6QgKZLoSilPn5y6Hp8qFhuLgAPr3skYJ95FQG6DGcVSVrppJ5f8PWD 40J9iaiiRUbNaJ7NCt0d7EF4IAWPtrpXoiY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Update the MemEncryptSevLib library to include an interface that can report the encryption state on a range of memory. The values will represent the range as being unencrypted, encrypted, a mix of unencrypted and encrypted, and error (e.g. ranges that aren't mapped). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf | 1 + OvmfPkg/Include/Library/MemEncryptSevLib.h | 33 ++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h | 35 +++- OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c | 31 ++- OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c | 32 ++- OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c | 19 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c | 20 ++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 207 +++++= +++++++++++++++ 10 files changed, 368 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index 4480e4cc7c89..8e3b8ddd5a95 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -36,6 +36,7 @@ [Sources] [Sources.X64] X64/MemEncryptSevLib.c X64/PeiDxeVirtualMemory.c + X64/VirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index faabd234e393..f30400a13cba 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -36,6 +36,7 @@ [Sources] [Sources.X64] X64/MemEncryptSevLib.c X64/PeiDxeVirtualMemory.c + X64/VirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf index 7cd0111fe47b..279c38bfbc2c 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf @@ -35,6 +35,7 @@ [Sources] [Sources.X64] X64/MemEncryptSevLib.c X64/SecVirtualMemory.c + X64/VirtualMemory.c X64/VirtualMemory.h =20 [Sources.IA32] diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 872abe6725dc..ec470b8d0363 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -33,6 +33,16 @@ typedef struct _SEC_SEV_ES_WORK_AREA { UINT64 EncryptionMask; } SEC_SEV_ES_WORK_AREA; =20 +// +// Memory encryption address range states. +// +typedef enum { + MemEncryptSevAddressRangeUnencrypted, + MemEncryptSevAddressRangeEncrypted, + MemEncryptSevAddressRangeMixed, + MemEncryptSevAddressRangeError, +} MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE; + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 @@ -147,4 +157,27 @@ MemEncryptSevGetEncryptionMask ( VOID ); =20 +/** + Returns the encryption state of the specified virtual address range. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress Base address to check + @param[in] Length Length of virtual address range + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed + @retval MemEncryptSevAddressRangeError Address range is not mapped +**/ +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +EFIAPI +MemEncryptSevGetAddressRangeState ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length + ); + #endif // _MEM_ENCRYPT_SEV_LIB_H_ diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h index 26d26cd922a4..996f94f07ebb 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h @@ -3,7 +3,7 @@ Virtual Memory Management Services to set or clear the memory encryption= bit =20 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
- Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -178,7 +178,17 @@ typedef struct { UINTN FreePages; } PAGE_TABLE_POOL; =20 +/** + Return the pagetable memory encryption mask. =20 + @return The pagetable memory encryption mask. + +**/ +UINT64 +EFIAPI +InternalGetMemEncryptionAddressMask ( + VOID + ); =20 /** This function clears memory encryption bit for the memory region specifi= ed by @@ -234,4 +244,27 @@ InternalMemEncryptSevSetMemoryEncrypted ( IN BOOLEAN Flush ); =20 +/** + Returns the encryption state of the specified virtual address range. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress Base address to check + @param[in] Length Length of virtual address range + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed + @retval MemEncryptSevAddressRangeError Address range is not mapped +**/ +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +EFIAPI +InternalMemEncryptSevGetAddressRangeState ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b= /OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c index b4f6e5738e6e..12a5bf495bd7 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c @@ -2,7 +2,7 @@ =20 Secure Encrypted Virtualization (SEV) library helper function =20 - Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -82,3 +82,32 @@ MemEncryptSevSetPageEncMask ( // return RETURN_UNSUPPORTED; } + +/** + Returns the encryption state of the specified virtual address range. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress Base address to check + @param[in] Length Length of virtual address range + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed + @retval MemEncryptSevAddressRangeError Address range is not mapped +**/ +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +EFIAPI +MemEncryptSevGetAddressRangeState ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length + ) +{ + // + // Memory is always encrypted in 32-bit mode + // + return MemEncryptSevAddressRangeEncrypted; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c b/= OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c index cf0921e21464..4fea6a6be0ac 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c @@ -2,7 +2,7 @@ =20 Secure Encrypted Virtualization (SEV) library helper function =20 - Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -88,3 +88,33 @@ MemEncryptSevSetPageEncMask ( Flush ); } + +/** + Returns the encryption state of the specified virtual address range. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress Base address to check + @param[in] Length Length of virtual address range + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed + @retval MemEncryptSevAddressRangeError Address range is not mapped +**/ +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +EFIAPI +MemEncryptSevGetAddressRangeState ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length + ) +{ + return InternalMemEncryptSevGetAddressRangeState ( + Cr3BaseAddress, + BaseAddress, + Length + ); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index 3a5bab657bd7..d3455e812bd1 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -28,14 +28,14 @@ typedef enum { } MAP_RANGE_MODE; =20 /** - Get the memory encryption mask + Return the pagetable memory encryption mask. =20 - @param[out] EncryptionMask contains the pte mask. + @return The pagetable memory encryption mask. =20 **/ -STATIC UINT64 -GetMemEncryptionAddressMask ( +EFIAPI +InternalGetMemEncryptionAddressMask ( VOID ) { @@ -200,7 +200,7 @@ Split2MPageTo4K ( =20 PageTableEntry1 =3D PageTableEntry; =20 - AddressEncMask =3D GetMemEncryptionAddressMask (); + AddressEncMask =3D InternalGetMemEncryptionAddressMask (); =20 ASSERT (PageTableEntry !=3D NULL); ASSERT (*PageEntry2M & AddressEncMask); @@ -286,7 +286,7 @@ SetPageTablePoolReadOnly ( LevelSize[3] =3D SIZE_1GB; LevelSize[4] =3D SIZE_512GB; =20 - AddressEncMask =3D GetMemEncryptionAddressMask(); + AddressEncMask =3D InternalGetMemEncryptionAddressMask(); PageTable =3D (UINT64 *)(UINTN)PageTableBase; PoolUnitSize =3D PAGE_TABLE_POOL_UNIT_SIZE; =20 @@ -431,7 +431,7 @@ Split1GPageTo2M ( =20 PageDirectoryEntry =3D AllocatePageTableMemory(1); =20 - AddressEncMask =3D GetMemEncryptionAddressMask (); + AddressEncMask =3D InternalGetMemEncryptionAddressMask (); ASSERT (PageDirectoryEntry !=3D NULL); ASSERT (*PageEntry1G & AddressEncMask); // @@ -485,7 +485,7 @@ SetOrClearCBit( { UINT64 AddressEncMask; =20 - AddressEncMask =3D GetMemEncryptionAddressMask (); + AddressEncMask =3D InternalGetMemEncryptionAddressMask (); =20 if (Mode =3D=3D SetCBit) { *PageTablePointer |=3D AddressEncMask; @@ -527,6 +527,7 @@ DisableReadOnlyPageWriteProtect ( /** Enable Write Protect on pages marked as read-only. **/ +STATIC VOID EnableReadOnlyPageWriteProtect ( VOID @@ -605,7 +606,7 @@ SetMemoryEncDec ( // // Check if we have a valid memory encryption mask // - AddressEncMask =3D GetMemEncryptionAddressMask (); + AddressEncMask =3D InternalGetMemEncryptionAddressMask (); if (!AddressEncMask) { return RETURN_ACCESS_DENIED; } diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c b/= OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c index 5c337ea0b820..bca5e3febb1b 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c @@ -13,6 +13,26 @@ =20 #include "VirtualMemory.h" =20 +/** + Return the pagetable memory encryption mask. + + @return The pagetable memory encryption mask. + +**/ +UINT64 +EFIAPI +InternalGetMemEncryptionAddressMask ( + VOID + ) +{ + UINT64 EncryptionMask; + + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); + EncryptionMask &=3D PAGING_1G_ADDRESS_MASK_64; + + return EncryptionMask; +} + /** This function clears memory encryption bit for the memory region specifi= ed by PhysicalAddress and Length from the current page table context. diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c new file mode 100644 index 000000000000..36aabcf556a7 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c @@ -0,0 +1,207 @@ +/** @file + + Virtual Memory Management Services to test an address range encryption s= tate + + Copyright (c) 2020, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include "VirtualMemory.h" + +/** + Returns the (updated) address range state based upon the page table + entry. + + @param[in] CurrentState The current address range state + @param[in] PageDirectoryEntry The page table entry to check + @param[in] AddressEncMask The encryption mask + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed +**/ +STATIC +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +UpdateAddressState ( + IN MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE CurrentState, + IN UINT64 PageDirectoryEntry, + IN UINT64 AddressEncMask + ) +{ + if (CurrentState =3D=3D MemEncryptSevAddressRangeEncrypted) { + if ((PageDirectoryEntry & AddressEncMask) =3D=3D 0) { + CurrentState =3D MemEncryptSevAddressRangeMixed; + } + } else if (CurrentState =3D=3D MemEncryptSevAddressRangeUnencrypted) { + if ((PageDirectoryEntry & AddressEncMask) !=3D 0) { + CurrentState =3D MemEncryptSevAddressRangeMixed; + } + } else if (CurrentState =3D=3D MemEncryptSevAddressRangeError) { + // + // First address check, set initial state + // + if ((PageDirectoryEntry & AddressEncMask) =3D=3D 0) { + CurrentState =3D MemEncryptSevAddressRangeUnencrypted; + } else { + CurrentState =3D MemEncryptSevAddressRangeEncrypted; + } + } + + return CurrentState; +} + +/** + Returns the encryption state of the specified virtual address range. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress Base address to check + @param[in] Length Length of virtual address range + + @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped + unencrypted + @retval MemEncryptSevAddressRangeEncrypted Address range is mapped + encrypted + @retval MemEncryptSevAddressRangeMixed Address range is mapped mi= xed + @retval MemEncryptSevAddressRangeError Address range is not mapped +**/ +MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE +EFIAPI +InternalMemEncryptSevGetAddressRangeState ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN Length + ) +{ + PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; + PAGE_MAP_AND_DIRECTORY_POINTER *PageUpperDirectoryPointerEntry; + PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; + PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; + PAGE_TABLE_ENTRY *PageDirectory2MEntry; + PAGE_TABLE_4K_ENTRY *PageTableEntry; + UINT64 AddressEncMask; + UINT64 PgTableMask; + PHYSICAL_ADDRESS Address; + PHYSICAL_ADDRESS AddressEnd; + MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE State; + + // + // If Cr3BaseAddress is not specified then read the current CR3 + // + if (Cr3BaseAddress =3D=3D 0) { + Cr3BaseAddress =3D AsmReadCr3(); + } + + AddressEncMask =3D MemEncryptSevGetEncryptionMask (); + AddressEncMask &=3D PAGING_1G_ADDRESS_MASK_64; + + PgTableMask =3D AddressEncMask | EFI_PAGE_MASK; + + State =3D MemEncryptSevAddressRangeError; + + // + // Encryption is on a page basis, so start at the beginning of the + // virtual address page boundary and walk page-by-page. + // + Address =3D (PHYSICAL_ADDRESS) (UINTN) BaseAddress & ~EFI_PAGE_MASK; + AddressEnd =3D (PHYSICAL_ADDRESS) + (UINTN) (BaseAddress + Length); + + while (Address < AddressEnd) { + PageMapLevel4Entry =3D (VOID*) (Cr3BaseAddress & ~PgTableMask); + PageMapLevel4Entry +=3D PML4_OFFSET (Address); + if (!PageMapLevel4Entry->Bits.Present) { + return MemEncryptSevAddressRangeError; + } + + PageDirectory1GEntry =3D (VOID *) ( + (PageMapLevel4Entry->Bits.PageTableBaseAddres= s << + 12) & ~PgTableMask + ); + PageDirectory1GEntry +=3D PDP_OFFSET (Address); + if (!PageDirectory1GEntry->Bits.Present) { + return MemEncryptSevAddressRangeError; + } + + // + // If the MustBe1 bit is not 1, it's not actually a 1GB entry + // + if (PageDirectory1GEntry->Bits.MustBe1) { + // + // Valid 1GB page + // + State =3D UpdateAddressState ( + State, + PageDirectory1GEntry->Uint64, + AddressEncMask + ); + + Address +=3D BIT30; + continue; + } + + // + // Actually a PDP + // + PageUpperDirectoryPointerEntry =3D + (PAGE_MAP_AND_DIRECTORY_POINTER *) PageDirectory1GEntry; + PageDirectory2MEntry =3D + (VOID *) ( + (PageUpperDirectoryPointerEntry->Bits.PageTableBaseAddress << + 12) & ~PgTableMask + ); + PageDirectory2MEntry +=3D PDE_OFFSET (Address); + if (!PageDirectory2MEntry->Bits.Present) { + return MemEncryptSevAddressRangeError; + } + + // + // If the MustBe1 bit is not a 1, it's not a 2MB entry + // + if (PageDirectory2MEntry->Bits.MustBe1) { + // + // Valid 2MB page + // + State =3D UpdateAddressState ( + State, + PageDirectory2MEntry->Uint64, + AddressEncMask + ); + + Address +=3D BIT21; + continue; + } + + // + // Actually a PMD + // + PageDirectoryPointerEntry =3D + (PAGE_MAP_AND_DIRECTORY_POINTER *)PageDirectory2MEntry; + PageTableEntry =3D + (VOID *)( + (PageDirectoryPointerEntry->Bits.PageTableBaseAddress << + 12) & ~PgTableMask + ); + PageTableEntry +=3D PTE_OFFSET (Address); + if (!PageTableEntry->Bits.Present) { + return MemEncryptSevAddressRangeError; + } + + State =3D UpdateAddressState ( + State, + PageTableEntry->Uint64, + AddressEncMask + ); + + Address +=3D EFI_PAGE_SIZE; + } + + return State; +} --=20 2.30.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 (#69870): https://edk2.groups.io/g/devel/message/69870 Mute This Topic: https://groups.io/mt/79485077/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69871+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69871+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160996824190218.566864584178916; Wed, 6 Jan 2021 13:24:01 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4K6GYY1788612xDPnANKSQaz; Wed, 06 Jan 2021 13:24:01 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.87]) by mx.groups.io with SMTP id smtpd.web10.469.1609968240900160784 for ; Wed, 06 Jan 2021 13:24:01 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VSvc5qLF27b/5+yY0zlMLsd+Qqa5ft8TJXW5lMvFE6bXaEM7Qm3enxc+SEUf3pDjmSldyLG/QirYMynE1CHKo+B7eHlRGTJLNCniJ3SpQ2yrOA12W5SuGDjfgTWmgcw4Ustsv5UULWn4teiG4Int8D+jeDsrpmB2kdQwkzN/qfsV2YwHRCvbQ0FDJxjUNUqjytf25Cq454MUC38vwponoTD9/Po6yGydh2DOqXMBxKfTN4x5Jbcv294t9Ly1xaw9oZmCMD7vo9Gus9jtzNcmtcOtAta4YmyN37CbHUn5xDg9L60Qr5lsmdwvYufb0MWqv0n5J8EUQbkJDgc5ixKcaw== 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-SenderADCheck; bh=ffHI3AmyEM4stUfCNSJ1IvNLlojYatXSvZa/W83VfSA=; b=m5W+aJo9xtG9FJRoH5TY2AYqERooY7btmYSP2owFGtrAblfl5AUj3c0WUDROh/s2cg6SYh9IWavIKaYFxC225MhDAAm3Kb2fcei/We/lL54e4weXeuTMD/84Her0YkJwJTMVucLpGKv812/uRnL93mR1t2iWUOruo2hgpbjPSauU6489QlfszihiT1jwQyhZJIkO9w5XiHyLmEh0ew2dp3m91IVCSsajNiDP4oRB6V/kyPEcOx2QLy0PpkjFAhFjJBUcTXrV9LQ63CHYxC8PytQ3X0TCk1w0SaNgF6WiUbbAcDzQrnvggXmbRTQh4t9kKQK4MKgMnS/+j6/ti+2nSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:59 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:59 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 13/15] OvmfPkg/VmgExitLib: Support nested #VCs Date: Wed, 6 Jan 2021 15:21:39 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0022.namprd05.prod.outlook.com (2603:10b6:805:de::35) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0022.namprd05.prod.outlook.com (2603:10b6:805:de::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.2 via Frontend Transport; Wed, 6 Jan 2021 21:23:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 310c2f81-fa8d-4cbd-b7e2-08d8b28961c3 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: wq6R7RRNC1GrlqEH9DJrI+D4pMV3iEik6Mw34IE2Du+FlXNJ0aiuuCoVx0jE4Y+rMtEMCFkVVA/sKps0eKiSnYnfMKyYV5pgoNQTn7GZn6omK2WWAzj4JC1sLHHQy5Me+Gq74PxR1ZfqBgfJQv+pPBGByvfTkk8yT7fyzRJpBcLVsmbtgfysGrDWR+uuLqSvVdMp8MBKiuFsUjnmnVorgReyk3sfAXdL6Dr4xZEb0uCiawEAurYecPAHw5vT2A2CnsV+G4YvBxZkI1IVqA/lq0l9pe9aH5lY7pg2+s+A5Ray6S13M501MrBmQLM3UY6tgdzVhLRciu2SUO+H4KgoE9yRq9dyejNQTxc6uDbJjPV/pVpThbsngb1IgSoQiX9Dsf0cvxWaJI9/vAp3AT7XSlVrVMCSeYX9EIb3K6NqvoH930XNJgHjt3luQW8a6tOG+FY9hEfU19cA9ca6kPmEvA== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ie9VQaIPFQa/D2rw0lrGutPBQnDuWByZ12VoYkuXG6Exw7UO+uZAyZY89s+r?= =?us-ascii?Q?/cwVEPUWGb3scSutkb+WIOmun5gPK0Aus94aohu55vIX6FZAbtsrh1JeaqSv?= =?us-ascii?Q?JBSdxPrqL4bQ3xkAYIYgRNJiNnvxw0Mg86tvwkeuAIW2/YG45v1Z/IbDlwmD?= =?us-ascii?Q?/Q1R58a+ESXXIwYL78G62gBUMZ64zLeF/VftpDmiLlFpHbIzChw6Twd/hwdu?= =?us-ascii?Q?VOBV6TZyI8danB+HpkOS4oFHJkxHgrqJYa0stNXsxNhrJBnvACrcCtLFLJas?= =?us-ascii?Q?bjVGAxbPdHH/E2FIGL31E/DL8jHfXamh1BT/bl+wOCdMzE8gmRURocmqWsWI?= =?us-ascii?Q?yOMJnf9N5EWsztbjhQksY0MGqRisiGnazfNelqHfjf5YU+YHWZP4vwXxHaEv?= =?us-ascii?Q?DZoXOmEwrgLrKw7o3Xg+qt5DVEy5DklAzXXHJJuYZdli4NkmzHHbYAoTlWix?= =?us-ascii?Q?1trR6mlTbzVGHOJxTmIz5j81xuuVAoaS2uVaGva4O9WkjISSvydRqk8w5mFX?= =?us-ascii?Q?paHoQfdoboETQN2vQqZt5P7pyP00+l+1AxVjmjpTqz2NN1MDfEj7HtYIlUKJ?= =?us-ascii?Q?uh1mzs9maxtBKxH9nG/9syQ3EUsuSaaUhISho1+e7QTaQTfOSlkh+fELADtN?= =?us-ascii?Q?V+QRtCYsfff+/8T2r4+4t9h+L56zki57+wZd5EyrPNIfTw40LbpmAe8lKNek?= =?us-ascii?Q?ywXFAgIleG/k4fG1mKLs2rZyakQOkJAT4lN+5tCqNMUngBhuJaPMLj6Nlnty?= =?us-ascii?Q?0K5YepXWygHD4ta8Pvg1sEdhvogt8nI5qzrSQJOUH00SNoZcL/OyDzN+Z5b3?= =?us-ascii?Q?XjEo4SEJDUqFhajb5U8IS9bewFKF48fO6fWKLGID19uiKDHoSZI4jLjzprTM?= =?us-ascii?Q?/kD4ots7WIZZV8MGQKBypev0Epot9e7D4T6Jj9lwlCmSJuyFAGif7jSvP7IR?= =?us-ascii?Q?SvA0zIYXk+93U19baDjX2kBoBWPVFsMXWMhA+WV0tqo6mH5exzj7wkKJDVeZ?= =?us-ascii?Q?ri2A?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:59.2385 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 310c2f81-fa8d-4cbd-b7e2-08d8b28961c3 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hjII9GoiNWLdsiMrZk8y8bP0S1oX91kkpBrub/YKR1xzj6rmiDgP8vNGBNbvG1BjkoXl3USHgBos1FEZA2lu3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: xTY0pv1w5clP59Tu6Or9m3bYx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968241; bh=9iv6yRR1XNet8es8n6QTft9VLtMF78yGu2ZH9O7yKIc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LAo3kVsvNCKyrUhkQr9xo/6o1eJP3ao5WaUYwXizvGOo+VtCz1Bz4YjKqB7vQSr9MDA kzFe0KVDt4+TB2uxOK9+IzBlJnjmfnTsLmYtCxAdXPj19r2xx93jybvxcU/BfbQQUtTNw f/Vegcm+IA7FzW8DExQt4AdlducosyHTAhc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 In order to be able to issue messages or make interface calls that cause another #VC (e.g. GetLocalApicBaseAddress () issues RDMSR), add support for nested #VCs. In order to support nested #VCs, GHCB backup pages are required. If a #VC is received while currently processing a #VC, a backup of the current GHCB content is made. This allows the #VC handler to continue processing the new #VC. Upon completion of the new #VC, the GHCB is restored from the backup page. The #VC recursion level is tracked in the per-vCPU variable area. Support is added to handle up to one nested #VC (or two #VCs total). If a second nested #VC is encountered, an ASSERT will be issued and the vCPU will enter CpuDeadLoop (). For SEC, the GHCB backup pages are reserved in the OvmfPkgX64.fdf memory layout, with two new fixed PCDs to provide the address and size of the backup area. For PEI/DXE, the GHCB backup pages are allocated as boot services pages using the memory allocation library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkg.dec | 2 + OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 3 + OvmfPkg/OvmfPkgX64.fdf | 3 + OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 43 ++++++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 4 +- OvmfPkg/Include/Library/MemEncryptSevLib.h | 23 +++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.h | 53 ++++++++++ OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c | 103 ++++++++++++++++= ++ OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c | 109 ++++++++++++++++= ++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 48 +++++---- OvmfPkg/PlatformPei/AmdSev.c | 38 +++++-- 13 files changed, 404 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 50d7b27d941c..54804962ec02 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -304,6 +304,8 @@ [PcdsFixedAtBuild] ## The base address of the SEC GHCB page used by SEV-ES. gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|0|UINT32|0x40 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize|0|UINT32|0x41 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase|0|UINT32|0x44 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize|0|UINT32|0x45 =20 ## The base address and size of the SEV Launch Secret Area provisioned # after remote attestation. If this is set in the .fdf, the platform diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index d39436e7afc9..c4d93f39b9f1 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -236,6 +236,7 @@ [LibraryClasses.common.SEC] !else CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif + VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 799468e08e92..bfa9dd7cac1f 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -265,6 +265,7 @@ [LibraryClasses.common.SEC] !else CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif + VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf index e8fd4b8c7b89..c0098502aa90 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.fdf +++ b/OvmfPkg/AmdSev/AmdSevX64.fdf @@ -62,6 +62,9 @@ [FD.MEMFD] 0x00C000|0x001000 gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase|gUefiOvmfPkgTokenSpaceGu= id.PcdSevLaunchSecretSize =20 +0x00D000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecGhcbBackupSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 1a2ef5bf2ae3..d519f8532822 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -85,6 +85,9 @@ [FD.MEMFD] 0x00B000|0x001000 gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.P= cdSevEsWorkAreaSize =20 +0x00C000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecGhcbBackupSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf b/OvmfPkg/Library= /VmgExitLib/SecVmgExitLib.inf new file mode 100644 index 000000000000..df14de3c21bc --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf @@ -0,0 +1,43 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SecVmgExitLib + FILE_GUID =3D dafff819-f86c-4cff-a70e-83161e5bcf9a + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib|SEC + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D X64 +# + +[Sources.common] + VmgExitLib.c + VmgExitVcHandler.c + VmgExitVcHandler.h + SecVmgExitVcHandler.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + PcdLib + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf index d003ac63173e..b3c3e56ecff8 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -12,7 +12,7 @@ [Defines] FILE_GUID =3D 0e923c25-13cd-430b-8714-ffe85652a97b MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D VmgExitLib + LIBRARY_CLASS =3D VmgExitLib|PEIM DXE_CORE DXE_DRIVER D= XE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER =20 # # The following information is for reference only and not required by the = build tools. @@ -23,6 +23,8 @@ [Defines] [Sources.common] VmgExitLib.c VmgExitVcHandler.c + VmgExitVcHandler.h + PeiDxeVmgExitVcHandler.c =20 [Packages] MdePkg/MdePkg.dec diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index ec470b8d0363..99f15a7d1271 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,29 @@ =20 #include =20 +// +// Define the maximum number of #VCs allowed (e.g. the level of nesting +// that is allowed =3D> 2 allows for 1 nested #VCs). I this value is chang= ed, +// be sure to increase the size of +// gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize +// in any FDF file using this PCD. +// +#define VMGEXIT_MAXIMUM_VC_COUNT 2 + +// +// Per-CPU data mapping structure +// Use UINT32 for cached indicators and compare to a specific value +// so that the hypervisor can't indicate a value is cached by just +// writing random data to that area. +// +typedef struct { + UINT32 Dr7Cached; + UINT64 Dr7; + + UINTN VcCount; + VOID *GhcbBackupPages; +} SEV_ES_PER_CPU_DATA; + // // Internal structure for holding SEV-ES information needed during SEC pha= se // and valid only during SEC phase and early PEI during platform diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.h b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.h new file mode 100644 index 000000000000..3a37cb04f616 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.h @@ -0,0 +1,53 @@ +/** @file + X64 #VC Exception Handler functon header file. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __VMG_EXIT_VC_HANDLER_H__ +#define __VMG_EXIT_VC_HANDLER_H__ + +#include +#include +#include + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] Ghcb Pointer to the GHCB + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +InternalVmgExitHandleVc ( + IN OUT GHCB *Ghcb, + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ); + +/** + Routine to allow ASSERT from within #VC. + + @param[in, out] SevEsData Pointer to the per-CPU data + +**/ +VOID +EFIAPI +VmgExitIssueAssert ( + IN OUT SEV_ES_PER_CPU_DATA *SevEsData + ); + +#endif diff --git a/OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c b/OvmfPkg/= Library/VmgExitLib/PeiDxeVmgExitVcHandler.c new file mode 100644 index 000000000000..fb4942df37ca --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/PeiDxeVmgExitVcHandler.c @@ -0,0 +1,103 @@ +/** @file + X64 #VC Exception Handler functon. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include "VmgExitVcHandler.h" + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + GHCB *GhcbBackup; + EFI_STATUS VcRet; + BOOLEAN InterruptState; + SEV_ES_PER_CPU_DATA *SevEsData; + + InterruptState =3D GetInterruptState (); + if (InterruptState) { + DisableInterrupts (); + } + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Ghcb =3D Msr.Ghcb; + GhcbBackup =3D NULL; + + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + SevEsData->VcCount++; + + // + // Check for maximum PEI/DXE #VC nesting. + // + if (SevEsData->VcCount > VMGEXIT_MAXIMUM_VC_COUNT) { + VmgExitIssueAssert (SevEsData); + } else if (SevEsData->VcCount > 1) { + // + // Nested #VC + // + if (SevEsData->GhcbBackupPages =3D=3D NULL) { + VmgExitIssueAssert (SevEsData); + } + + // + // Save the active GHCB to a backup page. + // To access the correct backup page, increment the backup page poin= ter + // based on the current VcCount. + // + GhcbBackup =3D (GHCB *) SevEsData->GhcbBackupPages; + GhcbBackup +=3D (SevEsData->VcCount - 2); + + CopyMem (GhcbBackup, Ghcb, sizeof (*Ghcb)); + } + + VcRet =3D InternalVmgExitHandleVc (Ghcb, ExceptionType, SystemContext); + + if (GhcbBackup !=3D NULL) { + // + // Restore the active GHCB from the backup page. + // + CopyMem (Ghcb, GhcbBackup, sizeof (*Ghcb)); + } + + SevEsData->VcCount--; + + if (InterruptState) { + EnableInterrupts (); + } + + return VcRet; +} diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c b/OvmfPkg/Lib= rary/VmgExitLib/SecVmgExitVcHandler.c new file mode 100644 index 000000000000..85853d334b35 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c @@ -0,0 +1,109 @@ +/** @file + X64 #VC Exception Handler functon. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include "VmgExitVcHandler.h" + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + GHCB *GhcbBackup; + EFI_STATUS VcRet; + BOOLEAN InterruptState; + SEV_ES_PER_CPU_DATA *SevEsData; + + InterruptState =3D GetInterruptState (); + if (InterruptState) { + DisableInterrupts (); + } + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Ghcb =3D Msr.Ghcb; + GhcbBackup =3D NULL; + + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + SevEsData->VcCount++; + + // + // Check for maximum SEC #VC nesting. + // + if (SevEsData->VcCount > VMGEXIT_MAXIMUM_VC_COUNT) { + VmgExitIssueAssert (SevEsData); + } else if (SevEsData->VcCount > 1) { + UINTN GhcbBackupSize; + + // + // Be sure that the proper amount of pages are allocated + // + GhcbBackupSize =3D (VMGEXIT_MAXIMUM_VC_COUNT - 1) * sizeof (*Ghcb); + if (GhcbBackupSize > FixedPcdGet32 (PcdOvmfSecGhcbBackupSize)) { + // + // Not enough SEC backup pages allocated. + // + VmgExitIssueAssert (SevEsData); + } + + // + // Save the active GHCB to a backup page. + // To access the correct backup page, increment the backup page poin= ter + // based on the current VcCount. + // + GhcbBackup =3D (GHCB *) FixedPcdGet32 (PcdOvmfSecGhcbBackupBase); + GhcbBackup +=3D (SevEsData->VcCount - 2); + + CopyMem (GhcbBackup, Ghcb, sizeof (*Ghcb)); + } + + VcRet =3D InternalVmgExitHandleVc (Ghcb, ExceptionType, SystemContext); + + if (GhcbBackup !=3D NULL) { + // + // Restore the active GHCB from the backup page. + // + CopyMem (Ghcb, GhcbBackup, sizeof (*Ghcb)); + } + + SevEsData->VcCount--; + + if (InterruptState) { + EnableInterrupts (); + } + + return VcRet; +} diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 5149ab2bc989..ce577e4677eb 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -9,11 +9,14 @@ #include #include #include +#include #include #include #include #include =20 +#include "VmgExitVcHandler.h" + // // Instruction execution mode definition // @@ -126,18 +129,6 @@ UINT64 SEV_ES_INSTRUCTION_DATA *InstructionData ); =20 -// -// Per-CPU data mapping structure -// Use UINT32 for cached indicators and compare to a specific value -// so that the hypervisor can't indicate a value is cached by just -// writing random data to that area. -// -typedef struct { - UINT32 Dr7Cached; - UINT64 Dr7; -} SEV_ES_PER_CPU_DATA; - - /** Return a pointer to the contents of the specified register. =20 @@ -1546,6 +1537,7 @@ Dr7ReadExit ( =20 Performs the necessary processing to handle a #VC exception. =20 + @param[in, out] Ghcb Pointer to the GHCB @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et as value to use on error. @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT @@ -1559,14 +1551,13 @@ Dr7ReadExit ( **/ EFI_STATUS EFIAPI -VmgExitHandleVc ( +InternalVmgExitHandleVc ( + IN OUT GHCB *Ghcb, IN OUT EFI_EXCEPTION_TYPE *ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { - MSR_SEV_ES_GHCB_REGISTER Msr; EFI_SYSTEM_CONTEXT_X64 *Regs; - GHCB *Ghcb; NAE_EXIT NaeExit; SEV_ES_INSTRUCTION_DATA InstructionData; UINT64 ExitCode, Status; @@ -1575,12 +1566,7 @@ VmgExitHandleVc ( =20 VcRet =3D EFI_SUCCESS; =20 - Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); - ASSERT (Msr.GhcbInfo.Function =3D=3D 0); - ASSERT (Msr.Ghcb !=3D 0); - Regs =3D SystemContext.SystemContextX64; - Ghcb =3D Msr.Ghcb; =20 VmgInit (Ghcb, &InterruptState); =20 @@ -1670,3 +1656,25 @@ VmgExitHandleVc ( =20 return VcRet; } + +/** + Routine to allow ASSERT from within #VC. + + @param[in, out] SevEsData Pointer to the per-CPU data + +**/ +VOID +EFIAPI +VmgExitIssueAssert ( + IN OUT SEV_ES_PER_CPU_DATA *SevEsData + ) +{ + // + // Progress will be halted, so set VcCount to allow for ASSERT output + // to be seen. + // + SevEsData->VcCount =3D 0; + + ASSERT (FALSE); + CpuDeadLoop (); +} diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 954d53eba4e8..dddffdebda4b 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -33,12 +33,17 @@ AmdSevEsInitialize ( VOID ) { - VOID *GhcbBase; - PHYSICAL_ADDRESS GhcbBasePa; - UINTN GhcbPageCount, PageCount; - RETURN_STATUS PcdStatus, DecryptStatus; - IA32_DESCRIPTOR Gdtr; - VOID *Gdt; + UINT8 *GhcbBase; + PHYSICAL_ADDRESS GhcbBasePa; + UINTN GhcbPageCount; + UINT8 *GhcbBackupBase; + UINT8 *GhcbBackupPages; + UINTN GhcbBackupPageCount; + SEV_ES_PER_CPU_DATA *SevEsData; + UINTN PageCount; + RETURN_STATUS PcdStatus, DecryptStatus; + IA32_DESCRIPTOR Gdtr; + VOID *Gdt; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -84,6 +89,27 @@ AmdSevEsInitialize ( "SEV-ES is enabled, %lu GHCB pages allocated starting at 0x%p\n", (UINT64)GhcbPageCount, GhcbBase)); =20 + // + // Allocate #VC recursion backup pages. The number of backup pages neede= d is + // one less than the maximum VC count. + // + GhcbBackupPageCount =3D mMaxCpuCount * (VMGEXIT_MAXIMUM_VC_COUNT - 1); + GhcbBackupBase =3D AllocatePages (GhcbBackupPageCount); + ASSERT (GhcbBackupBase !=3D NULL); + + GhcbBackupPages =3D GhcbBackupBase; + for (PageCount =3D 1; PageCount < GhcbPageCount; PageCount +=3D 2) { + SevEsData =3D + (SEV_ES_PER_CPU_DATA *)(GhcbBase + EFI_PAGES_TO_SIZE (PageCount)); + SevEsData->GhcbBackupPages =3D GhcbBackupPages; + + GhcbBackupPages +=3D EFI_PAGE_SIZE * (VMGEXIT_MAXIMUM_VC_COUNT - 1); + } + + DEBUG ((DEBUG_INFO, + "SEV-ES is enabled, %lu GHCB backup pages allocated starting at 0x%p\n= ", + (UINT64)GhcbBackupPageCount, GhcbBackupBase)); + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); =20 // --=20 2.30.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 (#69871): https://edk2.groups.io/g/devel/message/69871 Mute This Topic: https://groups.io/mt/79485080/1787277 Mute #vcs:https://edk2.groups.io/g/devel/mutehashtag/vcs Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69872+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69872+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968269633783.8171789802873; Wed, 6 Jan 2021 13:24:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id vCMmYY1788612xBp5tqwjbSd; Wed, 06 Jan 2021 13:24:29 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.74]) by mx.groups.io with SMTP id smtpd.web12.509.1609968263817507469 for ; Wed, 06 Jan 2021 13:24:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XmXyFFnvT7VBxYPIxhSggeLqEt2BW1aal2+aPw/TDVGUYL4sp5v5BgP1uz1n7ZhhfdjRSadybSJsDivsUdP+g1GTLXX+mH7OMUdNvHiJKqOd89U1dL1ExX89pSvNfgcOo19B0oNvQeuWEhUmyQZAIa/vbNEUrJQJE9EhiS2WZvuI1Gyouz/iJFszO1hIrlphRsful5CJH64yF+W+sS3YPRkZ5ez0MiuBxGqi82/lzHLHqunDaslonxlMEoD3qL3gYV2RQ5X+0JsssTAGfyCmQrnWcSxBmT+04afoPnVlpyv4ohwybDw+dRb5SOBj0xKEAfvOwrm/yhhKjVqjgTb2eA== 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-SenderADCheck; bh=mdmLM6cNCtI0J4G6FIYY5jcP+TMvniVf70QE2BrfEMk=; b=koc+AmTQaeAsdJrycOL4wH77NbRqjwY3nqRF/Tm4lnT1WWRPrnSLU+5I9/+B/c2rbtQzuhGuBAA+fUAGl8JuyF7MHqKgMiwhUyj90vIiuXE1QTakVDOMxpFhBXVfWa37k0Fk3FvpjU3vSJm49+sx63/JbidIobnFXZa/gqc1W5SZLSqxnRUCmX5UhfIGHMku2bQ5M7yXbcWXlQ4060xSocOm8s3PnmFjf8wuM9+PV7DxxA/7UfNxAYYXYGk8MKvPuQk79WLlQD+uMN+6RcgqLkmxNYtqUfO9MwHt8VH/tCWez3GbhnX2SnT2f5D0kA5cHo9SpfAZFu6GyUDnwGFxqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:24:22 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:24:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v2 14/15] OvmfPkg/PlatformPei: Reserve GHCB backup pages if S3 is supported Date: Wed, 6 Jan 2021 15:21:40 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.2 via Frontend Transport; Wed, 6 Jan 2021 21:24:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 76d6ba98-bcb7-4137-4d79-08d8b2896f7f X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: NL76Qdlj5wusn3wbJl97q4laHTc2ID6hUYPraLSow9YxkxKsHrPo95hpWKxkn7V2ePGWMAEUg6I0DBZToKu7i0Bvn4GEyUbesUitd/gq4Qz0To5o6dpgpd051hQMnEOQ6DvNjnlerS07zupPUDey35jNeEBzWB1EPG/DiKalNU/NjwtYudFmN3BPEyGrRm8CbaoPNXBFwrUz2nr6Yb+l1YSYpGkWcDvOJg+APMDpRcrJCW87Hmzx2SLx33vbgnhmWo802UonweQQbWykXR+T/Ntds0b9tf44Tx6nN27H0H60DaL4UVEC3fTb9xUOTirPIS+R+cnDLqkUKoBeWcI2YEUc4UjRC3pCfAKIX/Bu9AvPlcRYQBVPeFq6y4hXQ6Gl7uWQqZYkX/V1SgLPxAHG7AWD9bDBkMc3ISKEuZcFtmtVfUxOgXLkYgB1BcIUWy9agmcsJitQaa1dqfJr/k8Nfw== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?RcygM2CV5b14yc9cOscc64WEZwsR0b1jk2X2gAb3YPs9KSKVlVM4/jJndUqC?= =?us-ascii?Q?YmSmmGu2IsboPkQPnpPeDeNbDyXGoBisMRgUlur3MF8sw+QqexiFHw37KG+g?= =?us-ascii?Q?AYiOBp+29pwQZAQWo+DHd05FTfEPWXwdbCgReEB3q5uoo+cCW7E/E1pK9ern?= =?us-ascii?Q?/SpOD6ElkHbXEQz/2Vgl9AUZiwvQ93uHUntZ+144iiktRebbFLg0rcb9UGux?= =?us-ascii?Q?kEHaorwnEJXw6S7O9LIoyFEuLQi73YKfKYxtuQTZ4JeMdXQI+r3Wdnb6d28H?= =?us-ascii?Q?d7s68P3CGqAZ9puY4ritMinewY6+By4aOW7ATH6IVdlDJOmG+EqqlatZ2C9w?= =?us-ascii?Q?UsrKYAnB5fZDzLmfRQ1VJ5bxTu8n5V5cfVQROvb42hy7WlxPbgrKjKUdWwsb?= =?us-ascii?Q?i/YbKhj+yrhlR8s0Y325CPKYba8LlyawdxSKpnfW+IiSCmUll8d0GDRZrycl?= =?us-ascii?Q?ozBd/Wu5WfiyjYot8+hyGUheTYgzICLQPvU1M8UCS9OgLLN3bhpkCSkmwGu3?= =?us-ascii?Q?Rhm4eW60f0Zd8IAW6ecoyr+e87/81QEIOTCjyKn9/1ZE65CexdYBoYWfNh1e?= =?us-ascii?Q?QTVQ1BoZVsZBKGiqdSYBfiECOhK5PIOVvxy2HhjlX2e4UgKfz+6J7dIiREUj?= =?us-ascii?Q?1rSvvJMPij5bQK6Yyui0uDUs6f3xeL+EUJsOG+T7T+F6BiWbiqEzN/Q/hGgQ?= =?us-ascii?Q?ol9CMLCgty89KabYRnr4FDPqe1su5OKSdpykB1/UfXyZ0M32rHJ//5yM9MIH?= =?us-ascii?Q?+rI4HQM+XUG2fI79z8DWTWzX8UZ7DJrZ1ls1U+5JfKl9JKLLCyz9UWvoIzmx?= =?us-ascii?Q?Sg4RQJV8s9/HJYtZ2E4+xgbRxsjXOb9hPmAJwJoi0Cx5YmNk8XA+nvG5xteo?= =?us-ascii?Q?eLOs0NGZ87algmHIsZDJRTrozuVUTI10PRCAVIVMc+99PDuNr/OD4z3oCu00?= =?us-ascii?Q?cuCW2eGGSgIcUm2I2yr8KS+Q2C27nYwh9kUvcOm9UxzfAZOTUji1Z6en2E/a?= =?us-ascii?Q?HfId?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:24:22.2753 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 76d6ba98-bcb7-4137-4d79-08d8b2896f7f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lVggbJ/+nW3F/hxyZq4t6WT2IKLtyBMt8JpoI0JVO1IIe/AKvhdlsYreN9yCTOKHKSboQ1i5Gd2RZejy2Oq+Jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: ug54O7swAJyxajXUunEklwWYx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968269; bh=8zY6G1IUscwXa/v5pqF39oHEZpmzFGvsS/BQsJryI64=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vOV7o32SAqIrBrkl6XkYQZMcCNqwVdkyUU72doAu8cLQzxCgo0Nvp12jh/tiLb8fHlj mxAxXnwOQNKOHkSUzxesE9FgCrNNiQQbQI9YqjdA9OZsDKccqYDwzbULHLjWYOtVqd8WZ okcPTgevebkNw4f5ba4v1Re7/54ePrK9WdQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Protect the GHCB backup pages used by an SEV-ES guest when S3 is supported. Regarding the lifecycle of the GHCB backup pages: PcdOvmfSecGhcbBackupBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB backup pages are initialized when a nested #VC is received during the SEC phase [OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c]. (b) how it is protected from memory allocations during DXE If S3 and SEV-ES are enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS memory allocation HOB, in PEI. If S3 is disabled, then these ranges are not protected. PEI switches to the GHCB backup pages in permanent PEI memory and DXE will use these PEI GHCB backup pages, so we don't have to preserve PcdOvmfSecGhcbBackupBase. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index c53be2f4925c..6ef77ba7bb21 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index ffbbef891a11..c08aa2e45a53 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -888,6 +888,11 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), EfiACPIMemoryNVS ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupSize), + EfiACPIMemoryNVS + ); } #endif } --=20 2.30.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 (#69872): https://edk2.groups.io/g/devel/message/69872 Mute This Topic: https://groups.io/mt/79485096/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 10:17:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69873+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69873+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1609968273529526.8953342613863; Wed, 6 Jan 2021 13:24:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id G8mgYY1788612xHMOcxqkh8S; Wed, 06 Jan 2021 13:24:33 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.70]) by mx.groups.io with SMTP id smtpd.web09.475.1609968272496316535 for ; Wed, 06 Jan 2021 13:24:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aoD/ackcBAtBuZ0rxCE1IsQN859LRunqNh7HTzKFnFyfgA60iW8aQPUx4eV5if1jJcbkFDn/Hzsrd72FPiWMlCyEg/ooBmm8a08jzSEw2WHDTS2aRqUXSMS9p2dfKRLIFOeWCEgQ/KtSOpzcQDaKFYC3ZorYfU1DjW/zG/jE3n8CloL49wNhGNlYEcp9ZzJWB7tgS9pZS68omSRjU+r4Au2lJnIRMYMoNv8yjD30mQoWIYBcpq+nuBCZ6hquFViqBwGO5wyQOh5KA+VvI+rjyTIJb0UxpxoQEnZKPqrGLLLdVSs3A5nle4Jms18jtDHcsFvCS/cMPZawX2++5qabkg== 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-SenderADCheck; bh=g0jJGCLWbaS71xsnMvQjLxVO5/5Hug1e4WlzEU8SkCo=; b=EgKAq0MI28MSCUbfA7wXxXrwh5l1/49LVbEMuFwz7zU7zbHnw+GuHQdC3TJ3gbKhtQCdrO8FUe1znjbIcoHkRyDHq1Z14A0WtzXOOddTN5xHZitzfQTAYGVolF/aJAVfpkFpYQGI4fcSXNIZcKWXT1iVCBjQTH/bBlvaYYS6BpoOO2sT+ukGMOJCrPHUUro6pDOQnnzqHdKuVsLTK6j/jg9JycHR9W0hlKSxVB13fViG8MfcpShU6ybL0mgU1m/h7ys1zoxRo146NXAJGIJU250k1OsTlogdPh4sDrw7MD7LzQTMRTwjci4P0of1XQ843qHzcr2pHzjxOZd2V4hzpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:24:30 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:24:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 15/15] OvfmPkg/VmgExitLib: Validate #VC MMIO is to un-encrypted memory Date: Wed, 6 Jan 2021 15:21:41 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:805:66::43) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:805:66::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:24:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c4dce191-073e-478f-7717-08d8b2897431 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 9JnSKGohk2glCN+vOjgUz6rQa5Z3XwUvfFBm905uWoEKCTGLBRXPFkTihUNUFll8raeuNJE//szgTboK8rJ0lWHACzyLKg//B74BrRgXWZgwiw8mFw/cNJeCCFJ1FXg+kqT8VC1NCN5Bdu54s1HfSCimRcbr+PtaZbl1P+6g3aPrrN3cYbSiN5whhCzIGOKc46xby/GAlD3xff33TyAaqoFPyOuU6MopDF98hOHvn8QrGXZ9zgOT1n2xYuZMNP3dil8hGhOqxc5PmLz6Zz++FGXW3HnJZE7GO6EWxNvl/4S3pUZEdSMoDLpPT2iX/Y3AaMqwc7ymkvxqEDbyn6a8VUr6KhWFaL4UfKrtT/6aoARON8WloKcv5h0i1l4fotMxJHN3vDXhp+jQOePDjAsyQLvxKSQhVRmfXwfI56j5uLhUqyIxh+OVTyU9RF1KaCCbwhIqLd5BrR4xGkkUQZ7K8w== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?QtGTK4HFOf4mXdD4XDm3SJXIy4q4cNRT6UnrVNgQwXIJiBJLoLzRnHj9Qcn9?= =?us-ascii?Q?cMbMFIk2mwopBonGwilBkSphfLQ7Egjz2ptfp3VnSkicODbIQQjZQxliJjSh?= =?us-ascii?Q?bChWBChFAaxMp3Sb8z4IbzaQwCx71Jc8P3vb6M16FgQZxDAFye3BqoK7qEDJ?= =?us-ascii?Q?aVbhsIzt9sAlXTlcpTOfKnuGcSXeK+EUvSXQCMYJV+I39TNb3ahkqwbytKgp?= =?us-ascii?Q?sc5A8B6ZD2ZIOsIe0F9fbhbgdNNVDrjzC5B30ED/1HPK9rL/GWN4i9Q5A2o1?= =?us-ascii?Q?8BVzRbtakOAuVQsEU2+wZZUAYmpsal7vgbRVYKVJoqgxcYlQpmtxenidD5QP?= =?us-ascii?Q?mMra7AXoT5XoIiXP9VqbwqfNth+cdRFRFeraKl1VAzYxfayYHfuij6wSOe04?= =?us-ascii?Q?1SMjeJ0Nms8bWPwBewFJW4bIsXZvqUODDoTbFg85U43SKeqFcQVdEVIA/IHA?= =?us-ascii?Q?Qn0v0bEhKgknljqRXJb+bDK1ko7NU7MFPji0I4C6bDuhn2sPwu358IWUUEI+?= =?us-ascii?Q?bdjk7arR1nw38Nx9yxeKIy3dPcDJBBRR0O/TCUd9zo8UrUh9MZqTlE5SkHgw?= =?us-ascii?Q?1Vx6wcfUXQAPerXIK2RetNiFRErNy+e1DUJ4BzdD5RpX+aV9fYfjz4qBVPXu?= =?us-ascii?Q?h0lm/o1UmwNEjJFeM8KvuwxEhfRNQxOUr39XjugGttdFZ2TIeS/dx17uDjFI?= =?us-ascii?Q?+PZmfrQtuVUJUkaBShKTMRfR6ndH5tYbeeuc0kD9djFNfEhAgEWpB8FjsmkG?= =?us-ascii?Q?sdncNXeBDIEZuijEW0jjGZj7Vwg4gGRwk7vkS3uo9zykG9SOpxzILJ/uCCCl?= =?us-ascii?Q?Is9hQ/o0ZDh1maY49WpGWAqzqExAX6cjb+pnQ+qaM19TBCAJNH58xY3BtT71?= =?us-ascii?Q?Zs+ujKbeA1rfTusHHV6V+04LkC5m27B75JOcoFQrfcTJili7j5tQgLkdPI33?= =?us-ascii?Q?5OMTrl3ilnAjQlxBjWD5LNJWyoIBIjKpu+VhOseGcVockqYMcFIDJ9Mk9+wM?= =?us-ascii?Q?n5SI?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:24:30.1418 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: c4dce191-073e-478f-7717-08d8b2897431 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2p2fUPivR3+1qb+MubqLefW5aV3vEyNetPieVY9zCE6OWPVjsUlncqUAwYWAJ84JHkD2fv2tBi5UHT3Fx4V6+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: vwNkwPBKTAoHGjX1XZoiEuTVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968273; bh=zy1KJkvtEFAbtz8PVGryb9SS9K5vmoQ4CGbOfDkm+Zs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Cb3G4UadipaOpmxpmM1vPRRZ7mqRhIIYsg3VkUJDQ4d7Ho/BAHmFiWUSRxPTNnV9/Tk bdP0Q1nmXTP8B0gUPbs4S4ub8KDbgFbVyI9Ntza1vaiBTwpyXUks3rraelN426W2i4sGB /9ezRyAr13csSNixiAVBmuw58wkevYE3urE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 When SEV-ES is active, and MMIO operation will trigger a #VC and the VmgExitLib exception handler will process this MMIO operation. A malicious hypervisor could try to extract information from encrypted memory by setting a reserved bit in the guests nested page tables for a non-MMIO area. This can result in the encrypted data being copied into the GHCB shared buffer area and accessed by the hypervisor. Prevent this by ensuring that the MMIO source/destination is un-encrypted memory. For the APIC register space, access is allowed in general. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Brijesh Singh Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf | 2 +- OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 2 + OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 2 + OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 81 ++++++++= ++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index c4d93f39b9f1..dad8635c3388 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.SEC] CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLi= b.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index bfa9dd7cac1f..70ff2bcf2342 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -266,6 +266,7 @@ [LibraryClasses.common.SEC] CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif VmgExitLib|OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLi= b.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index 8e3b8ddd5a95..f2e162d68076 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -14,7 +14,7 @@ [Defines] FILE_GUID =3D c1594631-3888-4be4-949f-9c630dbc842b MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D MemEncryptSevLib|DXE_DRIVER DXE_RUNTI= ME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER + LIBRARY_CLASS =3D MemEncryptSevLib|DXE_CORE DXE_DRIVER = DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_DRIVER =20 # # The following information is for reference only and not required by the = build diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf b/OvmfPkg/Library= /VmgExitLib/SecVmgExitLib.inf index df14de3c21bc..e6f6ea7972fd 100644 --- a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf @@ -35,6 +35,8 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + LocalApicLib + MemEncryptSevLib PcdLib =20 [FixedPcd] diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf index b3c3e56ecff8..c66c68726cdb 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -35,4 +35,6 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + LocalApicLib + MemEncryptSevLib =20 diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index ce577e4677eb..24259060fd65 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -595,6 +596,61 @@ UnsupportedExit ( return Status; } =20 +/** + Validate that the MMIO memory access is not to encrypted memory. + + Examine the pagetable entry for the memory specified. MMIO should not be + performed against encrypted memory. MMIO to the APIC page is always allo= wed. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication = Block + @param[in] MemoryAddress Memory address to validate + @param[in] MemoryLength Memory length to validate + + @retval 0 Memory is not encrypted + @return New exception value to propogate + +**/ +STATIC +UINT64 +ValidateMmioMemory ( + IN GHCB *Ghcb, + IN UINTN MemoryAddress, + IN UINTN MemoryLength + ) +{ + MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE State; + GHCB_EVENT_INJECTION GpEvent; + UINTN Address; + + // + // Allow APIC accesses (which will have the encryption bit set during + // SEC and PEI phases). + // + Address =3D MemoryAddress & ~(SIZE_4KB - 1); + if (Address =3D=3D GetLocalApicBaseAddress ()) { + return 0; + } + + State =3D MemEncryptSevGetAddressRangeState ( + 0, + MemoryAddress, + MemoryLength + ); + if (State =3D=3D MemEncryptSevAddressRangeUnencrypted) { + return 0; + } + + // + // Any state other than unencrypted is an error, issue a #GP. + // + GpEvent.Uint64 =3D 0; + GpEvent.Elements.Vector =3D GP_EXCEPTION; + GpEvent.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + GpEvent.Elements.Valid =3D 1; + + return GpEvent.Uint64; +} + /** Handle an MMIO event. =20 @@ -653,6 +709,11 @@ MmioExit ( return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 + Status =3D ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Byte= s); + if (Status !=3D 0) { + return Status; + } + ExitInfo1 =3D InstructionData->Ext.RmData; ExitInfo2 =3D Bytes; CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes); @@ -683,6 +744,11 @@ MmioExit ( InstructionData->ImmediateSize =3D Bytes; InstructionData->End +=3D Bytes; =20 + Status =3D ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Byte= s); + if (Status !=3D 0) { + return Status; + } + ExitInfo1 =3D InstructionData->Ext.RmData; ExitInfo2 =3D Bytes; CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes); @@ -717,6 +783,11 @@ MmioExit ( return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 + Status =3D ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Byte= s); + if (Status !=3D 0) { + return Status; + } + ExitInfo1 =3D InstructionData->Ext.RmData; ExitInfo2 =3D Bytes; =20 @@ -748,6 +819,11 @@ MmioExit ( case 0xB7: Bytes =3D (Bytes !=3D 0) ? Bytes : 2; =20 + Status =3D ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Byte= s); + if (Status !=3D 0) { + return Status; + } + ExitInfo1 =3D InstructionData->Ext.RmData; ExitInfo2 =3D Bytes; =20 @@ -774,6 +850,11 @@ MmioExit ( case 0xBF: Bytes =3D (Bytes !=3D 0) ? Bytes : 2; =20 + Status =3D ValidateMmioMemory (Ghcb, InstructionData->Ext.RmData, Byte= s); + if (Status !=3D 0) { + return Status; + } + ExitInfo1 =3D InstructionData->Ext.RmData; ExitInfo2 =3D Bytes; =20 --=20 2.30.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 (#69873): https://edk2.groups.io/g/devel/message/69873 Mute This Topic: https://groups.io/mt/79485098/1787277 Mute #vc:https://edk2.groups.io/g/devel/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-