[PATCH 5/6] efi_memory: backfill EFI_CONVENTIONAL_MEMORY

Randolph Sapp rs at ti.com
Sat Apr 4 02:08:06 CEST 2026


On Fri Apr 3, 2026 at 12:28 AM CDT, Ilias Apalodimas wrote:
> [...]
>
>> >>
>> >>> +}
>> >>> +
>> >>>  /**
>> >>>   * efi_allocate_pages - allocate memory pages
>> >>>   *
>> >>> @@ -507,10 +528,20 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
>> >>>         /* Reserve that map in our memory maps */
>> >>>         ret = efi_update_memory_map(efi_addr, pages, memory_type, true, false);
>> >>
>> >> In theory the lmb and the EFI maps are in sync. I haven't checked
>> >> close enough yet, but do you have cases where lmb_alloc worked and
>> >> updating the efi memory map failed?
>> >
>> > Fair point. Now that I've fixed the FDT warning I should probably check if I can
>> > actually reproduce the issue that actually required this.
>>
>> Yeah, this patch isn't necessary anymore. I suppose it should be dropped as it
>> would potentially mask any discrepancies between the two maps.
>
> Yea and if we really need a similar fix in the future, it's best if we
> put in the lmb core code.
>
>>
>> Out of curiosity, is there any plan to merge the EFI and LMB allocators more in
>> the future, or is the current layering scheme the furthest we want to go?
>
> We do, but havent due to lack of time. It's been a while since I
> discussed this with Heinrich but iirc the only thing missing is for
> lmb to be aware of the memory flags EFI expects.
>
> /Ilias

I mean, trimming the last x bits off of the LMB allocation flag value to store
the current EFI enum is a little bit of a hack, but honestly it'll allow the
current allocation coalescence logic to continue to work as-is. It would just
need helpers to store and retrieve the enum type for the code that actually
cares about the EFI memory types. I could look into doing that if you guys think
that's a valid approach, or if you've got other ideas.

>>
>> >>>         if (ret != EFI_SUCCESS) {
>> >>> -               /* Map would overlap, bail out */
>> >>> +               /* Map would overlap, try something else */
>> >>>                 lmb_free(addr, (u64)pages << EFI_PAGE_SHIFT, flags);
>> >>>                 unmap_sysmem((void *)(uintptr_t)efi_addr);
>> >>> -               return  EFI_OUT_OF_RESOURCES;
>> >>> +
>> >>> +               /* See if there is any EFI_CONVENTIONAL_MEMORY allocations */
>> >>> +               if (type != EFI_ALLOCATE_ADDRESS) {
>> >>
>> >> Can you please inverse this. It's going to reduce the identation.
>> >> if (type == EFI_ALLOCATE_ADDRESS)
>> >>> +                       *memory = efi_get_conventional_start(pages);
>> >>> +                       if (*memory != 0)
>> >>
>> >> Same here
>> >>
>> >>> +                               return efi_allocate_pages(EFI_ALLOCATE_ADDRESS,
>> >>> +                                                         memory_type, pages,
>> >>> +                                                         memory);
>> >>> +               }
>> >>> +
>> >>> +               return EFI_OUT_OF_RESOURCES;
>> >>>         }
>> >>>
>> >>>         *memory = efi_addr;
>> >>> --
>> >>> 2.53.0
>> >>>
>> >>
>> >> Thanks
>> >> /Ilias
>>



More information about the U-Boot mailing list