From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.475.1587577344278837436 for ; Wed, 22 Apr 2020 10:42:25 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=zJjIlXj5; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bFC4x2tFiuDj9dQr7DcYDiTIhLxP0xBtU5RW3UO1ZYh/Yl73Og8PMUm6MX4XSpgVmajLMUsJK6BOPjT9YeVSyyy/v+UFRX1LNn0JOZ8lAk1ZcM1Lta3sRmd88wEXg3H2N09h0Dj76aSP8mU7hkuc8J/4xKPzh2mc5C6xxJqR++T01v3+T6/i79LSXjS9JksHOOjsYFEXadae3OtlgE/GwNh4eI80zjvKolR2tY2WAo08brtFl6RjlOu40OyqgGFTGOGOW5+7W0Wa9nS3h+t6ujvczr8S4xyzWIflrjIbfkjpvxfPP2jxd73q1dwpgIkzOUX4EeKYXbhSEq3nlCkg2Q== 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=hpOn5vSw4q74qp5JOBS57QX4sW1e25Z6NWC8slhRoHvStP36PejRzCMoBoBzEkDhomYREL8UAIzMpaG3UUxaB177EE1Bpmh0XLycghVfCFIfVfsbRREG6iTyUCkiI3gPGWax9aNqJTDtDcTx5DUfLhGLtsm0StAbwNsfgdWtIZRm55XRlMhIrlJ6sAQIDBk4s5yo5uQdc5bBod5nCP4AOK8JEGk/QWOzAZ6ZBm9LqInAk/jqhUIIZmS7K3Jx3FkUrO7bL5Z4+mmvxybfZXLnhI//Y9BOk4Gbq4Z6he+buSNM1eFhtjc8tDQqPjO7Fm1vIKFSJEfRYEfxGiX+DAuRuA== 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=zJjIlXj5GUDFQsSrF1CeNDjlFHiErWmwYR0dMRtlFKiCEHdPSxz/qhU7e/PuUrwcCOhaEo2KG5Yoq1Ltj9fLTA6ndcYT1LksSBeL3LaHtaH8ipO+B0o7IhbzeHk1ea81X7t2GXWdKVeft+M4jXRZRfTQDhT/caj8TbTuR2MIor0= 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 DM6PR12MB3449.namprd12.prod.outlook.com (2603:10b6:5:3b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.25; Wed, 22 Apr 2020 17:42:23 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:42: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: [PATCH v7 07/43] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Wed, 22 Apr 2020 12:41:22 -0500 Message-Id: <96aeac6f0faa5d4e51b3c0e316523db124e4fcf1.1587577317.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) 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 DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:22 +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: e77a27e7-f64d-4044-e462-08d7e6e48388 X-MS-TrafficTypeDiagnostic: DM6PR12MB3449:|DM6PR12MB3449: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(136003)(346002)(376002)(39860400002)(366004)(396003)(66556008)(16526019)(66476007)(186003)(5660300002)(4326008)(86362001)(54906003)(8936002)(81156014)(966005)(6486002)(66946007)(316002)(19627235002)(52116002)(7696005)(956004)(36756003)(6916009)(2906002)(2616005)(8676002)(478600001)(26005)(136400200001);DIR:OUT;SFP:1101; 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: 4e6btaw7H6Rx80MiqRnIj7SLZSkFidINXNnyIjIPvCbUmCWO/jZPBQhX/KXZ4KS/vzMmhoH2OuErcwGjhBc2U+nx6g0Dd4hFGsK4fsAudYsogF1rqH3Not3WxmOt8esbwJJhdlRW3rXvdFzKetGaunZKdh0JGlQqPQQxNQLhyYPM5zVOE7Yw3ppPBGKi/4E+0OXBGbBh05puPafFW2sj2oMaI38hGcVl70UqZoHM/fFB3gjssNu/nfOSxRKQXF79Z/8maLHEYiitupTJCjVwTJoyBZrD4ZvORi1wG0z3fBDRgSh0XJUgPAxM3Yuziw9uukWFiRAiT/a2y8Qc44h1EbqlehKS8VH+n9eAC8dMxxd/bxAEPscy6hYPW9LzaQMJG7SH0rv3M5RjfoHr6wTlhmt+DEbNYJtj2DSlH/4/GfLzKWNW3ZIkQ48hArdFvyAI9hyZwv6aKP0pzqY/CIn4znFL75hnj4AtKFWMyjXmmmvSu6wfgqH8ouV1wVG+p2+8fRNptmFFroLOi6J5LP6CQHd15GbOIQVkw+vDUkDcWvEmmfDioQefjXV1oEDtIQC8Ji7tGVJwzwVgG0p1wEdw/g== X-MS-Exchange-AntiSpam-MessageData: CGpTt8vJfUMg2HRUJ3tOrw0EllB6CrG2p3komTPnWaHt53NqnxFtmQjzC/ic76IahCAYjAxPlLuoy0/jyF/Dta+oF+hXjyag+BBUO6BDPEhJpuvx3ynxiuX/kM1+ODZoc25ZwwNSqhMSTk04vyhQXA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e77a27e7-f64d-4044-e462-08d7e6e48388 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:23.1412 (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: sK7nMoNXQvBt3QfojP3creieiHdp8KAKwrX+lO3kvdafdeetIZX7HVvrh6Xs43BI2Atv9D/yMZPLWVvFl/VMlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3449 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