From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.26.1616599956611292901 for ; Wed, 24 Mar 2021 08:32:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=EmTkv1Ig; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fDHOMgm7BpkkH6g95mKe1RfJ+jHqp5hLJYWJpM4giZFfmSc7yg/1RTP/KlKv1dH6PI9LnDrqVsMVcT71KzSfTlQshVeSm/2aJrAwOmRTO+oG0xWK4CvfyYuq0A/xsSkoOl/I9mpEInN48USNbWT0+ymC4PoxyyJgkoA30jyJZbQ4s8DOU82b2nrLqORP/vLsSy9fFIdTRPEU8H2guH30/9iQV3SsfygLGXwn3qdsZDoVshztV0b/Lh4o2Sr0Ngq7u+NeKgBl17e60U4brU7Nl+PkghEX7oTJ81cOzBdLK8htyw69z1q4gUSk186t5aIhSwXEDAXqqah0pnTIhFmYjQ== 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=mN0lrHh2N9o37YePojLbLWj8qG+CAxopK1MWUl59e6U=; b=RnknDqj9WEyA6eJyUyl3tP5GohLTiHjl5zrPhOBddFeWXnr2QhADaMYjNelAewhfuJIpvoSc05VryR6Oib4UagT6wHuKWXAG9AnT1oo+jvMm6G3KwFoOLG1TM+S38nG2GtcRODlY4WAEcStuuFvLq1df3R2Gyt6vTVYQwwiy5fusS6Q5kPXnTMXWxd3icDQrBv+nHczuMUuWykjvfO182DO/1VNGp/z95m0paO9XWPy4MgOZeAg8YlyLvmNwe5xrrDwcqzaz5a+3mdg7lVkH+CYFvG/yF9Z0O/jd4tgpK+eB/W+UbzlTcXIT1EEaEIfmkawCAPgUNwyQVWmrZdKB6Q== 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=mN0lrHh2N9o37YePojLbLWj8qG+CAxopK1MWUl59e6U=; b=EmTkv1IgdTR+/SZdH3jBuxpgd2i5TKs7QEJRMuVG5oDLgTuo32IoInah7eVu5QRfIYjxPZmzn5aowaqx20eqC+Kljl18/DHVbvLz7siKM4CC2b4bfZto26giymehNPmmlGa4PWr2abDZ0VB/mjKTx4yg4mLeHTKpe/sD/9oRMo0= 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 SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 24 Mar 2021 15:32:35 +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; Wed, 24 Mar 2021 15:32:35 +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 Subject: [RFC PATCH 09/19] MdePkg: Add AsmPvalidate() support Date: Wed, 24 Mar 2021 10:32:05 -0500 Message-Id: <20210324153215.17971-10-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210324153215.17971-1-brijesh.singh@amd.com> References: <20210324153215.17971-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) 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 SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 24 Mar 2021 15:32:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5a0c77db-9ffa-4e16-324d-08d8eeda0bb2 X-MS-TrafficTypeDiagnostic: SA0PR12MB4430: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IanKcUvuMCXuWzljWom5AVntL6NFC3FiRSetLiJ6nrrpi1EBmockbgxTZJrpOM9BE208crwPRNHo6SqbkkzuxvM+aBYqFX9nWtBbrtnaboa8tRmA1u6z/sr+ml3lcM3fX/BK0tZ8o1Pi4kXmNnGUuba51cAFFGgNJW6iTF9qjIJ9xvK590gPy8pMadFf0YrJkLQbuTGFk2ODwc+8IYCmwUZnZfi8GYDapOIc/7ro6wLGYWrDWudJQWOuZmmwN/0sZguQ4IMDEGGOvy93ipjEMVYG5ObURuIce+oksMs+9bJCoAa9FHFULXOtqv5JekTzr6R1vXzp+CBBp/L66hhymaqCYGQWT+xZm81UmslVm7BWPCq7r+brFRZXkdllDfQUvrUlhM7vCXAINsx2bZJ7j3FaJuuiz5C1wwcvyN6QjL+oTVZSkx9b4kb7sb2CGcHo76PTmaD86qvMZqRk+RJ47ftkCuUNtCasCP1efm6WeW8sbtc2GLJ7BKx51KK1pjATNArbMYIFgp/TEDLe812Ah8BSmJE21tXIbvWDwrqz0afjTwoHqz4G7gJKUIA1OqRn5NRn/hqu9UnQ9PK2IS1yzKBiyj+rmLV9tJ80UiWfu+VJO41SQptWx9zlt4uVSPQ01B54IOcM9XFdtzxW8mmeoD4MeJfeT9Fms05fjJ8Vy+FscKujbA3XI0TLuONM+Hrz8dyfVAp5zXG6qrSgfri73Fg3PEcTUi4yPBWRBgvyCNx2P2R5Y8VyQrpa+vu+kruV 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)(366004)(39860400002)(136003)(376002)(346002)(396003)(2616005)(83380400001)(66476007)(4326008)(44832011)(1076003)(6486002)(2906002)(86362001)(66946007)(478600001)(316002)(66556008)(966005)(16526019)(6666004)(26005)(54906003)(19627235002)(6916009)(186003)(5660300002)(8676002)(7696005)(956004)(8936002)(38100700001)(36756003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?P03d82hJkAdRcOAi3Q60NXMbn0zsAP7VGZ4fYY2RpzyeexCdrsNxFzvHP0UI?= =?us-ascii?Q?DbipPgLehwXqRftQwW7Q8Z+pCqNvxqX2dubm9NxdunUvp06dCxDOV8CUm2kj?= =?us-ascii?Q?psoL1Yr4k03e82Wr6ht4polu+K74NRrK66kNRFq6CJIBORe98cvAjuwmPgOO?= =?us-ascii?Q?ckeXVp+GhZhPT38kaAbZjBL8MytVO0Jsjsb3QqvZ6nRxubRV5PF4QV8FpaGs?= =?us-ascii?Q?dKZq6wNkx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qCMv9D9X?= =?us-ascii?Q?wi1mLW7nxYddEX6KuGvJzy2LLVX2BQbms5kmDdNWPDtTOZkO4OlkC4UyQz+P?= =?us-ascii?Q?eDc8qNscjVR56NHvzq6B0xM/TVt88yDK373ZFLOUAA+iwoWMe9HE9wwJcvsf?= =?us-ascii?Q?19crKanKNUsFPWHXJeZgN53apOhCd8m8dVj7tJwTNfhxMPHno8yJF1b26ipj?= =?us-ascii?Q?tKE5GPMMcdlseg5X7KbmaLzl?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a0c77db-9ffa-4e16-324d-08d8eeda0bb2 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2021 15:32:34.0763 (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: voKzd4A8wN9Quj2mqloHXc7mmJ6MZybLOxQaBSGRHZ5VsUu4fOu/TWLjvGLFOu8YoVxElfnmM5PIah+IuJJUVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4430 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 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 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 = 0, + PVALIDATE_PAGE_SIZE_2M, +} PvalidatePageSize; + +typedef enum { + PVALIDATE_RET_SUCCESS = 0, + PVALIDATE_RET_FAIL_INPUT = 1, + PVALIDATE_RET_FAIL_SIZEMISMATCH = 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