arm64: align randomized TEXT_OFFSET on 4 kB boundary
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 13 Aug 2014 17:53:03 +0000 (18:53 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 22 Jan 2015 21:27:27 +0000 (21:27 +0000)
commitc86df325d594f33eff078fe6b6014f1994f9bcb7
tree3411bca2c05530291d278827acde67055368f26d
parent432d182423d53bc7f03d3a399cd57482c5ca47b0
arm64: align randomized TEXT_OFFSET on 4 kB boundary

When booting via UEFI, the kernel Image is loaded at a 4 kB boundary and
the embedded EFI stub is executed in place. The EFI stub relocates the
Image to reside TEXT_OFFSET bytes above a 2 MB boundary, and jumps into
the kernel proper.

In AArch64, PC relative symbol references are emitted using adrp/add or
adrp/ldr pairs, where the offset into a 4 kB page is resolved using a
separate :lo12: relocation. This implicitly assumes that the code will
always be executed at the same relative offset with respect to a 4 kB
boundary, or the references will point to the wrong address.

This means we should link the kernel at a 4 kB aligned base address in
order to remain compatible with the base address the UEFI loader uses
when doing the initial load of Image. So update the code that generates
TEXT_OFFSET to choose a multiple of 4 kB.

At the same time, update the code so it chooses from the interval [0..2MB)
as the author originally intended.

Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 4190312beb2acfb7bfb1bb971e24a759aa96b0e8)
Signed-off-by: Mark Brown <broonie@kernel.org>
Conflicts:
arch/arm64/Makefile
arch/arm64/kernel/head.S
arch/arm64/Makefile
arch/arm64/kernel/head.S