From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.5706.1621501045963404034 for ; Thu, 20 May 2021 01:57:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bSm9LVRO; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621501045; 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=X0M385clBc4N23m5t0m5EWUw2KOe9UeywoRjyKYmVq4=; b=bSm9LVROSvR4FdEycPMblv6LibXz72uY6t2P+RS+cXk6kCawOXD59OtGPn8Gk65FLal2V2 GBwHv9XQSWTYjlCRXDZTYkO+krHlzHlIv+5d0/VA+ECJMmIpuMaqpZegNnp8PQOL1R0NAB AxCoIj4i/WrjqlR213hT9s9AOIbhwFU= 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-29-BjFdn-e0MCKDoxK9tKqk6Q-1; Thu, 20 May 2021 04:57:17 -0400 X-MC-Unique: BjFdn-e0MCKDoxK9tKqk6Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF65C501E8; Thu, 20 May 2021 08:57:15 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-217.ams2.redhat.com [10.36.112.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CD1119718; Thu, 20 May 2021 08:57:12 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v3 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: <20210519181949.6574-1-brijesh.singh@amd.com> <20210519181949.6574-9-brijesh.singh@amd.com> From: "Laszlo Ersek" Message-ID: Date: Thu, 20 May 2021 10:57:11 +0200 MIME-Version: 1.0 In-Reply-To: <20210519181949.6574-9-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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/19/21 20:19, 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..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 Rax, > + Rcx, and Rdx. Returns Eax. 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 Eax Thanks for fixing the Rax/Eax typo. Laszlo > +**/ > +UINT32 > +EFIAPI > +AsmRmpAdjust ( > + IN UINT64 Rax, > + IN UINT64 Rcx, > + IN UINT64 Rdx > + ); > #endif > > > 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 >