Skip to content

Commit e3cf2d9

Browse files
committed
efi/mokvar-table: Avoid repeated map/unmap of the same page
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/8f085931-3e9d-4386-9209-1d6c95616327@uncooperative.org/ Tested-By: Peter Jones <pjones@redhat.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 2b90e7a commit e3cf2d9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/firmware/efi/mokvar-table.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ static struct kobject *mokvar_kobj;
9999
*/
100100
void __init efi_mokvar_table_init(void)
101101
{
102+
struct efi_mokvar_table_entry __aligned(1) *mokvar_entry, *next_entry;
102103
efi_memory_desc_t md;
103104
void *va = NULL;
104105
unsigned long cur_offset = 0;
105106
unsigned long offset_limit;
106107
unsigned long map_size_needed = 0;
107108
unsigned long size;
108-
struct efi_mokvar_table_entry *mokvar_entry;
109109
int err;
110110

111111
if (!efi_enabled(EFI_MEMMAP))
@@ -142,7 +142,7 @@ void __init efi_mokvar_table_init(void)
142142
return;
143143
}
144144
mokvar_entry = va;
145-
145+
next:
146146
/* Check for last sentinel entry */
147147
if (mokvar_entry->name[0] == '\0') {
148148
if (mokvar_entry->data_size != 0)
@@ -156,7 +156,19 @@ void __init efi_mokvar_table_init(void)
156156
mokvar_entry->name[sizeof(mokvar_entry->name) - 1] = '\0';
157157

158158
/* Advance to the next entry */
159-
cur_offset += sizeof(*mokvar_entry) + mokvar_entry->data_size;
159+
size = sizeof(*mokvar_entry) + mokvar_entry->data_size;
160+
cur_offset += size;
161+
162+
/*
163+
* Don't bother remapping if the current entry header and the
164+
* next one end on the same page.
165+
*/
166+
next_entry = (void *)((unsigned long)mokvar_entry + size);
167+
if (((((unsigned long)(mokvar_entry + 1) - 1) ^
168+
((unsigned long)(next_entry + 1) - 1)) & PAGE_MASK) == 0) {
169+
mokvar_entry = next_entry;
170+
goto next;
171+
}
160172
}
161173

162174
if (va)

0 commit comments

Comments
 (0)