From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.3203.1595900055715064889 for ; Mon, 27 Jul 2020 18:34:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=uw5Hbf7C; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: liming.gao@intel.com) IronPort-SDR: ojeuaWPiaQ5R288/diAWNrHGhDiB+cggPF6dL+0GlmFtKwe8MxCrxU1gbV0JP8JR0vaWwVZCf1 Aoks8dvgutWg== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="131201405" X-IronPort-AV: E=Sophos;i="5.75,404,1589266800"; d="scan'208";a="131201405" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2020 18:34:14 -0700 IronPort-SDR: F/zUoXbKimCerH94LaN36bsPQpE1Ib34gvCeYBfywSE6a25+lmkr5nCqZVECWrohZZGSRqirr3 SBo9pzqseDuA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,404,1589266800"; d="scan'208";a="322011648" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga002.fm.intel.com with ESMTP; 27 Jul 2020 18:34:14 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 18:34:13 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 18:34:12 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 18:34:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZBdjpkwuY+k7BI6Fe/XGBiOSGjl0L78Vh+8vo98DLOXOxvUpESTDjZ56xbfDEP7CurA86aRgtXW/lafLWSDWwW033nDygzNm+V9cKOKK1Gsgn9HiUtT5A2kq8cPaCdRgq67I7TR9lVWHe2XfyL4cuzOKIdLRO9Gs0Q+MHIbBi1j0rrzdD+bDKuUWhMN9JJYS5qFtbz1VnGXJbUEYHPsXzIANGoIRRdDWCCgtxdd+OiCqr3VAbglqJcsV/VS2ZFXwAihWW3ulEiXyiui6Hw+PyXRxMFItTffCrf6CnwtbLfGIuI526Eo6Yohy4ifXkNa9mTnu3qxYd4r2BuoLe1BkBA== 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=PpFPcUqKF+M5C3KO0hjBgtYOp0vzeF++/X/PZ5vY1ic=; b=ij28k4mWWzslMaEqS5wXMSmDdbdNhC95VHaJr4oDz/QN6OQZ1jrswwWCUqwjy7bfssbsWR5asvv9hYka30IuxaF5ZlQqsRc8KphPUfWgPVwDxIi8OJO0NqJ7E59rW2/aBILSVczAqEHpbcGQ5fAzz6R+qYeqUjNhdD2C5FJBvct63//YF/UptmARrO6ZvmB+aQgG4rg/K+6CaAhTPPEji1H968fFYqi4X+G1a9/fHhO+DfsxGv36W87SBS1VeJMQ/cPkE+/tJRAALizDcnyXUeKOJLdxW4MXsDGu3IW2WluWIWkUB2eAm8SEVvEDWhEw9OBCEGp+PaYRNRu+BDgSYA== 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=PpFPcUqKF+M5C3KO0hjBgtYOp0vzeF++/X/PZ5vY1ic=; b=uw5Hbf7CodbtCDsxwyfzxPJ8zTD1APOxuw2RE3+Xt9nJfmhZF5isb9NA5pN1qaJW8O1zB8CVBK9ymJ/bZlnFohaBAM8O50JQKDi6Nmd3n6LdrZayOcPlX9sjd6OaTdAtgsXzLK4l/Wv4Ye0ta5A1Pbl+pGQuyKJmU2PWs2XWpRg= Received: from MWHPR11MB1630.namprd11.prod.outlook.com (2603:10b6:301:e::7) by MWHPR11MB1310.namprd11.prod.outlook.com (2603:10b6:300:28::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Tue, 28 Jul 2020 01:34:11 +0000 Received: from MWHPR11MB1630.namprd11.prod.outlook.com ([fe80::7847:b564:1b55:b67e]) by MWHPR11MB1630.namprd11.prod.outlook.com ([fe80::7847:b564:1b55:b67e%6]) with mapi id 15.20.3216.033; Tue, 28 Jul 2020 01:34:11 +0000 From: "Liming Gao" To: Tom Lendacky , "devel@edk2.groups.io" CC: Brijesh Singh , Ard Biesheuvel , "Dong, Eric" , "Justen, Jordan L" , Laszlo Ersek , "Kinney, Michael D" , "Ni, Ray" Subject: Re: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Thread-Topic: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Thread-Index: AQHWZCqFAhWLS6X4eU6Z3ttQo1HJGqkcKFtw Date: Tue, 28 Jul 2020 01:34:10 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: amd.com; dkim=none (message not signed) header.d=none;amd.com; 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: 1ea22fa1-8c27-42b4-cf4c-08d832965416 x-ms-traffictypediagnostic: MWHPR11MB1310: 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:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SJGJaYHnVRV4YqkNlRh+ef9PJKtpGGDJtB7xLHlcmewXsuljgsqISESCWFggpsyIfMtKGKemBVLp2A55vu+Axcj+WBF1F3nrtZX2fanqAkvp56tFd91pLcjokQtQ8OlFl7rf8+To9hIMyMGuMVW3NJTwZjPlQuFxdS0dCWVSGLbAq2vNW++iayNe6vCuaHk7QNO4+PPCoXRCUfofpRRz6ojAT9Dubztsa8jzruVYBRT0iV3EQCLYs5biKfe30wRgwG0E8Pc6QE0Ip0Xt8ZR4+m3e03YcP4Cqs2oJHRl4vAqYQM7qlyP9/LEcco9Nqh4Zbu6lRC3Fha92eVskFJzV6LqITsZq7qPMZDBDEe0f2Kiih7bvskyT+ctawvatpwtv7qEzYYUksBkUp5WJOsTP8g== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1630.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(346002)(396003)(136003)(366004)(376002)(86362001)(110136005)(6506007)(53546011)(316002)(33656002)(4326008)(54906003)(71200400001)(5660300002)(26005)(83380400001)(66946007)(66446008)(19627235002)(107886003)(66476007)(66556008)(64756008)(8936002)(52536014)(9686003)(966005)(7696005)(55016002)(8676002)(478600001)(186003)(2906002)(76116006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: COwk2PSisxPCzM383SNWvBm/ADNyb9+hbdadP+EdMWNUX0pXekAcIVJwRqRRb4FkIALsNfDoruPifYi4Gy5G5j30bAS+MbA5jeAHwRl0/DSTZDfKEpMR+RwIDdzWaKDH1WPHVBRq60iraxdwzsqw6LIlJuq3HuHvyI1fTM0C1yXanw7zPrEeVIUaT5OfIlZCGoWnShbTY5QXhzkBplkayB3rgfl3WJBdi/p+985s2I2nBbMOkIG4IRTXIY6WrN5GkBbYvJIaigiMoUmLYHfDGad1nlesWP/PecpKrj/Nl9NRv6FF881luD4KfalxGZEkid7tHZ8y1EBtDLsy+elw1P6yGtezFP3xLYDUgTvGPhvUlWAeNQLyBAPVvZd+lU++tpU2FDw1DT75rs+uYoChZro6P7fAysjrnMtaN8HpWs+fEzE7NeBHEpUjXv6fHu5ToN9xdJV6SRmzrQ3zeYloqJpmbmsnV0eIvvzD/AwJpKHNaiWuzr1sfU2T/rV8zEaC MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1630.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ea22fa1-8c27-42b4-cf4c-08d832965416 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jul 2020 01:34:10.7680 (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: mjucCcXkLe7YxTs3JftyNQQQacmXyUGotm/I3/ohHdXaxNj8M1GgwBcIu3HLNXa7oJWHXA+b8Xv0bRdckmSGlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1310 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 Tom: I meet with GCC failure on this patch. Can you help check it? If nasm doe= sn't support the vmmcall instruction in 32-bit mode, you have to use inline= assembly to support it.=20 Edk2/Build/IntelFsp2Pkg/DEBUG_GCC5/IA32/MdePkg/Library/BaseLib/BaseLib/OUTP= UT/Ia32/VmgExit.iii:33: error: elf32 output format does not support 64-bit = code GNUmakefile:741: recipe for target Thanks Liming -----Original Message----- From: Tom Lendacky =20 Sent: 2020=1B$BG/=1B(B7=1B$B7n=1B(B27=1B$BF|=1B(B 23:26 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: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT inst= ruction From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 VMGEXIT is a new instruction used for Hypervisor/Guest communication when r= unning as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) to o= ccur, 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/VmgExit.nasm | 37 ++++++++++++++++++++++++ Md= ePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 4 files changed, 85 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=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/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=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, so work=20 +around ; 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=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