From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.10434.1619783538721945423 for ; Fri, 30 Apr 2021 04:52:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=I7YD6y4k; 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=Q3dYMPXXIjDH5BuEbSAiTBACiZxCUJ532OqpyNxwhAY41fZiNPZ1V44KJpeZswazFhWB5zYHFDjWhYay6OjKVyojPbvlNfKFSAF8xJNlUnNDqGJnFiv4lQuFx+7mY2bkHvyAsVs2NRZNY7kVcjKaaFXXnDOvf/FJaRBX3XKm4V2d0Or52SkEpZwb8M3VJx/VcqI5P70MZTxMzTGCcPtBTtiMkVG4Xng5w+6620CBKYi3ddI+JGNl7+yYrfek/rohbfjuZpRzN0OExmrB9+nNRVajBYKfT0jxnNbJBFPtwCoZjz7YUDtGK3shTjlPWodPHB1ud44Snbumrds8CvCj1w== 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=hAnPWXrg58V4CkZ0Em68spUEBE/PSd1K5Rz1ZLF2O1I=; b=D/OTuHGQrwAJIdNU09OIoK4h+qwSpMx9k0OnbpI0x2qCYBzMgaNM6TQ8sfhSdl8mDhq8nHvw6GT97FwpOWtGUnNdOuoilNVsBanZFy4FhfPtuA+FL4548lbsX8u1Je3PiEj1RKxVojYwBE9jv5NXm2iJWO2qnmRl6gaglRpB0GpBT3kkyf0pnz10ORxe08p6Li3/SAdlPxDd9kEOoK/hSF6gYrFm507QCx7nAQnGoqD4iw5UGrtF1ocBDJhWwk8cYegkVs2vKLI1jZTL64ziQL0deuQW88tEuEHL8BLoyHQwpshP8apCQb45GSKQ5l0FvTmayN8PGWOnAv1Ixaflnw== 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=hAnPWXrg58V4CkZ0Em68spUEBE/PSd1K5Rz1ZLF2O1I=; b=I7YD6y4kO2Jmb7MlAmCuJnQf3mOZYiKqiHoU84Pdap5U/Hk41LJQTgF0HI3kiENLTNwo8hhjg/1poWIyNEzKua4IX9uH2G/eP6T6C0wbf6axNhRY5VfJQSbFaDEV6bAnMgVgBFQ3q533LdqaikSO0jwSQSQHl88glLrJloYLaKY= 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 SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Fri, 30 Apr 2021 11:52:18 +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.4065.027; Fri, 30 Apr 2021 11:52:18 +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 Subject: [PATCH RFC v2 05/28] MdePkg: Add AsmPvalidate() support Date: Fri, 30 Apr 2021 06:51:25 -0500 Message-Id: <20210430115148.22267-6-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210430115148.22267-1-brijesh.singh@amd.com> References: <20210430115148.22267-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::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 SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 11:52:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c23b56a3-befe-417b-45ed-08d90bce67af X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: 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: qQw/b8318W4uylgEu/ZeqIfg9h8xnSXre/cLU9UOPpYhNP2/Hp9UduRARYxQYju8wokcilZtTJNy5MeKjikxvhto91O83GTXnMrb8zjISa1RGXwNJtRhQbCO5bJHiV8L59yYOvkqSN34FydmXG6fNMTmxrt4AiIQ3vxxz+XsklSqpSzuBadBPHBFXzNzXxV7gHTN3FnpyrPF90Q5KHLN5lL3VQIoJClTUmnb3DMBzEbhbMo6WXgZYMKWfzsVittQfVqxa1CvL4TJZuyget7CslAveRj86ZCnQS+gh7ap0JStBsgyncp2W/tsC++6lkWY4OzTemlZ9F7dFg8o0yG+UIxvSV5QXG+1aLDnPpL6KnZ9N8dq77SmbkQFNMlMBYg21G0QoOHDO572kze0ItOMuak4lhxv/Dl/06lsavw5X7MEPhnklxZz7+GDaxlL+HgfFzVaWPRvl4sN9fkkLYsvjySFb5MqEtzwsS/ZKiV5KZnuaWUgdoVXxKVeAB8t7D5Cypm/1AUFmvhLiWnIJJw1L9BN8fWdnM5Tlc0kx79A4MVIK2eQdTPWVpwRgVOOTNTwaErfDKRBjzm4eqVjTSUs+djU47z/APg46bUXAFcH6BoxDsEGsRizXHEMp9UpOAyfJDrk/cqfKpIh4ZHAlVfTz/LpN2wk5qRnkac1XUICBEDleByqxy1kHe9DBdZyDwEqudqjOYPE7WnEp8tbp6v3Q3jddcaB3yNCURml0XaMPvA= 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)(366004)(396003)(346002)(136003)(376002)(966005)(38100700002)(2616005)(26005)(1076003)(86362001)(316002)(6916009)(8936002)(6666004)(2906002)(4326008)(52116002)(66946007)(5660300002)(186003)(54906003)(44832011)(36756003)(66556008)(8676002)(66476007)(16526019)(19627235002)(83380400001)(478600001)(956004)(7696005)(38350700002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?kDP7JcRao/WPqOZFiSBoIqsFioE+UUjR5P65x9tbRRlto7IPgwexcnJnrR4X?= =?us-ascii?Q?2Wcnkvzj6yoWyAIliSPuEuSYrfxIA6D0AYuXXTxxvfs6P9ks9MJH6S1BAb42?= =?us-ascii?Q?B1Jdpuruk38SHQjapGjNOOUacIGK5SPKPdKgtSOoON1C+DC41/9IfHL2Cm8z?= =?us-ascii?Q?67I5s54GajwW5AqA1tYzsytP8Z+MwWhqFk42j5VyPJPK24H1P0108rpSEaop?= =?us-ascii?Q?mYosIHNClg1ZXZIP7uHWF+95HRmanhLjrJIPGHUVN0R7lN1sRumrMHt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XkA1SpWxJhLuSkO2iRzWPXiVFG6YlgDFKEg8P/?= =?us-ascii?Q?yZoqOdP1UE5hEvWuh/rka9z9oYqiMBsLVEM9N3ltclK/AdtjpkzUV3jBp2m2?= =?us-ascii?Q?vQaY4LxaCJuGX284hZnt07WManXjEbJHUNdxotV04dsTbG48JmMl72v1E5In?= =?us-ascii?Q?LxkEh1H2tBYVGG7PJ8NFyXpr?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c23b56a3-befe-417b-45ed-08d90bce67af X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 11:52:18.2792 (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: uS6GJEZDfZejpo4moikyITDuadjroNK149oscxx3y8DAh0GyT17GgoLx7axBzKqa61W4hWFzk7Mw0UYdxKhCPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 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 Cc: Erdem Aktas 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 7253997a6f..92ce695e93 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7518,5 +7518,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 { + PvalidatePageSize4K = 0, + PvalidatePageSize2MB, +} PVALIDATE_PAGE_SIZE; + +typedef enum { + PvalidateRetSuccess = 0, + PvalidateRetFailInput = 1, + PvalidateRetFailSizemismatch = 6, +} PVALIDATE_RET_VALUE; + +PVALIDATE_RET_VALUE +EFIAPI +AsmPvalidate ( + IN PVALIDATE_PAGE_SIZE 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 b76f3af380..d33b4a8f7d 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -321,6 +321,7 @@ X64/XGetBv.nasm X64/XSetBv.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