OSDN Git Service

arm64: Set GP bit in kernel page tables to enable BTI for the kernel
authorMark Brown <broonie@kernel.org>
Wed, 6 May 2020 19:51:31 +0000 (20:51 +0100)
committerWill Deacon <will@kernel.org>
Thu, 7 May 2020 16:53:20 +0000 (17:53 +0100)
commitc8027285e3660e3b76eb2fb75a32f1596064b5e4
treed2ce438c458afd84e92feb479fc4eb9bb7c10250
parent714a8d02ca4da1479bf0b778fc1951dc88515c3d
arm64: Set GP bit in kernel page tables to enable BTI for the kernel

Now that the kernel is built with BTI annotations enable the feature by
setting the GP bit in the stage 1 translation tables.  This is done
based on the features supported by the boot CPU so that we do not need
to rewrite the translation tables.

In order to avoid potential issues on big.LITTLE systems when there are
a mix of BTI and non-BTI capable CPUs in the system when we have enabled
kernel mode BTI we change BTI to be a _STRICT_BOOT_CPU_FEATURE when we
have kernel BTI.  This will prevent any CPUs that don't support BTI
being started if the boot CPU supports BTI rather than simply not using
BTI as we do when supporting BTI only in userspace.  The main concern is
the possibility of BTYPE being preserved by a CPU that does not
implement BTI when a thread is migrated to it resulting in an incorrect
state which could generate an exception when the thread migrates back to
a CPU that does support BTI.  If we encounter practical systems which
mix BTI and non-BTI CPUs we will need to revisit this implementation.

Since we currently do not generate landing pads in the BPF JIT we only
map the base kernel text in this way.

Signed-off-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20200506195138.22086-5-broonie@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/pgtable-prot.h
arch/arm64/kernel/cpufeature.c
arch/arm64/mm/mmu.c