x86/mm: Introduce 'no5lvl' kernel parameter
Subsystems (2)
PATCH v2 1/1 x86/mm: Introduce 'no5lvl' kernel parameter
The kernel parameter allows to force kernel to use 4-level paging even if hardware and kernel support 5-level paging.
The option may be useful to workaround regressions related to 5-level paging.
Signed-off-by Kirill A. Shutemov <[email protected]>
---
v2:
- Fix build issue.
--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/boot/compressed/cmdline.c | 2 +- arch/x86/boot/compressed/head_64.S | 1 + arch/x86/boot/compressed/pgtable_64.c | 12 ++++++++++-- arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kernel/head64.c | 10 ++++++---- 6 files changed, 27 insertions(+), 7 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -2600,6 +2600,9 @@ emulation library even if a 387 maths coprocessor is present. + no5lvl [X86-64] Disable 5-level paging mode. Forces + kernel to use 4-level paging instead. + no_console_suspend [HW] Never suspend the console Disable suspending of consoles during suspend and
arch/x86/boot/compressed/cmdline.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "misc.h" -#if CONFIG_EARLY_PRINTK ||CONFIG_RANDOMIZE_BASE +#if CONFIG_EARLY_PRINTK ||CONFIG_RANDOMIZE_BASE ||CONFIG_X86_5LEVEL static unsigned long fs;static inline void set_fs (unsigned long seg)
arch/x86/boot/compressed/head_64.S +1 -0
@@ -346,6 +346,7 @@ ENTRY(startup_64) * this function call. */ pushq %rsi + movq %rsi, %rdi /* real mode address */ call paging_prepare popq %rsi
arch/x86/boot/compressed/pgtable_64.c +10 -2
@@ -37,16 +37,23 @@ extern char *top_pgtable;*/ unsigned long *trampoline_32bit __section(.data); -struct paging_config paging_prepare (void ) +extern struct boot_params *boot_params; +int cmdline_find_option_bool (const char *option); + +struct paging_config paging_prepare (void *rmode) {struct paging_config paging_config = {};unsigned long bios_start, ebda_start; +/* Initialize boot_params. Required for cmdline_find_option_bool(). */ + boot_params = rmode; +/* * Check if LA57 is desired and supported. * -* There are two parts to the check: +* There are several parts to the check: * - if the kernel supports 5-level paging: CONFIG_X86_5LEVEL=y +* - if user asked to disable 5-level paging: no5lvl in cmdline * - if the machine supports 5-level paging: * + CPUID leaf 7 is supported * + the leaf has the feature bit set
@@ -54,6 +61,7 @@ struct paging_config paging_prepare(void)* That's substitute for boot_cpu_has() in early boot code. */ if (IS_ENABLED (CONFIG_X86_5LEVEL ) && + !cmdline_find_option_bool ("no5lvl" ) &&native_cpuid_eax (0 ) >=7 && (native_cpuid_ecx (7 ) & (1 << (X86_FEATURE_LA57 &31 )))) { paging_config.l5_required =1 ;
arch/x86/kernel/cpu/common.c +6 -0
@@ -1004,6 +1004,12 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)*/ setup_clear_cpu_cap (X86_FEATURE_PCID );#endif + +#ifdef CONFIG_X86_5LEVEL +/* Clear the 5-level paging feature if user asked for 'no5lvl' */ +if (!__pgtable_l5_enabled) +setup_clear_cpu_cap (X86_FEATURE_LA57 ); +#endif }void __init early_cpu_init (void )
arch/x86/kernel/head64.c +6 -4
@@ -82,10 +82,12 @@ static unsigned int __head *fixup_int(void *ptr, unsigned long physaddr) static bool __head check_la57_support(unsigned long physaddr) { -if (native_cpuid_eax (0 ) <7 ) -return false; - -if (!(native_cpuid_ecx (7 ) & (1 << (X86_FEATURE_LA57 &31 )))) +/* +* 5-level paging is detected and enabled on kernel decomression +* stage. Back off if 5-level paging mode has not yet enabled by +* this point. +*/ +if (!(native_read_cr4 () &X86_CR4_LA57 ))return false; *fixup_int (&pgtable_l5_enabled, physaddr) =1 ;
Signature · 1 line
2.17.0