Skip to content

Commit 372fddf

Browse files
kirylIngo Molnar
authored andcommitted
x86/mm: Introduce the 'no5lvl' kernel parameter
This 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 work around regressions related to 5-level paging. 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-5-kirill.shutemov@linux.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ed7588d commit 372fddf

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,9 @@
26002600
emulation library even if a 387 maths coprocessor
26012601
is present.
26022602

2603+
no5lvl [X86-64] Disable 5-level paging mode. Forces
2604+
kernel to use 4-level paging instead.
2605+
26032606
no_console_suspend
26042607
[HW] Never suspend the console
26052608
Disable suspending of consoles during suspend and

arch/x86/boot/compressed/cmdline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include "misc.h"
33

4-
#if CONFIG_EARLY_PRINTK || CONFIG_RANDOMIZE_BASE
4+
#if CONFIG_EARLY_PRINTK || CONFIG_RANDOMIZE_BASE || CONFIG_X86_5LEVEL
55

66
static unsigned long fs;
77
static inline void set_fs(unsigned long seg)

arch/x86/boot/compressed/head_64.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ ENTRY(startup_64)
365365
* this function call.
366366
*/
367367
pushq %rsi
368+
movq %rsi, %rdi /* real mode address */
368369
call paging_prepare
369370
popq %rsi
370371

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,31 @@ static char trampoline_save[TRAMPOLINE_32BIT_SIZE];
3131
*/
3232
unsigned long *trampoline_32bit __section(.data);
3333

34-
struct paging_config paging_prepare(void)
34+
extern struct boot_params *boot_params;
35+
int cmdline_find_option_bool(const char *option);
36+
37+
struct paging_config paging_prepare(void *rmode)
3538
{
3639
struct paging_config paging_config = {};
3740
unsigned long bios_start, ebda_start;
3841

42+
/* Initialize boot_params. Required for cmdline_find_option_bool(). */
43+
boot_params = rmode;
44+
3945
/*
4046
* Check if LA57 is desired and supported.
4147
*
42-
* There are two parts to the check:
48+
* There are several parts to the check:
4349
* - if the kernel supports 5-level paging: CONFIG_X86_5LEVEL=y
50+
* - if user asked to disable 5-level paging: no5lvl in cmdline
4451
* - if the machine supports 5-level paging:
4552
* + CPUID leaf 7 is supported
4653
* + the leaf has the feature bit set
4754
*
4855
* That's substitute for boot_cpu_has() in early boot code.
4956
*/
5057
if (IS_ENABLED(CONFIG_X86_5LEVEL) &&
58+
!cmdline_find_option_bool("no5lvl") &&
5159
native_cpuid_eax(0) >= 7 &&
5260
(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31)))) {
5361
paging_config.l5_required = 1;

arch/x86/kernel/cpu/common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,21 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
10281028
*/
10291029
setup_clear_cpu_cap(X86_FEATURE_PCID);
10301030
#endif
1031+
1032+
/*
1033+
* Later in the boot process pgtable_l5_enabled() relies on
1034+
* cpu_feature_enabled(X86_FEATURE_LA57). If 5-level paging is not
1035+
* enabled by this point we need to clear the feature bit to avoid
1036+
* false-positives at the later stage.
1037+
*
1038+
* pgtable_l5_enabled() can be false here for several reasons:
1039+
* - 5-level paging is disabled compile-time;
1040+
* - it's 32-bit kernel;
1041+
* - machine doesn't support 5-level paging;
1042+
* - user specified 'no5lvl' in kernel command line.
1043+
*/
1044+
if (!pgtable_l5_enabled())
1045+
setup_clear_cpu_cap(X86_FEATURE_LA57);
10311046
}
10321047

10331048
void __init early_cpu_init(void)

arch/x86/kernel/head64.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ static unsigned int __head *fixup_int(void *ptr, unsigned long physaddr)
8080

8181
static bool __head check_la57_support(unsigned long physaddr)
8282
{
83-
if (native_cpuid_eax(0) < 7)
84-
return false;
85-
86-
if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31))))
83+
/*
84+
* 5-level paging is detected and enabled at kernel decomression
85+
* stage. Only check if it has been enabled there.
86+
*/
87+
if (!(native_read_cr4() & X86_CR4_LA57))
8788
return false;
8889

8990
*fixup_int(&__pgtable_l5_enabled, physaddr) = 1;

0 commit comments

Comments
 (0)