From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.1896.1615912524891070661 for ; Tue, 16 Mar 2021 09:35:25 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hrNmjreM; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615912524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KkdcrIr/aCExS6oOaolT7KFUMTM4KfpIchr/z6q4daE=; b=hrNmjreMkooZySCZrxfvn3iVdTarFqyL8DMdU2MCm0kNB3p/J/ynqaf56ZagFOnQ0BgWqi bJo7KrQyrIyqFdaiVoXLdNUit4CSAaT0m2RNVG3eEXrMVHOnvBz7fvs9vzbqiToZ/gYTA9 IhZOBcGAvTPdjHnPKAfWqs0d5S3vks0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-P324k2A4Mb2EFTTHIblK0A-1; Tue, 16 Mar 2021 12:35:20 -0400 X-MC-Unique: P324k2A4Mb2EFTTHIblK0A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 793071015C87; Tue, 16 Mar 2021 16:35:19 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-138.ams2.redhat.com [10.36.114.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 637BE60CCC; Tue, 16 Mar 2021 16:35:18 +0000 (UTC) Subject: Re: [PATCH 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB To: Ray Ni , devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar References: <20210316033350.2026-1-ray.ni@intel.com> <20210316033350.2026-3-ray.ni@intel.com> From: "Laszlo Ersek" Message-ID: Date: Tue, 16 Mar 2021 17:35:17 +0100 MIME-Version: 1.0 In-Reply-To: <20210316033350.2026-3-ray.ni@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 > Cc: Eric Dong > Cc: 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 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 Thanks Laszlo