public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Laszlo Ersek <lersek@redhat.com>
Cc: edk2-devel-01 <edk2-devel@ml01.01.org>
Subject: Re: [QUESTION] reservation of pool allocations performed during PEI
Date: Fri, 20 Jan 2017 16:42:21 +0000	[thread overview]
Message-ID: <CAKv+Gu89CR2CajNVAUKm4wOa4oGDSwx9uqDhPGKzWt7BF0gBVg@mail.gmail.com> (raw)
In-Reply-To: <9fdd45fb-710c-cd62-d65e-fe541037a069@redhat.com>

On 20 January 2017 at 16:38, Laszlo Ersek <lersek@redhat.com> wrote:
> On 01/20/17 17:05, Ard Biesheuvel wrote:
>> After a recent change to the AArch64 page table code, the root table
>> of the page tables is allocated using AllocatePool() rather than
>> AllocatePages() if its size is much smaller than a page. E.g., when
>> using 40 bits of translation, the root table only takes up 16 bytes
>>
>> However, what I have noticed is that pool allocations made during PEI
>> are listed as available memory in the EFI memory map (using memmap in
>> the UEFI Shell). Is this expected? Is it part of the contract that
>> AllocatePool() allocations are lost when entering DXE?
>
> Pool allocations in PEI are satisfied with HOBs (and therefore the pool
> allocation sizes are limited to ~64KB).
>
> In addition, soon after permanent PEI RAM is installed, objects from the
> temporary SEC/PEI heap are moved there (this is called "temporary RAM
> migration"). This includes the migration of the full HOB list, including
> those that were used to satisfy pool allocations prior to RAM migration.
>

So how is this supposed to work for code that holds a pointer to such
a pool allocation?

> If you want to allocate memory in PEI that is to survive in-place into
> DXE and later, I can think of two ways:
>
> - Call AllocatePages. This will only work after permanent PEI RAM has
> been installed (so you might want to make the PEIM performing the call
> dependent on gEfiPeiMemoryDiscoveredPpiGuid, with a DEPEX). The
> allocation will be carved out of the permanent PEI RAM.
>

The same code calls AllocatePages for the subsequent translation
levels, i.e., when using 40 bits of translation, there are 4 levels,
where all but the top level are full pages. So I could simply replace
AllocatePool with AllocaPages in this case, which would effectively
revert my 'improvement' to this code to use a pool allocation for the
root level.

> - Allocate a region (a whole multiple of pages) outside of the permanent
> PEI RAM, but in a spot that will later on be backed by system memory
> (due to a system memory resource descriptor HOB produced in PEI, or due
> to a GCD memory space addition during DXE). The way to perform this kind
> of allocation is simply to produce a memory allocation HOB, covering the
> range in question. This works even before the installation of permanent
> PEI RAM.
>
> ... I hope I remembered most of this stuff right.
>

Thanks for the lesson :-)


  reply	other threads:[~2017-01-20 16:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 16:05 [QUESTION] reservation of pool allocations performed during PEI Ard Biesheuvel
2017-01-20 16:38 ` Laszlo Ersek
2017-01-20 16:42   ` Ard Biesheuvel [this message]
2017-01-20 16:54     ` Laszlo Ersek
2017-01-20 16:44   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKv+Gu89CR2CajNVAUKm4wOa4oGDSwx9uqDhPGKzWt7BF0gBVg@mail.gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox