From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web12.115.1615998700361382537 for ; Wed, 17 Mar 2021 09:31:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FErz4ihK; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615998699; 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=onPcJzpkOLhvCZQxkOv+5pBrFm/WjuWssZJhXLZWj2I=; b=FErz4ihK7oaQl04WUlyFhVimzlFQsBb5JInxLL1EbJHBUEtl/sjVW55Mw4cmb03VejNffd FE1Kqkzl9dvfE3kPpPKC/etyEKRcMONk4FqA1XPZu4+XBvbps9tlgannTbT9Qdt8ZUx3wK HoDc2E/+wbyEtPqb1uUhjzdMaEq/wyY= 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-412-G5-KxJJUM7iylA7RaIsXwA-1; Wed, 17 Mar 2021 12:31:35 -0400 X-MC-Unique: G5-KxJJUM7iylA7RaIsXwA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89BAC802B7E; Wed, 17 Mar 2021 16:31:34 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-112.ams2.redhat.com [10.36.113.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9904219C66; Wed, 17 Mar 2021 16:31:33 +0000 (UTC) Subject: Re: [PATCH v2 2/2] UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB To: Ray Ni , devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar References: <20210317110640.489-1-ray.ni@intel.com> <20210317110640.489-3-ray.ni@intel.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 17 Mar 2021 17:31:32 +0100 MIME-Version: 1.0 In-Reply-To: <20210317110640.489-3-ray.ni@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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/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 > 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 > ) > { > + 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