Skip to content

Commit 37926f9

Browse files
committed
efi: runtime: Don't assume virtual mappings are missing if VA == PA == 0
The generic EFI stub can be instructed to avoid SetVirtualAddressMap(), and simply run with the firmware's 1:1 mapping. In this case, it populates the virtual address fields of the runtime regions in the memory map with the physical address of each region, so that the mapping code has to be none the wiser. Only if SetVirtualAddressMap() fails, the virtual addresses are wiped and the kernel code knows that the regions cannot be mapped. However, wiping amounts to setting it to zero, and if a runtime region happens to live at physical address 0, its valid 1:1 mapped virtual address could be mistaken for a wiped field, resulting on loss of access to the EFI services at runtime. So let's only assume that VA == 0 means 'no runtime services' if the region in question does not live at PA 0x0. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 53a7ea2 commit 37926f9

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

drivers/firmware/efi/arm-runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static bool __init efi_virtmap_init(void)
6363

6464
if (!(md->attribute & EFI_MEMORY_RUNTIME))
6565
continue;
66-
if (md->virt_addr == 0)
66+
if (md->virt_addr == U64_MAX)
6767
return false;
6868

6969
ret = efi_create_mapping(&efi_mm, md);

drivers/firmware/efi/libstub/fdt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,16 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
313313

314314
/*
315315
* Set the virtual address field of all
316-
* EFI_MEMORY_RUNTIME entries to 0. This will signal
317-
* the incoming kernel that no virtual translation has
318-
* been installed.
316+
* EFI_MEMORY_RUNTIME entries to U64_MAX. This will
317+
* signal the incoming kernel that no virtual
318+
* translation has been installed.
319319
*/
320320
for (l = 0; l < priv.boot_memmap->map_size;
321321
l += priv.boot_memmap->desc_size) {
322322
p = (void *)priv.boot_memmap->map + l;
323323

324324
if (p->attribute & EFI_MEMORY_RUNTIME)
325-
p->virt_addr = 0;
325+
p->virt_addr = U64_MAX;
326326
}
327327
}
328328
return EFI_SUCCESS;

drivers/firmware/efi/riscv-runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static bool __init efi_virtmap_init(void)
4141

4242
if (!(md->attribute & EFI_MEMORY_RUNTIME))
4343
continue;
44-
if (md->virt_addr == 0)
44+
if (md->virt_addr == U64_MAX)
4545
return false;
4646

4747
ret = efi_create_mapping(&efi_mm, md);

0 commit comments

Comments
 (0)