linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] efi/libstub: arm64: avoid SetVirtualAddressMap() when possible
@ 2022-09-16 10:18 Ard Biesheuvel
  2022-09-16 10:20 ` Ard Biesheuvel
  2022-10-19  3:24 ` Yicong Yang
  0 siblings, 2 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2022-09-16 10:18 UTC (permalink / raw)
  To: linux-efi
  Cc: linux-arm-kernel, mark.rutland, probinson, andersson,
	catalin.marinas, will, Ard Biesheuvel

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 <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/arm64-stub.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index cd3bea25c762..4fff6c32899e 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -31,6 +31,15 @@ efi_status_t check_platform_features(void)
 			efi_err("This 16 KB granular kernel is not supported by your CPU\n");
 		return EFI_UNSUPPORTED;
 	}
+
+	/*
+	 * If we have 48 bits of VA space for TTBR0 mappings, we can map the
+	 * UEFI runtime regions 1:1 and so calling SetVirtualAddressMap() is
+	 * unnecessary.
+	 */
+	if (VA_BITS_MIN >= 48)
+		efi_novamap = true;
+
 	return EFI_SUCCESS;
 }
 
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-23 14:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16 10:18 [PATCH] efi/libstub: arm64: avoid SetVirtualAddressMap() when possible Ard Biesheuvel
2022-09-16 10:20 ` Ard Biesheuvel
2022-10-19  3:24 ` Yicong Yang
2022-10-20 12:39   ` Thorsten Leemhuis
2022-10-20 13:04     ` Ard Biesheuvel
2022-10-21  1:59       ` Yicong Yang
2022-10-23 14:58     ` [PATCH] efi/libstub: arm64: avoid SetVirtualAddressMap() when possible #forregzbot Thorsten Leemhuis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).