From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (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 3D546210C2D92 for ; Thu, 2 Aug 2018 13:39:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4A4380D2F6B; Thu, 2 Aug 2018 20:39:00 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-123-32.rdu2.redhat.com [10.10.123.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB0E02166BA2; Thu, 2 Aug 2018 20:38:59 +0000 (UTC) To: Rafael Machado Cc: Andrew Fish , "Ni, Ruiyu" , "edk2-devel@lists.01.org" , "Yao, Jiewen" References: <74D8A39837DF1E4DA445A8C0B3885C503AC75235@shsmsx102.ccr.corp.intel.com> <734D49CCEBEEF84792F5B80ED585239D5BD4FFA1@SHSMSX104.ccr.corp.intel.com> <17C6FC15-6D2E-41A6-8996-15E665C4D28F@apple.com> <40832a91-0eca-3b9f-f533-f98666295a25@redhat.com> From: Laszlo Ersek Message-ID: <5aaec7be-37e0-39cf-8961-af7b20d14c51@redhat.com> Date: Thu, 2 Aug 2018 22:38:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 02 Aug 2018 20:39:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 02 Aug 2018 20:39:00 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: Question about memory map entries X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2018 20:39:02 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/02/18 21:18, Rafael Machado wrote: > Just found something interesting. > Based on the logs from the serial port. > > This system works fine: > > "PeiInstallPeiMemory MemoryBegin 0x93D50000, MemoryLength 0xA2B0000 > Temp Stack : BaseAddress=0x400000 Length=0x80000 > Temp Heap : BaseAddress=0x480000 Length=0x80000 > Total temporary memory: 1048576 bytes. > temporary memory stack ever used: 524288 bytes. > temporary memory heap used: 63304 bytes. > Old Stack size 524288, New stack size 524288 > Stack Hob: BaseAddress=0x93D50000 Length=0x80000 > Heap Offset = 0x93950000 Stack Offset = 0x93950000 > Loading PEIM at 0x0009DFF4000 EntryPoint=0x0009DFF4260 PeiCore.efi" > ... > "CoreInitializeMemoryServices: > BaseAddress - 0x93DE1000 Length - 0x8135000 MinimalMemorySizeNeeded - > 0x5AC0000" > > This one is bricked: > > "PeiInstallPeiMemory MemoryBegin 0x9C9000, MemoryLength 0x9D637000 > Temp Stack : BaseAddress=0x400000 Length=0x80000 > Temp Heap : BaseAddress=0x480000 Length=0x80000 > Total temporary memory: 1048576 bytes. > temporary memory stack ever used: 524288 bytes. > temporary memory heap used: 63304 bytes. > Old Stack size 524288, New stack size 524288 > Stack Hob: BaseAddress=0x9C9000 Length=0x80000 > Heap Offset = 0x5C9000 Stack Offset = 0x5C9000 > Loading PEIM at 0x0009DFF4000 EntryPoint=0x0009DFF4260 PeiCore.efi" > ... > "CoreInitializeMemoryServices: > BaseAddress - 0x0 Length - 0x0 MinimalMemorySizeNeeded - 0x98E47000 > " > ... > "ASSERT_EFI_ERROR (Status = Out of Resources) > ASSERT [DxeCore] ...\MdeModulePkg\Core\Dxe\DxeMain\DxeMain.c(299): > !EFI_ERROR (Status) > AllocatePoolPages: failed to allocate 1 pages > AllocatePool: failed to allocate 120 bytes" The location and the size of the permanent PEI RAM are extremely different between the two cases. - Functional system: PeiInstallPeiMemory MemoryBegin 0x93D50000, MemoryLength 0xA2B0000 Base address is ~2365 MB, size is ~162 MB - Unbootable system: PeiInstallPeiMemory MemoryBegin 0x9C9000, MemoryLength 0x9D637000 Base address is ~9 MB, size is ~2518 MB The numbers in the second (unbootable) case look very unusual to me. The permanent PEI RAM is usually tens or (maybe) hundreds of megabytes in size, and tends to start much higher (usually as high as possible under 4GB, on x86 anyway). Consult the following sections in the PI spec (v1.6), volume 3: - 4.3 Example HOB Producer Phase Memory Map and Usage - 5.3 PHIT HOB The CoreInitializeMemoryServices() function searches the HOB list for a tested system memory "Resource Descriptor HOB that contains PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop". (Quoted a comment from the code.) Basically, the function locates the system RAM HOB that contains the free permanent PEI RAM. If the search fails, then we trip an ASSERT(). This does not happen in your case, the search succeeds. If the search succeeds, then the DXE core will try to initialize itself in one of three locations in the RAM area defined by that HOB. In descending preference order: above the permanent PEI RAM, within the free permanent PEI RAM, and below the permanent PEI RAM. There is also a fallback (a fourth option) when even the third one from before proves too small -- the function will then search again for a memory descriptor HOB, top-down, avoiding the one HOB that it found earlier to contain the permanent PEI RAM (because, all three options for that have already failed, see above). As the result of this search, your broken system finishes with: BaseAddress - 0x0 Length - 0x0 MinimalMemorySizeNeeded - 0x98E47000 "MinimalMemorySizeNeeded" includes the previous measurements from MemoryTypeInformation, and the concrete value is very strange -- it seems to imply that you need ~2446 MB for initializing the DXE core. It's not surprising that the function cannot fit that anywhere, in either of the four options described above. If your system has more (high) RAM to spare, try to install a resource descriptor HOB for it. Then the fourth option might succeed. Honestly though, those permanent PEI RAM values (base address at ~9 MB, size ~2518 MB) look super fishy to me in the first place. Something must be wrong in the PEI phase with the calculation of those parameters. Possibly, the memory resource descriptor HOBs could be wrong too. ... Considering commit 3a05b13106d1 ("MdeModulePkg DxeCore: Take the range in resource HOB for PHIT as higher priority", 2015-09-18), it writes, "Also let the minimal memory size needed include the total memory bin size needed to make sure memory bin could be allocated successfully." This is the reason "MinimalMemorySizeNeeded" includes MemoryTypeInformation. Normally, MemoryTypeInformation tracks long-term maximums that are necessary for booting an OS without memory map fragmentation (including S4 resume). However, if you have a UEFI application that allocates huge amounts of memory, and then *doesn't* boot an OS, then it could invalidate MemoryTypeInformation. Because, the maximums that MemoryTypeInformation represents, no longer reflect requirements for booting an OS. In that case, the "MinimalMemorySizeNeeded" assumption (from commit 3a05b13106d1), for initializing the DXE core, could be invalid too. Thanks Laszlo