[PATCH] lmb: Reinstate access to memory above ram_top

Ilias Apalodimas ilias.apalodimas at linaro.org
Tue Mar 24 10:48:57 CET 2026


Apologies for being late to the party.

On Sun, 22 Mar 2026 at 23:59, Marek Vasut <marek.vasut at mailbox.org> wrote:
>
> On 3/22/26 10:45 PM, Gary Guo wrote:
>
> [...]
>
> >> Is your malloc area by any chance above the 4 GiB boundary ? Or how come
> >> does EFI allocate pages from above 4 GiB range? It should not be doing
> >> that and that is what should be fixed, at least until the DMA32
> >> allocator is in place.
> >>
> >> Please keep in mind, that revering this patch breaks other use cases,
> >> like loading into the DRAM above 4 GiB.
> >
> > Code in lib/efi_loader uses efi_allocate_pool (in lib/efi_loader/efi_memory.c)
> > whenever it allocates, which calls efi_allocate_pages, which calls into
> > lmb_alloc_mem. There's no malloc here.
> Does something like this make the issue go away ?
>
> "
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index b77c2f980cc..44eccc0cf35 100644
> --- a/lib/efi_loader/efi_memory.c
> +++ b/lib/efi_loader/efi_memory.c
> @@ -475,8 +475,10 @@ efi_status_t efi_allocate_pages(enum
> efi_allocate_type type,
>          flags = LMB_NOOVERWRITE | LMB_NONOTIFY;
>          switch (type) {
>          case EFI_ALLOCATE_ANY_PAGES:
> +               addr = map_to_sysmem((void *)(uintptr_t)0xffff0000);

This kind of breaks the EFI spec. The description in the spec is
"Allocation requests of Type AllocateAnyPages allocate any available
range of pages that satisfies the request. On
input, the address pointed to by Memory is ignored."

so in theory *addr should be ignored and in fact it's overwritten by
lmb_alloc_mem(). The reason it works is becase you change the argument
from _ANY to _MAX below.

I am noit against deviating a bit from the spec as long as we get
things working and have a long term plan on fixing it properly.
I'll go through the entire thread and see if there's an easier way out.

Cheers
/Ilias
> +
>                  /* Any page */
> -               err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, EFI_PAGE_SIZE, &addr,
> +               err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, EFI_PAGE_SIZE, &addr,
>                                      len, flags);
>                  if (err)
>                          return EFI_OUT_OF_RESOURCES;
> "
>
> If so, then maybe we need a temporary config option which limits the
> EFI_ALLOCATE_ANY_PAGES below 4 GiB on hardware that has DMA limitations.


More information about the U-Boot mailing list