From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.7510.1595921972482638705 for ; Tue, 28 Jul 2020 00:39:32 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=f07z9Iu2; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: liming.gao@intel.com) IronPort-SDR: wGFVoEvz7JlvG7ZzyY3aGYLSZ9Au6yuqjKvwHdwibGBxz3pPxRl0ionv/byG8fWhqvwfHo0p1G 2HHQtMgNt6jA== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="130728096" X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="130728096" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2020 00:39:30 -0700 IronPort-SDR: ZowWmaW2GQlq7sKjUysiOh+wOhD47JYfa1Ar8tfbnaG0pJWNvmJAR0gtbfsbxKD8XDNgeeIa3Z Bd+SZBAoQc7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="464362755" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by orsmga005.jf.intel.com with ESMTP; 28 Jul 2020 00:39:23 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX104.amr.corp.intel.com (10.22.225.131) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 28 Jul 2020 00:39:22 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 28 Jul 2020 00:39:22 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 28 Jul 2020 00:39:22 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.172) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 28 Jul 2020 00:39:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fGA5nMOOjs/UpRkmHen1tgyuZTKEAh3YO5cdK7Ld6YMgmb1jrbb+hw1poyPprEhfPrSCsKf1BXmeIOsfAQGeYoxyAv4n3AmJ8FYqyCO/HOWkQYatAHupQXV0tqh7YNvL/mhW/2VAzL69xoJV99TAIz6V/0+s9t5NjSiSTDoVaLjn4yPKtCCPxFhr5tFgQ1LPt6KN5NAxHzO6Fa9VI+eHhf2Y22YwO+496cOb8WIiJalswfCPPb8P4qN8qbOWNKYBi7UesxHWb3Ouy3jOBkUNK9uKLzWICs2s2FvPfWljeaAA3swIH/surBROodUqgUVMcBUPA40rPPOK5cAVJRJtKA== 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=BjGAhkIWLQKinr3eYEzVDapjXJJBzIt4q6Nmn9HbrtQ=; b=d50BIlrzQ3z5jElSRtUN3ytg3wA5cp4eA/wAwjRqPN9ijpoflHLMnw8vhIwE6qd6xIOVk6W/NPBs+PWBF62WTf2a8LnmFHZdIVq/EAU00+GJtpQw5zRoIw3AglR1uwrmVvYclcE872CPCmnKOIyWa9yqFMDwhS2vW+7MoO67xPABJZ0u1xWoer8CzPMyYvHc1Vie0v4h6nh4u2du3L7iBdMlABxx8LcPRwfwX4VIeFqfoBfDfHog/S69dlOeoqVsXqLZihxVwPSZKPB54NBG0c8WKlb1O5t8KP5bOJL6lu54FF9zmiDKFeBLGnuN3JQkPMZezHUR7n5TPUAzy/h+iA== 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=BjGAhkIWLQKinr3eYEzVDapjXJJBzIt4q6Nmn9HbrtQ=; b=f07z9Iu2jJP+LG07FsV5yWYdzcSbDId7OszuR7MRD0Zl/VVtdtcxCyuVyG729sDzb0Lm1q/KiIFx9b1bDFKheDxj9IugeI8DV/utbALmugecnO/86vZGmyjWsvGCz8w2E1cywW0/wqdTg0wLutHZdlbD10vfo5Pty5zLM1J/zSw= Received: from MWHPR11MB1630.namprd11.prod.outlook.com (2603:10b6:301:e::7) by MWHPR1101MB2109.namprd11.prod.outlook.com (2603:10b6:301:53::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Tue, 28 Jul 2020 07:39:19 +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 07:39:19 +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: AQHWZCqFAhWLS6X4eU6Z3ttQo1HJGqkcKFtwgAA4n4CAADdqoA== Date: Tue, 28 Jul 2020 07:39:19 +0000 Message-ID: References: <57cfa8bb-f683-08c4-7262-5762a9e0a4c1@amd.com> In-Reply-To: <57cfa8bb-f683-08c4-7262-5762a9e0a4c1@amd.com> 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: 7cf7ce2b-8e5f-4a12-50f7-08d832c956a6 x-ms-traffictypediagnostic: MWHPR1101MB2109: 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:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: rfMd9ALS9IgX3etWmtQ9Fs66BbqAUxyokoOGoJ2I7rB63EP9tq3FNo2XJdNR4k/M4WkRxzKjHoEwzpvD2Fk2zkZDsjq+uEsQ87qx/Q+/UmC1EylND5bupZlBrU3UI+EaBp2X/VYSGygj4yaknqdmHtkPVK5Jspq7Jy8Fc1f9KbGgNr0m8OmyVrjcHXfeM/Zp/FSxQUQ40PUMjU5Z4VEjbQP3E286XyPC1b4AQXaCt0sMsgnViwn9+uA3lsgYLZkOQ2+BJubuSgMUd9AO1U6JE9eKBDpkuBmZSpccdL4dfDHK948z3/fdnAISiqUwjHtWX0r3nra3QGIqgVpy7Z4vc16aJgmmnwUKq7CkSC57PMW8GUlyr2d/UTE+N4JoQFW51DKjDtn0R+3X1FDPyOnXTg== 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)(366004)(346002)(136003)(396003)(376002)(6506007)(45080400002)(7696005)(53546011)(55016002)(8676002)(19627235002)(478600001)(33656002)(83380400001)(83080400001)(52536014)(2906002)(5660300002)(8936002)(4326008)(76116006)(54906003)(71200400001)(186003)(107886003)(966005)(66946007)(316002)(9686003)(86362001)(110136005)(66476007)(66556008)(64756008)(66446008)(26005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: meNpDJSP+chpGwDxMJjUAiky/q7+M6H3HA08TOz6rIT8A575D63ux2Z2USFpqi+evDKuRMKby+RRVg+QU8+aROuxzVkMe+nKEHKhfxQNFXNyHljtFVBDYDX/qGAE3SqUGhI95dRVY/T5A1SZZMG4Dog+ibab+Cjq98IUxk7dWtJPdrgSgegCsphBBaVlDQeSe44nkTx6cghxSIQWG0koT9XbgLmcc7lnLVpJUTqWFIW3D190oR0BDrjys9N89PdEJhrE0XBKpiw6vbyizH9reS7fEHlPVqfzB2GwkVrmeSrWMN1xokRQxPq5lVQmr9O0qoKvBc4F0ROimJPHYIxkbvNlpaXeKQ53f6HxgFUnjXzz4QEF8eOQpKu2polvv10Ra8cJxMgg0ifsVP5aQVo4QWZyprMUpKg75702m0XbTIG0DUgtS5D7TqYra4fHp4+/UJUcp75Olk0zwHJfiiCYogaTf/x9zDTGB39TyHyuejJXAdtqMEjt48LhI1NaF1UU 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: 7cf7ce2b-8e5f-4a12-50f7-08d832c956a6 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jul 2020 07:39:19.4851 (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: fjHP2UkXBS9wm/Ft6gA9kZPjx/rhAaWqeamAkkVaJiuDXbqYB+84dim0tPXlpK7hz5SIiDQTOFQ2b3OQxGRL0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1101MB2109 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 This error is reported from nasm compiler. My nasm compiler version is 2.11= .08. It may be a little old. 2.12 should be fine.=20 This change also requires to update edk2\BaseTools\Conf\tools_def.template = and mention nasm compiler version.=20 Thanks Liming -----Original Message----- From: Tom Lendacky =20 Sent: 2020=1B$BG/=1B(B7=1B$B7n=1B(B28=1B$BF|=1B(B 12:08 To: Gao, Liming ; 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 On 7/27/20 8:34 PM, Gao, Liming wrote: > Tom: Hi Liming, > I meet with GCC failure on this patch. Can you help check it? If nasm = doesn't support the vmmcall instruction in 32-bit mode, you have to use inl= ine assembly to support it. What version of GCC are you using. I was able to successfully build the Ia32 version with my GCC level. The Ia32 version uses a trick to do switch = to 64-bit just to encode the instruction. Looks like that doesn't work with= your version of GCC. I can probably switch to defining the instruction as bytes. Let me look int= o that and possibly send you a patch to test. Thanks, Tom >=20 > Edk2/Build/IntelFsp2Pkg/DEBUG_GCC5/IA32/MdePkg/Library/BaseLib/BaseLib > /OUTPUT/Ia32/VmgExit.iii:33: error: elf32 output format does not=20 > support 64-bit code > GNUmakefile:741: recipe for target >=20 > Thanks > Liming > -----Original Message----- > From: Tom Lendacky > 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=20 > ; Dong, Eric ; Justen,=20 > Jordan L ; Laszlo Ersek=20 > ; Gao, Liming ; Kinney,=20 > Michael D ; Ni, Ray > Subject: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT=20 > instruction >=20 > From: Tom Lendacky >=20 > BZ:=20 > https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugz > illa.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=3D02%7C01%7Cthoma > s.lendacky%40amd.com%7C77c8250cd9e14f2929a008d832965726%7C3dd8961fe488 > 4e608e11a82d994e183d%7C0%7C0%7C637314968570901400&sdata=3D6zqseI3tVm > aw351w9mfEymMnDcjDzjvcBrhARU6r3Ho%3D&reserved=3D0 >=20 > 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. >=20 > Provide the necessary support to execute the VMGEXIT instruction, which i= s "rep; vmmcall". >=20 > 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 ++++++++++++++++++++++++ = MdePkg/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 >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf=20 > b/MdePkg/Library/BaseLib/BaseLib.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=20 > b/MdePkg/Include/Library/BaseLib.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 t= he byte, > word, dword or qword operand is encoded at the end of the=20 > instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm=20 > b/MdePkg/Library/BaseLib/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 ; ;=20 > +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=20 > +work 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=20 > b/MdePkg/Library/BaseLib/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 ; ;=20 > +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 > + > -- > 2.27.0 >=20