public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: "Wu, Jiaxin" <jiaxin.wu@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Dong, Eric" <eric.dong@intel.com>,
	"Zeng, Star" <star.zeng@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Kumar, Rahul R" <rahul.r.kumar@intel.com>
Subject: Re: [PATCH v2 1/5] UefiCpuPkg/SecCore: Migrate page table to permanent memory
Date: Fri, 12 May 2023 06:24:02 +0000	[thread overview]
Message-ID: <MN6PR11MB8244A35B9A12081A2F2FA8A18C759@MN6PR11MB8244.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20230512041548.6416-2-jiaxin.wu@intel.com>



> -----Original Message-----
> From: Wu, Jiaxin <jiaxin.wu@intel.com>
> Sent: Friday, May 12, 2023 12:16 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Zeng, Star
> <star.zeng@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Kumar, Rahul R
> <rahul.r.kumar@intel.com>
> Subject: [PATCH v2 1/5] UefiCpuPkg/SecCore: Migrate page table to permanent
> memory
> 
> Background:
> For arch X64, system will enable the page table in SPI to cover 0-512G range
> via CR4.PAE & MSR.LME & CR0.PG & CR3 setting (see ResetVector code).
> Existing
> code doesn't cover the higher address access above 512G before memory-
> discovered
> callback. That will be potential problem if system access the higher address
> after the transition from temporary RAM to permanent MEM RAM.
> 
> Solution:
> This patch is to migrate page table to permanent memory to map entire physical
> address space if CR0.PG is set during temporary RAM Done.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Zeng Star <star.zeng@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
> ---
>  UefiCpuPkg/SecCore/SecCore.inf       |   1 +
>  UefiCpuPkg/SecCore/SecCoreNative.inf |   1 +
>  UefiCpuPkg/SecCore/SecMain.c         | 152
> +++++++++++++++++++++++++++++++++++
>  UefiCpuPkg/SecCore/SecMain.h         |   4 +
>  4 files changed, 158 insertions(+)
> 
> diff --git a/UefiCpuPkg/SecCore/SecCore.inf b/UefiCpuPkg/SecCore/SecCore.inf
> index 3758aded3b..cab69b8b97 100644
> --- a/UefiCpuPkg/SecCore/SecCore.inf
> +++ b/UefiCpuPkg/SecCore/SecCore.inf
> @@ -53,10 +53,11 @@
>    CpuExceptionHandlerLib
>    ReportStatusCodeLib
>    PeiServicesLib
>    PeiServicesTablePointerLib
>    HobLib
> +  CpuPageTableLib
> 
>  [Ppis]
>    ## SOMETIMES_CONSUMES
>    ## PRODUCES
>    gEfiSecPlatformInformationPpiGuid
> diff --git a/UefiCpuPkg/SecCore/SecCoreNative.inf
> b/UefiCpuPkg/SecCore/SecCoreNative.inf
> index 1ee6ff7d88..fa241cca94 100644
> --- a/UefiCpuPkg/SecCore/SecCoreNative.inf
> +++ b/UefiCpuPkg/SecCore/SecCoreNative.inf
> @@ -50,10 +50,11 @@
>    CpuExceptionHandlerLib
>    ReportStatusCodeLib
>    PeiServicesLib
>    PeiServicesTablePointerLib
>    HobLib
> +  CpuPageTableLib
> 
>  [Ppis]
>    ## SOMETIMES_CONSUMES
>    ## PRODUCES
>    gEfiSecPlatformInformationPpiGuid
> diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c
> index 95375850ec..8ec0b654fb 100644
> --- a/UefiCpuPkg/SecCore/SecMain.c
> +++ b/UefiCpuPkg/SecCore/SecMain.c
> @@ -70,10 +70,139 @@ MigrateGdt (
>    AsmWriteGdtr (&Gdtr);
> 
>    return EFI_SUCCESS;
>  }
> 
> +/**
> +  Migrate page table to permanent memory mapping entire physical address
> space.
> +
> +  @retval   EFI_SUCCESS           The PageTable was migrated successfully.
> +  @retval   EFI_UNSUPPORTED       Unsupport to migrate page table to
> permanent memory if IA-32e Mode not actived.
> +  @retval   EFI_OUT_OF_RESOURCES  The PageTable could not be migrated due
> to lack of available memory.
> +
> +**/
> +EFI_STATUS
> +MigratePageTable (
> +  VOID
> +  )
> +{
> +  EFI_STATUS                      Status;
> +  IA32_CR4                        Cr4;
> +  BOOLEAN                         Page5LevelSupport;
> +  UINT32                          RegEax;
> +  CPUID_EXTENDED_CPU_SIG_EDX      RegEdx;
> +  BOOLEAN                         Page1GSupport;
> +  PAGING_MODE                     PagingMode;
> +  CPUID_VIR_PHY_ADDRESS_SIZE_EAX  VirPhyAddressSize;
> +  UINT32                          MaxExtendedFunctionId;
> +  UINTN                           PageTable;
> +  EFI_PHYSICAL_ADDRESS            Buffer;
> +  UINTN                           BufferSize;
> +  IA32_MAP_ATTRIBUTE              MapAttribute;
> +  IA32_MAP_ATTRIBUTE              MapMask;
> +
> +  VirPhyAddressSize.Uint32    = 0;
> +  PageTable                   = 0;
> +  BufferSize                  = 0;
> +  MapAttribute.Uint64         = 0;
> +  MapMask.Uint64              = MAX_UINT64;
> +  MapAttribute.Bits.Present   = 1;
> +  MapAttribute.Bits.ReadWrite = 1;
> +
> +  //
> +  // Check Page5Level Support or not.
> +  //
> +  Cr4.UintN         = AsmReadCr4 ();
> +  Page5LevelSupport = (Cr4.Bits.LA57 ? TRUE : FALSE);

1. "Cr4.Bits.LA57 != 0", to be consistent with other code in your patch.

> +
> +  //
> +  // Check Page1G Support or not.
> +  //
> +  Page1GSupport = FALSE;
> +  AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);
> +  if (RegEax >= CPUID_EXTENDED_CPU_SIG) {
> +    AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL,
> &(RegEdx.Uint32));

