lmb: Fix the allocation of overlapping memory areas with !LMB_NONE
At the moment the LMB allocator will return 'success' immediately on two consecutive allocations if the second one is smaller and the flags match without resizing the reserved area. This is problematic for two reasons, first of all the new updated allocation won't update the size and we end up holding more memory than needed, but most importantly it breaks the EFI SCT tests since EFI now allocates via LMB. More specifically when EFI requests a specific address twice with the EFI_ALLOCATE_ADDRESS flag set, the first allocation will succeed and update the EFI memory map. Due to the LMB behavior the second allocation will also succeed but the address ranges are already in the EFI memory map due the first allocation. EFI will then fail to update the memory map, returning EFI_OUT_OF_RESOURCES instead of EFI_NOT_FOUND which break EFI conformance. So let's remove the fast check with is problematic anyway and leave LMB resize and calculate address properly. LMB will now - try to resize the reservations for LMB_NONE - return -1 if the memory is not LMB_NONE and already reserved The LMB code needs some cleanup in that part, but since we are close to 2025.01 do the easy fix and plan to refactor it later. Also update the dm tests with the new behavior. Fixes: commit22f2c9ed9f("efi: memory: use the lmb API's for allocating and freeing memory") Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> (cherry picked from commit1d9aa4a283)
This commit is contained in:
committed by
Simon Glass
parent
88b3a6b237
commit
38a2583258
@@ -200,15 +200,6 @@ static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base,
|
||||
phys_addr_t rgnbase = rgn[i].base;
|
||||
phys_size_t rgnsize = rgn[i].size;
|
||||
phys_size_t rgnflags = rgn[i].flags;
|
||||
phys_addr_t end = base + size - 1;
|
||||
phys_addr_t rgnend = rgnbase + rgnsize - 1;
|
||||
if (rgnbase <= base && end <= rgnend) {
|
||||
if (flags == rgnflags)
|
||||
/* Already have this region, so we're done */
|
||||
return 0;
|
||||
else
|
||||
return -1; /* regions with new flags */
|
||||
}
|
||||
|
||||
ret = lmb_addrs_adjacent(base, size, rgnbase, rgnsize);
|
||||
if (ret > 0) {
|
||||
|
||||
Reference in New Issue
Block a user