Skip to content

Commit d3549a9

Browse files
committed
efi/arm64: libstub: avoid SetVirtualAddressMap() when possible
EFI's SetVirtualAddressMap() runtime service is a horrid hack that we'd like to avoid using, if possible. For 64-bit architectures such as arm64, the user and kernel mappings are entirely disjoint, and given that we use the user region for mapping the UEFI runtime regions when running under the OS, we don't rely on SetVirtualAddressMap() in the conventional way, i.e., to permit kernel mappings of the OS to coexist with kernel region mappings of the firmware regions. This means that, in principle, we should be able to avoid SetVirtualAddressMap() altogether, and simply use the 1:1 mapping that UEFI uses at boot time. (Note that omitting SetVirtualAddressMap() is explicitly permitted by the UEFI spec). However, there is a corner case on arm64, which, if configured for 3-level paging (or 2-level paging when using 64k pages), may not be able to cover the entire range of firmware mappings (which might contain both memory and MMIO peripheral mappings). So let's avoid SetVirtualAddressMap() on arm64, but only if the VA space is guaranteed to be of sufficient size. Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 3c6edd9 commit d3549a9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ efi_status_t check_platform_features(void)
1919
{
2020
u64 tg;
2121

22+
/*
23+
* If we have 48 bits of VA space for TTBR0 mappings, we can map the
24+
* UEFI runtime regions 1:1 and so calling SetVirtualAddressMap() is
25+
* unnecessary.
26+
*/
27+
if (VA_BITS_MIN >= 48)
28+
efi_novamap = true;
29+
2230
/* UEFI mandates support for 4 KB granularity, no need to check */
2331
if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
2432
return EFI_SUCCESS;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ efi_status_t efi_parse_options(char const *cmdline)
218218
efi_noinitrd = true;
219219
} else if (!strcmp(param, "efi") && val) {
220220
efi_nochunk = parse_option_str(val, "nochunk");
221-
efi_novamap = parse_option_str(val, "novamap");
221+
efi_novamap |= parse_option_str(val, "novamap");
222222

223223
efi_nosoftreserve = IS_ENABLED(CONFIG_EFI_SOFT_RESERVE) &&
224224
parse_option_str(val, "nosoftreserve");

0 commit comments

Comments
 (0)