From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=iZYxyVTX; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.56, mailfrom: thomas.lendacky@amd.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SG0/xz40UTc2ofcPShd0s/8+tONPPX8uNVFh9cVFY24=; b=iZYxyVTXIsejGyP10RhLQrMrEnvAuMYSTM8WASQPHSv37bvRUzBt6iuRap/cBbnUAyNFRhoQlrAkYK+BIKLFLaZD4FDU+ZNTRsiEx2T4iHBg+ZMq24ZFSY60trR1Y8TDJLn7pLhO9+l9lrMqjGNLDbxrqpV0kyQFj29fvpxoR68= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; 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 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: [PATCH v14 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Fri, 7 Aug 2020 14:38:52 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 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) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 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-Mailer: git-send-email 2.27.0 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: BCL:0; X-Microsoft-Antispam-Message-Info: hCSqE3OYOXYq+kx/YVCMqnld0PlAYhL5Wc0rH97vAzxJx2BACnr2wX5WGjFLO9ScJj7MHfCuaLAyunglK8E1CyN1DOVU1hJTLqW3paMgxdsHeWBs+HtXUXbUvSwQrNaMiEC1tUSZbV0C7vwboYtRcSAnJpT1unUlDFQt+ecdCzEG2YsjnoELdDSe+8BBjgkxexiM5G0ZMbj4tLzAT/Ud1BAEgh1YArWDPwETglKnUTbwfW6ZM46Ii69LP74H2HRCn7d7LdhdXGx3wbdlUfOdwaMyCP8G98QXU//lS5nvu3X8lxd4aSQFKeqDQP7no0dnMBG+9BDmpXSDSlUm4+AbXZqRlc1rfe62XMk5tCZFFlyvhH7I3lXMg8h0dbFnFzDwJxpnnhB8ydMILwyjaMjvU+QjVn3xziR628wcO3mkAiP7GU0vq0rdnAjEQHdJlxby0pRfkmA84kC9dddLPAQLGg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(39860400002)(346002)(366004)(376002)(52116002)(7696005)(6486002)(8676002)(186003)(2616005)(16526019)(26005)(36756003)(2906002)(8936002)(19627235002)(956004)(6916009)(4326008)(86362001)(6666004)(54906003)(478600001)(5660300002)(316002)(966005)(66556008)(66476007)(66946007)(136400200001);DIR:OUT;SFP:1101; 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 --- 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