From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.84]) by mx.groups.io with SMTP id smtpd.web10.6278.1616669657510526952 for ; Thu, 25 Mar 2021 03:54:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=zm+U0eMa; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.76.84, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=am1ePOZIpwzxkSuNbHTtFYczyoJpHAaTHfck38S6jtDvmfQfkvW61USk6Cv63hx1zRo001RqtbqnEMdv5rZBcL1UdyzLinR9bgpDZD3Qh1bJfM54Wq69eEakrRuBWOspE0DVHBO8AyleW1u05A5mwe9RgH9tcHscodVJv6xmmAGIFepFMX4f72P/kK49GZHYWmxDkuLW2DmTGYnI2z7lNxS+/QBQslA0ec+d/LkgIr1SaoEKFl8ZJs2EY7rLhuRELfecuNznFRKlLggbPo4a4SNAWDClq7Pm5UD+7pJKJcovF89k76ic0FVRo6nhB7U5d6e4vL4RekfoHeeLW2cOIA== 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=no4fLRqiWEWZ+BrpbZaIsNYsNsi+hYZLuEQaRutt+MQ=; b=FX78GNOa8drxs5+gH/x4m8XfdKG1ruS7Eeeiee1rcug6tmsRv0G2HI2qXle9R449nxKU7Wgzu3KYFOUbrw3l5JEpFDYx92e4zqotP84Zzhtb0U3TNWZdwDTa2HEix1GwZFLBXOixtl7y8wekWwGS1e8soHTdcSzV9KIj0On74TCHJFic4HAPvxPsnNLaxaI1DSiSMxfOIbU2Xmqb+aAx+vZ1CtDYYZ5h0XZjJZxvRF+jTJ5u1W67+iCBlRjy6n5QhU98tb4oJMrczR9AP+on1U+IATYgFrtRvbTpZzI6uxHjiYh/jRUelgWK907FDyyDSMFX6jetOuqnT2hCWx0Wiw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=no4fLRqiWEWZ+BrpbZaIsNYsNsi+hYZLuEQaRutt+MQ=; b=zm+U0eMa9diZ802HWnwTAkB9KnkuCua8/xtsupna0GsZg2Q8OtNRV/BGr4hWvT4zUsDkHfgzkGYxtPxW8VPtKFun2WMJQHQFh2rWOz8CSM4A8TqrXQydhYelxkBclttRwDxrTV6JEA/UxbuaAUN/RluWpPG2XdnCacRUgpQ/gJ0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2639.namprd12.prod.outlook.com (2603:10b6:805:75::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Thu, 25 Mar 2021 10:54:15 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d%3]) with mapi id 15.20.3955.027; Thu, 25 Mar 2021 10:54:15 +0000 CC: brijesh.singh@amd.com, 'James Bottomley' , 'Min Xu' , 'Jiewen Yao' , 'Tom Lendacky' , 'Jordan Justen' , 'Ard Biesheuvel' , 'Laszlo Ersek' Subject: =?UTF-8?B?UmU6IOWbnuWkjTogW2VkazItZGV2ZWxdIFtSRkMgUEFUQ0ggMDkvMTldIE1kZVBrZzogQWRkIEFzbVB2YWxpZGF0ZSgpIHN1cHBvcnQ=?= To: gaoliming , devel@edk2.groups.io References: <20210324153215.17971-1-brijesh.singh@amd.com> <20210324153215.17971-10-brijesh.singh@amd.com> <00c201d72121$850873c0$8f195b40$@byosoft.com.cn> From: "Brijesh Singh" Message-ID: <49ccb3e7-f878-56b1-e613-c0014832c392@amd.com> Date: Thu, 25 Mar 2021 05:54:13 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 In-Reply-To: <00c201d72121$850873c0$8f195b40$@byosoft.com.cn> X-Originating-IP: [70.112.153.56] X-ClientProxiedBy: SN4PR0201CA0017.namprd02.prod.outlook.com (2603:10b6:803:2b::27) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from Brijeshs-MacBook-Pro.local (70.112.153.56) by SN4PR0201CA0017.namprd02.prod.outlook.com (2603:10b6:803:2b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Thu, 25 Mar 2021 10:54:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b96ed9d1-4d69-4708-ecc5-08d8ef7c5516 X-MS-TrafficTypeDiagnostic: SN6PR12MB2639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wyPpaQVXygMUaQhUWFS97veW0rjHzYolYOUbHfIwBsXiXc4+b98nT+8VAjZmbV22mnvCuXMnpJBpm1gY0JBzn/wJ7QgaZmTie2F6ccJkrHyYyOFBrSaOITA4+rukD46H/2nXlV3NaO9TyW+SASNSV2SEPJsAz7455tJM+STywh0coqMAp+O8IJ42JIekQrHcOaqYK+qQTL+JLYmHeTz3Fk+21Ff+jC0k0rczulX91d/65thQlyHz4cTvnjWWGCqckVezRc4ZyBbSxrzfjD53VuMMuowGBVv+d4Sw+nKh1J8cDfzuDBxOWASjKfct3IkFFUvDsngYjSHMh71ZCJhbE+5ddZb0/rVrK/wJMKh22eqiMM/L/JeP9urtX2odBZJDzod8evM9dBHfeHUlDh3KSzANPbSY4Eq618y47F7Mr17SDFYY4P1iXLX1U5Lw8Hhv4nF62ShN4M9wwyJe2Pv1BN4rnAeQ92TbptCoiD4VMGdtdYlG7bPidbYZGnjw0iVbAeautmEGnoRMrBnuxlH4bjPNAS7ukX39ntihxjbFFJrwKdTzH9xiOe1RKIDoQ4GrWTbSW9NtrzY6HB/gf4DkXVUufYlzE/cZKvaY8KMQwejmbrOkZnNNBXzxR9xowJuf1P33nIO1JD+s1YjsUVp9Qv/zIZbs4AHP7HXQ+IFvlSRNzw1lu+F9jP/iKXZxLNL/tCbdp5lZGzgnaQiyYQCVd1vqQywOVdujicxl0LBIgrOQRmpcXKSOWAyoKyEpykiTsWmrLlwsUxXa7HtqmUSkNMcn5IqYoHwf6UMOGZtdkbSLV+NnGdtxI2HgNV3kOjVr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(346002)(136003)(366004)(396003)(376002)(2616005)(6512007)(44832011)(966005)(956004)(224303003)(478600001)(45080400002)(83380400001)(31696002)(52116002)(53546011)(6506007)(2906002)(54906003)(6486002)(66476007)(66556008)(19627235002)(316002)(8936002)(66946007)(36756003)(26005)(5660300002)(16526019)(186003)(4326008)(38100700001)(31686004)(86362001)(43740500002)(45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ZL2dv/s?= =?us-ascii?Q?JFOqVP7WNKsa7cIuDkOel587i0fSWL/IoSzXq+qHkejw+vKdwsm4OOcgGK/3?= =?us-ascii?Q?wrT7oyWH0Ceymk3q9KJIcSBvcYYGcBYFh3wp//WA8Nv+cOv3VBpg6PdkURx9?= =?us-ascii?Q?YWpcKCOBvZYG185RLQuwxDhsV/NIFsYrrRqDAwwe4TE/mVG+SuoXgF9sTLUp?= =?us-ascii?Q?AeN6eYAN7xcLxj8obU0RG4jxiApdeoGh5Wd1fVECvWpBdZchkE10gdJMKj3x?= =?us-ascii?Q?XYU0fEFh9CvCrcsWwO9czNfL0sqZI57K10EiMlNAEe59gwacm5PjWyJJv1iW?= =?us-ascii?Q?IPzFqW0/KJW+G8yHk96fI4YEADqu5qLtrl5UaaN/SDPxfGNEmYipN36ch4TA?= =?us-ascii?Q?JUqXUfPSvr53lcBgKgkj+gg3ldo8AFLKdezHic0MK0bfZf1l1EzX4pJZnP49?= =?us-ascii?Q?Z7O0DvrhQy6lBcBKHsHwdazeEWEByxI8C9smF59VnNWC7ViYXCxwDdHRaZ5p?= =?us-ascii?Q?dBOAYOBv0icIsmVheDMAEx1x?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b96ed9d1-4d69-4708-ecc5-08d8ef7c5516 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2021 10:54:15.7093 (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: +vRpDV6vCPeVfTLxEVMdmVTMEstDFAIBRNUL/aIzGN081kZkYE9VpiBgV+BGP/AN+za3UE1j/+/bumOXuWP3+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2639 Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: quoted-printable Content-Language: en-US On 3/24/21 9:49 PM, gaoliming wrote: > Is this API X64 only? Or IA32 and X64 both? Theoretically the instruction is available on both IA32 and X64 but its used only in X64. AMD SEV, SEV-ES and SEV-SNP support is available for X64 arch only. I was not sure if the EDK2 community is okay with the dead-code. Do you think it still makes sense to add the IA32 API for it ? > > 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 >> >> BZ: https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2= Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3275&data=3D04%7C01%7Cbri= jesh.singh%40amd.com%7C125d11ea64cf4f4ecd2108d8ef38a8e7%7C3dd8961fe4884e608= e11a82d994e183d%7C0%7C0%7C637522373939810930%7CUnknown%7CTWFpbGZsb3d8eyJWIj= oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sda= ta=3Df3fM%2Fnw3X1lHhf7SPKTxDOLo0GcnU465yvyf0IIyD80%3D&reserved=3D0 >> >> 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. >> >> For more information about the instruction see AMD APM volume 3. >> >> 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(+) >> >> 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 >> ); >> >> +/** >> + 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 eFlag= s > 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 >> >> [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 >> > >