]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_loader: fix AllocatePages overlap status
authorHarsimran Singh Tungal <harsimransingh.tungal@arm.com>
Mon, 27 Apr 2026 15:05:30 +0000 (16:05 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 18 May 2026 06:32:58 +0000 (08:32 +0200)
Return EFI_NOT_FOUND for EFI_ALLOCATE_ADDRESS overlap

When efi_allocate_pages() is called with EFI_ALLOCATE_ADDRESS, UEFI
expects EFI_NOT_FOUND if the requested address range is already
allocated or unavailable. U-Boot currently returns
EFI_OUT_OF_RESOURCES when efi_update_memory_map() detects an overlap
after a successful lmb_alloc_mem(), which does not match
EFI_ALLOCATE_ADDRESS semantics.

Return EFI_NOT_FOUND for EFI_ALLOCATE_ADDRESS requests that fail due
to an overlapping EFI memory descriptor, while keeping
EFI_OUT_OF_RESOURCES for other allocation types.

The UEFI specification [1] specifies that
EFI_BOOT_SERVICES.AllocatePages must return EFI_NOT_FOUND when the
requested address range is unavailable or already allocated;
EFI_OUT_OF_RESOURCES applies to non‑address‑specific allocation
failures.

[1] https://uefi.org/specs/UEFI/2.10_A/07_Services_Boot_Services.html

Signed-off-by: Harsimran Singh Tungal <harsimransingh.tungal@arm.com>
The UEFI specification does not clearly specify the behavior.
But let's follow the EDK II precedent here.

Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_loader/efi_memory.c

index 046a2bb46413b6d38ff0a9d2852e737361aa3443..2feb29f0a2c335dbf2da12c2e4d920ceff42720a 100644 (file)
@@ -495,7 +495,9 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
                /* Map would overlap, bail out */
                lmb_free(addr, (u64)pages << EFI_PAGE_SHIFT, flags);
                unmap_sysmem((void *)(uintptr_t)efi_addr);
-               return  EFI_OUT_OF_RESOURCES;
+               if (type == EFI_ALLOCATE_ADDRESS)
+                       return EFI_NOT_FOUND;
+               return EFI_OUT_OF_RESOURCES;
        }
 
        *memory = efi_addr;