From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B9FC8211D391D for ; Fri, 8 Mar 2019 07:08:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AC79307D779; Fri, 8 Mar 2019 15:08:12 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-179.rdu2.redhat.com [10.10.121.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9475F1001DFB; Fri, 8 Mar 2019 15:08:11 +0000 (UTC) To: "Yao, Jiewen" , Andrew Fish , edk2-devel References: <96DCE1C9-B02B-4520-A483-F72BBAAAB3B8@apple.com> <480fe32f-032e-0bf8-a561-c41a16213b82@redhat.com> <74D8A39837DF1E4DA445A8C0B3885C503F55C19B@shsmsx102.ccr.corp.intel.com> From: Laszlo Ersek Message-ID: <656e8ae9-7163-6993-592e-75fa6b1c768d@redhat.com> Date: Fri, 8 Mar 2019 16:08:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503F55C19B@shsmsx102.ccr.corp.intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 08 Mar 2019 15:08:12 +0000 (UTC) Subject: Re: UefiCpuPkg CpuDxe GDT init question? X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Mar 2019 15:08:14 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/08/19 15:13, Yao, Jiewen wrote: > I guess the historic reason is that AP and BSP share same GDT before. As such, the GDT need to be below 4G, to let AP switch from real mode to protected mode. > We don't get issue, because Runtime memory is in BIN, and most platform allocates BIN under 4G. > > Some thought: > 1) I am think we not sure if AP is using same GDT as BSP today. If yes, we need GDT under 4G, by using MaxAddress. If no, there should be no restriction for BSP GDT. The (UINT32) case should be removed for BSP. But we still AP GDT below 4G, to support wake from INIT-SIPI-SIPI. > 2) I am not sure why we need runtime memory. Do we need touch GDT at UEFI runtime? I could be confusing things *very badly*, but I vaguely remember that APs could be woken up spuriously later, and they must be able to execute code "enough" to go back to sleep. The following commits look relevant: - 7615702169b8 ("UefiCpuPkg/MpInitLib: Add AsmRelocateApLoop() assembly code", 2016-08-17) - 4d3314f69488 ("UefiCpuPkg/MpInitLib: Place APs in safe loop before hand-off to OS", 2016-08-17) - bf2786dc7900 ("UefiCpuPkg/DxeMpLib: Allocate new safe stack < 4GB", 2016-11-28) Laszlo > > > > Thank you > Yao Jiewen > > >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >> Laszlo Ersek >> Sent: Friday, March 8, 2019 12:00 AM >> To: Andrew Fish ; edk2-devel >> Subject: Re: [edk2] UefiCpuPkg CpuDxe GDT init question? >> >> Hi Andrew, >> >> On 03/07/19 23:37, Andrew Fish via edk2-devel wrote: >>> I'm trying to understand why gdtPtr.Base is casting to (UINT32)? >>> 1) gdtPtr.Base is a a UINTN >>> 2) It is legal for AllocateRuntimePool() to return an address > 4GB >>> >>> It seems like the code should just cast to (UINTN)? >>> >>> >>> >> https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/CpuDxe/CpuG >> dt.c#L151 >> >> I think you are right. >> >> I'm missing the background on this too. I tried to see if any >> justification was given in a git commit message, but according to "git >> blame", this code dates back to the original addition of the driver, >> namely commit a47463f28382 ("Add CPU DXE driver for IA32 & X64 >> processor >> architectures.", 2009-05-27). The commit message is unhelpful (for 3119 >> lines added). >> >> Thanks >> Laszlo >> >>> >>> >>> >>> VOID >>> InitGlobalDescriptorTable ( >>> VOID >>> ) >>> { >>> GDT_ENTRIES *gdt; >>> IA32_DESCRIPTOR gdtPtr; >>> >>> // >>> // Allocate Runtime Data for the GDT >>> // >>> gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8); >>> ASSERT (gdt != NULL); >>> gdt = ALIGN_POINTER (gdt, 8); >>> >>> // >>> // Initialize all GDT entries >>> // >>> CopyMem (gdt, &GdtTemplate, sizeof (GdtTemplate)); >>> >>> // >>> // Write GDT register >>> // >>> gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt; >>> gdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 1); >>> AsmWriteGdtr (&gdtPtr); >>> >>> Thanks, >>> >>> Andrew Fish >>> _______________________________________________ >>> edk2-devel mailing list >>> edk2-devel@lists.01.org >>> https://lists.01.org/mailman/listinfo/edk2-devel >>> >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel