[RFT PATCH 1/2] arm64: efi: Prefer a flat virtual mapping of the runtime services

Ard Biesheuvel ardb at kernel.org
Tue Jan 17 06:27:17 PST 2023


With some systems, we cannot omit the boot time call to
SetVirtualAddressMap() even if the kernel VA space is sufficiently
large, because some buggy EFI implementations exist that misbehave if
SetVirtualAddressMap() is never called.

However, this does not mean we must reshuffle the EFI memory map: we can
simply invoke SetVirtualAddressMap() with a memory map that places each
EFI runtime region at the same virtual address that it takes up in the
physical address map.

Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
---
 arch/arm64/include/asm/efi.h            | 2 ++
 drivers/firmware/efi/libstub/efi-stub.c | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index de4ff90785b2c96a..98c4dc4da5a90e8c 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -114,6 +114,8 @@ static inline unsigned long efi_get_kimg_min_align(void)
 #define EFI_ALLOC_ALIGN		SZ_64K
 #define EFI_ALLOC_LIMIT		((1UL << 48) - 1)
 
+#define EFI_USE_FLAT_VA_MAPPING	(VA_BITS_MIN >= 48)
+
 /*
  * On ARM systems, virtually remapped UEFI runtime services are set up in two
  * distinct stages:
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 2955c1ac6a36ee00..40869320d601492a 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -44,8 +44,12 @@
 #define EFI_RT_VIRTUAL_OFFSET	0
 #endif
 
+#ifndef EFI_USE_FLAT_VA_MAPPING
+#define EFI_USE_FLAT_VA_MAPPING	(EFI_RT_VIRTUAL_OFFSET != 0)
+#endif
+
 static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
-static bool flat_va_mapping = (EFI_RT_VIRTUAL_OFFSET != 0);
+static bool flat_va_mapping = EFI_USE_FLAT_VA_MAPPING;
 
 struct screen_info * __weak alloc_screen_info(void)
 {
-- 
2.39.0




More information about the linux-arm-kernel mailing list