efi_loader: Track size of pool allocations to allow freeing
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 4/7 efi_loader: Track size of pool allocations to allow freeing
We need a functional free_pool implementation, as otherwise each allocate_pool causes growth of the memory descriptor table.
Different to free_pages, free_pool does not provide the size for the to be freed allocation, thus we have to track the size ourselves.
As the only EFI requirement for pool allocation is an alignment of 8 bytes, we can keep allocating a range using the page allocator, reserve the first 8 bytes for our bookkeeping and hand out the remainder to the caller. This saves us from having to use any independent data structures for tracking.
To simplify the conversion between pool allocations and the corresponding page allocation, we create an auxiliary struct efi_pool_allocation.
Given the allocation size free_pool size can handoff freeing the page range, which was indirectly allocated by a call to allocate_pool, to free_pages.
--- include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 6 +++--- lib/efi_loader/efi_memory.c | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-)
include/efi_loader.h +2 -0
@@ -122,6 +122,8 @@ efi_status_t efi_free_pages(uint64_t memory, unsigned long pages);/* EFI memory allocator for small allocations */ efi_status_t efi_allocate_pool (int pool_type,unsigned long size,void **buffer); +/* EFI pool memory free function. */ +efi_status_t efi_free_pool (void *buffer);/* Returns the EFI memory map */ efi_status_t efi_get_memory_map(unsigned long *memory_map_size, struct efi_mem_desc *memory_map,
lib/efi_loader/efi_boottime.c +3 -3
@@ -141,12 +141,12 @@ static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,return EFI_EXIT (r); } -static efi_status_t EFIAPI efi_free_pool(void *buffer) +static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) {efi_status_t r;EFI_ENTRY ("%p" , buffer); - r =efi_free_pages ((ulong )buffer,0 ); + r =efi_free_pool (buffer);return EFI_EXIT (r); }
@@ -736,7 +736,7 @@ static const struct efi_boot_services efi_boot_services = { .free_pages = efi_free_pages_ext, .get_memory_map = efi_get_memory_map_ext, .allocate_pool = efi_allocate_pool_ext, - .free_pool = efi_free_pool, + .free_pool = efi_free_pool_ext, .create_event = efi_create_event, .set_timer = efi_set_timer, .wait_for_event = efi_wait_for_event,
lib/efi_loader/efi_memory.c +39 -3
56 lines not on this page · raw message
Signature · 1 line
2.10.0
PATCH v4 4/7 efi_loader: Track size of pool allocations to allow freeing
Quoted 12 lines · Stefan Br?ns
We need a functional
free_poolimplementation, as otherwise eachallocate_poolcauses growth of the memory descriptor table.Different to
free_pages,free_pooldoes not provide the size for the to be freed allocation, thus we have to track the size ourselves.As the only EFI requirement for pool allocation is an alignment of 8 bytes, we can keep allocating a range using the page allocator, reserve the first 8 bytes for our bookkeeping and hand out the remainder to the caller. This saves us from having to use any independent data structures for tracking.
Quoted 8 lines
To simplify the conversion between pool allocations and the corresponding page allocation, we create an auxiliary struct
efi_pool_allocation.Given the allocation size
free_poolsize can handoff freeing the page range, which was indirectly allocated by a call toallocate_pool, tofree_pages.Signed-off-by Stefan Br?ns <[email protected]>
Alex
Alexander Graf
AppliedPATCH v4 4/7 efi_loader: Track size of pool allocations to allow freeing
In reply to Stefan BrünsQuoted 15 lines
We need a functional
free_poolimplementation, as otherwise eachallocate_poolcauses growth of the memory descriptor table.Different to
free_pages,free_pooldoes not provide the size for the to be freed allocation, thus we have to track the size ourselves.As the only EFI requirement for pool allocation is an alignment of 8 bytes, we can keep allocating a range using the page allocator, reserve the first 8 bytes for our bookkeeping and hand out the remainder to the caller. This saves us from having to use any independent data structures for tracking.
To simplify the conversion between pool allocations and the corresponding page allocation, we create an auxiliary struct
efi_pool_allocation.
Quoted 6 lines
Given the allocation size
free_poolsize can handoff freeing the page range, which was indirectly allocated by a call toallocate_pool, tofree_pages.Signed-off-by Stefan Br?ns <[email protected]>Reviewed-by Alexander Graf <[email protected]>
Thanks, applied to