From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web12.3204.1596421787998920226 for ; Sun, 02 Aug 2020 19:29:48 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=zWFSVYKj; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: liming.gao@intel.com) IronPort-SDR: 5KpEbun85eMScWK0i0OXejwEus/iWNWSw5eEKVc0gEmqlSxImdi8u28XSIBXOMTQDC53UbWbPh PsXP+xZjrATA== X-IronPort-AV: E=McAfee;i="6000,8403,9701"; a="153241362" X-IronPort-AV: E=Sophos;i="5.75,428,1589266800"; d="scan'208";a="153241362" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2020 19:29:47 -0700 IronPort-SDR: oPflyilxdEFLLbGiKBSJ+A8hrfY7KCtVC8Um4V6NGjJzfW7ZAmhU793yS0xUG8qa3PK1dkDmAm UB2NbMFAmnnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,428,1589266800"; d="scan'208";a="491662799" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by fmsmga006.fm.intel.com with ESMTP; 02 Aug 2020 19:29:46 -0700 Received: from orsmsx605.amr.corp.intel.com (10.22.229.18) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sun, 2 Aug 2020 19:29:46 -0700 Received: from orsmsx111.amr.corp.intel.com (10.22.240.12) by orsmsx605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Sun, 2 Aug 2020 19:29:46 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by ORSMSX111.amr.corp.intel.com (10.22.240.12) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 2 Aug 2020 19:29:45 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.175) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 2 Aug 2020 19:29:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oINU+VPIAyHy0UltrMyxpXFlocsM+uokLilWstcqrTx17Y1scdmKZj3PwloNmtyPEUHUE1HNmSa6c3On72Yh4JFiInhUomFhwnhCsfE1kkzncfmuVr5w/HKAAo+hVpHCrCjOFzdRcEwIj5s1QmOnqKFrtfdoHlh3PyJrDrEg4VxjWVcje03c9oVdWPMvBqb873Z32k+ukALzBpGLs4moCp6fiiva/I61uVQ2Tbmz0qCRcuACfg/+knggvHqnSTnErIymX+MGUe8ljIy44WIuZPfMmnfwcF52CV5mjAwf+8tXlgb0LEO0syOJjilczHkteITbcsRcYiJoQ3cnlX0hHA== 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=JgnKO+IaAj552R4cCewdOY/eXToOatCZDEMhIeOIhZ0=; b=eqTOXUtIZ/f2jhpKyJJDr+kBNoCyyAIyh9RRwC4m9Cftx+lw1SdOLljibUnFT6PYZnlRkEOz5K41+ang34NIqpGn16rW3X9fxuXcyM17O1s92FqucrHfYjC8ooTTrtCeKRzdi5lg9Yf82M2PZ9gUFwrcVcN4Gecryjq9x0Ifr9vJtcbTSZkN1mX+bIZ9KAcu7XqfpFSoHje5LZV93YTkvsNJx9bvbVYArwEX8C0tN11AeUqB7wMXI+QMt9tD/19sF/Tl97MSDHh0x8z0aeR/+aPmxfS0jFn5kc+eMz98nSTYUO/Rp9x62mxTur5QrlHoFVVTLJa+kf/U5WOkGLzl3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JgnKO+IaAj552R4cCewdOY/eXToOatCZDEMhIeOIhZ0=; b=zWFSVYKj6wHJvNJp1GenJTeI8LrS5xkH9c1GnSduD7a7jFaNBUMXfuFXOZUr5kpWBlCO95NH2qNS2GS7SpCt4CEDTXz/iGA4yof8Flm6GFv8NATipQy4eofLbPgq43X2OJqfTsL0leot5yaq/NXEpRl48rmiZn6/G0FEAQpaDPI= Received: from CY4PR11MB1526.namprd11.prod.outlook.com (2603:10b6:910:7::10) by CY4PR1101MB2343.namprd11.prod.outlook.com (2603:10b6:903:ba::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Mon, 3 Aug 2020 02:29:44 +0000 Received: from CY4PR11MB1526.namprd11.prod.outlook.com ([fe80::f8c4:711:84e3:4c97]) by CY4PR11MB1526.namprd11.prod.outlook.com ([fe80::f8c4:711:84e3:4c97%4]) with mapi id 15.20.3239.021; Mon, 3 Aug 2020 02:29:44 +0000 From: "Liming Gao" To: "devel@edk2.groups.io" , "thomas.lendacky@amd.com" CC: Brijesh Singh , Ard Biesheuvel , "Dong, Eric" , "Justen, Jordan L" , Laszlo Ersek , "Kinney, Michael D" , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v13 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Thread-Topic: [edk2-devel] [PATCH v13 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Thread-Index: AQHWZqGdJdtj8aHs3kqdiZjt6TPnhaklrprA Date: Mon, 3 Aug 2020 02:29:44 +0000 Message-ID: References: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.194] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 32adf675-ec89-4282-0be4-08d83755155b x-ms-traffictypediagnostic: CY4PR1101MB2343: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr 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: uNSGMMtKij1DZN8OnL/v1FJ9hHY6HNr/qILk98dV/FLXbQbARf52dpolXr0GViA8GDW8iGyDw5oumzUig/L84a8e+fYSki+iX5cYOrI3GAl52vLFIqEI2m/wEwNm+63XiKHvGHnW4r8Joht8tC60AzCryOAdp7lSAcRcgGroplP0AiXLjteryRYR0NKsuoxfwiUdqlt89AUUxzACEkCnWsotV6OVEkGy93Nk7f2x9tbZFrdiNfSiqljlNf8pisVIT0JBv52kbDR4Cma+pO9NsCtJ22ak+r9S/mb1Ye0pJ4uXwL166Da2YwgE2Ax8UWygSQkLt9JurJNSS0kxWambGpYs2UPdVoXWd17W2MJbT45ZNIGqsew6taxYfLa+cGxQv9z8EUDynEh467hRUP7rFg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB1526.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(376002)(366004)(346002)(136003)(39860400002)(19627235002)(76116006)(64756008)(66446008)(71200400001)(8936002)(66946007)(4326008)(54906003)(66476007)(186003)(966005)(8676002)(5660300002)(316002)(478600001)(55016002)(83380400001)(66556008)(9686003)(110136005)(52536014)(33656002)(86362001)(6506007)(2906002)(107886003)(7696005)(26005)(53546011);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: XAKJNKLvt8Y+Cj/+VHo7PfJyxBn2t6+veGJoKdEbGCH9Qs6VBY1yJagOiHnCCJyaWAhk7naO268XycUe8LNxp9cuOJP/DlbQKce0Lc67KSxkWMPBsZmnGwiLD7rkcMmLEJ0jwNEr4zJFOg5ykFZAM3z+cho+tFn8phuJQVyXxGieXeb0ngC+s7km3uma0uvcIO0iolYv6W9iS+fazjR1aTfpCD4ksbawAoSvJyQwSfrO80CXI7BYqqGRROzKfd34dYb94Odfq3poskbcOFn+xOAphseRqsgzpwEj5CR2zuUaccITr1UaC2xl32HRj11T+8rCJsJEg7xgZQviWY58ajEvPx90WgcmOs6cmqNKEt4DR5xrRE9OvahT1cASBxLyyxvIzVlgRvynZNAjfWowdZBN/PFk9UPbc5OKYF40Qa2wm497wv1JmUZst0MF0zTIed1aMQuZpzIrOlD4+RPFAx63sw1yB2yorCDl/wr0kZ7oH0uAFJeEBcvaQM4162wuqlof7u2FJa6nYtYkJ3P/aaS/ThiZh5batTvyClypxrTugTZmVWtS1UMk0ZY6TSA7gzvUUWreqUbIdLF2NV8GSC5z0iDciKP6Lk3StvI0Gcz1lY4sym76nds6vKAdKVibTYR3bSQUakhMBUtbspsJRg== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB1526.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32adf675-ec89-4282-0be4-08d83755155b X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Aug 2020 02:29:44.1981 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3VpgpxHDUx2sQwbFuVGNIvE0mrblTZuzlXNtQGNpezhV8LjCAbKRYjNVdI/uE1rXJIpUdHGmG15xB9zYEjLKNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1101MB2343 Return-Path: liming.gao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao -----Original Message----- From: devel@edk2.groups.io On Behalf Of Lendacky, T= homas Sent: 2020=1B$BG/=1B(B7=1B$B7n=1B(B31=1B$BF|=1B(B 2:43 To: devel@edk2.groups.io Cc: Brijesh Singh ; Ard Biesheuvel ; Dong, Eric ; Justen, Jordan L ; Laszlo Ersek ; Gao, Liming ; Kinney, Michael D ; Ni, Ray Subject: [edk2-devel] [PATCH v13 07/46] MdePkg/BaseLib: Add support for th= e VMGEXIT instruction 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 t= o execute the VMGEXIT instruction, which is coded as "rep vmmcall". For IA3= 2, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT should = never be called, provide a stub implementation that is identical to CpuBrea= kpoint(). 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 ++++++++++++++++++++++++ M= dePkg/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/B= aseLib.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/Bas= eLib.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=20 + 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/Bas= eLib/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=20 +reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module= =20 +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=20 +versions ; before 2.12 cannot translate the 64-bit "rep vmmcall"=20 +instruction into elf32 ; format. Given that VMGEXIT does not make sense= =20 +on IA32, provide a stub ; implementation that is identical to=20 +CpuBreakpoint(). In practice, AsmVmgExit() ; should never be called on IA= 32. +; + int 3 + ret + diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/Base= Lib/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=20 +reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module= =20 +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.27.0