From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.81]) by mx.groups.io with SMTP id smtpd.web12.16147.1620419954580423372 for ; Fri, 07 May 2021 13:39:14 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=OKwn08cL; 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.220.81, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dhSyYbwb5CH9qh1f1JKHmK1dNtGv5qFZ42uu8r957IkOJ2q/Mruc17v+ix3WM5QYNgxxF6rb1BETrRZZLBcp6qZluI3zuppdEhjzYzllRXNTulC0grX5XFirpOmFHibNU9GdJW9zInLhn4/wiNfGGvdCzPf5cOODyDacVhgDvplctzunSb7wwkkIIbApbiDFuUJn7w4ZLsvyN7XKeSbeCiP+0HkqEz1Tg1+cdStA4Bygsm85rQen8rmDtH3qUtSKmI+XRDaoKnfr7r4VqySmXVH62Zn21ewnMcyog3TkqQsVxWqqFcSFq1o5r0T+1OpQpriCR9mxO70tM8bEV2gpXg== 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=N0t72K4f956Hzlhb0PoYdd8GO1jJ4uaLgrHF3/+vS2M=; b=BZ5Iz/rLkm3JIbprDLxkeBBm2f4dFnJ0c/ODtjoCyrYwicBss8WKeKIxJexgGwQmvT8u+uaQmqnqBxnPPqHFDqHfs5XPyHZow7QwaeEj0d/+++7BMTAqGmGXDU5iw3/A5ulac26o6vZD/wpcv0l/Bp6v/y+tInb9x2qRcHUuapOueDvU4Yhg7hRhOJ7wjIuLKp/XdTkNh3Lr5XsAK6YySVeNxzOHRUBUtrAwrxWt0pLBpsl0nKP/u7Ks+ecfCir5MkTWsIMnCB3crBnqxP5Mh40JvjaEUh0J9FpJ1v8VgmcSTehVpbq4nQuv9GIQf54c/SQy8MiAS4u8cenTJJslFg== 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=N0t72K4f956Hzlhb0PoYdd8GO1jJ4uaLgrHF3/+vS2M=; b=OKwn08cLdNJyAygcQIJaJMvpoKxtrCjZ3WOsk4bb2q/WfGQA+MBN59ORnE823t8B9g6W9dsM5Ka0uyvE8rFXZL2rdhiSeeaC5UjiHjH1JdkKBI1Z9JwrhHapDloAM50LEzjCcGYQjg88+xfz2Z9qjZjIQT0UY4wEACNBPGmvDUk= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2829.namprd12.prod.outlook.com (2603:10b6:805:e8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Fri, 7 May 2021 20:39:13 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4108.029; Fri, 7 May 2021 20:39:13 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [PATCH 07/13] MdePkg/BaseLib: add support for PVALIDATE instruction Date: Fri, 7 May 2021 15:38:32 -0500 Message-ID: <20210507203838.23706-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210507203838.23706-1-brijesh.singh@amd.com> References: <20210507203838.23706-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0020.namprd04.prod.outlook.com (2603:10b6:806:f2::25) 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 sbrijesh-desktop.amd.com (165.204.77.1) by SN7PR04CA0020.namprd04.prod.outlook.com (2603:10b6:806:f2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 20:39:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 522b6da7-3dd1-479d-861c-08d911982c7a X-MS-TrafficTypeDiagnostic: SN6PR12MB2829: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MEc65lDYb2kxFTQ2RnS4YmERGFOyIGCl4tfwAkQm0T16d2yNYACQwfIabp4KGL+C38JkehfuxuJRf3IHAWs5yIz0E+UUa3LiW0jGnYUntExnJ9ISEE6AQRw8IWAWTCsr01buFaSQKEdWeZQ2Hly4YYvMxhT49xJdpOAtbhgyEtTYtL5nmclxOuPn4nEjZDEUuMsM/nSPc7QIljasy+KH4DXlpdGQ7/6XENQksZ3F2c467d+PB/zwLXkrA9BfiQ2BImt8tgY8Adlj+0IjsKyDbjcStj/gbA/dEXE5Uk1BqS/xvWVmMaWGxPowqNoiHkfCHK6mnzA2xNFzfyFVGmkv2WJvKF3smgkByMwW+EFQGMAsda1uRmVOwfeMHrhobEvuW4rCFKUsrsSqo1y/FSY7zhlssVp4RfxvQn7G8cZ9PYkr78Y7PpYFLcI2mOaLHOaEIsWC/gzUpBzPYpJvMVg7Dcm+UmV9hn4wy5qGsyRRxrX/BWTQMLEmvdEQvUpfcEN2v61pdOBSDZiMigixxh7G6FuEge8Ok6f/s6E2fzcrx26F5QyTI0dp6VQufnvIcZs7CBeOjAqz6AkBSMmoXtCcOw6hBlq7esfaB1WUUh+x134rYNMD09AejhWAYDgeQs4470hua9NEyWql1KBciHCbFN1bO1kEkgVXM95kTXGT9fsn139lb/VshB1qawPfv8XBbJl02RJqE4p5fxJOUnXNsYsx6KvEuH5MOLYJhCQ5+ek= 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)(396003)(376002)(366004)(136003)(346002)(39860400002)(2906002)(1076003)(86362001)(44832011)(8936002)(6916009)(186003)(8676002)(6666004)(956004)(478600001)(26005)(7696005)(2616005)(83380400001)(19627235002)(16526019)(52116002)(316002)(36756003)(66946007)(66476007)(54906003)(38100700002)(66556008)(38350700002)(4326008)(7416002)(966005)(6486002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ecS/rH9lUetN67zTILpl1adg/OHdb1QnwtnaXqwLaD7OUx+o2jN+wSc63CYc?= =?us-ascii?Q?CEXp7/AW2yKiCmPzH1+FNpZ4fbezIcu2CmCf4d2TXQv3DFUNffjoGT61yPPS?= =?us-ascii?Q?tX6HephdgnXNnqiWpxCmkH698+z6vLaVi29HY2jzAB5HafbMq13O3V5YZHPO?= =?us-ascii?Q?zHU6wwi4D7jAxRCVL/0EwA1sXsMyFMRk29gfjXrysifJwXXNE04Nxp83gkiT?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3PpFzQlqVrNCX4m/OBISR1e?= =?us-ascii?Q?unmk+ISSvcPppHOwWnmcvQJru868lLq7LDNCYey8fmXDwcuAFScHFyGQHUEW?= =?us-ascii?Q?m5xQqepF8CvG2021fZhjF9TewVVvChsg0CjFFT8yQ1TkWC5f0MjPpTisGpWl?= =?us-ascii?Q?r+ASeosZZRlm7NllRxSrcB6dHBRl6xdHcOeFwO8TaXaB4fmi5gojWRqckriD?= =?us-ascii?Q?4p7tXs87jFZz1ukGdXDAfiFl?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 522b6da7-3dd1-479d-861c-08d911982c7a X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 20:39:13.0343 (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: 7NgXXzFJptf/kmFKCyLul0YPo4PkYqWFDrMAK0p9oyQJ6U2rOuQmsJKBEuNvaxH5vwy+ZWyqNLdXjDnpzTP/kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2829 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 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 Cc: Erdem Aktas Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Brijesh Singh --- MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Include/Library/BaseLib.h | 46 +++++++++++++++++++++++ MdePkg/Include/X64/Nasm.inc | 8 ++++ MdePkg/Library/BaseLib/X64/Pvalidate.nasm | 42 +++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 MdePkg/Library/BaseLib/X64/Pvalidate.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index b76f3af380ea..89a52f72c08a 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -317,6 +317,7 @@ [Sources.X64] X64/GccInlinePriv.c | GCC X64/EnableDisableInterrupts.nasm X64/DisablePaging64.nasm + X64/Pvalidate.nasm X64/RdRand.nasm X64/XGetBv.nasm X64/XSetBv.nasm diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7253997a6f8c..f177034af6a1 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -4813,6 +4813,52 @@ SpeculationBarrier ( VOID ); =20 +#if defined (MDE_CPU_X64) +// +// The page size for the PVALIDATE instruction +// +typedef enum { + PvalidatePageSize4K =3D 0, + PvalidatePageSize2MB, +} PVALIDATE_PAGE_SIZE; + +// +// PVALIDATE Return Code. +// +#define PVALIDATE_RET_SUCCESS 0 +#define PVALIDATE_RET_FAIL_INPUT 1 +#define PVALIDATE_RET_SIZE_MISMATCH 6 + +// +// The PVALIDATE instruction did not made any changes to the RMP entry. +// +#define PVALIDATE_RET_NO_RMPUPDATE 255 + +/** + Execute a PVALIDATE instruction to validate or rescinds validation of a g= uest + page's RMP entry. + + The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=3D1. + + The function is available on X64. + + @param[in] PageSize The page size to use. + @param[in] Validate Validate or rescinds. + @param[in] Address The guest virtual address to validate. + + @retval The return value from the PVALIDATE instruction, and + PVALIDATE_RET_NO_RMPUPDATE when there was no change in + the RMP entry. +**/ +UINTN +EFIAPI +AsmPvalidate ( + IN PVALIDATE_PAGE_SIZE PageSize, + IN BOOLEAN Validate, + IN PHYSICAL_ADDRESS Address + ); +#endif + =20 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) /// diff --git a/MdePkg/Include/X64/Nasm.inc b/MdePkg/Include/X64/Nasm.inc index 527f71e9eb4d..528bb3385609 100644 --- a/MdePkg/Include/X64/Nasm.inc +++ b/MdePkg/Include/X64/Nasm.inc @@ -33,6 +33,14 @@ DB 0xF3, 0x48, 0x0F, 0xAE, 0xE8 %endmacro =20 +; +; Macro for the PVALIDATE instruction, defined in AMD APM volume 3. +; NASM feature request URL: https://bugzilla.nasm.us/show_bug.cgi?id=3D339= 2753 +; +%macro PVALIDATE 0 + DB 0xF2, 0x0F, 0x01, 0xFF +%endmacro + ; NASM provides built-in macros STRUC and ENDSTRUC for structure definitio= n. ; For example, to define a structure called mytype containing a longword, ; a word, a byte and a string of bytes, you might code diff --git a/MdePkg/Library/BaseLib/X64/Pvalidate.nasm b/MdePkg/Library/Bas= eLib/X64/Pvalidate.nasm new file mode 100644 index 000000000000..b20dac7e6831 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/Pvalidate.nasm @@ -0,0 +1,42 @@ +;-------------------------------------------------------------------------= ---- +; +; Copyright (c) 2021, AMD. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ---- + +%include "Nasm.inc" + + SECTION .text + +;-------------------------------------------------------------------------= ---- +; UINTN +; EFIAPI +; AsmPvalidate ( +; IN UINT32 RmpPageSize +; IN UINT32 Validate, +; IN PHYSICAL_ADDRESS Address +; ) +;-------------------------------------------------------------------------= ---- +global ASM_PFX(AsmPvalidate) +ASM_PFX(AsmPvalidate): + mov rax, r8 + + PVALIDATE + + ; Save the carry flag. + setb dl + + ; The PVALIDATE instruction returns the status in rax register. + cmp rax, 0 + jne PvalidateExit + + ; Check the carry flag to determine if RMP entry was updated. + cmp dl, 0 + jz PvalidateExit + + ; Return the PVALIDATE_RET_NO_RMPUPDATE. + mov rax, 255 + +PvalidateExit: + ret --=20 2.17.1