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 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB
Date: Tue, 16 Mar 2021 17:35:17 +0100	[thread overview]
Message-ID: <d3ec5ea0-64e7-112b-c3da-23dc14705fe5@redhat.com> (raw)
In-Reply-To: <20210316033350.2026-3-ray.ni@intel.com>

On 03/16/21 04:33, 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>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: 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 322ce87142..98d5551702 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 (gGdtTemplate) + 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

(1) s/waken/woken/

> +  // the GDT needs to be below 4GB.
> +  //
> +  Memory = SIZE_4GB - 1;
> +  Status = gBS->AllocatePages (
> +                  AllocateMaxAddress,
> +                  EfiRuntimeServicesData,
> +                  EFI_SIZE_TO_PAGES (sizeof (gGdtTemplate)),
> +                  &Memory
> +                  );
> +  ASSERT_EFI_ERROR (Status);
> +  ASSERT ((Memory != 0) && (Memory < SIZE_4GB));

(2) Can we drop the (Memory < SIZE_4GB) sub-condition? That should be
guaranteed by the UEFI spec.

> +  Gdt = (GDT_ENTRIES *) (UINTN) Memory;
>  
>    //
>    // Initialize all GDT entries
> 

Anyway...

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

Thanks
Laszlo


      parent reply	other threads:[~2021-03-16 16:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16  3:33 [PATCH 0/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Ni, Ray
2021-03-16  3:33 ` [PATCH 1/2] UefiCpuPkg/CpuDxe: Rename variables to follow EDKII coding standard Ni, Ray
2021-03-16 13:58   ` Dong, Eric
2021-03-16 16:30   ` Laszlo Ersek
2021-03-17  2:47     ` Ni, Ray
2021-03-16  3:33 ` [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Ni, Ray
2021-03-16 13:59   ` Dong, Eric
2021-03-16 16:35   ` 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=d3ec5ea0-64e7-112b-c3da-23dc14705fe5@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