OSDN Git Service

efi/libstub/arm64: Replace 'preferred' offset with alignment check
authorArd Biesheuvel <ardb@kernel.org>
Fri, 27 Mar 2020 16:23:52 +0000 (17:23 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 23 Apr 2020 18:15:06 +0000 (20:15 +0200)
commit82046702e288bdd81673b81ab5138e498d155918
treecf2540190119b87cf6618845c5bb2cd9c9d29201
parentc37c9162a2fae026dc8570ad7c5ade0422b0a267
efi/libstub/arm64: Replace 'preferred' offset with alignment check

The notion of a 'preferred' load offset for the kernel dates back to the
times when the kernel's primary mapping overlapped with the linear region,
and memory below it could not be used at all.

Today, the arm64 kernel does not really care where it is loaded in physical
memory, as long as the alignment requirements are met, and so there is no
point in unconditionally moving the kernel to a new location in memory at
boot. Instead, we can
- check for a KASLR seed, and randomly reallocate the kernel if one is
  provided
- otherwise, check whether the alignment requirements are met for the
  current placement of the kernel, and just run it in place if they are
- finally, do an ordinary page allocation and reallocate the kernel to a
  suitably aligned buffer anywhere in memory.

By the same reasoning, there is no need to take TEXT_OFFSET into account
if it is a round multiple of the minimum alignment, which is the usual
case for relocatable kernels with TEXT_OFFSET randomization disabled.
Otherwise, it suffices to use the relative misaligment of TEXT_OFFSET
when reallocating the kernel.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/arm64-stub.c