From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.51]) by mx.groups.io with SMTP id smtpd.web09.717.1583190455917588890 for ; Mon, 02 Mar 2020 15:07:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=mSl5epUh; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.51, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EoZ24VowRU47Myfi02+ztJKGJVFHu1oHRE+H5XYlTcmc24WY0Falt9WQpsKEZvZyAY+kHywRO0VKIfANDUEUFzDV78tvjkcqs5uFK55mwopyZfkb9Tt49UhPbwZEWREaV3KaQ95Kd5gWElot9hdKgFw0qrjPCIvY/4S4WMJDqTC0oVZYBvEI+vo36A8N6+fPIX+eeGl924HMFQzKZov0VZ9kQOGXc2/x0JiEq1INlkMfzJ7Ow7x6JQkZ6mPuGgZ7NRDgRIa9M430YA3DIq+mX0e+u73hT4OVv/qhB0u4TldSyylCI9aqtScMLDgABq6Uv1WkxWFN51raaaNUID14YA== 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=FicVz/jSnhCHv5hbmtJN2MKy4bsVE6O0Bjys+Kndisc=; b=UokoTaz1W5TNXi8ZEjDGFOznGXigkOpot+DSo76TpjwrlnAttqU6drssb8oZSOhD7jJAUKYho0PPhr0XJIQyMf5a3K+13bxEq1IXArVtKXRBtXcjbS6E33pMNNWJw1hZXvMCc5YEWRryEq8B2JoerNUexeummdSHhfi+CjPa8mGcE2E4Npk5HEekZwG2wZH10pYXNBg4Xjqn0ylSQ1F+mDVNbNyJsRAixK4eXRWl4nbR9fJ7JM6hxtwwlY5SdFPh6G3zrzCx+yxwD+9t6Wf/qedo9NYI6wkXd78uc9gOIYjMR2XYFE2nmAXmDXM48s7qLd3++SUYibcDBqD577+DHg== 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=FicVz/jSnhCHv5hbmtJN2MKy4bsVE6O0Bjys+Kndisc=; b=mSl5epUhdqOm/yiheCxyNu7VjQnhuS1hrFNaOKCM++5UdWfAC74htCicLExJ4wUlDOY52u0AW3S67n0/Dni5wj5OObSJEVTlCrOMkGkq8NmV9ZzOvWFCXp8xtJsDiintYaWgfZakuYxNFxxncRiSxsOVsWbEMx4otJHnRNW+JaI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB4041.namprd12.prod.outlook.com (2603:10b6:5:210::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15; Mon, 2 Mar 2020 23:07:35 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 23:07:35 +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 v5 06/42] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Mon, 2 Mar 2020 17:06:37 -0600 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:34 +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: 2b7f1271-3e0d-4c9e-8680-08d7befe7e6f X-MS-TrafficTypeDiagnostic: DM6PR12MB4041:|DM6PR12MB4041: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(39860400002)(366004)(346002)(396003)(136003)(199004)(189003)(478600001)(86362001)(5660300002)(81156014)(36756003)(6916009)(316002)(4326008)(54906003)(2906002)(6486002)(8936002)(81166006)(8676002)(966005)(956004)(2616005)(66476007)(66556008)(7696005)(52116002)(19627235002)(66946007)(186003)(26005)(16526019);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4041;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: /ByjlU61tEA4r2UIYvexcZAgFlEmBLmWYnAkqsrdcC81LuVRsHRf5hji4OFY6VL/Mj/4YKTLz4+EJKlY6aFeNxtB8RnyWJ0v32LrjDIaazqZnYrUDjZVeDcN/U3oXry+rkRMPFEly2kKb6qs0nPF2ck1QFxSr8vuP3LADXKGiEvzuEeHpdI3eAAEh7yPXIEV713XnA2gSTI3prztExkmC59ocO7a4i5WnFYp8Cvqia2k47pVaS0PZFM/qQMg/mLPPNXfW5uafx4LavqWycExmRegwANEjqcWwRh9igbX05FB705MAXbXniS8x5k8MyaWkMS1gys4Qhkh4n8lisD35x1hh+wnrGeekPP/btrKAo/qNlfl1PEpPUKZtZtQ04YX8sNwrgOiOa05MZq0ytVEBMnaFp1YBzsFAg1FfzQ7Lsojee+3xq08QuSXbMU55u+1r3D+CcyiK48QkHw0w/hn+Ml0ObEsuo0ZQm5Iozn/Ls9Z2Yb0DGimkqdunafOVZmwgzs7TVeaHiTU0hIUS2/L3g== X-MS-Exchange-AntiSpam-MessageData: pqATGVncxX6J6axg4vXSWolg3jWNTB49dCUztPLZaArMj4y79ZnSDem25iEKEBnP97Tt1RNslFsZJW5GnQS8jGS66oEU1nVFdMYXpsxxl04/zcOleywJfGx2O1qnYanXvpt4pSMlstkaTwOHbeMz2g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b7f1271-3e0d-4c9e-8680-08d7befe7e6f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:35.0302 (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: U0Mu/0APUDf7/jZLKZvcGqdWdcuqNB2Q/QYrc/lOlLcAxXFoR2WbdmLkvuUxZDuguVJiK3F/ktHj5Q2ulOq9+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4041 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 d0cbb52ed8f9..99fff8af5a3c 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7906,6 +7906,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..cdf727825400 --- /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..6537a97b273c --- /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