Skip to content

Commit 7212b58

Browse files
kirylIngo Molnar
authored andcommitted
x86/mm/64: Make 5-level paging support unconditional
Both Intel and AMD CPUs support 5-level paging, which is expected to become more widely adopted in the future. All major x86 Linux distributions have the feature enabled. Remove CONFIG_X86_5LEVEL and related #ifdeffery for it to make it more readable. Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Cc: Dave Hansen <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cba5d9b commit 7212b58

File tree

19 files changed

+10
-102
lines changed

19 files changed

+10
-102
lines changed

Documentation/arch/x86/cpuinfo.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ For example, when an old kernel is running on new hardware.
173173
The kernel disabled support for it at compile-time
174174
--------------------------------------------------
175175

176-
For example, if 5-level-paging is not enabled when building (i.e.,
177-
CONFIG_X86_5LEVEL is not selected) the flag "la57" will not show up [#f1]_.
176+
For example, if Linear Address Masking (LAM) is not enabled when building (i.e.,
177+
CONFIG_ADDRESS_MASKING is not selected) the flag "lam" will not show up.
178178
Even though the feature will still be detected via CPUID, the kernel disables
179-
it by clearing via setup_clear_cpu_cap(X86_FEATURE_LA57).
179+
it by clearing via setup_clear_cpu_cap(X86_FEATURE_LAM).
180180

181181
The feature is disabled at boot-time
182182
------------------------------------
@@ -200,5 +200,3 @@ missing at runtime. For example, AVX flags will not show up if XSAVE feature
200200
is disabled since they depend on XSAVE feature. Another example would be broken
201201
CPUs and them missing microcode patches. Due to that, the kernel decides not to
202202
enable a feature.
203-
204-
.. [#f1] 5-level paging uses linear address of 57 bits.

Documentation/arch/x86/x86_64/5level-paging.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ QEMU 2.9 and later support 5-level paging.
2222
Virtual memory layout for 5-level paging is described in
2323
Documentation/arch/x86/x86_64/mm.rst
2424

25-
26-
Enabling 5-level paging
27-
=======================
28-
CONFIG_X86_5LEVEL=y enables the feature.
29-
30-
Kernel with CONFIG_X86_5LEVEL=y still able to boot on 4-level hardware.
31-
In this case additional page table level -- p4d -- will be folded at
32-
runtime.
33-
3425
User-space and large virtual address space
3526
==========================================
3627
On x86, 5-level paging enables 56-bit userspace virtual address space.

arch/x86/Kconfig

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ config DYNAMIC_PHYSICAL_MASK
427427

428428
config PGTABLE_LEVELS
429429
int
430-
default 5 if X86_5LEVEL
431-
default 4 if X86_64
430+
default 5 if X86_64
432431
default 3 if X86_PAE
433432
default 2
434433

@@ -1464,25 +1463,6 @@ config X86_PAE
14641463
has the cost of more pagetable lookup overhead, and also
14651464
consumes more pagetable space per process.
14661465

1467-
config X86_5LEVEL
1468-
bool "Enable 5-level page tables support"
1469-
default y
1470-
depends on X86_64
1471-
help
1472-
5-level paging enables access to larger address space:
1473-
up to 128 PiB of virtual address space and 4 PiB of
1474-
physical address space.
1475-
1476-
It will be supported by future Intel CPUs.
1477-
1478-
A kernel with the option enabled can be booted on machines that
1479-
support 4- or 5-level paging.
1480-
1481-
See Documentation/arch/x86/x86_64/5level-paging.rst for more
1482-
information.
1483-
1484-
Say N if unsure.
1485-
14861466
config X86_DIRECT_GBPAGES
14871467
def_bool y
14881468
depends on X86_64

arch/x86/Kconfig.cpufeatures

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ config X86_DISABLED_FEATURE_OSPKE
132132
def_bool y
133133
depends on !X86_INTEL_MEMORY_PROTECTION_KEYS
134134

135-
config X86_DISABLED_FEATURE_LA57
136-
def_bool y
137-
depends on !X86_5LEVEL
138-
139135
config X86_DISABLED_FEATURE_PTI
140136
def_bool y
141137
depends on !MITIGATION_PAGE_TABLE_ISOLATION

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
#define BIOS_START_MIN 0x20000U /* 128K, less than this is insane */
1111
#define BIOS_START_MAX 0x9f000U /* 640K, absolute maximum */
1212

13-
#ifdef CONFIG_X86_5LEVEL
1413
/* __pgtable_l5_enabled needs to be in .data to avoid being cleared along with .bss */
1514
unsigned int __section(".data") __pgtable_l5_enabled;
1615
unsigned int __section(".data") pgdir_shift = 39;
1716
unsigned int __section(".data") ptrs_per_p4d = 1;
18-
#endif
1917

2018
/* Buffer to preserve trampoline memory */
2119
static char trampoline_save[TRAMPOLINE_32BIT_SIZE];
@@ -114,18 +112,13 @@ asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgtable)
114112
* Check if LA57 is desired and supported.
115113
*
116114
* There are several parts to the check:
117-
* - if the kernel supports 5-level paging: CONFIG_X86_5LEVEL=y
118115
* - if user asked to disable 5-level paging: no5lvl in cmdline
119116
* - if the machine supports 5-level paging:
120117
* + CPUID leaf 7 is supported
121118
* + the leaf has the feature bit set
122-
*
123-
* That's substitute for boot_cpu_has() in early boot code.
124119
*/
125-
if (IS_ENABLED(CONFIG_X86_5LEVEL) &&
126-
!cmdline_find_option_bool("no5lvl") &&
127-
native_cpuid_eax(0) >= 7 &&
128-
(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31)))) {
120+
if (!cmdline_find_option_bool("no5lvl") &&
121+
native_cpuid_eax(0) >= 7 && (native_cpuid_ecx(7) & BIT(16))) {
129122
l5_required = true;
130123

131124
/* Initialize variables for 5-level paging */

arch/x86/boot/header.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,8 @@ xloadflags:
361361
#endif
362362

363363
#ifdef CONFIG_X86_64
364-
#ifdef CONFIG_X86_5LEVEL
365364
#define XLF56 (XLF_5LEVEL|XLF_5LEVEL_ENABLED)
366365
#else
367-
#define XLF56 XLF_5LEVEL
368-
#endif
369-
#else
370366
#define XLF56 0
371367
#endif
372368

arch/x86/boot/startup/map_kernel.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ extern unsigned int next_early_pgt;
1616

1717
static inline bool check_la57_support(void)
1818
{
19-
if (!IS_ENABLED(CONFIG_X86_5LEVEL))
20-
return false;
21-
2219
/*
2320
* 5-level paging is detected and enabled at kernel decompression
2421
* stage. Only check if it has been enabled there.
@@ -129,7 +126,7 @@ unsigned long __head __startup_64(unsigned long p2v_offset,
129126
pgd = rip_rel_ptr(early_top_pgt);
130127
pgd[pgd_index(__START_KERNEL_map)] += load_delta;
131128

132-
if (IS_ENABLED(CONFIG_X86_5LEVEL) && la57) {
129+
if (la57) {
133130
p4d = (p4dval_t *)rip_rel_ptr(level4_kernel_pgt);
134131
p4d[MAX_PTRS_PER_P4D - 1] += load_delta;
135132

arch/x86/entry/vsyscall/vsyscall_64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ void __init set_vsyscall_pgtable_user_bits(pgd_t *root)
341341
pgd = pgd_offset_pgd(root, VSYSCALL_ADDR);
342342
set_pgd(pgd, __pgd(pgd_val(*pgd) | _PAGE_USER));
343343
p4d = p4d_offset(pgd, VSYSCALL_ADDR);
344-
#if CONFIG_PGTABLE_LEVELS >= 5
345344
set_p4d(p4d, __p4d(p4d_val(*p4d) | _PAGE_USER));
346-
#endif
347345
pud = pud_offset(p4d, VSYSCALL_ADDR);
348346
set_pud(pud, __pud(pud_val(*pud) | _PAGE_USER));
349347
pmd = pmd_offset(pud, VSYSCALL_ADDR);

arch/x86/include/asm/page_64.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ static inline void clear_page(void *page)
6262
void copy_page(void *to, void *from);
6363
KCFI_REFERENCE(copy_page);
6464

65-
#ifdef CONFIG_X86_5LEVEL
6665
/*
6766
* User space process size. This is the first address outside the user range.
6867
* There are a few constraints that determine this:
@@ -93,7 +92,6 @@ static __always_inline unsigned long task_size_max(void)
9392

9493
return ret;
9594
}
96-
#endif /* CONFIG_X86_5LEVEL */
9795

9896
#endif /* !__ASSEMBLER__ */
9997

arch/x86/include/asm/page_64_types.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@
4848
/* See Documentation/arch/x86/x86_64/mm.rst for a description of the memory map. */
4949

5050
#define __PHYSICAL_MASK_SHIFT 52
51-
52-
#ifdef CONFIG_X86_5LEVEL
5351
#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled() ? 56 : 47)
54-
/* See task_size_max() in <asm/page_64.h> */
55-
#else
56-
#define __VIRTUAL_MASK_SHIFT 47
57-
#define task_size_max() ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - PAGE_SIZE)
58-
#endif
5952

6053
#define TASK_SIZE_MAX task_size_max()
6154
#define DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE)

0 commit comments

Comments
 (0)