From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web12.2783.1616640593214812146 for ; Wed, 24 Mar 2021 19:49:54 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: byosoft.com.cn, ip: 58.240.74.242, mailfrom: gaoliming@byosoft.com.cn) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Thu, 25 Mar 2021 10:49:47 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'James Bottomley'" , "'Min Xu'" , "'Jiewen Yao'" , "'Tom Lendacky'" , "'Jordan Justen'" , "'Ard Biesheuvel'" , "'Laszlo Ersek'" References: <20210324153215.17971-1-brijesh.singh@amd.com> <20210324153215.17971-10-brijesh.singh@amd.com> In-Reply-To: <20210324153215.17971-10-brijesh.singh@amd.com> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1JGQyBQQVRDSCAwOS8xOV0gTWRlUGtnOiBBZGQgQXNtUHZhbGlkYXRlKCkgc3VwcG9ydA==?= Date: Thu, 25 Mar 2021 10:49:47 +0800 Message-ID: <00c201d72121$850873c0$8f195b40$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQGiVDAZjNz1PVVCjP3Nexg1zWlhUwHJLD0Cqu9RJSA= Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Is this API X64 only? Or IA32 and X64 both? Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: devel@edk2.groups.io =B4=FA= =B1=ED Brijesh Singh > =B7=A2=CB=CD=CA=B1=BC=E4: 2021=C4=EA3=D4=C224=C8=D5 23:32 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Brijesh Singh ; James Bottomley > ; Min Xu ; Jiewen Yao > ; Tom Lendacky ; > Jordan Justen ; Ard Biesheuvel > ; Laszlo Ersek > =D6=F7=CC=E2: [edk2-devel] [RFC PATCH 09/19] MdePkg: Add AsmPvalidate() = support >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 >=20 > The PVALIDATE instruction validates or rescinds validation of a guest > page RMP entry. Upon completion, a return code is stored in EAX, rFLAGS > bits OF, ZF, AF, PF and SF are set based on this return code. If the > instruction completed succesfully, the rFLAGS bit CF indicates if the > contents of the RMP entry were changed or not. >=20 > For more information about the instruction see AMD APM volume 3. >=20 > Cc: James Bottomley > Cc: Min Xu > Cc: Jiewen Yao > Cc: Tom Lendacky > Cc: Jordan Justen > Cc: Ard Biesheuvel > Cc: Laszlo Ersek > Signed-off-by: Brijesh Singh > --- > MdePkg/Include/Library/BaseLib.h | 37 +++++++++++++++++ > MdePkg/Library/BaseLib/BaseLib.inf | 1 + > MdePkg/Library/BaseLib/X64/Pvalidate.nasm | 43 ++++++++++++++++++++ > 3 files changed, 81 insertions(+) >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 1171a0ffb5..fee27e9a1b 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -7495,5 +7495,42 @@ PatchInstructionX86 ( > IN UINTN ValueSize > ); >=20 > +/** > + Execute a PVALIDATE instruction to validate or rescnids validation of = a guest > + page's RMP entry. > + > + Upon completion, in addition to the return value the instruction also > updates > + the eFlags. A caller must check both the return code as well as eFlags to > + determine if the RMP entry has been updated. > + > + The function is available on x64. > + > + @param[in] Address The guest virtual address to validate. > + @param[in] PageSize The page size to use. > + @param[i] Validate Validate or rescinds. > + @param[out] Eflags The value of Eflags after PVALIDATE > completion. > + > + @retval PvalidateRetValue The return value from the PVALIDATE > instruction. > +**/ > +typedef enum { > + PVALIDATE_PAGE_SIZE_4K =3D 0, > + PVALIDATE_PAGE_SIZE_2M, > +} PvalidatePageSize; > + > +typedef enum { > + PVALIDATE_RET_SUCCESS =3D 0, > + PVALIDATE_RET_FAIL_INPUT =3D 1, > + PVALIDATE_RET_FAIL_SIZEMISMATCH =3D 6, > +} PvalidateRetValue; > + > +PvalidateRetValue > +EFIAPI > +AsmPvalidate ( > + IN PvalidatePageSize PageSize, > + IN BOOLEAN Validate, > + IN UINTN Address, > + OUT IA32_EFLAGS32 *Eflags > + ); > + > #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) > #endif // !defined (__BASE_LIB__) > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index 3b85c56c3c..01aa5cc7a4 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -319,6 +319,7 @@ > X64/RdRand.nasm > X64/XGetBv.nasm > X64/VmgExit.nasm > + X64/Pvalidate.nasm > ChkStkGcc.c | GCC >=20 > [Sources.EBC] > diff --git a/MdePkg/Library/BaseLib/X64/Pvalidate.nasm > b/MdePkg/Library/BaseLib/X64/Pvalidate.nasm > new file mode 100644 > index 0000000000..f2aba114ac > --- /dev/null > +++ b/MdePkg/Library/BaseLib/X64/Pvalidate.nasm > @@ -0,0 +1,43 @@ > +;------------------------------------------------------------------------= -- --- > +; > +; Copyright (c) 2020-2021, AMD. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; Pvalidate.Asm > +; > +; Abstract: > +; > +; AsmPvalidate function > +; > +; Notes: > +; > +;------------------------------------------------------------------------= -- --- > + > + SECTION .text > + > +;------------------------------------------------------------------------= -- --- > +; PvalidateRetValue > +; EFIAPI > +; AsmPvalidate ( > +; IN UINT32 RmpPageSize > +; IN UINT32 Validate, > +; IN UINTN Address, > +; OUT UINTN *Eflags, > +; ) > +;------------------------------------------------------------------------= -- --- > +global ASM_PFX(AsmPvalidate) > +ASM_PFX(AsmPvalidate): > + mov rax, r8 > + > + ; PVALIDATE instruction opcode > + DB 0xF2, 0x0F, 0x01, 0xFF > + > + ; Read the Eflags > + pushfq > + pop r8 > + mov [r9], r8 > + > + ; The PVALIDATE instruction returns the status in rax register. > + ret > -- > 2.17.1 >=20 >=20 >=20 >=20 >=20