From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (NAM02-BL2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.10840.1591363676588816927 for ; Fri, 05 Jun 2020 06:27:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=1aCNnodG; 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=UPx2AN36LXpcUIhV9X03oeWE51tuf51TMr5Z76jeP4SP5GtSLJXbk0Of3S68i5B/CRDrVzXcI544fJkvcIWyzHWhqUbCsgxr3ZlSjBxLbFJkpODYATs8gziuUT5S+tIxuiO9XmieFud8I49aAgCdFtXk2AEEQjDK+/f+PPi52IfNrrlPmXS5/0mwlNcIR74Ocq3oalEQ3ivdQlHxTvLlHdwKIfczcX3bu/FuKob8AsblaTB4jtwRaWgoEApT+9sMSa0vgx5RNlGBBxIW1csmkhdRTZDu8aqpPksvKfPijJzfmQI6eqSARhwGQwwOAXvDr5vjiF7/oxcsJMX0FMoJFw== 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=8Yohn+ephFgei0G+USV0uR9V42/hFsRIc48Ya+aYj6k=; b=JTKA0DEq+vTbIgaqIZehvQ4thWnOwW+ldpwC54L10KmJrH5cCh/NJOLcO8TJGnYoIClV2Ki1n6VgSD9O6Gi+Z4RS5Z8Efq4G8Z3VoJ36l9p+9YsDQZek6RZMTbCq1IYx/tcGFbD59E+yYFwhVFwaQWH3MjOerQAYnXILaqcVtBvcG/nXPgsYBxAsNUq/q67/R+9gamvAFrf/q7DaL9C/RxLpKSAuVJFyYTSM/uKFNP4VvMKCZqFxtpmckt2j8q/guBhGNZ7o9Ow4uCOyBR6m89BAt7pjDmy8QMbs2gm+2NB5vaNCUJlVkpGW3FcBVgBh/hm/oGQS5W+b8/Z5B/YEHg== 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=8Yohn+ephFgei0G+USV0uR9V42/hFsRIc48Ya+aYj6k=; b=1aCNnodGZDX7KyyfdrHtl/7Wyj4cP7Nr99RXgCJA5xJMaVdrXT0FFo+6CChugAfyOM/iqjKKfbi+z4jbHBrHq0nmTM4i6PvAP5Ur4haSuPDqtX9IY0QWBLTb2SC3b6/cIKiXt0Yfj/xvhrQ5msSeoP7atPx2Zu3SrOe6AVPcsXU= 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 DM5PR12MB1594.namprd12.prod.outlook.com (2603:10b6:4:e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Fri, 5 Jun 2020 13:27:56 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3066.019; Fri, 5 Jun 2020 13:27:56 +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 v9 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Fri, 5 Jun 2020 08:26:58 -0500 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::22) 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 DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18 via Frontend Transport; Fri, 5 Jun 2020 13:27:55 +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: 0d43ac1c-17af-43f0-f588-08d809544202 X-MS-TrafficTypeDiagnostic: DM5PR12MB1594: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0425A67DEF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2pm8afMFC4eb4ask19LZdbbgFfl0cahjma5RBO37iWSoFZRESR9iE9AMEzhIh2KRgaB07d7EO5C18EUcKxrXp/qhK//NvwP3gRVoTkkyuDktGOPwlpOtPpMlxtPvd3rUn8kjVniHLArsvQEl7GavP3q1q7Sv3pQyJWUsgMhO69FrrwQi6YylSufvll8tsvxaWy934r+R09fdxN9Xb2j1p6ATx9AVQL1tFCe4qnkRa4+KsvWxZ2mG0V52x5zzFLsNcPV959rDj/MUtF0RT+3bu9/WnEnQph6UfghW2PCFZq2NlYCRFaUtfKguzwbA3ifuySA13uF+J4EwL5kXu7gFI8Qr1aPKaj2nXmvh3WH/Qmd0OARD1t1NhrefEz4bE+K4NtFEvu/9x0l8s8iY1Boqg94m9jG9bGveWNk4P842TCcTsgnxxzK6wE6j1/gHMWQOxMqqtQP66U8yZ8GCgdoKsw== 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)(39860400002)(366004)(346002)(376002)(396003)(136003)(6486002)(4326008)(16526019)(26005)(2906002)(2616005)(956004)(186003)(8936002)(7696005)(52116002)(8676002)(6916009)(19627235002)(36756003)(66476007)(66946007)(5660300002)(66556008)(966005)(316002)(478600001)(86362001)(54906003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mNwxqg1U6PJyN3f3r07cyzPH4KiobpcJa+v4iihgv4qo/Z6zq6H1SgmEFiZwVysw8VsURzob7EKLwPBEoxLqRXwQlQNoEm/qKL9e350MIX9exSG4mo0YsKrEnQAeo40cYCaD5MyYXHa7Z8HKYTz1H3Av1a5AQ2oWLL3UrHI/T064N6v/UQSZ2Py8VbjQsrcIvOzR5E31bw67UChWSIh5AzMzXXHHZLMfvwkmH593yXBOKZdUeR1iKL6wFJc2dno7uDGxfjnAweYpFBGp7PnWQFtPAWWXbkkZWot61SiInn95quMJSFmJ9pxHbbqOjA6zTrveBjBlI/cN0TmhsgbUoXxdDn+QWNdkUZN5TvtrE7VkrSSaRzqzM7kGy1yB1AAhmZy3B5SRsMGXZhbcPwoTNitsneX1CVDGH5yRQZwgW0rDDnK8X/Xn1dns3LLnbT5l6SGs0/u5b3Y3Ou6vv/i0iEvRn5ENo62Hu2uUJHFW81w= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d43ac1c-17af-43f0-f588-08d809544202 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2020 13:27:56.4707 (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: QAKoJrKsqVBXaJgCfScjmYjWWKqWe7p/4hYRgeZ5UgXzuIpRatUu3XdUJtlpw2ZHIHFVUM5yvY8e0LwJpuYNeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1594 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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(+) diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index da6bc22a3e2b..7cf6467fa77b 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -154,6 +154,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT=0D Ia32/DisableCache.c | MSFT=0D Ia32/XGetBv.nasm | MSFT=0D + Ia32/VmgExit.nasm | MSFT=0D =0D =0D Ia32/GccInline.c | GCC=0D @@ -289,6 +290,7 @@ [Sources.X64] X64/ReadCr0.nasm| MSFT=0D X64/ReadEflags.nasm| MSFT=0D X64/XGetBv.nasm | MSFT=0D + X64/VmgExit.nasm | MSFT=0D =0D =0D X64/Non-existing.c=0D 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 ( );=0D =0D =0D +/**=0D + Executes a VMGEXIT instruction (VMMCALL with a REP prefix)=0D +=0D + Executes a VMGEXIT instruction. This function is only available on IA-32= and=0D + x64.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +AsmVmgExit (=0D + VOID=0D + );=0D +=0D +=0D /**=0D Patch the immediate operand of an IA32 or X64 instruction such that the = byte,=0D word, dword or qword operand is encoded at the end of the instruction's= =0D diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index c962bcfa4617..d6a7581b36f6 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -1791,3 +1791,20 @@ AsmXGetBv ( }=0D =0D =0D +/**=0D + Executes a VMGEXIT instruction.=0D +=0D + Executes a VMGEXIT instruction. This function is only available on IA-32= and=0D + X64.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +AsmVmgExit (=0D + VOID=0D + )=0D +{=0D + __asm__ __volatile__ ("rep; vmmcall":::"memory");=0D +}=0D +=0D +=0D diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 915555198f9f..0685337bbb56 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -1828,3 +1828,20 @@ AsmXGetBv ( }=0D =0D =0D +/**=0D + Executes a VMGEXIT instruction.=0D +=0D + Executes a VMGEXIT instruction. This function is only available on IA-32= and=0D + X64.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +AsmVmgExit (=0D + VOID=0D + )=0D +{=0D + __asm__ __volatile__ ("rep; vmmcall":::"memory");=0D +}=0D +=0D +=0D 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 @@ +;-------------------------------------------------------------------------= -----=0D +;=0D +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.=0D +; SPDX-License-Identifier: BSD-2-Clause-Patent=0D +;=0D +; Module Name:=0D +;=0D +; VmgExit.Asm=0D +;=0D +; Abstract:=0D +;=0D +; AsmVmgExit function=0D +;=0D +; Notes:=0D +;=0D +;-------------------------------------------------------------------------= -----=0D +=0D + SECTION .text=0D +=0D +;-------------------------------------------------------------------------= -----=0D +; VOID=0D +; EFIAPI=0D +; AsmVmgExit (=0D +; VOID=0D +; );=0D +;-------------------------------------------------------------------------= -----=0D +global ASM_PFX(AsmVmgExit)=0D +ASM_PFX(AsmVmgExit):=0D +;=0D +; NASM doesn't support the vmmcall instruction in 32-bit mode, so work aro= und=0D +; this by temporarily switching to 64-bit mode.=0D +;=0D +BITS 64=0D + rep vmmcall=0D +BITS 32=0D + ret=0D +=0D 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 @@ +;-------------------------------------------------------------------------= -----=0D +;=0D +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.=0D +; SPDX-License-Identifier: BSD-2-Clause-Patent=0D +;=0D +; Module Name:=0D +;=0D +; VmgExit.Asm=0D +;=0D +; Abstract:=0D +;=0D +; AsmVmgExit function=0D +;=0D +; Notes:=0D +;=0D +;-------------------------------------------------------------------------= -----=0D +=0D + DEFAULT REL=0D + SECTION .text=0D +=0D +;-------------------------------------------------------------------------= -----=0D +; VOID=0D +; EFIAPI=0D +; AsmVmgExit (=0D +; VOID=0D +; );=0D +;-------------------------------------------------------------------------= -----=0D +global ASM_PFX(AsmVmgExit)=0D +ASM_PFX(AsmVmgExit):=0D + rep vmmcall=0D + ret=0D +=0D --=20 2.27.0