From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.8079.1617285032822223201 for ; Thu, 01 Apr 2021 06:50:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=OiDhrP4o; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: jiaxin.wu@intel.com) IronPort-SDR: o4/oU7eMKkYQdaelaoA97Su1hpaEsRTvCWlMBe1jG8u5by/j2zg0JgRCcoOqWBIKGw23knCjTc U1fHYJ5u4QOg== X-IronPort-AV: E=McAfee;i="6000,8403,9941"; a="179377518" X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="179377518" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 06:50:31 -0700 IronPort-SDR: mby11sERvuNYCsgunOmefTujqCVflaA2EjeZbaiHuy2ueFizU7HcIRmtuSnK6Zz95xa1Mb1C4T Xp52zMJGy1UQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="446097356" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by FMSMGA003.fm.intel.com with ESMTP; 01 Apr 2021 06:50:31 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) 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.2106.2; Thu, 1 Apr 2021 06:50:30 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Thu, 1 Apr 2021 06:50:30 -0700 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (104.47.37.51) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2106.2; Thu, 1 Apr 2021 06:50:30 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PpmU3qb6czRdgZ7catM7MBJNDoAxKQOBiO6pWl4gyLgpmsxVeV1sCER9UC2n5efCxMrsBO8dOHrKst5CYGRezoX6xqtifB0bT803ugmwwedjle+GLQxFQMyVN4T/xr3mJGNm7MR1F1BD3vZb8QLjnJhZBoj++JT74m2JFIrKEvBfGn4w0ilUobNnbGtedM3sNtJ8PWx7DpNJYM+J2tTdB6J1Vd5SKRG6r/Tpz9sA96gVOdKj8q+MEyj30oLZO6wVDYr3O0YgCQqLkCmOk21bRr5Fr7h2hAjgAzVxQhi/0TA+kNNdWsBgbXim1kjv1EQm3Ctbfp/9O8TnBROM9JXDBg== 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=vPFFL2zEfWbdfmUO24hKjLEhTwlfAXVG2FLtpmVdyeQ=; b=CWMiAqKuVQnxv0S8N6WhPP27g/sx1fP1WauM5SC0WQIW4ba5UJ2665JYUtgY3GHozK3HvuiOhDSUi7OJncsoaOgXRJtu8hA9EkN+9eEZBJc1hEBykg/uRI/XO9PoFKP+APEqiJ9zk0u7UkMKFIZTi483kH+A/xFD8M2H1VcsV+SXnJxsY6FB9UR/DRMPdxsOKIWCV6WBFP4i2LHtph7w68dYXgA+J0oZsskTzalzEMJAHaN04/9KRCXss2sfldQ97oiyZzDMjf7ZZtvRgWDI4fbNZK6fNEr9w71E/3UejLsqyRwcjYW356L+NxORkB9FrKYYxU65H9a6oaT6apYYhg== 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=vPFFL2zEfWbdfmUO24hKjLEhTwlfAXVG2FLtpmVdyeQ=; b=OiDhrP4ouI7srkoot6SrTbPf0vZMBI7U30eS9GtCuok5S0zVtkPV2bHcmeO4Vgzu0OayRv35x+Te4hhR52bJB4Uil7d7k6EIGf07vabskl9k1MESGe84VZmc/oOTQ2c8Ga7QbQS4u/AR/AEf9tvRp6Y47/oAgWLH6Ql9G5Uo+rg= Received: from DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) by DM4PR11MB5405.namprd11.prod.outlook.com (2603:10b6:5:394::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26; Thu, 1 Apr 2021 13:50:29 +0000 Received: from DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::7810:33d:859a:f05a]) by DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::7810:33d:859a:f05a%4]) with mapi id 15.20.3977.033; Thu, 1 Apr 2021 13:50:29 +0000 From: "Wu, Jiaxin" To: "devel@edk2.groups.io" , "Wu, Jiaxin" CC: "Kinney, Michael D" , Liming Gao , "Liu, Zhiguang" , "Yao, Jiewen" , "Zhang, Hongbin1" Subject: Re: [edk2-devel] [PATCH v1] MdePkg/BaseLib: Add support for the XSETBV instruction Thread-Topic: [edk2-devel] [PATCH v1] MdePkg/BaseLib: Add support for the XSETBV instruction Thread-Index: AQHXJgMFFcTOhEfqzEiUYAhtE2R216qfr7GQ Date: Thu, 1 Apr 2021 13:50:29 +0000 Message-ID: References: <16715E20BB70A728.7099@groups.io> In-Reply-To: <16715E20BB70A728.7099@groups.io> Accept-Language: zh-CN, 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.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6377f276-00e9-4934-2fc2-08d8f5151c9a x-ms-traffictypediagnostic: DM4PR11MB5405: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1247; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7P5YPD03tJye9T1KYXmUmEmc3XgWa7M9e+V5Q6bXdGPYDBmRVkDwYsXRihBNDj4RJ8vG7Hg7GPsR5MVImaXcpKLWiDICQAxt6d8ii9tzojLR1rQBMmlaKwZ1MDEEQbdTxEEilPQL8fhOcrmmWiaciZ2X7lf7kq0fZqmGTL0qWXnqO8wF19VD9ZNDB85wy7HKK+yCLDAthOdT15+mbx5BIKqC6SBaNDfRdvFFadPpO5dvpOopeKVSR5+bJcwE2BbCaLHKO2ycCuo0BHnXNNqI0VL/GS07GcArAPn3ZhJ8zkCls2VGlHT12aE3fd+vjNJkG4SLyFDpmdZtQiXDtJczC8byEGBhPms48XUsIZz6NJFUdbc4Rd05Mfk+vK407d8tdmCBpTdMCWuamsp6x6xOPrmoyKyys6mG6hlcMag3WMlxh7eT7Khytj9gowLQSiHk4rA/v0VIcJuCuhE6NNc7PmhOR9nuaW2MJmRitSTvY6bP3qQHwo+vrzTGc7KEczPIh9I72nK+OgELtfd2M5aybpT00pn8gif8+Va5PsidMUru6N1Zvf2n10kkMJpJ8he7EVr6KhbKP9KNerZgoKrZL09Qz/3/R0HXq4QFIBjdPZppCb+D89vls2Rm5lQASCBAgv2wKzf8FChOQ30dY/YSawLn6tC6HepVgBC+5hrkYMlAN9ae9xnP6kINTijomX0voWmBEan1ndnlJnrWYvaAaj+MMv97hoxAqqmZ8H0qnVAMFDkTgC6NfCDoKtIZX5jn x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1372.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(366004)(136003)(376002)(396003)(346002)(33656002)(186003)(8936002)(110136005)(107886003)(6506007)(19627235002)(966005)(54906003)(4326008)(55016002)(45080400002)(8676002)(9686003)(52536014)(66446008)(66476007)(76116006)(2906002)(66556008)(64756008)(478600001)(86362001)(5660300002)(26005)(53546011)(38100700001)(7696005)(71200400001)(66946007)(316002)(83380400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?TXSZb9Aa0Dyu4n3KOiTo6CRYoMVaLBsja3PYymZ8HdP81NradjdJGviH13l5?= =?us-ascii?Q?rNd3D39G/rd6//uFYAqxkLIURdjr1EnHd3HwKIT55m+4vQAoK7R16+O8ZaFT?= =?us-ascii?Q?4JFBWZszVLzcuWhnyfS1otv1QOQuZU/See636cgIQloQQl2CLWQvBu1dJ7rR?= =?us-ascii?Q?PkP+UMkCpB0F3aU4x1u3Wb+XLBmVGgMqlQXXhwnsMlBuKsQKLq1LRL6tIEy5?= =?us-ascii?Q?WWo8CpiaeitKQkNBQiSjlhROwUYe4LDk9mc8nebutbnbPouRQ/eIO8UyU6Y7?= =?us-ascii?Q?1NK1pzQdLzj8oznF8vaCs83KJYxzeh6o5filYc+lhr7AaJceDgT62k5+oB1k?= =?us-ascii?Q?NgG+VHR0EF0MVDAeQ+4MDr1TKX9N4+89ZWXBjCcA/Z6fAtxWFjffDCuvwUkS?= =?us-ascii?Q?osVkY9I+57N9fJHGdUOOJ9dQfzL4JrL6E09fPQmfM4DI9dis+2clMuFmgJNK?= =?us-ascii?Q?vx4SHrP7KfNsnW46mynsBicl7ZzarsDjetlSbnLuVDNcjqbS2s8O0wbDuXo6?= =?us-ascii?Q?QT9+bRmSq1qKCtdqSm6Nh0Dcg2WwbOKYhVCJaYnSVE08Rnha3KWyr1JG/Q1J?= =?us-ascii?Q?OGz5qBskAozTLBmJLxLD3IIcfN+DMZ04I9XEXUpQ4QvCsWKu75h5NDAnXm2i?= =?us-ascii?Q?g5U+PBOuCH03fw0RETyCMw/GEdxc1IOmYWnvjbFX4mnnCF85iMuOV3uPxoyn?= =?us-ascii?Q?T+uOIm90fg9ba5UehzTxNTmiSq8MWCT5v0svfwc1SfQv3khJAKzSsHCjeS7W?= =?us-ascii?Q?rsADIf0AO+kfE4wbJuBSuZDp77Ra7tXYfB8Tj3El8OsuHAUI3Nic5lmRTCxe?= =?us-ascii?Q?37pYpjf+W1o24fTk4vdekBDeEbL9na38rpmlnlM6ivhhLlSxkoxjkHJzvgpI?= =?us-ascii?Q?eUSKqyrBjgOvciZ0MXDF1DW7hgqJocpP6B9Er+AS64zDNdLnaN24xrrffmgs?= =?us-ascii?Q?sWkENHrI+yWhKxCA9IuW8cFW8z7OORoOOP2PkGl50G7p6A5hmFxMRdbWEeMe?= =?us-ascii?Q?pFMtGcTKOkJEsz6vXBpBbZVkvblMSSI5wooHnUT7XQFf5kSLjMRFJFTIgN7N?= =?us-ascii?Q?R4WM/G7Twz/M9BWffDEzWaTbMXj8k5ZFAXbbyTnhHJD/QWa7KfVmqRHqKyCK?= =?us-ascii?Q?mwuy54Hcaa4Xl9PQlqrgiY4AhjinmRBKqr7Zm2JDF8j+IXFYthkrHOTIzguY?= =?us-ascii?Q?QYtxzufz6hSFg69H3kB+wqk8k7mrKwwlXOozXgV4Z/PxEVCzjzI3BhK+8pLy?= =?us-ascii?Q?tq9rzaIwPfCahwNNxcq8s0yXYdPhGzXck5P08xFD+t7534wXpvcz3M5Y5fuM?= =?us-ascii?Q?305d/SBenlW//83Fed54ZH4n?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1372.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6377f276-00e9-4934-2fc2-08d8f5151c9a X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Apr 2021 13:50:29.3601 (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: ofCd2a+ZelSLwOOCdr803YsE/BT4vlzcXpTgwznhiV1jnhzgU3M3jGvuiaiyk5Tf2sL12VGDAoNv2KhGLSY4HA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5405 Return-Path: jiaxin.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Liming and Jiewen, Could you help review the patch? Thanks, Jiaxin > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, > Jiaxin > Sent: Wednesday, March 31, 2021 3:54 PM > To: devel@edk2.groups.io > Cc: Kinney, Michael D ; Liming Gao > ; Liu, Zhiguang ; Yao, > Jiewen ; Zhang, Hongbin1 > > Subject: [edk2-devel] [PATCH v1] MdePkg/BaseLib: Add support for the > XSETBV instruction >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D3284 >=20 > This patch is to support XSETBV instruction so as to support > Extended Control Register(XCR) write. >=20 > Extended Control Register(XCR) read has already been supported > by below commit to support XGETBV instruction: > 9b3ca509abd4e45439bbdfe2c2fa8780c950320a >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Yao Jiewen > Signed-off-by: Jiaxin Wu > Signed-off-by: Zhang Hongbin1 > --- > MdePkg/Include/Library/BaseLib.h | 25 +++++++++++++++++++++++- > MdePkg/Library/BaseLib/BaseLib.inf | 4 +++- > MdePkg/Library/BaseLib/Ia32/XSetBv.nasm | 34 > +++++++++++++++++++++++++++++++++ > MdePkg/Library/BaseLib/X64/XSetBv.nasm | 34 > +++++++++++++++++++++++++++++++++ > 4 files changed, 95 insertions(+), 2 deletions(-) > create mode 100644 MdePkg/Library/BaseLib/Ia32/XSetBv.nasm > create mode 100644 MdePkg/Library/BaseLib/X64/XSetBv.nasm >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 1171a0ffb5..035d6b655d 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -1,10 +1,10 @@ > /** @file > Provides string functions, linked list functions, math functions, > synchronization > functions, file path functions, and CPU architecture-specific functio= ns. >=20 > -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> Copyright (c) Microsoft Corporation.
> Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP.= All > rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -7436,10 +7436,33 @@ UINT64 > EFIAPI > AsmXGetBv ( > IN UINT32 Index > ); >=20 > +/** > + Executes a XSETBV instruction to write a 64-bit value to a Extended C= ontrol > Register(XCR), > + and returns the value. > + > + Writes the 64-bit value specified by Value to the XCR specified by In= dex. > The > + 64-bit value written to the XCR is returned. No parameter checking is > + performed on Index or Value, and some of these may cause CPU > exceptions. The > + caller must either guarantee that Index and Value are valid, or the c= aller > + must establish proper exception handlers. This function is only avail= able on > + IA-32 and x64. > + > + @param Index The 32-bit XCR index to write. > + @param Value The 64-bit value to write to the XCR. > + > + @return Value > + > +**/ > +UINT64 > +EFIAPI > +AsmXSetBv ( > + IN UINT32 Index, > + IN UINT64 Value > + ); >=20 > /** > Executes a VMGEXIT instruction (VMMCALL with a REP prefix) >=20 > Executes a VMGEXIT instruction. This function is only available on IA= -32 and > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index 3b85c56c3c..fe8f68bbcf 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -1,9 +1,9 @@ > ## @file > # Base Library implementation. > # > -# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved. > +# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved. > # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<= BR> > # Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved. > # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All r= ights > reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -182,10 +182,11 @@ > Ia32/LShiftU64.nasm| GCC > Ia32/EnableCache.nasm| GCC > Ia32/DisableCache.nasm| GCC > Ia32/RdRand.nasm > Ia32/XGetBv.nasm > + Ia32/XSetBv.nasm > Ia32/VmgExit.nasm >=20 > Ia32/DivS64x64Remainder.c > Ia32/InternalSwitchStack.c | MSFT > Ia32/InternalSwitchStack.nasm | GCC > @@ -316,10 +317,11 @@ > X64/GccInlinePriv.c | GCC > X64/EnableDisableInterrupts.nasm > X64/DisablePaging64.nasm > X64/RdRand.nasm > X64/XGetBv.nasm > + X64/XSetBv.nasm > X64/VmgExit.nasm > ChkStkGcc.c | GCC >=20 > [Sources.EBC] > Ebc/CpuBreakpoint.c > diff --git a/MdePkg/Library/BaseLib/Ia32/XSetBv.nasm > b/MdePkg/Library/BaseLib/Ia32/XSetBv.nasm > new file mode 100644 > index 0000000000..9fa2f761cd > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Ia32/XSetBv.nasm > @@ -0,0 +1,34 @@ > +;----------------------------------------------------------------------= -------- > +; > +; Copyright (c) 2021, Intel Corporation. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; XSetBv.nasm > +; > +; Abstract: > +; > +; AsmXSetBv function > +; > +; Notes: > +; > +;----------------------------------------------------------------------= -------- > + > + SECTION .text > + > +;----------------------------------------------------------------------= -------- > +; UINT64 > +; EFIAPI > +; AsmXSetBv ( > +; IN UINT32 Index, > +; IN UINT64 Value > +; ); > +;----------------------------------------------------------------------= -------- > +global ASM_PFX(AsmXSetBv) > +ASM_PFX(AsmXSetBv): > + mov edx, [esp + 12] > + mov eax, [esp + 8] > + mov ecx, [esp + 4] > + xsetbv > + ret > \ No newline at end of file > diff --git a/MdePkg/Library/BaseLib/X64/XSetBv.nasm > b/MdePkg/Library/BaseLib/X64/XSetBv.nasm > new file mode 100644 > index 0000000000..aa72419e7f > --- /dev/null > +++ b/MdePkg/Library/BaseLib/X64/XSetBv.nasm > @@ -0,0 +1,34 @@ > +;----------------------------------------------------------------------= -------- > +; > +; Copyright (c) 2021, Intel Corporation. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; XSetBv.nasm > +; > +; Abstract: > +; > +; AsmXSetBv function > +; > +; Notes: > +; > +;----------------------------------------------------------------------= -------- > + > + DEFAULT REL > + SECTION .text > + > +;----------------------------------------------------------------------= -------- > +; UINT64 > +; EFIAPI > +; AsmXSetBv ( > +; IN UINT32 Index, > +; IN UINT64 Value > +; ); > +;----------------------------------------------------------------------= -------- > +global ASM_PFX(AsmXSetBv) > +ASM_PFX(AsmXSetBv): > + mov rax, rdx ; meanwhile, rax <- return valu= e > + shr rdx, 0x20 ; edx:eax contains the value t= o write > + xsetbv > + ret > \ No newline at end of file > -- > 2.16.2.windows.1 >=20 >=20 >=20 >=20 >=20