From nobody Tue Nov 26 00:37:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63849+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63849+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1596829242092647.7537994699046; Fri, 7 Aug 2020 12:40:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 32NgYY1788612xNMazo56U0M; Fri, 07 Aug 2020 12:40:41 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.56]) by mx.groups.io with SMTP id smtpd.web10.4142.1596829241078753668 for ; Fri, 07 Aug 2020 12:40:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IjrXPb3S///9qnF4Yw7kCLvdeUiIbCY+L1PI+PCtj254a1g6dcq+PcxJil23wY7GUJQqiIjMPHqkmjTJIx8aO82XHoe4JbKh/bs4B2posYBfTmlZm3rCReKznHCkLAHsrMI6HKRCacwHzyzdT3+W9nZ4e2BT1cPb+vFPhJhPeB6s4AtC+gOmXVMcxdpiaET4h4mtGxJZPqKxZWTB8mgaK+bU+2FoUFam0d7wbYkGlbDa6J5yf62FqbbZmCiZfjcGchptJkLqOo4P9Rz+mcNpHXoPygVQWORQKaUbb8q840rz7651xR9HXMLndUwiVD8/bKBHsyTapJus2eMFJ55K2Q== 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=SG0/xz40UTc2ofcPShd0s/8+tONPPX8uNVFh9cVFY24=; b=Gy24eUtcufUN2ONTa9pbv6oovUjPTMaOiAI4yXrM4QWzyCG9zLyIBxgAUepX7NL4lbKuEbQNzEL42nEg4th1740Dk4l+YHQzW157R7H7FENrwXhijbfKWe6R6Jr5Bxl3SJ44POTY4mtKo3s0FF3o9whMD4/wkcIdUJ4Eg9Vfx9TGmKR8gomx2lMdWhtjskvknA6VV9KLHS4TTlJ5DrYBJeRBqh9uFz74wJxWLouVSB1rqzQLLrp+XEsnvjl5DciHnZTVI6MO4cjbCMi0kouphCsRrN8wB3xoSkpzXE6niJNldqCRL4sveEuEAiFGEjyaE75dA9/4iPnoQUEqkFP3Qg== 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:39 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Fri, 7 Aug 2020 14:38:52 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19:40:38 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 12549db4-b395-46b0-ac77-08d83b09c383 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: hCSqE3OYOXYq+kx/YVCMqnld0PlAYhL5Wc0rH97vAzxJx2BACnr2wX5WGjFLO9ScJj7MHfCuaLAyunglK8E1CyN1DOVU1hJTLqW3paMgxdsHeWBs+HtXUXbUvSwQrNaMiEC1tUSZbV0C7vwboYtRcSAnJpT1unUlDFQt+ecdCzEG2YsjnoELdDSe+8BBjgkxexiM5G0ZMbj4tLzAT/Ud1BAEgh1YArWDPwETglKnUTbwfW6ZM46Ii69LP74H2HRCn7d7LdhdXGx3wbdlUfOdwaMyCP8G98QXU//lS5nvu3X8lxd4aSQFKeqDQP7no0dnMBG+9BDmpXSDSlUm4+AbXZqRlc1rfe62XMk5tCZFFlyvhH7I3lXMg8h0dbFnFzDwJxpnnhB8ydMILwyjaMjvU+QjVn3xziR628wcO3mkAiP7GU0vq0rdnAjEQHdJlxby0pRfkmA84kC9dddLPAQLGg== X-MS-Exchange-AntiSpam-MessageData: /CupCScTChccsNeARCgz5zCjlN1VuIyNbOOvj8CZZWSWa5Z19IbC7n3GeLrGYoakTfg8EvX00j7/h9RFGXNRZhLM7oV8ZquWlSXG3358hWAOI0DL1sK4s3p9WAC503qdPdbXAqqcEmaAzBrVmCMKSZpxi2UXzvkSdYzQsTP8jW6gsxjR4UC1hGJdXGqw73j9SXC2/pyL57+IXKoPv1RUNTw8EtbqplJgLo40Maq/m/bcW2myz7jBKstkY2YPfBOrXIkpElehCi/9F6r/sCGU9IqNG2cat1hOzKfU5s+t07kadX+QhB/rnq2qpUlCSAgVd1EFlLCzyb22nhfBNOBDYnQV1bIj4k8vcuYDZkDQ+a/NONEbppAb7WCEjAXZNmXcvvn3ttwD/VfbSH50O8n+uhm7s9RXvZCXigfhRBPHuZvYBnJfhOJb4IM67JjOCYCSRwzHQM0pQ+nb3gMiz2ZbVLfS+5OIV15590nq2EZNwTz3rWTWU+xtTnV7Y8ezM46qenjVMfgS6Cr+Ad4bYXqZ6QL07AdsYrTRS3sRWy1Nq1gXW3cswqee2VOUhprqMuVlVd/i2ZxhY+mHGHcz3Y8gjqjgtlJkJ4kKFMN2LB27d11VtFK/zXvyT6DRAXTeKFdnm/+s5s9F1xhxv/5tCsquEA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12549db4-b395-46b0-ac77-08d83b09c383 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:39.5625 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oCe0P86usF0JGRnIG208GrcVy0t3d3g3qqty9sEzOku0etUZstrgMJrqfRrzwtRfYneD+/s4tJG+imXSv+iD7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: UxEvXEqGu3prUNP0VuquiqOWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829241; bh=WmBe8OAq1Mq/GPk+EEK0YMg+Yr6p5q5yEWjYF8TuMtI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MWQHwIqPFratgNNQ12MUBJ+5mLcoR/6veT8FHe5/VO8uomEhMZbVO1A18DEPsl3UtHq Ji9ciwRbBKGT+CBPKLDtHKhM7negEd/lnnhHBVj82QQI1dmhBqSaU9s94w3kPJvJm8hhO gW6G0DcmTWV/wLR68Np7bVuiDbVYNr+6pbc= 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=3D2198 VMGEXIT is a new instruction used for Hypervisor/Guest communication when running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) to occur, resulting in a #VMEXIT with an exit code value of 0x403. Since SEV-ES is only supported in X64, provide the necessary X64 support to execute the VMGEXIT instruction, which is coded as "rep vmmcall". For IA32, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT should never be called, provide a stub implementation that is identical to CpuBreakpoint(). Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 38 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 3b93b5db8d24..3b85c56c3c03 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -184,6 +184,7 @@ [Sources.Ia32] Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm Ia32/XGetBv.nasm + Ia32/VmgExit.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -317,6 +318,7 @@ [Sources.X64] X64/DisablePaging64.nasm X64/RdRand.nasm X64/XGetBv.nasm + X64/VmgExit.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7edf0051a0a0..04fb329eaabb 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7848,6 +7848,20 @@ AsmXGetBv ( ); =20 =20 +/** + Executes a VMGEXIT instruction (VMMCALL with a REP prefix) + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + x64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..69f7fbf3506a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,38 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): +; +; NASM doesn't support the vmmcall instruction in 32-bit mode and NASM ver= sions +; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into e= lf32 +; format. Given that VMGEXIT does not make sense on IA32, provide a stub +; implementation that is identical to CpuBreakpoint(). In practice, AsmVmg= Exit() +; should never be called on IA32. +; + int 3 + ret + diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseL= ib/X64/VmgExit.nasm new file mode 100644 index 000000000000..26f034593c67 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm @@ -0,0 +1,32 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): + rep vmmcall + ret + --=20 2.27.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 (#63849): https://edk2.groups.io/g/devel/message/63849 Mute This Topic: https://groups.io/mt/76056483/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-