From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com [40.107.69.59]) by mx.groups.io with SMTP id smtpd.web10.13509.1574280444755971226 for ; Wed, 20 Nov 2019 12:07:24 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=RSmEbjLr; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.69.59, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mJdlMq0gQQuLbZy/PmhS0A4q/fv2qQKhJqzGOMAo/rVpxtXLZONobKHSfwGbmTEOh3dUBH+FBpVMgDZJGkf58P9ItMXltW9/2B9KXNDosHapbw3imC6zdSp9vXo9hj7r1cEV4vJoe/Xlrkr+iO3OCqPo+eFrXrGEvwxcJxJHfWEHjWuqqfw4PPpAs1sNblCjlL3ZrenkVOX/FMlwekpaxDX0827Fyxv4BD4iJO7vx4lM2iuvf56FvKDicjo92QYgBKXF3xlJtgZ/q3PmwMyOZx/FR4cNFLrvQRY0KKLr2Q63g74KLZlRnDIj4L9+SD+izD4pdAcTjBEPWv+BQfvxOA== 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=4tiW6clsAmJvPZCd48/8M19+A9VTpwqUeDmO9DkZu3w=; b=de7tssF59O2igMamo4o9fd0VyMMVXCasDsGM8WvmVX6Hoxu9UXB5XPPeifnYWn7vdppq5mLZIE0SBSbC/WOWL4B9VifJr3HyMvCPP6CD6Xal0pH4iTEKZGnIOU5CW/NhKyfBuDaDhNNxXMOSxEIZ+7NY3XCpF3HCpbIrFU8OUJxcktD+U84jj5Z2aKgtMiFYyHAJYBTnap9OEbkF/xiLaVMPXYmV+tmR3+qrM/ABJpTVu6F3toP4bb4kY6QF60uveoNiRS6yZn2aN/A4VDTP8wzxdDDJBu1QwsUUndxoP0ohfi2PyDgKD2wvoyAwGi6jY4oSUYvmWPtII7XmoKYqLw== 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=4tiW6clsAmJvPZCd48/8M19+A9VTpwqUeDmO9DkZu3w=; b=RSmEbjLrTFylVMAeo2My6nRE+qPQt5aRlQcxZQruunThE+Ix0gF1+JZfDbAT9zEALBN29lqPuxHq2Wsp6pknkCwGEF1XEU5kLcrYRpvN/qU6dDBYE8Gg2z0Dvj0m670RUOgD3HfYd+YEboQZAojptT9CGWbR2vyBDXwJtjuSyyw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3370.namprd12.prod.outlook.com (20.178.198.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.29; Wed, 20 Nov 2019 20:07:23 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:23 +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: [RFC PATCH v3 06/43] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Wed, 20 Nov 2019 14:06:28 -0600 Message-Id: <85d5fdd20ee1b2527a3afd289e92e604f90ceb3f.1574280425.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 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: e6297f1b-52c8-4199-ddce-08d76df54150 X-MS-TrafficTypeDiagnostic: DM6PR12MB3370: X-MS-Exchange-PUrlCount: 1 X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(39860400002)(346002)(136003)(366004)(396003)(199004)(189003)(36756003)(66946007)(66556008)(50466002)(2906002)(3846002)(48376002)(6116002)(118296001)(5660300002)(6486002)(2351001)(2361001)(6306002)(6512007)(6436002)(14454004)(4326008)(6916009)(316002)(966005)(14444005)(25786009)(478600001)(19627235002)(26005)(186003)(16586007)(8676002)(50226002)(54906003)(66066001)(66476007)(99286004)(47776003)(8936002)(81166006)(81156014)(51416003)(6506007)(386003)(52116002)(76176011)(446003)(7736002)(486006)(2616005)(476003)(86362001)(11346002)(305945005);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3370;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LwZctqYVpaEZ95x2l4PpXFHSGIIAjL6zK+sy3kKHbwwp2QuvXdZ9N9U5oYhnbNJJNN8O+jxNQQPm8z11Fi78yAfNXrSDIol5woYtL+m1jfzeqRmhmhz4GxFBl5hbDDBOF0qrYr6VX8AZZRKKxx+Mzein3U1Kgp9TUbIoD61QfYYkPfxJAajh3yB4ptt4mFR+WDAWb8J6upDraL4U/8eFuBrZgIDh7mEe7gIglClxcO4zJK54ykFq0alj6WyaKLoeIdh6V7RhfwIoH9uvZjceSnloyXG91MwOe5MJALNBisz4CQRYkaoQ6VkxvQjC2zsBYLfIxfVkoMdRlEJ9R8DoHllscMIOMqIQ9PWRXNfFaBJV3zNYIyOp13va2vg/ThFej11o72vzEwAzQsd/wa/Nm9RA3tRdUvJtd2wDXaTXfakxK922mleMfXCzJGzNA++Kct6fTZZVaTyiEiCHjpgm4P620t64T0tM85FVJvk5w2E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6297f1b-52c8-4199-ddce-08d76df54150 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:23.0725 (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: 5NV7Q08olh9B4UXKcFlou7bug87MnV56aR1zN1VebUtLtMEun5JS2NHrAGEM4OzoFrv3A0XwZEwgjA0bZPP5Rw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3370 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 d7a1dd017e95..62a09197b8a8 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -153,6 +153,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT Ia32/XGetBv.nasm | MSFT + Ia32/VmgExit.nasm | MSFT Ia32/GccInline.c | GCC @@ -288,6 +289,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 8b710dcc0aad..378f5c1b18fb 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7897,6 +7897,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..85e6260b4e2c --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,37 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2019, 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..400d0302c4a3 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm @@ -0,0 +1,32 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2019, 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