From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by mx.groups.io with SMTP id smtpd.web10.4038.1655962234084815273 for ; Wed, 22 Jun 2022 22:30:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CAW3LlzX; spf=pass (domain: gmail.com, ip: 209.85.166.47, mailfrom: ayushdevel1325@gmail.com) Received: by mail-io1-f47.google.com with SMTP id k15so2824390iok.5 for ; Wed, 22 Jun 2022 22:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=rOBDPK/3qedSv/s/ShdWaNRixAkCG8W9H89HJNt3TZo=; b=CAW3LlzXVRqnBVg2Qo3jw5z+5B2lVPGr6QdQxBVkpLrwp0VC6Z6iqtsccKYbI0ZS/3 yH7n3DuHbRWb9R+o72xd3jXOsxZRpCQZrOB5iKe09VoPZD09DYO1O+oMPZ/I/O76eEJd bF6tuyM5z/LuKiPictPt9TkGs+2AcqEJAK2r5L/AZC/sulShjwYUeVno1gsnLWCPIWNH omOK9A3x/FJ+SwmK5hAhSA7s7SgzbImlCKhe/R4NyD+Wft+iebz7hGqfCQ2gopBuZr4W AmZH/+WipiZX/QyBV4yPUONowjALO5kjJ+6R0VOtu4o24ycGgkdSGmBKSvdLAUzZvY4X /ppA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=rOBDPK/3qedSv/s/ShdWaNRixAkCG8W9H89HJNt3TZo=; b=SxWpps1Y+7ObEHL2XTyKMosNkwFDfsRsuaPPu9p+YX+yTKhkNltNNVP6oHm9NT9euy CwwAJU5RYLVocqIvi4sfO73pXYhr/Bb4lQIO1Neaka6TmJbIjY5E9yOdkNwQItmHbgjo 6BWis+0dEjlqM8QviX1LZJebtqy7rDYhmaia9f/MPnXIddBmjiFJZD64rFUeB2rcx7Y4 SvvsYAY4uodDt2A8nQ/8JZHqHMgr9WWnD01PBL38gxV3pWYJl7gyPjXW0ZSFPwzKEHtR i5a9sB53HQ8xm1Ng+2TF4uHmcO6tWIhbxi3JA6pmmsu2QZejnFeGRV7i5yykxu+5+ZI5 7joQ== X-Gm-Message-State: AJIora939rNLVMWsAE+VfIbWZ3XLl9p+e0AvhnDQCNR4N2gder6t4hGn NkJKgZpzm2RRoinLUHiU2uhBrKndaXJLL3hQuAz2zhtNsRQ= X-Google-Smtp-Source: AGRyM1umfR4yLURg+0G8deO28haTetdOsjOzdNd+GYRls0cVYqnEhIyJ654i5gnJngNetStRK4ROIK4v/eET0zBZq8g= X-Received: by 2002:a05:6638:168a:b0:331:9c9a:90b4 with SMTP id f10-20020a056638168a00b003319c9a90b4mr4317936jat.236.1655962233289; Wed, 22 Jun 2022 22:30:33 -0700 (PDT) MIME-Version: 1.0 References: <500949D4-FFB9-4BC1-8655-430BC788765A@apple.com> In-Reply-To: From: "Ayush Singh" Date: Thu, 23 Jun 2022 11:00:34 +0530 Message-ID: Subject: Re: [edk2-devel] Clarification of Memory management in PEI phase To: edk2-devel-groups-io , Nate DeSimone Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello everyone, Thanks for the helpful answers. After discussion with the mentors, it was decided that we should first get the Rust std to work in DXE phase. So for now, that is the goal. Once DXE is complete and there is still time left (or I can just do it after GSoC as well), then I might look into implementing std for the PEI. Yours Sincerely Ayush Singh On Thu, Jun 23, 2022 at 4:28 AM Nate DeSimone wrote: > > Hi Ayush, > > > > For your work to make Rust run in PEI I would recommend writing a generic= heap manager that uses the PEI services AllocatePage() and FreePage(). PEI= does allow you to truly free up memory but only when allocated in 4KB incr= ements. Your heap manager can allow the Rust program to go to a smaller gra= nularity. > > > > In parallel, I can see merit in the argument for adding proper heap manag= ement to PEI, but that would be a PI specification update that is way outsi= de the scope of your GSoC project and won=E2=80=99t happen fast enough for = the work you need to do this summer =F0=9F=98=8A. > > > > Thanks, > > Nate > > > > From: devel@edk2.groups.io On Behalf Of Ayush Sing= h > Sent: Thursday, June 9, 2022 10:23 PM > To: Andrew Fish > Cc: devel@edk2.groups.io > Subject: Re: [edk2-devel] Clarification of Memory management in PEI phase > > > > Thanks for the wonderful answer. > > > > Ayush Singh > > > On Thu, Jun 9 2022 at 01:26:58 PM -0700, Andrew Fish wr= ote: > > On Jun 9, 2022, at 10:28 AM, Ayush Singh wrote= : Hello everyone, Can anyone help me with understanding dynamic memory mana= gement in PEI phase? In the UEFI Platform Integration Specification, versio= n 1.7 Errata A, Section 4.6, PEI Memory services are given which include: 1= . InstallPeiMemory() > > This is basically: (*PeiServices)->InstallPeiMemory (PeiServices, MemoryB= egin, MemoryLength); This is how you tell the PEI Core the location of the = memory that will can be used in PEI. > > 2. AllocatePages() 3. AllocatePool() 4. CopyMem() 5. SetMem() 6. FreePage= s() However, no `FreePool()` service seems to be present. So how is the mem= ory allocated using `AllocatePool()` freed? > > It basically gets Freed when you transition to the DXE phase. To step bac= k for a minute I think it is important to remember that the main job of PEI= is to initialize DRAM, and deal with S3 (resuming from suspend to RAM). So= as soon as you have DRAM you are kind done and ready for the DXE IPL so yo= u can load the DXE Phase and start up EFI. Remember PEI is Pre EFI. The rea= lity is programming DRAM is complex and lots of code got written, then lots= more code got written and PEI has become large for some ports. That was ne= ver the intent. PEI is designed as a way to run C code when you code is run= ning from ROM and you don=C4=81=EF=BF=BD=EF=BF=BDt have any DRAM. For x86 n= ot having DRAM means you are using the cache as RAM. For some SoCs there is= actually an SRAM you can use. Thus the PEI memory allocation scheme is des= igned to deal with this very constrained environment. You start PEI with a = heap and stack. You can also allocate HOBs (Hand Off Blocks). A pool alloca= tion in PEI is just a HOB. See [1]. There is no way to free a HOB. So the A= llocatePool() kind of leaks into DXE too as an entry in the HOB list. But w= hen the OS called gBS->ExitBootServices() that frees all non runtime memory= back to the OS. If you look a AllocatePages/FreePages you will see Allocat= ePages creates a HOB that points to the memory region, and FreePages just m= arks that HOB as not used. That code is also in this file [1]. TL;DR there = is no pool manager in PEI. [1] https://github.com/tianocore/edk2/blob/maste= r/MdeModulePkg/Core/Pei/Memory/MemoryServices.c#L878 Thanks, Andrew Fish > > Ayush Singh > >=20