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.76]) by mx.groups.io with SMTP id smtpd.web12.9709.1597325081943605793 for ; Thu, 13 Aug 2020 06:24:42 -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=bddzJwh/; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.76, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LUFdeX4RYVP+NY2cKzz5oXjbsa4BOwJdDk36hzKaDUrb66ZI4KgipYsyGtsvHqXMNj2QJGG44U7YjbNDiAkUnGdaR8NtLmx+7WlHME12PVjgS8Q9dymUpgoVltk73AkZ1ySRaNoM9S5Q7UZOPa/fDijyYaC9EQAsy07dIvjmLk8PG5IJTqwJnOiU35yl373L3o078MgNc9+28TVjT+7sKAkeKgYa6f4D/EjLM8j2MECJaxvIaKQxN45wgXvts1NgMFQWKc0yppnItqAVqBYpvsjhRWe6umDYEw/ZDRLx0wHeJ8tURNxGAdn+EA9op5lUkb53iJVfY0/KciTpS8ueLQ== 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=n45VDVnMpaFrLCS1vZp6pCcqNKvTdUDLq3yT+MVIelw=; b=ExZs85wfzI7vt25u5/PCizJ1zs0lrQTgVNtQNnHF0SYGX0QGSvJZmaEkMaw5k0XYgLZfGk1kTzmYCGLuR0rNQAsDmwAO2MDRgNpVECN4TU7+8axJC/JJ8PgcBBIaaFIdrRc3JjjvGoLEt87miqDNnFEQTYeht0WMkA0DypvX8SLpCEN8lkA43+UE2ys6oczhAdZXhNXU6+GDtsevrnIQ1bkQ0uHNCVJ65QnItquejoMmV7UiElsDpGTk+XE38hEEjjjuwtKlDFdqnRjZFjGREoCkX5ljss6sDoO950XM4ueTNKEbU8pnu5jVupcwBEyoLf0nr5MFRLIimk9uqmTa5w== 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=n45VDVnMpaFrLCS1vZp6pCcqNKvTdUDLq3yT+MVIelw=; b=bddzJwh/t+LjSvvM+OJ0KV6xPJ8ZW/pkrrtwD/TP01KuEvAeyHWsiWbXu0c7mfzKUrIKK9LeboLSFJepKeGt0quXz3rwmwqL5WsQjjVajwbnCYAwXql8dUfWfjdR8lsTdEeHzAxhwj5w73VZOAgClkVjoyQrvgzKeOWtS7IBEJs= 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 DM5PR1201MB0026.namprd12.prod.outlook.com (2603:10b6:4:52::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Thu, 13 Aug 2020 13:24:40 +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.3261.025; Thu, 13 Aug 2020 13:24:40 +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 v15 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Thu, 13 Aug 2020 08:22:54 -0500 Message-ID: <055fe626231898d932229309e80395bc32264c9a.1597325013.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0065.namprd13.prod.outlook.com (2603:10b6:5:134::42) 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 DM6PR13CA0065.namprd13.prod.outlook.com (2603:10b6:5:134::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.15 via Frontend Transport; Thu, 13 Aug 2020 13:24:39 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 72c4afbb-dfc9-4d43-5c0f-08d83f8c3bad X-MS-TrafficTypeDiagnostic: DM5PR1201MB0026: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WmN6xlK8hVVhr1gbLLiR4oB5fDn8LH7WSh8okHmuaFd7ku5nzzAkw3n6tyov3rOCnHk8u0LNBPmUsbfqKvUP0H+3DbuiHabYm514nrtSVFVXQ+wV0/95tRFquepbTLUA72a7SvkyCr9tZV5uej/pTfOlmPWVZ0upD+Kv0vHXdTx3G+QRf46onge/YwLbJg7cgHd5gIjkS2CQHKFkCxSd+XvKRg0XBjq1kyFvOaJSNVXyVwNs0u2dXYPQGC4RTUhooDgJqCJWlB0d6dO1Neo/fc9Bpz95phEn0C4B8m15CvSLIf70pEm0b7c95GqzqPnfn0N2FbT7bL/wWlEFT2Cul6p8gTlre0sTnZzG/14qv8bSfcIj64k/49fpFVtaM2QxBR0cLPyL0IeDgJ+XimZOKAh9+UdF+FzFr2h+G2nAULcpLZE8h/SxkN9dkYEnYB0mLP8HOKLUTPoblAcqxyuwZg== 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)(136003)(346002)(396003)(366004)(39860400002)(316002)(8936002)(5660300002)(54906003)(8676002)(6486002)(2906002)(6666004)(6916009)(956004)(2616005)(4326008)(66476007)(26005)(52116002)(7696005)(66556008)(16526019)(36756003)(966005)(19627235002)(478600001)(66946007)(86362001)(186003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: XfgBhmtWguxAe5pPEUNrWSNAyJN1vxkR69kVdSHc27brO2h24NurAxSxhzn29nBxySD0nHHP02is0i3A+M1V9IawF0UpBT1lHvyWlyogIJ5TBVTXHvtZfcGrVSXEHE7hK3m3ldjJJ0jCPZ/mX6wn8KF6yNw54TFhnrmHeU4Ti7gcDHqD5zew8sVbIv4aEU/bff0hJ14Jj5LIGne8gQUJUhnz4m7EhT3yxEdHUaVVQ0HznmGEwUBrg9hFgzbq0ykDwvIn0HmvS6xQONT6qpaZ58a8cmFIb2GEg3BgUilOaJTuKuzoP1/bpu/yOzcnzzdlgHctdzq6kIPLXgfFKuStCp1S9gKqi5dum8SWt8ZpdwsO3IBPqGtKNm/917wTqpEfcdZG90NNkOs5+Vbk1/ATWJb7zW8U/KAQiwnA4KmyymmrGGM/w0lgXoav8ebxSBNNi5TsvdrDykCoObEptUkG3gyrF2WU4csZqV3HWO9MEGTW9CQLExk4+p0m0etoW77OE5CP2uCPwnn3ShSAw0aW7XCKjYJ4SP5EgkvssNB+C73pM4nrwT/CKuuARG+7D/tMSwy8ozlgY5XzCACcu3ldfhkuzxkd+K2OWxiPkzV5FTE53Vi14zb7mIc5m68tq4bTG1dDkgZY+cVH9s3eOli4Kw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72c4afbb-dfc9-4d43-5c0f-08d83f8c3bad X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2020 13:24:40.4502 (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: 7q9im4OUxdWP0W/yfk36xvAogSGWlsaLu9OYVrbnNlL+JMSd5DBk34LF0tEtDVRpxTuvN+LXrQCurkm7RMKogw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0026 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. Since SEV-ES is only supported in X64, provide the necessary X64 support to execute the VMGEXIT instruction, which is coded as "rep vmmcall". For IA32, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT should never be called, provide a stub implementation that is identical to CpuBreakpoint(). Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 ++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 38 ++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 +++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 3b93b5db8d24..3b85c56c3c03 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -184,6 +184,7 @@ [Sources.Ia32] Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm Ia32/XGetBv.nasm + Ia32/VmgExit.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -317,6 +318,7 @@ [Sources.X64] X64/DisablePaging64.nasm X64/RdRand.nasm X64/XGetBv.nasm + X64/VmgExit.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] 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/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..69f7fbf3506a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,38 @@ +;-------------------------------------------------------------------------= ----- +; +; 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 and NASM ver= sions +; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into e= lf32 +; format. Given that VMGEXIT does not make sense on IA32, provide a stub +; implementation that is identical to CpuBreakpoint(). In practice, AsmVmg= Exit() +; should never be called on IA32. +; + int 3 + 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.28.0