Skip to content

Commit 2e9f46e

Browse files
kirylbp3tk0v
authored andcommitted
efi/x86: Get full memory map in allocate_e820()
Currently allocate_e820() is only interested in the size of map and size of memory descriptor to determine how many e820 entries the kernel needs. UEFI Specification version 2.9 introduces a new memory type -- unaccepted memory. To track unaccepted memory, the kernel needs to allocate a bitmap. The size of the bitmap is dependent on the maximum physical address present in the system. A full memory map is required to find the maximum address. Modify allocate_e820() to get a full memory map. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dcdfdd4 commit 2e9f46e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -681,28 +681,24 @@ static efi_status_t allocate_e820(struct boot_params *params,
681681
struct setup_data **e820ext,
682682
u32 *e820ext_size)
683683
{
684-
unsigned long map_size, desc_size, map_key;
684+
struct efi_boot_memmap *map;
685685
efi_status_t status;
686-
__u32 nr_desc, desc_version;
686+
__u32 nr_desc;
687687

688-
/* Only need the size of the mem map and size of each mem descriptor */
689-
map_size = 0;
690-
status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key,
691-
&desc_size, &desc_version);
692-
if (status != EFI_BUFFER_TOO_SMALL)
693-
return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED;
694-
695-
nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS;
688+
status = efi_get_memory_map(&map, false);
689+
if (status != EFI_SUCCESS)
690+
return status;
696691

697-
if (nr_desc > ARRAY_SIZE(params->e820_table)) {
698-
u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table);
692+
nr_desc = map->map_size / map->desc_size;
693+
if (nr_desc > ARRAY_SIZE(params->e820_table) - EFI_MMAP_NR_SLACK_SLOTS) {
694+
u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table) +
695+
EFI_MMAP_NR_SLACK_SLOTS;
699696

700697
status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size);
701-
if (status != EFI_SUCCESS)
702-
return status;
703698
}
704699

705-
return EFI_SUCCESS;
700+
efi_bs_call(free_pool, map);
701+
return status;
706702
}
707703

708704
struct exit_boot_struct {

0 commit comments

Comments
 (0)