From: "Ni, Ray" <ray.ni@intel.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Laszlo Ersek <lersek@redhat.com>,
Rahul Kumar <rahul1.kumar@intel.com>
Subject: [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB
Date: Tue, 16 Mar 2021 11:33:50 +0800 [thread overview]
Message-ID: <20210316033350.2026-3-ray.ni@intel.com> (raw)
In-Reply-To: <20210316033350.2026-1-ray.ni@intel.com>
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
+ // 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));
+ Gdt = (GDT_ENTRIES *) (UINTN) Memory;
//
// Initialize all GDT entries
--
2.27.0.windows.1
next prev parent reply other threads:[~2021-03-16 3:34 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 ` Ni, Ray [this message]
2021-03-16 13:59 ` [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Dong, Eric
2021-03-16 16:35 ` 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=20210316033350.2026-3-ray.ni@intel.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