x86/boot: Set LA57 boot CPU capability very early during boot

Currently, some source files in the core kernel #define
USE_EARLY_PGTABLE_L5 to opt into an alternative implementation of
pgtable_l5_enabled(), which is based on a variable that is set during
early boot. This is needed because the late version relies on CPU
features, which are detected only much later, and pgtable_l5_enabled()
is used very early, when populating the kernel page tables.

Having two sources of truth is problematic, given that VA space related
constants (such as KASAN_SHADOW_START) are derived from it, and may
therefore assume different values depending on which object they are
referenced from.

So instead, set the LA57 capability on the boot CPU before setting up
the page tables. This removes the need for two different sources of
truth in the core kernel, and allows a single, efficient implementation
of pgtable_l5_enabled() to be used (one that uses code patching to
optimize away the capability mask test entirely). This also removes the
need for exposing the variable __pgtable_l5_enabled to the startup code.

Note that even the decompressor does not manipulate any page tables
before updating CR4.LA57, so it can also avoid the associated global
variables entirely. In this case, just access CR4.LA57 directly in its
implementation of pgtable_l5_enabled().

This change also removes the need to disable KASAN while performing
alternatives patching, as KASAN_SHADOW_START no longer assumes different
values depending on whether the source file that pulls it in #define's
USE_EARLY_PGTABLE_L5 or not.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
9 files changed