Skip to content

Commit e7d445a

Browse files
tlendackysuryasaimadhu
authored andcommitted
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: aad9839 ("x86/mm/encrypt: Simplify sme_populate_pgd() and sme_populate_pgd_large()") Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Cc: <[email protected]> # 4.18.x Link: https://lkml.kernel.org/r/2cb8329655f5c753905812d951e212022a480475.1634318656.git.thomas.lendacky@amd.com
1 parent c688bd5 commit e7d445a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
#undef CONFIG_PARAVIRT_XXL
2828
#undef CONFIG_PARAVIRT_SPINLOCKS
2929

30+
/*
31+
* This code runs before CPU feature bits are set. By default, the
32+
* pgtable_l5_enabled() function uses bit X86_FEATURE_LA57 to determine if
33+
* 5-level paging is active, so that won't work here. USE_EARLY_PGTABLE_L5
34+
* is provided to handle this situation and, instead, use a variable that
35+
* has been set by the early boot code.
36+
*/
37+
#define USE_EARLY_PGTABLE_L5
38+
3039
#include <linux/kernel.h>
3140
#include <linux/mm.h>
3241
#include <linux/mem_encrypt.h>

0 commit comments

Comments
 (0)