From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.77]) by mx.groups.io with SMTP id smtpd.web10.1723.1596134724466807625 for ; Thu, 30 Jul 2020 11:45:24 -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=DsB+0eo2; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.237.77, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fT5npP5xvcfNfm/qLlkFYcx9jBCxWJXjohDoA476qeOJaokp4p3i0DDG1x3dfm9Ss8tzyaeJrwWQf+LjeXaiS687XGnekXXoX4tIoivfUGqY75W+ye9ozVwSBGjTdgrmmn4+p9oLmkr+pNb4IU+pRr/G5bf9mmT4MKLzUUpj411cPnATOxBtzqr5LUAPmMBvpgf8q62aJ2qikO7XCOWcv9y4dTvaVSnjVEJ4K2PEs9KFW3yN5gr4E6b8SKaR6jomRudhkFrWlD9ivohjr5U13vm9FtjNhG4YswfFRPbUO4Qr54s6biw/QkPn3SinyvEuxKBDlu5+IheOD8kZcW+jAw== 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=wtj544/t64Lo8TNHL/DjTcFV0mcHUy5IZTtfblArQrE=; b=nmDTe+uZvLpgC9IOgy7kZdsMtI8N4qLgkiUNcJzr/R/X4P75RwLwzeJlS9UOVqtb63jsndCEmxbwLv4z7NvVIC6I92AlGkyoBoRf2QX7rbZXm0vl6xuldUxA/hB6MmPAHAVtxvIvbvDJ0Pa8R+TfzrVRg+5qSW6CNZJTyJFmno5rVdn58AB0fdkmAiDJz9EEAt+lqqQBSxG12oau1P1xIx6qfl45XaL02xEgcsBAzZE9/A/32yNtu1Fob/zuN0clHPQy0C6aau6jVSNRBzyWwer+qPfqL/K8y6dXj3yVWhU/bQd9DY6mJccM4V11LTGQajenejUB9qv64xialg0lSg== 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=wtj544/t64Lo8TNHL/DjTcFV0mcHUy5IZTtfblArQrE=; b=DsB+0eo27vg3UCNtcJaQZc3y1edXAfIZ6VUKRoyNcndCePqB/rztHmz/MXppmRfnDrX0goflR+ES2lBLZGdO1zt0nDeSCNXuasyb5VtUQIE+GDg6M+cEMoSUcGrYDbl0q/vQGG/m8K/NdYJPxmdbWLy9iYMkU1CL63bFF79ysFg= 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:21 +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.3239.020; Thu, 30 Jul 2020 18:45:21 +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 v13 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Thu, 30 Jul 2020 13:43:19 -0500 Message-ID: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0015.prod.exchangelabs.com (2603:10b6:805:b6::28) 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 SN6PR01CA0015.prod.exchangelabs.com (2603:10b6:805:b6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:45:20 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 63de5302-7910-4cd5-3a74-08d834b8b6a0 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: R81Dh2Utw9c6OOj7pUKA98whnzD7brnwMBvL5ojRXIe/d8WOVmZ+5TMHaV8c/VwjIce8gVHQpFNUyfPqA8Y2XZMd7fYxOVjNxLf3A9/Yi+2kHkNt4x59bP93ohMuikUWWM+K42r7Hm1fDXzTW4a27mML7r2ibldQPTmfp/9W2VAD7OkWMsYjCnBZAyaAxQcxHoiPKxtlBQUGC9SHkrP0EyudClkfxdqJzvTKnTNbYDHkj6+yuahzMryEtqhtz8hG8W02xQXGR2GQSp1wYRVDfilgdAFPPT6Qv4wdekk0Jh8XzElVjmTAlB0oMMPCx+A3cFiYer9NNU7OnFN7Ec0AhApJfLcOiqNqUqX4su+9m0ZhqzVsnt1VnnFkKB+MxV9vYGp0NlLb2zRyiHKMvlnMaG1XjC5YXokyo9gUQNtl8TyZRJYtVRZ9f9I7HIDVBajrnGBDmPcGvWpod6Xq3i+Fyg== 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)(366004)(346002)(376002)(136003)(396003)(39860400002)(2616005)(5660300002)(36756003)(966005)(316002)(52116002)(19627235002)(6916009)(6486002)(86362001)(7696005)(956004)(54906003)(8936002)(2906002)(186003)(16526019)(8676002)(66946007)(26005)(66556008)(66476007)(478600001)(4326008)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: d/pJaOC5CvRaWP+kS7m5ydBDAZqB8mJvHIthsM6Wf26RFFUChsb7QlLXj1y9PA7yUU2B/2+CWPta3evPeiaugpSv3EVLYdeMruyDZCtYAIL7aC2QuKNEj6hjRio3S31iMc77l/kQDj8rkcX/5WXLIKcxYutvgWZOP8PQHT1rXRIDt21vphRNdbm5ntafo03ZOnqLTJb3d/ZDnymyQcfv7ITJ6bpJ6mr/VoEUwjN6Wku3cISs8Qhv+iCrsMjhFTc1/aczGbmW7miHiAObrzdQ9m3ApLZxCNx18SOEDlJPOVgy/lPLBqg33UzTDNSTtnyXlfrUWeWMeorKIHY73MnMLW/gBEWkhG++w/OwpjxtW8chQXflFCg1O9csY6x10DluFbtlt7wgLHolQ3N7LC0itk4Jkr9yRjxzXOqXPZoE/9PE2d7YkfHasM0pllwQ0t0Y/SWlosS+TKBktDqM3F/MjNAcHj3u36S0XzncJWyQwps= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63de5302-7910-4cd5-3a74-08d834b8b6a0 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:21.8704 (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: 3YhPnO1CFysTBmndAmwsk0rNG0E4cEoni0QGbF/1VmakxE70MeVNIeQLrm0puAth7AHdJYeDbzXjILTKU1GuTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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 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(+) 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/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.27.0