From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.8292.1614785642637723183 for ; Wed, 03 Mar 2021 07:34:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cJEt6hnH; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614785641; 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=7BgaMxrNtRM6ZxD4yE1vQJ5awpoU15H3x56ioNgs1nw=; b=cJEt6hnHngmp1rH81YFAkzIRi/x3CPE8uy4YJFD8CNFpVT980TZQMryjIj2/6fQ6IT9k2c P72NJNlH5H6XPXHtVcw86GtRaDajIiPJgyAcCaVaGBeQ5mFHOp37C6oOurskh8x4TiIHX0 SOYvyB3pjZza6z4BR/iIB1ptoyWy3GM= 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-344-Y-OXiMv2Mo-MwOFHQmfqYg-1; Wed, 03 Mar 2021 10:33:57 -0500 X-MC-Unique: Y-OXiMv2Mo-MwOFHQmfqYg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D4A2189C440; Wed, 3 Mar 2021 15:33:56 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-245.ams2.redhat.com [10.36.113.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE1D60BFA; Wed, 3 Mar 2021 15:33:53 +0000 (UTC) Subject: Re: [PATCH v4 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance To: Kun Qin , devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Hao A Wu , Jiewen Yao References: <20210302200438.1901-1-kun.q@outlook.com> From: "Laszlo Ersek" Message-ID: <5e239d7d-9639-42ab-26ea-4bd2273d556c@redhat.com> Date: Wed, 3 Mar 2021 16:33:52 +0100 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 03/02/21 21:04, Kun Qin wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 > > This interface provides an abstration layer to allow MM modules to access > requested areas that are outside of MMRAM. On MM model that blocks all > non-MMRAM accesses, areas requested through this API will be mapped or > unblocked for accessibility inside MM environment. > > For MM modules that need to access regions outside of MMRAMs, the agents > that set up these regions are responsible for invoking this API in order > for these memory areas to be accessible from inside MM. > > Example usages: > 1. To enable runtime cache feature for variable service, Variable MM > module will need to access the allocated runtime buffer. Thus the agent > sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this > API to make these regions accessible by Variable MM. > 2. For TPM ACPI table to communicate to physical presence handler, the > corresponding NVS region has to be accessible from inside MM. Once the > NVS region are assigned, it needs to be unblocked thourgh this API. > > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Hao A Wu > Cc: Jiewen Yao > Cc: Laszlo Ersek > > Signed-off-by: Kun Qin > --- > > Notes: > v4: > - Added more commit message [Laszlo] The commit message looks great, thanks for that. However, I notice the only "RETURN_xxx" macro in the patch is the "RETURN_UNSUPPORTED" return code, in the Null library instance. My point was that the *interface* should be downgraded to RETURN_xxx (that is, the lib class header -- the EFI_STATUS return type should be RETURN_STATUS; the documented @retval codes should all be RETURN_xxx, and so on). An example here is the PcdLib class. It uses the RETURN_STATUS return type, and documents the RETURN_INVALID_PARAMETER retval in some spots. And then edk2 provides several lib instances: - MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf - MdePkg/Library/PeiPcdLib/PeiPcdLib.inf - MdePkg/Library/DxePcdLib/DxePcdLib.inf The first of these is "BASE" (with no particular module type restriction), the 2nd is "PEIM" (with PEIM PEI_CORE SEC restrictions), and the 3rd is "DXE_DRIVER" (restricted to all the remaining module types). Every instance uses RETURN_xxx just fine. ... In case I'm wrong, please correct me, of course. Yet another comment: I'm just noticing that "@return" is used with actual constants. That's wrong, "@retval" needs to be used for constants; "@return" is only suitable if you provide a natural language description without a constant. Example: @retval TRUE It is currently raining. @retval FALSE It is currently not raining. vs. @return Whether it's currently raining or not. Thanks! Laszlo > - Added UNI file [Hao] > > v3: > - Move interface to MdePkg [Hao, Liming, Jiewen] > - Remove Dxe prefix [Jiewen] > > v2: > - Resend with practical usage. No change [Hao] > > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ > MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ > MdePkg/MdePkg.dec | 5 +++ > MdePkg/MdePkg.dsc | 1 + > 6 files changed, 149 insertions(+) > > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c > new file mode 100644 > index 000000000000..abdce41f10d1 > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c > @@ -0,0 +1,44 @@ > +/** @file > + Null instance of MM Unblock Page Library. > + > + This library provides an interface to request non-MMRAM pages to be mapped/unblocked > + from inside MM environment. > + > + For MM modules that need to access regions outside of MMRAMs, the agents that set up > + these regions are responsible for invoking this API in order for these memory areas > + to be accessed from inside MM. > + > + Copyright (c) Microsoft Corporation. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > + > +/** > + This API provides a way to unblock certain data pages to be accessible inside MM environment. > + > + @param UnblockAddress The address of buffer caller requests to unblock, the address > + has to be page aligned. > + @param NumberOfPages The number of pages requested to be unblocked from MM > + environment. > + > + @return EFI_SUCCESS The request goes through successfully. > + @return EFI_NOT_AVAILABLE_YET The requested functionality is not produced yet. > + @return EFI_UNSUPPORTED The requested functionality is not supported on current platform. > + @return EFI_SECURITY_VIOLATION The requested address failed to pass security check for > + unblocking. > + @return EFI_INVALID_PARAMETER Input address either NULL pointer or not page aligned. > + @return EFI_ACCESS_DENIED The request is rejected due to system has passed certain boot > + phase. > + > +**/ > +EFI_STATUS > +EFIAPI > +MmUnblockMemoryRequest ( > + IN EFI_PHYSICAL_ADDRESS UnblockAddress, > + IN UINT64 NumberOfPages > + ) > +{ > + return RETURN_UNSUPPORTED; > +} > diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h > new file mode 100644 > index 000000000000..980afe9a5fd3 > --- /dev/null > +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h > @@ -0,0 +1,44 @@ > +/** @file > + MM Unblock Memory Library Interface. > + > + This library provides an interface to request non-MMRAM pages to be mapped/unblocked > + from inside MM environment. > + > + For MM modules that need to access regions outside of MMRAMs, the agents that set up > + these regions are responsible for invoking this API in order for these memory areas > + to be accessed from inside MM. > + > + Copyright (c) Microsoft Corporation. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ > +#define MM_UNBLOCK_MEMORY_LIB_H_ > + > +/** > + This API provides a way to unblock certain data pages to be accessible inside MM environment. > + > + @param UnblockAddress The address of buffer caller requests to unblock, the address > + has to be page aligned. > + @param NumberOfPages The number of pages requested to be unblocked from MM > + environment. > + > + @return EFI_SUCCESS The request goes through successfully. > + @return EFI_NOT_AVAILABLE_YET The requested functionality is not produced yet. > + @return EFI_UNSUPPORTED The requested functionality is not supported on current platform. > + @return EFI_SECURITY_VIOLATION The requested address failed to pass security check for > + unblocking. > + @return EFI_INVALID_PARAMETER Input address either NULL pointer or not page aligned. > + @return EFI_ACCESS_DENIED The request is rejected due to system has passed certain boot > + phase. > + > +**/ > +EFI_STATUS > +EFIAPI > +MmUnblockMemoryRequest ( > + IN EFI_PHYSICAL_ADDRESS UnblockAddress, > + IN UINT64 NumberOfPages > +); > + > +#endif // MM_UNBLOCK_MEMORY_LIB_H_ > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > new file mode 100644 > index 000000000000..8ecb767ff7bd > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > @@ -0,0 +1,34 @@ > +## @file > +# Null instance of MM Unblock Page Library. > +# > +# This library provides an interface to request non-MMRAM pages to be mapped/unblocked > +# from inside MM environment. > +# > +# For MM modules that need to access regions outside of MMRAMs, the agents that set up > +# these regions are responsible for invoking this API in order for these memory areas > +# to be accessed from inside MM. > +# > +# Copyright (c) Microsoft Corporation. > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = MmUnblockMemoryLibNull > + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni > + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = MmUnblockMemoryLib > + > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources] > + MmUnblockMemoryLibNull.c > + > +[Packages] > + MdePkg/MdePkg.dec > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni > new file mode 100644 > index 000000000000..d7f2709a3dce > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni > @@ -0,0 +1,21 @@ > +// /** @file > +// Null instance of MM Unblock Page Library. > +// > +// This library provides an interface to request non-MMRAM pages to be mapped/unblocked > +// from inside MM environment. > +// > +// For MM modules that need to access regions outside of MMRAMs, the agents that set up > +// these regions are responsible for invoking this API in order for these memory areas > +// to be accessed from inside MM. > +// > +// Copyright (c) Microsoft Corporation. > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." > + > +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" > + "For MM modules that need to access regions outside of MMRAMs, the agents that set up these regions are responsible for invoking this API in order for these memory areas to be accessed from inside MM." > + > diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec > index 3928db65d188..32a9e009c813 100644 > --- a/MdePkg/MdePkg.dec > +++ b/MdePkg/MdePkg.dec > @@ -257,6 +257,11 @@ [LibraryClasses] > # > UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h > > + ## @libraryclass This library provides an interface for DXE drivers to request MM environment > + # to map/unblock a memory region for accessibility inside MM. > + # > + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h > + > [LibraryClasses.IA32, LibraryClasses.X64] > ## @libraryclass Abstracts both S/W SMI generation and detection. > ## > diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc > index ce009086815f..79629e3f93ba 100644 > --- a/MdePkg/MdePkg.dsc > +++ b/MdePkg/MdePkg.dsc > @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] > MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf > MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf > MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf > + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > > [Components.EBC] > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf >