Skip to content

Commit

Permalink
efi/mokvar-table: Avoid repeated map/unmap of the same page
Browse files Browse the repository at this point in the history
Tweak the logic that traverses the MOKVAR UEFI configuration table to
only unmap the entry header and map the next one if they don't live in
the same physical page.

Link: https://lore.kernel.org/all/[email protected]/
Tested-By: Peter Jones <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
  • Loading branch information
ardbiesheuvel committed Feb 27, 2025
1 parent 2b90e7a commit e3cf2d9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drivers/firmware/efi/mokvar-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ static struct kobject *mokvar_kobj;
*/
void __init efi_mokvar_table_init(void)
{
struct efi_mokvar_table_entry __aligned(1) *mokvar_entry, *next_entry;
efi_memory_desc_t md;
void *va = NULL;
unsigned long cur_offset = 0;
unsigned long offset_limit;
unsigned long map_size_needed = 0;
unsigned long size;
struct efi_mokvar_table_entry *mokvar_entry;
int err;

if (!efi_enabled(EFI_MEMMAP))
Expand Down Expand Up @@ -142,7 +142,7 @@ void __init efi_mokvar_table_init(void)
return;
}
mokvar_entry = va;

next:
/* Check for last sentinel entry */
if (mokvar_entry->name[0] == '\0') {
if (mokvar_entry->data_size != 0)
Expand All @@ -156,7 +156,19 @@ void __init efi_mokvar_table_init(void)
mokvar_entry->name[sizeof(mokvar_entry->name) - 1] = '\0';

/* Advance to the next entry */
cur_offset += sizeof(*mokvar_entry) + mokvar_entry->data_size;
size = sizeof(*mokvar_entry) + mokvar_entry->data_size;
cur_offset += size;

/*
* Don't bother remapping if the current entry header and the
* next one end on the same page.
*/
next_entry = (void *)((unsigned long)mokvar_entry + size);
if (((((unsigned long)(mokvar_entry + 1) - 1) ^
((unsigned long)(next_entry + 1) - 1)) & PAGE_MASK) == 0) {
mokvar_entry = next_entry;
goto next;
}
}

if (va)
Expand Down

0 comments on commit e3cf2d9

Please sign in to comment.