From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=17.151.62.66; helo=nwk-aaemail-lapp01.apple.com; envelope-from=afish@apple.com; receiver=edk2-devel@lists.01.org Received: from nwk-aaemail-lapp01.apple.com (nwk-aaemail-lapp01.apple.com [17.151.62.66]) (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 4927D211D675B for ; Mon, 11 Mar 2019 08:59:16 -0700 (PDT) Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id x2BFq7vG008592; Mon, 11 Mar 2019 08:59:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=mime-version : content-type : sender : from : message-id : subject : date : in-reply-to : cc : to : references; s=20180706; bh=rzTWgPLoQAmVVUCG6eyPIBat3TDbJ95yY9tIz4J9HJ4=; b=jjjds3rKoJLxeY7i3dFDfMDw+uIV+zcZcy7ioxR+Nvj1DLDNtKX/cEgcyppF4FijDKQT dTEqbW452s1wHQAEko0X7eYmj6bb6DrfVwSNdtHgpkdXPonM1k8OkkAn40Ew/YilFfbB t7SPYXgaUHuL5Od/HxAOgpT2i40WMxczFWuVtF5eGhIf6wtPPrAhqqzh+coHfdbNGMNd onjXPtUi7e83KWl7gaGGfRB+pmkw9q99aRqqAY5Sp5F1vIC/vxu7MNcxm4tuO39t+BDJ J6BXHhcMMQlxy6K0CAViFDDsfBZFwirmoawGFFKpoxfq/kzh1VPFq0KNTWgo2DaBxztV FA== Received: from ma1-mtap-s01.corp.apple.com (ma1-mtap-s01.corp.apple.com [17.40.76.5]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2r4da7fyes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 11 Mar 2019 08:59:15 -0700 MIME-version: 1.0 Received: from ma1-mmpp-sz10.apple.com (ma1-mmpp-sz10.apple.com [17.171.128.150]) by ma1-mtap-s01.corp.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) with ESMTPS id <0PO700BXWLQQ7K20@ma1-mtap-s01.corp.apple.com>; Mon, 11 Mar 2019 08:59:15 -0700 (PDT) Received: from process_milters-daemon.ma1-mmpp-sz10.apple.com by ma1-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) id <0PO700C00LIOOF00@ma1-mmpp-sz10.apple.com>; Mon, 11 Mar 2019 08:59:14 -0700 (PDT) X-Va-A: X-Va-T-CD: 81ca60fce39c2560b6c4a7e5841f9b8f X-Va-E-CD: 4a87056218bf70415eb744810156915e X-Va-R-CD: e30b436eaaf3a02eee625f8c32ed8927 X-Va-CD: 0 X-Va-ID: a6e93665-1151-4b8d-9c52-d899c3bf0e34 X-V-A: X-V-T-CD: 81ca60fce39c2560b6c4a7e5841f9b8f X-V-E-CD: 4a87056218bf70415eb744810156915e X-V-R-CD: e30b436eaaf3a02eee625f8c32ed8927 X-V-CD: 0 X-V-ID: c8263085-1af5-4766-92b6-c44669f73051 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-11_12:,, signatures=0 Received: from [17.234.186.230] (unknown [17.234.186.230]) by ma1-mmpp-sz10.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) with ESMTPSA id <0PO700MZELQHK010@ma1-mmpp-sz10.apple.com>; Mon, 11 Mar 2019 08:59:09 -0700 (PDT) Sender: afish@apple.com From: Andrew Fish Message-id: <2477C2FC-463E-46C2-AA99-522350B3A8E9@apple.com> Date: Mon, 11 Mar 2019 08:59:03 -0700 In-reply-to: <026A6544-28E8-427A-8C69-EE58B5C5639E@apple.com> Cc: edk2-devel , Laszlo Ersek To: "Yao, Jiewen" References: <96DCE1C9-B02B-4520-A483-F72BBAAAB3B8@apple.com> <480fe32f-032e-0bf8-a561-c41a16213b82@redhat.com> <74D8A39837DF1E4DA445A8C0B3885C503F55C19B@shsmsx102.ccr.corp.intel.com> <656e8ae9-7163-6993-592e-75fa6b1c768d@redhat.com> <026A6544-28E8-427A-8C69-EE58B5C5639E@apple.com> X-Mailer: Apple Mail (2.3445.6.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-11_12:, , signatures=0 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Mon, 11 Mar 2019 15:59:16 -0000 Content-Type: text/plain; CHARSET=US-ASCII Content-Transfer-Encoding: 7BIT Jiewen, These three fixes got me past the CpuDxe driver: https://bugzilla.tianocore.org/show_bug.cgi?id=1613 Now I getting page faults loading SMM.... Thanks, Andrew Fish > On Mar 8, 2019, at 7:10 PM, Andrew Fish wrote: > > > >> On Mar 8, 2019, at 7:08 AM, Laszlo Ersek > wrote: >> >> 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. > > Jiewen, > > It looks like there are several places that assume memory is < 4 GB in the CpuDxe driver. > > I noticed SetCodeSelector () is using a far jump to change the CS at that is limited < 4 GB. I had to hack around it via: > popq %rax > pushq %rcx > pushq %rax > lretq > > There is some other crash later on. > > >>> 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) >> > > If I'm remembering correctly there are optional idle states for the AP. I think the real mode hlt loop might have used too much power on an UP OS. > > It is also not clear to me that we don't need the GDT when in real mode. In big-real mode you go to protected mode set the GDT and then it can get used for big-real so it seems like the GDT is in play even in real mode. > > Thanks, > > Andrew Fish > > >> 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