x86/sme: Use #define USE_EARLY_PGTABLE_L5 in mem_encrypt_identity.c
authorTom Lendacky <thomas.lendacky@amd.com>
Fri, 15 Oct 2021 17:24:16 +0000 (12:24 -0500)
committerBorislav Petkov <bp@suse.de>
Tue, 19 Oct 2021 12:07:17 +0000 (14:07 +0200)
commite7d445ab26db833d6640d4c9a08bee176777cc82
treee32724a851b61bafed62ac90c06ac82c43d305d6
parentc688bd5dc94ee2677f820e4a566fbe98018847ff
x86/sme: Use #define USE_EARLY_PGTABLE_L5 in mem_encrypt_identity.c

When runtime support for converting between 4-level and 5-level pagetables
was added to the kernel, the SME code that built pagetables was updated
to use the pagetable functions, e.g. p4d_offset(), etc., in order to
simplify the code. However, the use of the pagetable functions in early
boot code requires the use of the USE_EARLY_PGTABLE_L5 #define in order to
ensure that the proper definition of pgtable_l5_enabled() is used.

Without the #define, pgtable_l5_enabled() is #defined as
cpu_feature_enabled(X86_FEATURE_LA57). In early boot, the CPU features
have not yet been discovered and populated, so pgtable_l5_enabled() will
return false even when 5-level paging is enabled. This causes the SME code
to always build 4-level pagetables to perform the in-place encryption.
If 5-level paging is enabled, switching to the SME pagetables results in
a page-fault that kills the boot.

Adding the #define results in pgtable_l5_enabled() using the
__pgtable_l5_enabled variable set in early boot and the SME code building
pagetables for the proper paging level.

Fixes: aad983913d77 ("x86/mm/encrypt: Simplify sme_populate_pgd() and sme_populate_pgd_large()")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: <stable@vger.kernel.org> # 4.18.x
Link: https://lkml.kernel.org/r/2cb8329655f5c753905812d951e212022a480475.1634318656.git.thomas.lendacky@amd.com
arch/x86/mm/mem_encrypt_identity.c