public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: mikuback@linux.microsoft.com, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>
Subject: Re: [PATCH v2 4/4] UefiCpuPkg/SmmCpuFeaturesLib: Add Standalone MM support
Date: Mon, 15 Feb 2021 21:33:20 +0100	[thread overview]
Message-ID: <96e8e185-ce9e-91a4-0ce4-f98b697b48c1@redhat.com> (raw)
In-Reply-To: <20210213005806.2927-5-mikuback@linux.microsoft.com>

On 02/13/21 01:58, mikuback@linux.microsoft.com wrote:
> From: Michael Kubacki <michael.kubacki@microsoft.com>
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3218
> 
> Adds an INF for StandaloneMmCpuFeaturesLib, which supports building
> the SmmCpuFeaturesLib code for Standalone MM. Minimal code changes
> are made to allow reuse of existing code for Standalone MM.
> 
> The original INF file names are left intact (continue to use SMM
> terminology) to retain backward compatibility with platforms that
> use those INFs. Similarly, the pre-existing C file names are
> unchanged to be consistent with the INF file names.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
> ---
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c            |  2 +-
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c       |  2 +-
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c                       |  2 +-
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c   | 51 ++++++++++++++++++++
>  UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf | 38 +++++++++++++++
>  UefiCpuPkg/UefiCpuPkg.dsc                                           |  1 +
>  6 files changed, 93 insertions(+), 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> index a494988898b8..990fdb098865 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
> @@ -7,7 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
>  
> -#include <PiSmm.h>
> +#include <PiMm.h>
>  #include <Library/SmmCpuFeaturesLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/MtrrLib.h>
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> index eebbbfd00a83..5946081afbb7 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
> @@ -8,7 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
>  
> -#include <PiSmm.h>
> +#include <PiMm.h>
>  #include <Library/SmmCpuFeaturesLib.h>
>  #include "CpuFeaturesLib.h"
>  
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> index 4b6bf958cedf..cda1ab8e78de 100644
> --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
> @@ -6,7 +6,7 @@
>  
>  **/
>  
> -#include <PiSmm.h>
> +#include <PiMm.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/MemoryAllocationLib.h>