2. &RegEdx.Uint32. No need for the bracket.

> +    if ((RegEdx.Bits.Page1GB) != 0) {
3. No need for the bracket.

> +  //
> +  Cr0.UintN = AsmReadCr0 ();
> +  if (Cr0.Bits.PG != 0) {
> +    //
> +    // CR4.PAE must be enabled.
> +    //
> +    ASSERT ((AsmReadCr4 () & BIT5) != 0);

4. No need to check PAE bit because 64bit long mode should set PAE bit.

> +
> +    //
> +    // Assume CPU runs in 64bit mode if paging is enabled.
> +    //
> +    ASSERT (sizeof (UINTN) == sizeof (UINT64));
> +
> +    Status = MigratePageTable ();
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_WARN, "SecTemporaryRamDone: Failed to migrate page
> table to permanent memory: %r.\n", Status));
> +      ASSERT_EFI_ERROR (Status);

5. Can you add CpuDeadLoop ()? Failure of page table migration is unacceptable.


  reply	other threads:[~2023-05-12  6:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12  4:15 [PATCH v2 0/5] Target to enable paging from temporary RAM Done Wu, Jiaxin
2023-05-12  4:15 ` [PATCH v2 1/5] UefiCpuPkg/SecCore: Migrate page table to permanent memory Wu, Jiaxin
2023-05-12  6:24   ` Ni, Ray [this message]
2023-05-12  4:15 ` [PATCH v2 2/5] UefiCpuPkg/CpuMpPei: Enable PAE page table if CR0.PG is not set Wu, Jiaxin
2023-05-12  6:37   ` [edk2-devel] " Ni, Ray
2023-05-12  4:15 ` [PATCH v2 3/5] MdeModulePkg/DxeIpl: Align Page table Level setting with previous level Wu, Jiaxin
2023-05-12  6:40   ` Ni, Ray
2023-05-12  4:15 ` [PATCH v2 4/5] OvmfPkg: Add CpuPageTableLib required by SecCore & CpuMpPei Wu, Jiaxin
2023-05-12  4:15 ` [PATCH v2 5/5] UefiPayloadPkg: " Wu, Jiaxin

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=MN6PR11MB8244A35B9A12081A2F2FA8A18C759@MN6PR11MB8244.namprd11.prod.outlook.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