public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: Ray Ni <ray.ni@intel.com>, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Rahul Kumar <rahul1.kumar@intel.com>
Subject: Re: [PATCH v2 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB
Date: Wed, 17 Mar 2021 17:31:32 +0100	[thread overview]
Message-ID: <e5737486-c809-6af1-c348-08ee1bef1a00@redhat.com> (raw)
In-Reply-To: <20210317110640.489-3-ray.ni@intel.com>

On 03/17/21 12:06, Ray Ni wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3233
> 
> GDT needs to be allocated below 4GB in 64bit environment
> because AP needs it for entering to protected mode.
> CPU running in big real mode cannot access above 4GB GDT.
> 
> But CpuDxe driver contains below code:
>   gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
>   .....
>   gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;
> 
> The AllocateRuntimePool() may allocate memory above 4GB.
> Thus, we cannot use AllocateRuntimePool (), instead,
> we should use AllocatePages() to make sure GDT is below 4GB space.
> 
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Reviewed-by: Eric Dong <eric.dong@intel.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/CpuDxe/CpuGdt.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c
> index 8847bc4819..692402c55d 100644
> --- a/UefiCpuPkg/CpuDxe/CpuGdt.c
> +++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
> @@ -124,15 +124,26 @@ InitGlobalDescriptorTable (
>    VOID
>    )
>  {
> +  EFI_STATUS            Status;
>    GDT_ENTRIES           *Gdt;
>    IA32_DESCRIPTOR       Gdtr;
> +  EFI_PHYSICAL_ADDRESS  Memory;
>  
>    //
> -  // Allocate Runtime Data for the GDT
> -  //
> -  Gdt = AllocateRuntimePool (sizeof (mGdtTemplate) + 8);
> -  ASSERT (Gdt != NULL);
> -  Gdt = ALIGN_POINTER (Gdt, 8);
> +  // Allocate Runtime Data below 4GB for the GDT
> +  // AP uses the same GDT when it's waken up from real mode so
> +  // the GDT needs to be below 4GB.
> +  //
> +  Memory = SIZE_4GB - 1;
> +  Status = gBS->AllocatePages (
> +                  AllocateMaxAddress,
> +                  EfiRuntimeServicesData,
> +                  EFI_SIZE_TO_PAGES (sizeof (mGdtTemplate)),
> +                  &Memory
> +                  );
> +  ASSERT_EFI_ERROR (Status);
> +  ASSERT ((Memory != 0) && (Memory < SIZE_4GB));
> +  Gdt = (GDT_ENTRIES *) (UINTN) Memory;
>  
>    //
>    // Initialize all GDT entries
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


      reply	other threads:[~2021-03-17 16:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 11:06 [PATCH v2 0/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Ni, Ray
2021-03-17 11:06 ` [PATCH v2 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII coding standard Ni, Ray
2021-03-17 16:31   ` Laszlo Ersek
2021-03-18  0:37   ` Dong, Eric
2021-03-17 11:06 ` [PATCH v2 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Ni, Ray
2021-03-17 16:31   ` Laszlo Ersek [this message]

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=e5737486-c809-6af1-c348-08ee1bef1a00@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