From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.14074.1621221964025080159 for ; Sun, 16 May 2021 20:26:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c2cLTgog; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621221963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8BdWeJBw6vfaaz6wxwGx7G22WQNd2Y+V1jXEv7LTMPM=; b=c2cLTgog9m7DtB4y3qeA9QkG85Qb7KdHW6zRkv5moZfNnI9ZeV6AWT4KgXZ8Yy+7La15uq 2W6zWSZfiYbc3adI+QuXmbyOa3Kz+Ch74A+3pZGXcv32Wayv27Okj9Gf2vmbNh68pQCpTO 3ARM2Y0ci6zRFq00C5AHxVtuocPOQs4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-50-lR9uQD4sMtClWm1XR8P59w-1; Sun, 16 May 2021 23:25:56 -0400 X-MC-Unique: lR9uQD4sMtClWm1XR8P59w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85921501F0; Mon, 17 May 2021 03:25:54 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02D9739A73; Mon, 17 May 2021 03:25:51 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v2 08/13] MdePkg/BaseLib: add support for RMPADJUST instruction To: devel@edk2.groups.io, brijesh.singh@amd.com Cc: Tom Lendacky , James Bottomley , Min Xu , Jiewen Yao , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael D Kinney , Liming Gao , Zhiguang Liu References: <20210512234615.1726-1-brijesh.singh@amd.com> <20210512234615.1726-9-brijesh.singh@amd.com> From: "Laszlo Ersek" Message-ID: Date: Mon, 17 May 2021 05:25:50 +0200 MIME-Version: 1.0 In-Reply-To: <20210512234615.1726-9-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 05/13/21 01:46, Brijesh Singh wrote: > From: Tom Lendacky > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 > > 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/BaseLib.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/BaseLib.h > index a2cd134bea9a..e8eff32716b8 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 Rax, > + Rcx, and Rdx. Returns Rax. This function is only available on X64. > + > + The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1. > + > + @param[in] Rax The value to load into RAX before executing the RMPADJUST > + instruction. > + @param[in] Rcx The value to load into RCX before executing the RMPADJUST > + instruction. > + @param[in] Rdx The value to load into RDX before executing the RMPADJUST > + instruction. > + > + @return Rax > +**/ > +UINT32 > +EFIAPI > +AsmRmpAdjust ( > + IN UINT64 Rax, > + IN UINT64 Rcx, > + IN UINT64 Rdx > + ); > #endif (1) Relative to v1, the updates are all good (thanks!), except for one: "@return Rax" is actually a regression -- "@return Eax" was correct, in my opinion. This also affects the top of the leading comment, where Eax was also replaced with Rax. My R-b stands, but please fix the docs on this function again, because now the documentation ("Rax", twice) is actually inconsistent with the return type UINT32. Thanks Laszlo > > > 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 > > +; > +; Macro for the RMPADJUST instruction, defined in AMD APM volume 3. > +; NASM feature request URL: https://bugzilla.nasm.us/show_bug.cgi?id=3392754 > +; > +%macro RMPADJUST 0 > + DB 0xF3, 0x0F, 0x01, 0xFE > +%endmacro > + > ; NASM provides built-in macros STRUC and ENDSTRUC for structure definition. > ; 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/BaseLib/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 >