From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.44]) by mx.groups.io with SMTP id smtpd.web11.5494.1595366439995846620 for ; Tue, 21 Jul 2020 14:20:40 -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=PDGqU7b6; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.44, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GO3fpyb/tiFsBz2C9m4mcA0s0l7aPgqGciJpxyVDYcy2L7YZ1D2DI+yK1VC8IkRIkFtiGhvNhtxUtXzpUPciCldBTL9OhIigVIdUDmQGEzO7ReuC2k7TF4jxk2iIUdeDBBiPFMNU4QWZtUInJY5O8DQStaiyEkJYWf0MZtR4k7OF99rITaCPAYjs6q/yoMgO6uFntWJOsgLbvAc1QdY6I9eEPs5so+fqBJ5n2ni9LIVfbDWqWN4bfOek7YtV/jHKhCBOX06IM4b3mUth0aaMLYbSFVcs/LAnJrORfKLdenaJnhSF436/DmFKFkY6VbE0FxtEV6Bj8MNfEqwQ7a5VzA== 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=lCOhEwJaFD0Tm2qEF7vWUe/Mwd9En5D3z82fbsggc88=; b=lfqHVfEU9CYmEsc7YoTq2XRdY0r7S2qiPAd4fOEfTKRqT3DPOTrFLyGGF7SS3z3TUdmqDCG9WDSGNOuubtPB6xvBRGcGIi9YjodXzF0XxTwlmrBvY5Rb1OEItzzOK6YzvG4ORGu5yST4o2VWXZbR4haHlgYzoMxaczoJaOx4m9oxlo9ersWtHgpKwk4t6pao7j/Iz6SbGMTMy+5KtJlj4lfhpjdjd0Vr7hCLtPzsOuyFnJWBXDDdWFT9Rdyna5VcmPrv6ogzdCIJV8QGSgCw3kzgnFKncE8rOGnpXvybeajC2dw7tcSpOYMVvURhyrs7N9izNdm3Zu4bm6K1gDk2Gw== 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=lCOhEwJaFD0Tm2qEF7vWUe/Mwd9En5D3z82fbsggc88=; b=PDGqU7b6+gVGAsG7hAmQpuNbUHiBiQ7s+Cp7yq5F9H8yIMxw0Xe0VfZtwbzXRwk3qZBE8KK4G8EMeKXJcXx/F1AAo4AK7+nCfz8QniolC/eNNRKTSY60Tk8nOZiczEYYMgyt34ChLkQOypsesbgf/wVhPL6wFBTCueCrFqfu6Yg= 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1606.namprd12.prod.outlook.com (2603:10b6:910:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul 2020 21:20:37 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3216.020; Tue, 21 Jul 2020 21:20:37 +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 v11 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 21 Jul 2020 16:18:44 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:20:36 +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: 0e14ad61-6048-4bba-528f-08d82dbbe9a1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TzFnJmDfBVLVMIw3/f70w2tdpKQalfn+kETDtxXyvybMKaGQ6ie4UaDADtiOllJwGr9R+RlQosaFV86THMH6QTF9Bd+n9V66Ps147RnuV8ZK4HUWR74FIpqcol/gEImMDMIOfwOUfnvW7ebHfgJLhd1auhOZStQhOYKgewNz6m9ckr347YJzHIn9MK7ecINn88a+GwCiMKqHDoniY30mUVGi9gHSaVlg/nEHeBnQa4rSncmpgqQweOtATUsjEgiMMrdRX/MiaQRjrl5CtOoHwcNuU/GSe7zANvpGOjhPTnXp8Tz4vHp+0SCC0vRGfalyaI4a6gkI9IeoZYGGPDl/bY+Hz7nV0HhfTUP+MH2hBap5zBuGAlPMGNnME3p+dMEW+UDRPz7sWZc1uzP2vbwjJE578UHFAjPklJV+UwKyU3bz+NuqjTlWAuQoObcBYyweqxMVycwDW3tft8iauXKnWg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(39860400002)(346002)(396003)(366004)(376002)(6916009)(54906003)(2616005)(956004)(316002)(6666004)(26005)(4326008)(186003)(66476007)(19627235002)(36756003)(16526019)(66556008)(66946007)(2906002)(6486002)(8676002)(52116002)(966005)(5660300002)(478600001)(86362001)(8936002)(7696005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4r9OVrJ5V0/NKW64iz73uYnz1IMD2t46Oa+zI4mcqgj3ATwJoJHAI1czKgeG2iME/2/55rYZP05W/BqM1CkDvpuOfBx3bZoWgOypXTvLqyc+WpFeld2aR/Vw4LRW7hc6rOiml+K2U8hLeAEQmA7lwTbv/II1jPYFoHUivUSjLsCUR4wJhHObzcKMil6eqiHHGOpygy0IGeOgF7Y4loWYR5V4IZG/PBQs/3KewfP5pYj23+K2Kl4okQV7Zd7iwszWc+swdDvtvpItvWs71b2cseINYOzbMbxscS/0IWXY5Jn4dTnfY+nsaLoREL3wSygV+PXNWWVDbbbAjwRUM3O2P6OWwtvLDms4iCFu6l40mVq1NR80zlarPu4pYjglqQpJTrBCEKQg/bRFkNxAJvw1ZDfOoXs3VS8KCl+fX1zQ/6PvFtD1wG8/oI9J4n4adRUQfdK2/3DxE8s+IVckLgPC+G04w894eF4BeVlbu9FR5iI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e14ad61-6048-4bba-528f-08d82dbbe9a1 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:20:37.7491 (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: TkAY+Mw1sZDioOmMP8wRZjGuLK4KTEBNL1jxNp5gFJJDIy/ZQelRilIQQzic77PQvCNfxwrY6eRDXfGL0p0mIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 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. 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/Ba= seLib.inf index e26c0d8cb0ac..1bcc90d5a4c9 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -154,6 +154,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT Ia32/XGetBv.nasm | MSFT + Ia32/VmgExit.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -290,6 +291,7 @@ [Sources.X64] X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT X64/XGetBv.nasm | MSFT + X64/VmgExit.nasm | MSFT =20 =20 X64/Non-existing.c 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/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index c2565ab9a183..26732acd8431 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -612,3 +612,20 @@ AsmXGetBv ( =20 return Data; } + + +/** + 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/BaseLi= b/X64/GccInline.c index 65f864e35922..1f584b6e50fe 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -590,3 +590,20 @@ AsmXGetBv ( =20 return (((UINT64)HighData) << 32) | LowData; } + + +/** + 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/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..a4b37385cc7a --- /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 aro= und +; 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/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