From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.9406.1595379347314540996 for ; Tue, 21 Jul 2020 17:55:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=NflNHFVm; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: zhiguang.liu@intel.com) IronPort-SDR: zMFEStVqOK+dt3pOL3bVM7UiMmcHfoo3s0XKt9WNzkbjC0SCd5Vqp6NeghgXcUJiaB7hLm+ndB tsSlj5xzTCrQ== X-IronPort-AV: E=McAfee;i="6000,8403,9689"; a="147749751" X-IronPort-AV: E=Sophos;i="5.75,381,1589266800"; d="scan'208";a="147749751" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2020 17:55:46 -0700 IronPort-SDR: 1+ne0S6svTk1QzTQgg2xxMopgDDbKJuulMoCiwT/CqV+HMxL7suRrKlZ2JqtTugX8TgWKvL2Ox APAB55v04INA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,381,1589266800"; d="scan'208";a="318512539" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2020 17:55:45 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 21 Jul 2020 17:55:45 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by orsmsx612.amr.corp.intel.com (10.22.229.25) 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, 21 Jul 2020 17:55:45 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.105) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 21 Jul 2020 17:55:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=feDsJIf9L7e/xFw55fMwBCPa+UKAntyhsxdc/Qz8tDZEY95/tF2ofA0g5FjHqh2YdCFnNCl/OxX5akbIQ/xhRTsDt2x8sfm/AyWQ5mJu/O73Ds32KZ1kUD897Cx39xdEDzTNl6ZII2qt1cblRLLaOsr3X/PYzxc9hqiGiQqF8y2na6PNYmgysJ+8V2cSn3a9qh3x6gKj2ZxAh7GFVKbXjHFlAe9V9TfITjOIfc2oOA1ON70r+XSXPu9w0OnwvrI7NbaTzKmDp0Rc4bhhYSOsUW3bUzyb2edsO3TfhEfeFyes8oD2bbVW/lxXQMHOeItUjAecy3e3LR76JWLXbMl9Kg== 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=e/lbvN1XHpEeDKHovRN7Kdb4NVizb7Hwre9WRLCNV6o=; b=FvH2rzYDVarnO0w7fNudJ7jiqiSyKO8yUiQurWh4nnmG6YvMk31N7TBtoGeHB/5q84viMjXPyIto68uWDn8mTl4w01KfRLGicihixPkOULLwU5Y0QM8sovDqwYVditit5fSiwY7BaLo315nMkLtYFi1EPXkvncigSZVd21bXKXA5N0sPIcit2EVVb8j59QN4EuN4BZYyygc0OqkZCUZD4d0V3uIFCB1K/xXZfbNz+/yzAJRu4fNIsKN+QXHF5UYmyjxMdXehcZ/2l4QII8jzM9udXaXt9Cx2YEAUFZECA5gL7Ql7CmOfD8h6JChXhX100Kg8iGWVkXIpRtdhgHQS4Q== 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=e/lbvN1XHpEeDKHovRN7Kdb4NVizb7Hwre9WRLCNV6o=; b=NflNHFVmFL9KV1+Xdn3U4BnPVE/5NBCUCTd+kyqLcnAEAIz1CjQ08ygYLqReNX0OSxpu3JJujPlPENpFNP8xP+uSpWrosXgpDvhcam76qC8lLiLSsaHWnG36jPNxoj2iNDMJ3XUiOP7qPA68B0Ml7Y5CL10Q6rlMTSqqQnN5Oo4= Received: from CY4PR11MB1687.namprd11.prod.outlook.com (2603:10b6:903:2e::11) by CY4PR11MB1366.namprd11.prod.outlook.com (2603:10b6:903:2b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Wed, 22 Jul 2020 00:55:37 +0000 Received: from CY4PR11MB1687.namprd11.prod.outlook.com ([fe80::1490:81c1:9ca1:df58]) by CY4PR11MB1687.namprd11.prod.outlook.com ([fe80::1490:81c1:9ca1:df58%9]) with mapi id 15.20.3195.025; Wed, 22 Jul 2020 00:55:37 +0000 From: "Zhiguang Liu" To: "devel@edk2.groups.io" , "thomas.lendacky@amd.com" CC: Brijesh Singh , Ard Biesheuvel , "Dong, Eric" , "Justen, Jordan L" , Laszlo Ersek , "Gao, Liming" , "Kinney, Michael D" , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v11 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Thread-Topic: [edk2-devel] [PATCH v11 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Thread-Index: AQHWX6TNLMyH9gGVY0OW8uHBWakzsKkSxF2A Date: Wed, 22 Jul 2020 00:55:37 +0000 Message-ID: References: <0d091f43ae96ca4617f6a95a018bfaed6280eec2.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: <0d091f43ae96ca4617f6a95a018bfaed6280eec2.1595366363.git.thomas.lendacky@amd.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows 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.102.204.45] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 605c2f70-cfca-4d4e-01e1-08d82dd9f282 x-ms-traffictypediagnostic: CY4PR11MB1366: 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:6790; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xxBskZfoi+KDX/HcjTR5Kn7Gb7iHkHQgNUuVy/0zneh1B6f4Y5PH0Rn7HTYauaKPMLBrAcJn/9shrgfIAdnhM0uahoQmo91etzSi4PRMMVINEcfLulwK4XaHqSaSJpinQmpOO6iQpLP0T2pGUpmjHbF4uJjN2Op9MQUo91C/mZSn/X1beTuCo0HajIlV/wVd8gu5mMkgU2xqThM21+2/PH39ic7epFXHBWSv3z7IXXjkulVkbmne0GWul3e0z3nN10kubzi77WTmeusmMxD+S1eDVI8g7mMhPfw1M6UeCzlOg/LGiIl2WkoSsydv9j1hSROxif1AzubxZRoCZLhESssSRzApqb8281C7o+E9S9htl+kg0RUcWp+kBc4vxZWlYNA894CAyzIkyzwY/clLTg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB1687.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(136003)(346002)(396003)(366004)(376002)(76116006)(5660300002)(4326008)(110136005)(55016002)(966005)(9686003)(2906002)(316002)(19627235002)(54906003)(8676002)(71200400001)(66476007)(64756008)(66556008)(66946007)(66446008)(6506007)(8936002)(26005)(186003)(52536014)(107886003)(53546011)(83380400001)(7696005)(478600001)(86362001)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: ZSwM3jWcVjQ6WXUugvB95xpirct9Df9TL37JoJsvO0B/3gg5+XCKsNqPlprHwHKCzF+p7bqTfaSgQX3QlpfDOj9dUanzSTsUwt5C1BJBm2Be5T3nRWsntzhVm7R7/X7PezBc81SdOUbODR//SWhw4X8ooC+eKLgGtcSsKugGYfYN82ov+iFmEJSykEDcmnjKPjlGT5RZe3e4mXjk/wO3FLFGfDm1CA9QtBUfo1xvsJ328O2KUbZvg7K0UO92KjY1TCFoo7NvnkAd83JZW7VIZu/JU9llh97ZBgS1u6AAUDx8hHCKT4XcPoYWTNNtBxIQqjoShasDYIGURaet6eIlIqAJvrKRimKsht0toMt9kEN6d1rWS6TUO4/0rXZvxxYVogp9ivg7ZW8AfvEl11b7QY0zFbkYZVPsn0fZTewHSDO7sOFNoJ8K11dAQpkRVuF3TGtZxCYq+b+VYlDAxs1hgVTa9KwEhhzxJ5TdECR6zG7oi7SMmr5vnkbhHacjGpJJ MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB1687.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 605c2f70-cfca-4d4e-01e1-08d82dd9f282 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jul 2020 00:55:37.0885 (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: 4sdeSuWCVz7YBSq+KuyNFE2mJCAVEnkS6aEimyaJgl4o8Tz3uA45Mqy3EvIOrgfs4LxzCtZqj/EQ9AkkL8sxkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR11MB1366 Return-Path: zhiguang.liu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Tom, Nasm is a cross-OS assembly code and can be used in Linux. So I think we don't need implement the same function in GccInline.c, we ca= n just use the nasm file in Linux. Thanks Zhiguang > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of > Lendacky, Thomas > Sent: Wednesday, July 22, 2020 5:19 AM > 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 v11 06/46] MdePkg/BaseLib: Add support for > the XGETBV instruction >=20 > From: Tom Lendacky >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 >=20 > Under SEV-ES, a CPUID instruction requires the current value of the XCR0 > register. In order to retrieve that value, the XGETBV instruction needs > to be executed. >=20 > Provide the necessary support to execute the XGETBV instruction. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Signed-off-by: Tom Lendacky > --- > MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ > MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ > MdePkg/Library/BaseLib/Ia32/GccInline.c | 28 ++++++++++++++++++++ > MdePkg/Library/BaseLib/X64/GccInline.c | 30 ++++++++++++++++++++++ > MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 > ++++++++++++++++++++++ > MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 > +++++++++++++++++++++++++ > 6 files changed, 142 insertions(+) > create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm > create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index c740a819cacf..e26c0d8cb0ac 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -153,6 +153,7 @@ [Sources.Ia32] > Ia32/ARShiftU64.c | MSFT > Ia32/EnableCache.c | MSFT > Ia32/DisableCache.c | MSFT > + Ia32/XGetBv.nasm | MSFT >=20 >=20 > Ia32/GccInline.c | GCC > @@ -288,6 +289,7 @@ [Sources.X64] > X64/ReadCr2.nasm| MSFT > X64/ReadCr0.nasm| MSFT > X64/ReadEflags.nasm| MSFT > + X64/XGetBv.nasm | MSFT >=20 >=20 > X64/Non-existing.c > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 8e7b87cbda4e..7edf0051a0a0 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -7831,6 +7831,23 @@ AsmLfence ( > VOID > ); >=20 > +/** > + Executes a XGETBV instruction > + > + Executes a XGETBV instruction. This function is only available on IA-= 32 and > + x64. > + > + @param[in] Index Extended control register index > + > + @return The current value of the extended control reg= ister > +**/ > +UINT64 > +EFIAPI > +AsmXGetBv ( > + IN UINT32 Index > + ); > + > + > /** > 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 instruction= 's > diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c > b/MdePkg/Library/BaseLib/Ia32/GccInline.c > index 6ed938187a08..c2565ab9a183 100644 > --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c > +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c > @@ -584,3 +584,31 @@ AsmReadTsc ( >=20 > return Data; > } > + > + > +/** > + Executes a XGETBV instruction > + > + Executes a XGETBV instruction. This function is only available on IA-= 32 and > + x64. > + > + @param[in] Index Extended control register index > + > + @return The current value of the extended control reg= ister > +**/ > +UINT64 > +EFIAPI > +AsmXGetBv ( > + IN UINT32 Index > + ) > +{ > + UINT64 Data; > + > + __asm__ __volatile__ ( > + "xgetbv" > + : "=3DA" (Data) > + : "c" (Index) > + ); > + > + return Data; > +} > diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c > b/MdePkg/Library/BaseLib/X64/GccInline.c > index 40a208f1985f..65f864e35922 100644 > --- a/MdePkg/Library/BaseLib/X64/GccInline.c > +++ b/MdePkg/Library/BaseLib/X64/GccInline.c > @@ -560,3 +560,33 @@ AsmReadTsc ( >=20 > return (((UINT64)HiData) << 32) | LowData; > } > + > + > +/** > + Executes a XGETBV instruction > + > + Executes a XGETBV instruction. This function is only available on IA-= 32 and > + x64. > + > + @param[in] Index Extended control register index > + > + @return The current value of the extended control reg= ister > +**/ > +UINT64 > +EFIAPI > +AsmXGetBv ( > + IN UINT32 Index > + ) > +{ > + UINT32 LowData; > + UINT32 HighData; > + > + __asm__ __volatile__ ( > + "xgetbv" > + : "=3Da" (LowData), > + "=3Dd" (HighData) > + : "c" (Index) > + ); > + > + return (((UINT64)HighData) << 32) | LowData; > +} > diff --git a/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm > b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm > new file mode 100644 > index 000000000000..9f7b03bbff35 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm > @@ -0,0 +1,31 @@ > +;----------------------------------------------------------------------= -------- > +; > +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.=
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; XGetBv.Asm > +; > +; Abstract: > +; > +; AsmXgetBv function > +; > +; Notes: > +; > +;----------------------------------------------------------------------= -------- > + > + SECTION .text > + > +;----------------------------------------------------------------------= -------- > +; UINT64 > +; EFIAPI > +; AsmXGetBv ( > +; IN UINT32 Index > +; ); > +;----------------------------------------------------------------------= -------- > +global ASM_PFX(AsmXGetBv) > +ASM_PFX(AsmXGetBv): > + mov ecx, [esp + 4] > + xgetbv > + ret > diff --git a/MdePkg/Library/BaseLib/X64/XGetBv.nasm > b/MdePkg/Library/BaseLib/X64/XGetBv.nasm > new file mode 100644 > index 000000000000..09f3be8ae0a8 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/X64/XGetBv.nasm > @@ -0,0 +1,34 @@ > +;----------------------------------------------------------------------= -------- > +; > +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.=
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; XGetBv.Asm > +; > +; Abstract: > +; > +; AsmXgetBv function > +; > +; Notes: > +; > +;----------------------------------------------------------------------= -------- > + > + DEFAULT REL > + SECTION .text > + > +;----------------------------------------------------------------------= -------- > +; UINT64 > +; EFIAPI > +; AsmXGetBv ( > +; IN UINT32 Index > +; ); > +;----------------------------------------------------------------------= -------- > +global ASM_PFX(AsmXGetBv) > +ASM_PFX(AsmXGetBv): > + xgetbv > + shl rdx, 32 > + or rax, rdx > + ret > + > -- > 2.27.0 >=20 >=20 >=20