x86/mm: Unify pgtable_l5_enabled usage in early boot code
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fri, 18 May 2018 10:35:23 +0000 (13:35 +0300)
committerIngo Molnar <mingo@kernel.org>
Sat, 19 May 2018 09:56:57 +0000 (11:56 +0200)
Usually pgtable_l5_enabled is defined using cpu_feature_enabled().
cpu_feature_enabled() is not available in early boot code. We use
several different preprocessor tricks to get around it. It's messy.

Unify them all.

If cpu_feature_enabled() is not yet available, USE_EARLY_PGTABLE_L5 can
be defined before all includes. It makes pgtable_l5_enabled rely on
__pgtable_l5_enabled variable instead. This approach fits all early
users.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Hugh Dickins <hughd@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180518103528.59260-3-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/boot/compressed/kaslr.c
arch/x86/boot/compressed/misc.h
arch/x86/include/asm/pgtable_64_types.h
arch/x86/kernel/head64.c
arch/x86/mm/kasan_init_64.c

index a0a50b91ecefe2874b754334f77d452a9190071e..b87a7582853dd34a91b8d007a9a146574a4ca674 100644 (file)
@@ -47,7 +47,7 @@
 #include <linux/decompress/mm.h>
 
 #ifdef CONFIG_X86_5LEVEL
-unsigned int pgtable_l5_enabled __ro_after_init;
+unsigned int __pgtable_l5_enabled;
 unsigned int pgdir_shift __ro_after_init = 39;
 unsigned int ptrs_per_p4d __ro_after_init = 1;
 #endif
@@ -734,7 +734,7 @@ void choose_random_location(unsigned long input,
 
 #ifdef CONFIG_X86_5LEVEL
        if (__read_cr4() & X86_CR4_LA57) {
-               pgtable_l5_enabled = 1;
+               __pgtable_l5_enabled = 1;
                pgdir_shift = 48;
                ptrs_per_p4d = 512;
        }
index 9e11be4cae19baae1023f40246ee1a6ee2a4cb3c..a423bdb426862dc25c7df6ab8309b3d0d6108a38 100644 (file)
 #undef CONFIG_PARAVIRT_SPINLOCKS
 #undef CONFIG_KASAN
 
-#ifdef CONFIG_X86_5LEVEL
-/* cpu_feature_enabled() cannot be used that early */
-#define pgtable_l5_enabled __pgtable_l5_enabled
-#endif
+/* cpu_feature_enabled() cannot be used this early */
+#define USE_EARLY_PGTABLE_L5
 
 #include <linux/linkage.h>
 #include <linux/screen_info.h>
index adb47552e6bb700158788b4d42094f2d83931c86..c14a4116a6939d50760db0752b89181dfff65d3e 100644 (file)
@@ -22,12 +22,19 @@ typedef struct { pteval_t pte; } pte_t;
 
 #ifdef CONFIG_X86_5LEVEL
 extern unsigned int __pgtable_l5_enabled;
-#ifndef pgtable_l5_enabled
+
+#ifdef USE_EARLY_PGTABLE_L5
+/*
+ * cpu_feature_enabled() is not available in early boot code.
+ * Use variable instead.
+ */
+#define pgtable_l5_enabled __pgtable_l5_enabled
+#else
 #define pgtable_l5_enabled cpu_feature_enabled(X86_FEATURE_LA57)
-#endif
+#endif /* USE_EARLY_PGTABLE_L5 */
 #else
 #define pgtable_l5_enabled 0
-#endif
+#endif /* CONFIG_X86_5LEVEL */
 
 extern unsigned int pgdir_shift;
 extern unsigned int ptrs_per_p4d;
index 2d29e47c056ea17d7c24103f41187b494a611da7..494fea1dbd6e0d086ab4949f4e0597a3ea1f1186 100644 (file)
@@ -6,6 +6,10 @@
  */
 
 #define DISABLE_BRANCH_PROFILING
+
+/* cpu_feature_enabled() cannot be used this early */
+#define USE_EARLY_PGTABLE_L5
+
 #include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/types.h>
 #include <asm/microcode.h>
 #include <asm/kasan.h>
 
-#ifdef CONFIG_X86_5LEVEL
-#undef pgtable_l5_enabled
-#define pgtable_l5_enabled __pgtable_l5_enabled
-#endif
-
 /*
  * Manage page tables very early on.
  */
@@ -46,7 +45,6 @@ pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);
 
 #ifdef CONFIG_X86_5LEVEL
 unsigned int __pgtable_l5_enabled __ro_after_init;
-EXPORT_SYMBOL(__pgtable_l5_enabled);
 unsigned int pgdir_shift __ro_after_init = 39;
 EXPORT_SYMBOL(pgdir_shift);
 unsigned int ptrs_per_p4d __ro_after_init = 1;
@@ -88,7 +86,7 @@ static bool __head check_la57_support(unsigned long physaddr)
        if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31))))
                return false;
 
-       *fixup_int(&pgtable_l5_enabled, physaddr) = 1;
+       *fixup_int(&__pgtable_l5_enabled, physaddr) = 1;
        *fixup_int(&pgdir_shift, physaddr) = 48;
        *fixup_int(&ptrs_per_p4d, physaddr) = 512;
        *fixup_long(&page_offset_base, physaddr) = __PAGE_OFFSET_BASE_L5;
index 980dbebd0ca76c81a5d1e50e7a4ba5ad4f4fb241..340bb9b32e018e44394717f4b36a9401e12bcfc8 100644 (file)
@@ -2,10 +2,8 @@
 #define DISABLE_BRANCH_PROFILING
 #define pr_fmt(fmt) "kasan: " fmt
 
-#ifdef CONFIG_X86_5LEVEL
-/* Too early to use cpu_feature_enabled() */
-#define pgtable_l5_enabled __pgtable_l5_enabled
-#endif
+/* cpu_feature_enabled() cannot be used this early */
+#define USE_EARLY_PGTABLE_L5
 
 #include <linux/bootmem.h>
 #include <linux/kasan.h>