From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com []) by mx.groups.io with SMTP id smtpd.web10.4830.1615979210659892135 for ; Wed, 17 Mar 2021 04:06:52 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: ray.ni@intel.com) IronPort-SDR: JoRJja70u2IesQDwX9tOd42+PytivuNcJ3HcdSRMymCcVw4m/Wup9XlygtKO+ybDTmRmsYPf7t QM8sMbUkT9Mg== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="250798773" X-IronPort-AV: E=Sophos;i="5.81,256,1610438400"; d="scan'208";a="250798773" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 04:06:52 -0700 IronPort-SDR: gMI7Dy0MA1ndoK7XmQs3iw/gdei9QTr7kbBzxRZ4D6yF8hIXp/ni7fSVjr3ZHwIgwsqyZvQtEE zD7cbw4TcYTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,256,1610438400"; d="scan'208";a="379244623" Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by fmsmga007.fm.intel.com with ESMTP; 17 Mar 2021 04:06:50 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB Date: Wed, 17 Mar 2021 19:06:40 +0800 Message-Id: <20210317110640.489-3-ray.ni@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20210317110640.489-1-ray.ni@intel.com> References: <20210317110640.489-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3233 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 =3D AllocateRuntimePool (sizeof (GdtTemplate) + 8); ..... gdtPtr.Base =3D (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 Reviewed-by: Eric Dong Reviewed-by: Laszlo Ersek Cc: Rahul Kumar --- 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=0D )=0D {=0D + EFI_STATUS Status;=0D GDT_ENTRIES *Gdt;=0D IA32_DESCRIPTOR Gdtr;=0D + EFI_PHYSICAL_ADDRESS Memory;=0D =0D //=0D - // Allocate Runtime Data for the GDT=0D - //=0D - Gdt =3D AllocateRuntimePool (sizeof (mGdtTemplate) + 8);=0D - ASSERT (Gdt !=3D NULL);=0D - Gdt =3D ALIGN_POINTER (Gdt, 8);=0D + // Allocate Runtime Data below 4GB for the GDT=0D + // AP uses the same GDT when it's waken up from real mode so=0D + // the GDT needs to be below 4GB.=0D + //=0D + Memory =3D SIZE_4GB - 1;=0D + Status =3D gBS->AllocatePages (=0D + AllocateMaxAddress,=0D + EfiRuntimeServicesData,=0D + EFI_SIZE_TO_PAGES (sizeof (mGdtTemplate)),=0D + &Memory=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D + ASSERT ((Memory !=3D 0) && (Memory < SIZE_4GB));=0D + Gdt =3D (GDT_ENTRIES *) (UINTN) Memory;=0D =0D //=0D // Initialize all GDT entries=0D --=20 2.27.0.windows.1