From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web10.9844.1594828575267557617 for ; Wed, 15 Jul 2020 08:56:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O1oI+5El; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594828574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jVjtT4qtfFsdpu5ucAadz3e7uGbSc6ro9y5vK18CW3w=; b=O1oI+5ElhG/38JKr39thgL/hVuqa6dnuEja9MAHwCey9tcdf+tDs0iEcMbss1MmF5ELiO9 WDcr91ddEl7TcWKFKu9wJH0sDvLy79lBRvMu3ra5Wc3TZjWZRgErGz5NUhTaollv98yGhZ q/2ck/Xw96B+eiRw5G0RdqK2o0bdiNE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-327-rUtg-p4xMfe6zBOSqDIwPA-1; Wed, 15 Jul 2020 11:56:03 -0400 X-MC-Unique: rUtg-p4xMfe6zBOSqDIwPA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F7C7800C64; Wed, 15 Jul 2020 15:56:01 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-3.ams2.redhat.com [10.36.114.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 829CC60BF4; Wed, 15 Jul 2020 15:55:59 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v10 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction To: devel@edk2.groups.io, thomas.lendacky@amd.com Cc: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Liming Gao , Michael D Kinney , Ray Ni References: <20ddae98568fa4379cf10a73baef1418f5de307f.1594736896.git.thomas.lendacky@amd.com> From: "Laszlo Ersek" Message-ID: <15224b54-1914-2c88-b9a5-ce56ad3aad94@redhat.com> Date: Wed, 15 Jul 2020 17:55:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20ddae98568fa4379cf10a73baef1418f5de307f.1594736896.git.thomas.lendacky@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi Tom, On 07/14/20 16:27, Lendacky, Thomas wrote: > From: Tom Lendacky > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 > > 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 > 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 This patch no longer applies, it conflicts with commit d3c9e40abcc8 ("MdePkg/BaseLib: Break out IA32/X64 GCC inline privileged functions", 2020-07-15). The conflict persists if I successfully apply the series on c7195b9ec3c5 -- just preceding Mike's series "[Patch v3 00/16] UnitTestFrameworkPkg: Enhancements and bug fixes" --, and then try to rebase to current master (e77966b341b9) from there. Can you please investigate? Thanks, Laszlo > > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf > index a57ae2da31f3..da6bc22a3e2b 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 > > > Ia32/GccInline.c | GCC > @@ -287,6 +288,7 @@ [Sources.X64] > X64/ReadCr2.nasm| MSFT > X64/ReadCr0.nasm| MSFT > X64/ReadEflags.nasm| MSFT > + X64/XGetBv.nasm | MSFT > > > 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 > ); > > +/** > + 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 register > +**/ > +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/GccInline.c b/MdePkg/Library/BaseLib/Ia32/GccInline.c > index 5287200f8754..c962bcfa4617 100644 > --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c > +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c > @@ -1763,3 +1763,31 @@ AsmFlushCacheLine ( > } > > > +/** > + 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 register > +**/ > +UINT64 > +EFIAPI > +AsmXGetBv ( > + IN UINT32 Index > + ) > +{ > + UINT64 Data; > + > + __asm__ __volatile__ ( > + "xgetbv" > + : "=A" (Data) > + : "c" (Index) > + ); > + > + return Data; > +} > + > + > diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLib/X64/GccInline.c > index 154ce1f57e92..915555198f9f 100644 > --- a/MdePkg/Library/BaseLib/X64/GccInline.c > +++ b/MdePkg/Library/BaseLib/X64/GccInline.c > @@ -1798,3 +1798,33 @@ AsmFlushCacheLine ( > } > > > +/** > + 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 register > +**/ > +UINT64 > +EFIAPI > +AsmXGetBv ( > + IN UINT32 Index > + ) > +{ > + UINT32 LowData; > + UINT32 HighData; > + > + __asm__ __volatile__ ( > + "xgetbv" > + : "=a" (LowData), > + "=d" (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 > + >