[PATCH RFC 1/5] efi/x86: Disable paging when booting via efistub

From: Baskov Evgeniy
Date: Wed Nov 10 2021 - 05:57:02 EST


Some UEFI implementations protect lower 1M memory regions and memory
regions allocated by libstub from being executable, which prevents
Linux kernel from booting.

Disable paging after returning from efi_main() before jumping
to potentially relocated code to prevent page fault from happening.

Signed-off-by: Baskov Evgeniy <baskov@xxxxxxxxx>
---
arch/x86/boot/compressed/head_32.S | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 659fad53ca82..c66fccaa90a2 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -156,6 +156,18 @@ SYM_FUNC_START_ALIAS(efi_stub_entry)
add $0x4, %esp
movl 8(%esp), %esi /* save boot_params pointer */
call efi_main
+
+#ifdef CONFIG_EFI_STRICT_PGTABLE
+ /*
+ * Disable paging before jumping to relocated address to prevent
+ * page faulting on EFI firmware versions that enforces restricted
+ * permissions on identity page tables
+ */
+ movl %cr0, %ecx
+ btrl $31, %ecx
+ movl %ecx, %cr0
+#endif
+
/* efi_main returns the possibly relocated address of startup_32 */
jmp *%eax
SYM_FUNC_END(efi32_stub_entry)
--
2.33.1