(1) Do you really need to update this header file? It's never built for
the standalone MM lib instance. (If you do it for consistency, I guess
that's OK, but then it should be mentioned in the commit message.)


> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c
> new file mode 100644
> index 000000000000..114b177e5e57
> --- /dev/null
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.c
> @@ -0,0 +1,51 @@
> +/** @file
> +Standalone MM CPU specific programming.
> +
> +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +#include <Library/PcdLib.h>
> +#include "CpuFeaturesLib.h"
> +
> +/**
> +  Gets the maximum number of logical processors from the PCD PcdCpuMaxLogicalProcessorNumber.
> +
> +  This access is abstracted from the PCD services to enforce that the PCD be
> +  FixedAtBuild in the Standalone MM build of this driver.
> +
> +  @retval  The value of PcdCpuMaxLogicalProcessorNumber.

(2) Sorry, I'm just noticing -- given that we don't provide a constant
return value here, we should use "@return", not "@retval".

(Applies to all occurrences of the GetCpuMaxLogicalProcessorNumber()
documentation.)


> +
> +
> +**/
> +UINT32
> +GetCpuMaxLogicalProcessorNumber (
> +  VOID
> +  )
> +{
> +  return FixedPcdGet32 (PcdCpuMaxLogicalProcessorNumber);
> +}
> +
> +/**
> +  The Standalone MM library constructor.
> +
> +  @param[in] ImageHandle  Image handle of this driver.
> +  @param[in] SystemTable  A Pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS     This constructor always returns success.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +StandaloneMmCpuFeaturesLibConstructor (
> +  IN EFI_HANDLE           ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  CpuFeaturesLibInitialization ();
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
> new file mode 100644
> index 000000000000..64f0a0853337
> --- /dev/null
> +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
> @@ -0,0 +1,38 @@
> +## @file
> +#  Standalone MM CPU specific programming.
> +#
> +#  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) Microsoft Corporation.<BR>
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = StandaloneMmCpuFeaturesLib
> +  MODULE_UNI_FILE                = SmmCpuFeaturesLib.uni
> +  FILE_GUID                      = BB554A2D-F5DF-41D3-8C62-46476A2B2B18
> +  MODULE_TYPE                    = MM_STANDALONE
> +  VERSION_STRING                 = 1.0
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = SmmCpuFeaturesLib
> +  CONSTRUCTOR                    = StandaloneMmCpuFeaturesLibConstructor
> +
> +[Sources]
> +  CpuFeaturesLib.h
> +  StandaloneMmCpuFeaturesLib.c
> +  SmmCpuFeaturesLib.c
> +  SmmCpuFeaturesLibNoStm.c

(3) Darn. I'm displeased with my previous feedback. Unfortunately, I
couldn't foresee the end result of my v1 comments, at such a distance.

With v2 applied, we build the SmmCpuFeaturesLibConstructor() function
from "SmmCpuFeaturesLibNoStm.c" for the StandaloneMmCpuFeaturesLib
instance as well -- we just never call it. It's not really clean.

The "feature map" (?) is something like this:

                   traditional,  traditional,  standalone,
                   no STM        STM           no STM

entry point type   DXE           DXE           MM

lib inst. init.    basic         STM           basic

processor init.    basic         STM           basic

PCD access         any           any           fixed

The first two properties, i.e. "entry point type" and "library instance
initialization", dictate the constructor implementation *together*. And
that suggests we need three separate files (DXE-basic, DXE-STM,
MM-basic). In other words, the SmmCpuFeaturesLibConstructor() function
should be re-added to yet another new file, in patch#2.

On the other hand, creating yet another C file with just the DXE-basic
constructor seems awkward. :( (This C file would be listed in
"SmmCpuFeaturesLib.inf", but not "StandaloneMmCpuFeaturesLib.inf".)

Any suggestions / preferences?

(I apologize again for missing this in the v1 review.)

Thanks
Laszlo


> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  MemoryAllocationLib
> +  PcdLib
> +
> +[FixedPcd]
> +  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber        ## SOMETIMES_CONSUMES
> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index 9128cef076dd..7db419471deb 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -154,6 +154,7 @@ [Components.IA32, Components.X64]
>    UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf
>    UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
>    UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
> +  UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
>    UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
>    UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
>    UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
> 


  reply	other threads:[~2021-02-15 20:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-13  0:58 [PATCH v2 0/4] UefiCpuPkg/StandaloneMmCpuFeaturesLib: Add Standalone MM support Michael Kubacki
2021-02-13  0:58 ` [PATCH v2 1/4] UefiCpuPkg/SmmCpuFeaturesLib: Move multi-instance function decl to header Michael Kubacki
2021-02-15 19:23   ` Laszlo Ersek
2021-02-13  0:58 ` [PATCH v2 2/4] UefiCpuPkg/SmmCpuFeaturesLib: Cleanup library constructors Michael Kubacki
2021-02-15 19:31   ` Laszlo Ersek
2021-02-13  0:58 ` [PATCH v2 3/4] UefiCpuPkg/SmmCpuFeaturesLib: Abstract PcdCpuMaxLogicalProcessorNumber Michael Kubacki
2021-02-15 19:35   ` Laszlo Ersek
2021-02-13  0:58 ` [PATCH v2 4/4] UefiCpuPkg/SmmCpuFeaturesLib: Add Standalone MM support Michael Kubacki
2021-02-15 20:33   ` Laszlo Ersek [this message]
2021-02-16 20:11     ` Michael Kubacki
2021-02-17 14:19       ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96e8e185-ce9e-91a4-0ce4-f98b697b48c1@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox