From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.74]) by mx.groups.io with SMTP id smtpd.web09.15906.1621448415547919253 for ; Wed, 19 May 2021 11:20:15 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=4s6r2I3E; 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.243.74, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HfqmhLVquM+PFVMt4gP7FPV6gxoVTCIS+v49NkZPkzgbna9nGuiTDSo+rEUMi+LZk4DGOHzFheyCssshO9Nbnz3ZjQ1Hd5DYfE7A2q5W4JMCZpzKUbMutSgowfLg1Zo4cnNo5LJFuQFVbm9ImiO/kfLiGMm3TsLc6e+l0pkS2R1mGwdykLMKI9lYK50GJvl/5FR4NSl7if9zwZZ3gkyK24VKokl6/vwsN/H1vH08VBf23LAUFRnfIEydXNbjRA0hJnXyJiN7Cr3cFpEBD9QMl9ocCkLL0hTgonVaGspMjC6idVok6NB4J97DAtxQnjtboBfQwGdlIIL8AkcvpoUMBQ== 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=1tvYEFOwi8/ZqSrzInCjgbQLT+kzDJGBR9yEjpijtsk=; b=YdXZSVnsvY5Ja4RjKfvg/STskrcTboBQ8VsHN+mHw74jqrNO0muHM6HQKrN+5fng6l7y1D1sFbd71LqdNxUQhw9o6dY2hmmnETTppKMw91ZBUijSfkOJZ071s7fwW7EdEXb39P9GafW/+K+yJta8qyVJjhehYDli7yjxmldX2G3NEW9iN7kPIXfTh6Bd3/fhGE8GqFOEhGeeNIZlfFawMwEyBOmO9CwpDKkltu1JWJYuKszPfUFUMK4+FDvAXUL88BeOfTB8vA9WZFqU9mJxF1co9mDuogc0SdomxyZClwXwFdmpapTjVWCnTHwlfkMHuZom19fqRTQBxt/uTYszqA== 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=1tvYEFOwi8/ZqSrzInCjgbQLT+kzDJGBR9yEjpijtsk=; b=4s6r2I3EUcis0tbmqXMt9mrxvJtyDWEiNBkDRvIq8qVaRY3wrAYA5FctLN3OO8C45/uPjxS4Afsop/VWj+Sh+hmSZyoPKSjyCbJqMB43JMHR8GHLFspeaLMGsOB7ppXF/ieSaPU8xZjQUOYN4o6KmAl1P9uDZwJu86hyqq7x5og= 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 SN1PR12MB2413.namprd12.prod.outlook.com (2603:10b6:802:2b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Wed, 19 May 2021 18:20:11 +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.4129.032; Wed, 19 May 2021 18:20:11 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: Tom Lendacky , James Bottomley , Min Xu , Jiewen Yao , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Michael D Kinney , Liming Gao , Zhiguang Liu , Brijesh Singh Subject: [PATCH v3 08/13] MdePkg/BaseLib: add support for RMPADJUST instruction Date: Wed, 19 May 2021 13:19:44 -0500 Message-ID: <20210519181949.6574-9-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210519181949.6574-1-brijesh.singh@amd.com> References: <20210519181949.6574-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0212.namprd04.prod.outlook.com (2603:10b6:806:127::7) 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 SN7PR04CA0212.namprd04.prod.outlook.com (2603:10b6:806:127::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25 via Frontend Transport; Wed, 19 May 2021 18:20:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3ae180c7-6ee6-4953-a157-08d91af2bd99 X-MS-TrafficTypeDiagnostic: SN1PR12MB2413: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uGb2ypqj1r1SyGjiBfM7x0CSBPRUP0bTax2pfDBR+YXmMEtQ/cJEQvlnp8FeYS04BBl09clRYYgyzEL2X3UUXEWxetqF7j3j7EMcbeveSfD9ow+RBHI8AmpBVISSJsaL4gy4hLyKlr3ahcpE3mrV7BaJqc2GqYp7FU0Jji0fkRcrshSjtDq8wIKHx/q+xC8Lz6GPWqERpoCQP0QqbjqlSdoLnLO6Pmyyvz74IdZKEd+GyPAYyKeGhlg4kbCaH3FXPLPbYZ4VLnk++66KckNHegSSzbE9uXapyJ2LHsaYloSXnTkCJ2rtIuOHccPva+D9jZsf0ge4kw49FFWHscHI8zQ3GNIgBwsoztD1j224ecI9tR66kLyIxVpOgPjdRUGsTmomYc3AcphDpTC9+SdeHS1EWLJba0hG1/gmzzXXOK5zcG8dD6YvPOlObUUqazEwPMEWuXw7x2sx/+Fd2TWd/BXTZTfyeZ5cDqHnuz9nTYI1E+7BVTsDMrVZSwoWN9WpAO29A5A0Q2sbpNlvA8iruus4qrXT+Yaajpl9c2YfJDyi3KkSgyMnIx5jwgibS5NK6Da8ApFCcOEUSyJwovWfd6cZD6srOULIR0alnD+LxfBOYLDLRqwTb9yc9QXTH1zCbGkDkYyXiSb0+kWnpDJRkKLkv3QWrsnRFQ+oltHtE3vhIP4hm9tmUtA07Wx6f3l+R3on0dGLDOJ5vACb5MpRmf7fDyVIcngcf75UBgXXXW4= 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)(346002)(39860400002)(136003)(44832011)(1076003)(54906003)(8936002)(19627235002)(8676002)(26005)(186003)(316002)(6916009)(5660300002)(38100700002)(16526019)(38350700002)(2906002)(83380400001)(956004)(2616005)(7696005)(52116002)(7416002)(6486002)(66556008)(86362001)(36756003)(6666004)(4326008)(966005)(66946007)(66476007)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?s2Qz0j/74roQ5odGQc1ZPABRcG0kD9nDntrzxCeT0QsBiJNxIBtiSkYtUK3K?= =?us-ascii?Q?xZpbb4eL11Et++56Pc3SCJOHmamrVv42V3YKjd9cx8DFC26BaAX4TvcAtTpu?= =?us-ascii?Q?tP//8EDUXT409XAETnE1Kw760hDIuk88CT3OWXlEBKSMyqHQGHjOX/EypEO2?= =?us-ascii?Q?OYpsfoyVS9DTv8z8fEsJHKslcXdzcjvAxGJHUsozBSHTYRXQi6LJ/Sk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blc09tLLb0CUvk0YbpHyGbwXF?= =?us-ascii?Q?9R+YK7KrPvT0+yNdAVe/d/xkxcjqPK8RwRfRVzB/zuhVEWETc6YAhNhEEFgB?= =?us-ascii?Q?8dQLNuQnFJu6+UB14FOCGgR21VYW2q8Lr5P/DPDk5q8+9LAaC6Wjihb6SUOu?= =?us-ascii?Q?QaVRslWFMPYO4iZB4WQoTh5QExhB0Dtf0DdeFW6Wr1DboMTX9+FCGDjdy4u1?= =?us-ascii?Q?LIF0n0x0vhu83VsnY/UyIRtH?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ae180c7-6ee6-4953-a157-08d91af2bd99 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2021 18:20:11.6005 (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: UmxuDPlSvObrMCpqoIUP+ciPVZiUikqNuVQtqbdmdRXc09u5jJuZAInl/7+GEX/Bshcb8emjIugiNLADr+6V+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2413 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The RMPADJUST instruction will be used by the SEV-SNP guest to modify the RMP permissions for a guest page. See AMD APM volume 3 for further details. 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 Reviewed-by: Laszlo Ersek Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh --- MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Include/Library/BaseLib.h | 35 ++++++++++++++++++++ MdePkg/Include/X64/Nasm.inc | 8 +++++ MdePkg/Library/BaseLib/X64/RmpAdjust.nasm | 40 +++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 MdePkg/Library/BaseLib/X64/RmpAdjust.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 89a52f72c08a..6ccb8997b7e8 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -319,6 +319,7 @@ [Sources.X64] X64/DisablePaging64.nasm X64/Pvalidate.nasm X64/RdRand.nasm + X64/RmpAdjust.nasm X64/XGetBv.nasm X64/XSetBv.nasm X64/VmgExit.nasm diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index a2cd134bea9a..2452c1d92e51 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -4861,6 +4861,41 @@ AsmPvalidate ( IN BOOLEAN Validate, IN PHYSICAL_ADDRESS Address ); + +// +// RDX settings for RMPADJUST +// +#define RMPADJUST_VMPL_MAX 3 +#define RMPADJUST_VMPL_MASK 0xFF +#define RMPADJUST_VMPL_SHIFT 0 +#define RMPADJUST_PERMISSION_MASK_MASK 0xFF +#define RMPADJUST_PERMISSION_MASK_SHIFT 8 +#define RMPADJUST_VMSA_PAGE_BIT BIT16 + +/** + Adjusts the permissions of an SEV-SNP guest page. + + Executes a RMPADJUST instruction with the register state specified by Ra= x, + Rcx, and Rdx. Returns Eax. This function is only available on X64. + + The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=3D1. + + @param[in] Rax The value to load into RAX before executing the RMPADJ= UST + instruction. + @param[in] Rcx The value to load into RCX before executing the RMPADJ= UST + instruction. + @param[in] Rdx The value to load into RDX before executing the RMPADJ= UST + instruction. + + @return Eax +**/ +UINT32 +EFIAPI +AsmRmpAdjust ( + IN UINT64 Rax, + IN UINT64 Rcx, + IN UINT64 Rdx + ); #endif =20 =20 diff --git a/MdePkg/Include/X64/Nasm.inc b/MdePkg/Include/X64/Nasm.inc index 528bb3385609..cfb14edc9449 100644 --- a/MdePkg/Include/X64/Nasm.inc +++ b/MdePkg/Include/X64/Nasm.inc @@ -41,6 +41,14 @@ DB 0xF2, 0x0F, 0x01, 0xFF %endmacro =20 +; +; Macro for the RMPADJUST instruction, defined in AMD APM volume 3. +; NASM feature request URL: https://bugzilla.nasm.us/show_bug.cgi?id=3D339= 2754 +; +%macro RMPADJUST 0 + DB 0xF3, 0x0F, 0x01, 0xFE +%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/RmpAdjust.nasm b/MdePkg/Library/Bas= eLib/X64/RmpAdjust.nasm new file mode 100644 index 000000000000..c307f64b518a --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/RmpAdjust.nasm @@ -0,0 +1,40 @@ +;-------------------------------------------------------------------------= ---- +; +; Copyright (c) 2021, Advanced Micro Devices, Inc. All rights reserved. +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; RmpAdjust.Asm +; +; Abstract: +; +; AsmRmpAdjust function +; +; Notes: +; +;-------------------------------------------------------------------------= ---- + +%include "Nasm.inc" + + SECTION .text + +;-------------------------------------------------------------------------= ---- +; UINT32 +; EFIAPI +; AsmRmpAdjust ( +; IN UINT64 Rax, +; IN UINT64 Rcx, +; IN UINT64 Rdx +; ) +;-------------------------------------------------------------------------= ---- +global ASM_PFX(AsmRmpAdjust) +ASM_PFX(AsmRmpAdjust): + mov rax, rcx ; Input Rax is in RCX by calling convention + mov rcx, rdx ; Input Rcx is in RDX by calling convention + mov rdx, r8 ; Input Rdx is in R8 by calling convention + + RMPADJUST + + ; RMPADJUST returns the status in the EAX register. + ret --=20 2.17.1