]> git.ipfire.org Git - thirdparty/grub.git/commit
loader/i386/linux: Prefer entry in long mode when booting via EFI
authorArd Biesheuvel <ardb@kernel.org>
Thu, 3 Aug 2023 13:24:09 +0000 (15:24 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 22 Sep 2023 16:38:36 +0000 (18:38 +0200)
commit67ae3981dc5113e5af3a0539174bcd7eab8f7722
tree04772cdc442f2a2bf60062d7b04480c9684f4f82
parent7ce5b4911005b2a0bfd716d92466b6711844068c
loader/i386/linux: Prefer entry in long mode when booting via EFI

The x86_64 Linux kernel can be booted in 32-bit mode, in which case the
startup code creates a set of preliminary page tables that map the first
4 GiB of physical memory 1:1 and enables paging. This is a prerequisite
for 64-bit execution and can therefore only be implemented in 32-bit code.

The x86_64 Linux kernel can also be booted in 64-bit mode directly: this
implies that paging is already enabled and it is the responsibility of
the bootloader to ensure that the active page tables cover the entire
loaded image, including its BSS space, the size of which is described in
the image's setup header.

Given that the EFI spec mandates execution in long mode for x86_64 and
stipulates that all system memory is mapped 1:1, the Linux/x86
requirements for 64-bit entry can be met trivially when booting on
x86_64 via EFI. So, enter via the 64-bit entry point in this case.

This involves inspecting the xloadflags field in the setup header to
check whether the 64-bit entry point is supported. This field was
introduced in Linux version v3.8 (early 2013).

This change ensures that all EFI firmware tables and other assets passed
by the firmware or bootloader in memory remain mapped and accessible
throughout the early startup code.

Avoiding the drop out of long mode will also be needed to support
upcoming CPU designs that no longer implement 32-bit mode at all
(as recently announced by Intel [0]).

[0] https://www.intel.com/content/www/us/en/developer/articles/technical/envisioning-future-simplified-architecture.html

Cc: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Julian Andres Klode <julian.klode@canonical.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/loader/i386/linux.c
include/grub/i386/linux.h