From nobody Tue Nov 26 01:51:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63848+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63848+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159682923335241.49554879102686; Fri, 7 Aug 2020 12:40:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SbV4YY1788612xwIuVDPpQId; Fri, 07 Aug 2020 12:40:33 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.55]) by mx.groups.io with SMTP id smtpd.web12.4192.1596829232476844191 for ; Fri, 07 Aug 2020 12:40:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Et4qu34fDr4g/tFtidKoD2eqwQ9MfenMWPmJQkRa600wRTytGBNq/UF4h+pLok17Kegfb+sKgQO8HaYa55/hJ6kVcC8GoJAhh45JKa/8PjM2tsxwpRpQCXw9Ue8V5E+vgFUujhTblYNYFJdYBbJ5rkplQpKDia6jkMZNHNYftaxrEhDoaE1Qz1SNsU4FuRf16X6Sj1uVfYA2564T2OTQfg3pg1qDG+kOIcTNOpCrEPtiRdllroNhGnVQeXrj+BuIo9RG6HNWEcfygxcDM9yo+YWAm/QKoVtwHbcGJeVE6xxcRX/GUa+b/cA3S2/l4hFEdkOC4c7ev8T/JLpSW7ST7A== 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=3ozCs/ZVggMJEwwyBP/NbeOfp3jjnVRv7aWB6hRKksA=; b=GG1brXFulI7CZOfYuWVGUIkNR61h25zf1c+VWAeLit29d+qPf3j10cKg9nq/htctT5jHAhcdklQpkwLrNKhLF9OrzEAT6y9D97qVY8BI3ELL6HBpNffyh5I9ZI5LeXIZgCHQc1/jE6RfaK44a254Pf2okzFhS5BT3IDAcvYJXFscNIbYbLbEos59qK/2UIXfCfN3mkQI5j+TLvEye90SJBtb5WuQ0Pjz9jZUygN20CXZZmf0JQv9mbKANN8gex0rvD9Fe6khrAw/613usf24I67EgZ7CU2ShBKiwdEem18ZkHlnOdTsoM6BYyMoCCwpAAa1sB+p9HLXyiQcrXLKcrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:31 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Fri, 7 Aug 2020 14:38:51 -0500 Message-ID: <2c48f43ea66ee1b2392f7eeb68fde664af412cf0.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:40:30 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 600e23cb-2b5b-41c9-4be4-08d83b09be7c X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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-Message-Info: AySVcJ3TmDU6F2K7e7E1x9L5TNrF8xToelWs3tVDxRfyd38u4HG1n708LQyk4AwDprhlkAciDLZZKq0Ve4IZDHvZKlQZVuXOfzSBLyjccr//XRuO5HfqiS4Hh+rzWoRLQZqxlL9ga7biI8kGNaQilfqiHZm6X4NX7s6SzdcwSKLothqYNgj990mb230bk4ohSCX00znyduiJWLlalp3ZsjuA9aIEALSi/f2SSrnqHUgwXK/Ivj+3TUP+x0cks97JZ7rpC44ze42SgzHRNNOZOBOFPPdxVetq8HlxFyxScAydJX2EK89xRJFOY+OOJc2+dnGQMyTwaUX785vI+9FpW1MykVhkhxBwwuO0KUJZdEehwNv64qmxwQhIDnigFr+EIuRnjOiNUDXSWsGOk6g9rgGakXOLBZ9OLijILyQTaleIHlBa4UlAjhp8ylQ5CaUOGrAN4bvorKWyTbrNRKRjRA== X-MS-Exchange-AntiSpam-MessageData: YDAPLc1NQK22vXqScFpbzexe4/9Lv4eFujoHuIfcagcq+Wr/npgvmuWO5by8Do/0w0pbYuZrkiZ7b/8jyOj7NfpYJL87sI5jPvWh0SNhNIZ9zgpTRozhNPAyGGLV8bXvs3eNHXIgywzFa8mofwwUbe14T5ftD92pMnwoXl3yjuvQSbVZlFmC96vTcgaf/exWuToof1FuOJfe1cagO4sB3d581bZx61aWd0JYPwIMyQPvQUlaksk/AFnqJ7zoc6vCJRDcANRsABq+kumFRYXxLmz6rreB4HbPeRe9qW30+c2691QoHtlz6vd5MmTINFjme1mhnjGfPHtsdgsV6bk4/e8zpjeofg+qG7D3wQrYnXDh4GEmLEx44WrVXOfyTPTbS2h4UA4Kw/OSRcp9lxWjznQLtmdDyXqu9fupUTC/yhX7XTaVHG07NWdU40X6V55UrrWEHqXcvhQASoy0mWOeyqC23pX8Ue0kQzPULQ/90t1Nmh8T+BryKLIDluWxsJaCYrTGbBU74gLtvv7ihohxaSP7sAOPnWt9cFhQpnzL/dXfeNf0ofAjMWNhOXaft2NuF7HbfHNXkQrU5i1SZUOU03jCQ3PR+EZKQ18pnDcpAjE2KzWUz1t60COEJNUVSWfZ8izcX6yV6O+LxCiUeWDkEg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 600e23cb-2b5b-41c9-4be4-08d83b09be7c X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:31.1115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8s3wIXRShCamaTxsXyWr7P+hIswUG61CflWaK/Yy8yREg4cTSb1r4DpVAnRoP3Usc9c6Jw+WsXsPAbkdNbqnOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: anvf39KGsIWERXSgsZZHBjirx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829233; bh=kE4HkMs0oIX/bJUNbN7DKw3IePvPGge+Px0Q7dv9Nyw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=iQUkhZrFrEfG+h9QtEzqc172/1mNO5o081BkfB447qCzMb9phvJ4XbVMg2/V+3fqGI9 JfLmNgdyt31/lXH2m+Ch2mPFKMKtwPGDk0N9CIqznVQoyYTt/dF56lZV9eGWeH6HVY/Q2 dLyJ0GqCgwhAnSK2EhgFpdLdtGX9AJ2aEEc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 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. Provide the necessary support to execute the XGETBV instruction. Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 +++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index c740a819cacf..3b93b5db8d24 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -183,6 +183,7 @@ [Sources.Ia32] Ia32/EnableCache.nasm| GCC Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm + Ia32/XGetBv.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -315,6 +316,7 @@ [Sources.X64] X64/EnableDisableInterrupts.nasm X64/DisablePaging64.nasm X64/RdRand.nasm + X64/XGetBv.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.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 regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ); + + /** 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/XGetBv.nasm b/MdePkg/Library/BaseL= ib/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/BaseLi= b/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 + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63848): https://edk2.groups.io/g/devel/message/63848 Mute This Topic: https://groups.io/mt/76056480/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-