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.64]) by mx.groups.io with SMTP id smtpd.web12.20825.1594737009017022499 for ; Tue, 14 Jul 2020 07:30:09 -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=bH1XLned; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.64, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nr0SvLZ8dkX1J2+XXdtxN52vro50e0xJ6tSczqBbBKFt3ABVWp6edmGsKeSu1uqSX1Ehu5KZVcLyd0L3yk21+gDYeOyBoooWOAF59qCOVdmhHxVerl3MbnnBwatrTlx4fNpNbAuWMglvpd5YQEokrLbJ0GWNWqrb9P26O3oECEYbSsEoDwhyMbM2J4POMGYTpLvL86umWbfGAN+dc6rY4pnj4svVnMeA0J5uZAQWQZgAVUUUKw45svmZZmFIjXcXvCL+y6sGgLL9Au/FX2tnh/n/i/75oCdtN4X/22vMrzE6UGWF1oeO6qAF334gRgztabu2eT1JMNxKLhgCDorrpw== 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=mXGdTj/oZNZnIsvWPfSMO+dFD7IT2Ixch+ABgjZXfkc=; b=St1BWTbw7e7n3Xcn6QtmgAeSs4EjZYKzLsquu1z88FDKk+pZrabUoJj3w3zhCrkfZ2dmuhptA/+4zaeDiJNtGmohqZdmLrF8OhouWwZHsy56tTEqMngk9Bmw+f9pAo3xRpzR9J6Sl7C4zv7+nUIHtmA68SZURiIxoNbmnPNYx3JfuiWD+juQ7LDPPTIwpROdemcDGq6FxZVEOBJ5DlP2OQSV/TtVuGp4XCHxHNpJ6O+NeDPWGDbjxxXzXVFFs1d/SBPZgx9t+0z5mqNcHYeYT5MarZNSSxY0HiAHDN80poDnVOc6HbDBCfzqR73UlWMi5p2JtdP6DmgYw/h+fF4FjA== 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=mXGdTj/oZNZnIsvWPfSMO+dFD7IT2Ixch+ABgjZXfkc=; b=bH1XLnednvitcC38njgOBIAOnNlcDJfaaO5Vvo82ih10tm3Cilh/vpLulT69UoZoCxwTy0vPLSzhP1tn2CAGgbhgsFUIOsvQMHbdtgs90JR3/mYJizdLV1c7AES+cvzXDSLexccPki7WPmzAyGWi2AfOrV+aOuuwwbcQNz+U/zI= 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:06 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:06 +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 v10 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 14 Jul 2020 09:27:38 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0039.namprd02.prod.outlook.com (2603:10b6:803:2e::25) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) 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 SN4PR0201CA0039.namprd02.prod.outlook.com (2603:10b6:803:2e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:30:05 +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: 33dd205c-bd17-4c4c-140d-08d82802670d X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: 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: BCL:0; X-Microsoft-Antispam-Message-Info: CbYDge3XU3To/0od80+J95nYcTFSsj8Rxhb79sBgduVI4c+GQrS2CKSJUY7zFyRhtmlCBlyQftlZt6Xx48+cEKdBUobc33xg/1snemdzfhJZ/ResPp54db0HgnAxvNRn+khRFm0GLXWjzcA3Pftxc6CMqEBwzv8J7qsINj1aOFxxUWiJMOPtgRHcpfrCXyGVAOWG0Cpa8umgVsvOTgqJP4b5lHAUlTodl3+jtR8cmAfzb9pMp5B7B9RPJXP0faV7FlLEpIu7bdYOYvLU8Cy+yMQk/Lfr4RoVoDq7SZsBrlTliVJZs+Vt84Mvq67a/QdZ9/VU3TGIybYLgINgNiD1ZgMiemEdje0N6UKtvj9c5HY1kzYA8Z8obWfwuC/zBqOdJCxUVGQOYywDsXVUOy3yftvhxNGa9CmvnIN9RwIUraoahQPXtLTnQ+xvFTzy91AAikyovdmQehpgZUJpD0SY8g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(39860400002)(136003)(346002)(366004)(376002)(86362001)(478600001)(8676002)(54906003)(6916009)(2906002)(8936002)(956004)(6486002)(2616005)(52116002)(966005)(7696005)(66946007)(4326008)(19627235002)(6666004)(66476007)(186003)(66556008)(16526019)(26005)(5660300002)(316002)(36756003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4sed9gcMYkn/UjS5yHvOMAs/zZxA+iW18CU0hMgR6f8U4KEb1Y5zOuKti/VRGu/cwp/AJu3DjFZDC/QMJch7BeLSM+zAol6wNh5NT3UlBNzETe8SWRuu7GWCS7lRD47k+TyPBiUUuAy8qi2UNTkYzJRktyPbnbliNC7BrTzfOy2iZttHhLYfTS6xkn5tAiv/ViOXy5phKwwNEQZkhxdGvXUFMQZ8XGYo3Og8j5PPm4ywJI4QecEbH60tXcmpl+4Tlzjc5qoRGAJQcquIIMMqW2NXkZb6WV5fSxWKiHK/iENwT0lEBK7aZ9T9aDEH+Ax0MCHqiR4Vot/k45mhSxTx5wG4sleITk3gsgrg3bsP4kSMjJGapQZylyyGu6NO+L2OxMr9GEmjzao6Yha1N4X/cpNVFlQfPm15gVcDwPYUJ0SbLzAJm1bS3AMgPrhzSDkX153OdaFMdIISGFvSM1eq141vHbjKaxtjJa3hViCe5mQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33dd205c-bd17-4c4c-140d-08d82802670d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:05.9330 (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: DC5smlibgvkHq8GrKJORDNu4VDSijfe2eGAtMW125gbfYjWN5yBlAYpY0LkkHxPGukDTZMcVWX5yl4GgRSCCBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 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. Provide the necessary support to execute the VMGEXIT instruction, which is "rep; vmmcall". Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/X64/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 6 files changed, 119 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 da6bc22a3e2b..7cf6467fa77b 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -154,6 +154,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT Ia32/XGetBv.nasm | MSFT + Ia32/VmgExit.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -289,6 +290,7 @@ [Sources.X64] X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT X64/XGetBv.nasm | MSFT + X64/VmgExit.nasm | MSFT =20 =20 X64/Non-existing.c 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/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index c962bcfa4617..d6a7581b36f6 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -1791,3 +1791,20 @@ AsmXGetBv ( } =20 =20 +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} + + diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 915555198f9f..0685337bbb56 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -1828,3 +1828,20 @@ AsmXGetBv ( } =20 =20 +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} + + diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..a4b37385cc7a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,37 @@ +;-------------------------------------------------------------------------= ----- +; +; 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, so work aro= und +; this by temporarily switching to 64-bit mode. +; +BITS 64 + rep vmmcall +BITS 32 + 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