From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.954.1589925097911028907 for ; Tue, 19 May 2020 14:51:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=cupZs5gN; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.50, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l4VVV98sRjxE8iHY5M3h+KJ1UOW+0DHE8ZmRfSI1Nz8WMqFCGPgcyFIU/hQIM7n78KBRNk8sn4tC9gLcghoTvssRJYdsvj0CQyBIkn/xsBb8x20DB6Mey/3ToOrrWaLpFydav1A0rJy40jlHO4Uzw4mgMag6CKMzYMJXnN35czypUaPNea78s9nfCzHBVB4nBBS1BJ7B8P++kXme39m5U3uWituqPnroaOHJgiqnsBWp2bJ3+BokNp7eFRt/lXaNo18AaLnQ7kHGuw3XEfEd06Tj52FPhRRFmEHSKgVcnzO3imbhKpijLbfpLJ/d5viLptsjfqlp9YwUCizN5Lh7HA== 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=twip0zpfQL+ol70EosxC9Jd77pWuFjGjzs3em7gK+GE=; b=MYfkmnao62eFCYZBxI2Q/bBRw77k4tioqWfgusF+Btm2n5wXIG5kfPFY73QYuQQhOzqAJD8ueOYg/TxMghHPrb5+wu2V3EQONDyGtUbOt5zM0BGABohmFpRF8+3QRSkOPdv3KA0EcdJeeDG5/dU1rhqgEhY9m7oEcoJNIJJwK6oi+v7WvuYBlfypARx0DJwnQw02d+Gz/iGy1d//a7lyQhydqOFVQsonLrH/2LTr4j/7vKu+IAivo+k+IKDKYC5sAjr4aYztM6bLwAzGZRKhv19zJP83jYFiTiIaaOMfpzdFm9wfgACDahEV6SSuIkaBLcB1m/8n2PqEmc6G/6KFbg== 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=twip0zpfQL+ol70EosxC9Jd77pWuFjGjzs3em7gK+GE=; b=cupZs5gNXYjROJXiq67HuDdoeG7a+YnzWVmJfKToTkP0NBzxsI0fQWezx9oE1zqTlIlRGwVc4Ei4v7dn0xLTaoEsxail96hiwdXkV3ZBHAQeFWdvyCIMjLoLmair7DbaziRP/m1i7XN7jdwjsrrSBWOCq+toRaUaFq4CG2nIeGo= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:36 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:36 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [PATCH v8 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 19 May 2020 16:50:35 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:35 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a1547d8e-6394-4b23-c945-08d7fc3ecd44 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tGLcGffUDQZQ5aQQTi0D+J0lh9e5NI4mkw5OTqzZQv/0CYFxSA9fPImY8GJrfjwtk2/bOAmQ2eZwPmN10IIVF/qL8zfmsAwsEezR2N7FB9PYw4h+n3dLfMBc7P4aU5h6TFXPBE3PggK2ZBN5FKGMWGX5d5/+iyIqdKrZzUqDvIjJydG/fmXxTCIbv5Cxba5HC5jDp+gMjtEx4x6reDzqnSHvHjyCpb0A11dr2C3xTKVHfujHG8L8nhfR1BYRMXKjP/t27x/t7Qx/M7MA7Htwwsh3Q7be2X/PwziPVNb7AixOYnOCx6cUA3SQ74vmFQcxvE7OXs9OCip9WRV9eozae45mOq83yq9II26COknm2HNsyWn2xqCDNrCBWIDQSbZZBB5hOV9lM8JyX+11BCj60Uw6KLq0qIVRTfucPKhSgB/MNgD3qvCsMuRWP1opv4FirqtBNc77isfn/aySRYK9QFkXG/2CWU///qYnXjYmtvXb6Hrq7T63I0Rd9WKxt9qeCtZvDJ1V88/n7kPXSsH8da7+DR5B0f46xEu0sKtUvvi/Jf4r/dZddLxzBOegJqqtmKBoDbkuogzYs6MlAU29xg== 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)(376002)(39860400002)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(19627235002)(66556008)(36756003)(26005)(16526019)(186003)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lNtuHro9e3NUCWRi7imX+W5bzN5nuU63rm90La75v532ifGe3nJPMp/kC/pQlIXbyPua4nVRb3N3ApssHXNJ0NJNzkeSyqYdrIRXQJiftghiaEHxKKvnhljS+D2Re4gVIGQQsH6RVDjslaJFaP+OLYi0fRTyzl/ZA+NnWhdGGuoABm6eUbPIsnlLwVB15jaU2pE9u6xhZJK3DOiAONWceWNwafSIbijnBZu98C8gZc4nbN/kzHeaO/i07tO3J7IkW1uf9nmxMtta6+rktC+6McYuLKhHBTdxd5hqY67VmgMprXGArZg3+oRDekiVbRd0B6LLTYSa1CiO7llcr1rHrU/AHLI5e+MDRl4Q+rBFEbz5BBMpqY7ocj7mVTLOdGqCDcTVDIBuE81fcaFxS1Wg5hBhM8xWHOsSLndWRW/vyPKIp0/+ly4hIQp+LGYBOniTyhoQp2C2hXJnVI4OIdZZ6gXmMhAiYzYyYxV4QL2gH9w= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1547d8e-6394-4b23-c945-08d7fc3ecd44 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:36.0532 (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: KWYtuit+xKZMVxEcx0wNzTIRQfuj/uyeaRX8nDV0gTsLePquPz9SbpaEBIx7y4PwHidIAveWkoIL1GFpXW+WXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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/BaseLib.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 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 X64/Non-existing.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 049fd1b872b8..2d131b2ac8a1 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7959,6 +7959,20 @@ AsmXGetBv ( ); +/** + 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/BaseLib/Ia32/GccInline.c index 591f0bb0e097..ee8c62c79c93 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -1791,3 +1791,20 @@ AsmXGetBv ( } +/** + 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/BaseLib/X64/GccInline.c index 3eed1205adb2..277974eff9ee 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -1828,3 +1828,20 @@ AsmXGetBv ( } +/** + 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/BaseLib/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 around +; 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/BaseLib/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 + -- 2.17.1