5-level paging changes for v4.18
Subsystems (7)
v5 cover 5-level paging changes for v4.18
Here's several patches that I would like to queue for v4.18. Please review and consider applying.
In this version I've addressed Thomas' feedback.
Changing __pgtable_l5_enabled to __initdata is not as trivial as I hoped. It requires few tricks to avoid section mismatch. I'm not sure if it worth the gain. We can keep it __ro_after_init.
If you feel it's too invasive, just drop last three patches.
Kirill A. Shutemov (7):
x86/boot/compressed/64: Fix trampoline page table address calculation x86/mm: Unify pgtable_l5_enabled usage in early boot code x86/mm: Stop pretending pgtable_l5_enabled is a variable x86/mm: Introduce 'no5lvl' kernel parameter
x86/cpu: Move early cpu initialization into a separate translation
unit
x86/mm: Mark p4d_offset() __always_inline
x86/mm: Mark __pgtable_l5_enabled __initdata
.../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/kaslr.c | 4 +- arch/x86/boot/compressed/misc.h | 6 +- arch/x86/boot/compressed/pgtable_64.c | 14 +- arch/x86/include/asm/page_64_types.h | 2 +- arch/x86/include/asm/paravirt.h | 4 +- arch/x86/include/asm/pgalloc.h | 4 +- arch/x86/include/asm/pgtable.h | 12 +- arch/x86/include/asm/pgtable_32_types.h | 2 +- arch/x86/include/asm/pgtable_64.h | 2 +- arch/x86/include/asm/pgtable_64_types.h | 25 ++- arch/x86/include/asm/sparsemem.h | 4 +- arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 179 +++--------------- arch/x86/kernel/cpu/cpu.h | 7 + arch/x86/kernel/cpu/early.c | 159 ++++++++++++++++ arch/x86/kernel/head64.c | 25 ++- arch/x86/kernel/machine_kexec_64.c | 3 +- arch/x86/mm/dump_pagetables.c | 6 +- arch/x86/mm/fault.c | 4 +- arch/x86/mm/ident_map.c | 2 +- arch/x86/mm/init_64.c | 8 +- arch/x86/mm/kasan_init_64.c | 14 +- arch/x86/mm/kaslr.c | 8 +- arch/x86/mm/tlb.c | 2 +- arch/x86/platform/efi/efi_64.c | 2 +- arch/x86/power/hibernate_64.c | 2 +- 29 files changed, 279 insertions(+), 228 deletions(-) create mode 100644 arch/x86/kernel/cpu/early.c
Signature · 1 line
2.17.0
PATCH v5 1/7 x86/boot/compressed/64: Fix trampoline page table address calculation
Hugh noticied that I calculate address of trampoline page table wrongly in cleanup_trampoline(). TRAMPOLINE_32BIT_PGTABLE_OFFSET has to be divided by sizeof(unsigned long) since trampoline_32bit is unsigned long pointer.
TRAMPOLINE_32BIT_PGTABLE_OFFSET is zero so the bug doesn't have a visible effect.
--- arch/x86/boot/compressed/pgtable_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/pgtable_64.c +1 -1
@@ -130,7 +130,7 @@ void cleanup_trampoline(void *pgtable) {void *trampoline_pgtable; - trampoline_pgtable = trampoline_32bit +TRAMPOLINE_32BIT_PGTABLE_OFFSET ; + trampoline_pgtable = trampoline_32bit +TRAMPOLINE_32BIT_PGTABLE_OFFSET /sizeof (unsigned long );/* * Move the top level page table out of trampoline memory,
Signature · 1 line
2.17.0
Re: [PATCH 1/7] x86/boot/compressed/64: Fix trampoline page table address calculation
Quoted 11 lines · Kirill A. Shutemov
Hugh noticied that I calculate address of trampoline page table wrongly in
cleanup_trampoline().TRAMPOLINE_32BIT_PGTABLE_OFFSEThas to be divided by sizeof(unsigned long) sincetrampoline_32bitis unsigned long pointer.
TRAMPOLINE_32BIT_PGTABLE_OFFSETis zero so the bug doesn't have a visible effect.Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hugh Dickins <[email protected]>Fixes e9d0e6330eb8 ("x86/boot/compressed/64: Prepare new top-level page table for trampoline")
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/boot/compressed/64: Fix trampoline page table address calculation
In reply to Kirill A. Shutemovx86/boot/compressed/64: Fix trampoline page table address calculation
Commit-ID: 30bbf728ba91b1e8b0e539126cd105ad7e2fa16a Gitweb: https://git.kernel.org/tip/30bbf728ba91b1e8b0e539126cd105ad7e2fa16a Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:22 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:57 +0200
x86/boot/compressed/64: Fix trampoline page table address calculation
Hugh noticied that we calculate the address of the trampoline page table incorrectly in cleanup_trampoline().
TRAMPOLINE_32BIT_PGTABLE_OFFSET has to be divided by sizeof(unsigned long), since trampoline_32bit is an 'unsigned long' pointer.
TRAMPOLINE_32BIT_PGTABLE_OFFSET is zero so the bug doesn't have a visible effect.
--- arch/x86/boot/compressed/pgtable_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/pgtable_64.c +1 -1
@@ -130,7 +130,7 @@ void cleanup_trampoline(void *pgtable) {void *trampoline_pgtable; - trampoline_pgtable = trampoline_32bit +TRAMPOLINE_32BIT_PGTABLE_OFFSET ; + trampoline_pgtable = trampoline_32bit +TRAMPOLINE_32BIT_PGTABLE_OFFSET /sizeof (unsigned long );/* * Move the top level page table out of trampoline memory,
PATCH v5 2/7 x86/mm: Unify pgtable_l5_enabled usage in early boot code
In reply to Kirill A. ShutemovUsually 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.
--- arch/x86/boot/compressed/kaslr.c | 4 ++-- arch/x86/boot/compressed/misc.h | 6 ++---- arch/x86/include/asm/pgtable_64_types.h | 13 ++++++++++--- arch/x86/kernel/head64.c | 12 +++++------- arch/x86/mm/kasan_init_64.c | 6 ++---- 5 files changed, 21 insertions(+), 20 deletions(-)
arch/x86/boot/compressed/kaslr.c +2 -2
@@ -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 ; }
arch/x86/boot/compressed/misc.h +2 -4
@@ -12,10 +12,8 @@#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>
arch/x86/include/asm/pgtable_64_types.h +10 -3
@@ -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;
arch/x86/kernel/head64.c +5 -7
@@ -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>
@@ -32,11 +36,6 @@#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;
arch/x86/mm/kasan_init_64.c +2 -4
@@ -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>
Signature · 1 line
2.17.0
Re: [PATCH 2/7] x86/mm: Unify pgtable_l5_enabled usage in early boot code
Quoted 4 lines · Kirill A. Shutemov
Usually
pgtable_l5_enabledis defined usingcpu_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.
Quoted 8 lines
Unify them all.
If
cpu_feature_enabled()is not yet available,USE_EARLY_PGTABLE_L5can be defined before all includes. It makespgtable_l5_enabledrely on__pgtable_l5_enabledvariable instead. This approach fits all early users.Signed-off-by Kirill A. Shutemov <[email protected]>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/mm: Unify pgtable_l5_enabled usage in early boot code
In reply to Kirill A. Shutemovx86/mm: Unify pgtable_l5_enabled usage in early boot code
Commit-ID: ad3fe525b9507d8d750d60e8e5dd8e0c0836fb99 Gitweb: https://git.kernel.org/tip/ad3fe525b9507d8d750d60e8e5dd8e0c0836fb99 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:23 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:57 +0200
x86/mm: Unify pgtable_l5_enabled usage in early boot code
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.
--- arch/x86/boot/compressed/kaslr.c | 4 ++-- arch/x86/boot/compressed/misc.h | 6 ++---- arch/x86/include/asm/pgtable_64_types.h | 13 ++++++++++--- arch/x86/kernel/head64.c | 12 +++++------- arch/x86/mm/kasan_init_64.c | 6 ++---- 5 files changed, 21 insertions(+), 20 deletions(-)
arch/x86/boot/compressed/kaslr.c +2 -2
@@ -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 ; }
arch/x86/boot/compressed/misc.h +2 -4
@@ -12,10 +12,8 @@#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>
arch/x86/include/asm/pgtable_64_types.h +10 -3
@@ -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;
arch/x86/kernel/head64.c +5 -7
@@ -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>
@@ -32,11 +36,6 @@#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;
arch/x86/mm/kasan_init_64.c +2 -4
@@ -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>
PATCH v5 3/7 x86/mm: Stop pretending pgtable_l5_enabled is a variable
In reply to Kirill A. Shutemovpgtable_l5_enabled is defined using cpu_feature_enabled() but we refer to it as a variable. This is misleading.
Make pgtable_l5_enabled() a function.
We cannot literally define it as a function due to circular dependencies between header files. Function-alike macros is close enough.
--- arch/x86/include/asm/page_64_types.h | 2 +- arch/x86/include/asm/paravirt.h | 4 ++-- arch/x86/include/asm/pgalloc.h | 4 ++-- arch/x86/include/asm/pgtable.h | 10 +++++----- arch/x86/include/asm/pgtable_32_types.h | 2 +- arch/x86/include/asm/pgtable_64.h | 2 +- arch/x86/include/asm/pgtable_64_types.h | 14 +++++++++----- arch/x86/include/asm/sparsemem.h | 4 ++-- arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/machine_kexec_64.c | 3 ++- arch/x86/mm/dump_pagetables.c | 6 +++--- arch/x86/mm/fault.c | 4 ++-- arch/x86/mm/ident_map.c | 2 +- arch/x86/mm/init_64.c | 8 ++++---- arch/x86/mm/kasan_init_64.c | 8 ++++---- arch/x86/mm/kaslr.c | 8 ++++---- arch/x86/mm/tlb.c | 2 +- arch/x86/platform/efi/efi_64.c | 2 +- arch/x86/power/hibernate_64.c | 2 +- 19 files changed, 47 insertions(+), 42 deletions(-)
arch/x86/include/asm/page_64_types.h +1 -1
@@ -53,7 +53,7 @@#define __PHYSICAL_MASK_SHIFT 52#ifdef CONFIG_X86_5LEVEL -#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled ? 56 : 47) +#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled() ? 56 : 47)#else #define __VIRTUAL_MASK_SHIFT 47#endif
arch/x86/include/asm/paravirt.h +2 -2
@@ -574,14 +574,14 @@ static inline void __set_pgd(pgd_t *pgdp, pgd_t pgd) }#define set_pgd (pgdp, pgdval) do { \ - if (pgtable_l5_enabled) \ + if (pgtable_l5_enabled()) \ __set_pgd(pgdp, pgdval); \ else \ set_p4d((p4d_t *)(pgdp), (p4d_t) { (pgdval).pgd }); \ } while (0)#define pgd_clear (pgdp) do { \ - if (pgtable_l5_enabled) \ + if (pgtable_l5_enabled()) \ set_pgd(pgdp, __pgd(0)); \ } while (0)
arch/x86/include/asm/pgalloc.h +2 -2
@@ -167,7 +167,7 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,#if CONFIG_PGTABLE_LEVELS >4 static inline void pgd_populate (struct mm_struct *mm,pgd_t *pgd,p4d_t *p4d) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return ;paravirt_alloc_p4d (mm,__pa (p4d) >>PAGE_SHIFT );set_pgd (pgd,__pgd (_PAGE_TABLE |__pa (p4d)));
@@ -193,7 +193,7 @@ extern void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d);static inline void __p4d_free_tlb (struct mmu_gather *tlb,p4d_t *p4d,unsigned long address) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())___p4d_free_tlb (tlb, p4d); }
arch/x86/include/asm/pgtable.h +5 -5
@@ -65,7 +65,7 @@ extern pmdval_t early_pmd_flags;#ifndef __PAGETABLE_P4D_FOLDED#define set_pgd (pgdp, pgd) native_set_pgd(pgdp, pgd) -#define pgd_clear (pgd) (pgtable_l5_enabled ? native_pgd_clear(pgd) : 0) +#define pgd_clear (pgd) (pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0)#endif #ifndef set_p4d
@@ -881,7 +881,7 @@ static inline unsigned long p4d_index(unsigned long address)#if CONFIG_PGTABLE_LEVELS >4 static inline int pgd_present (pgd_t pgd) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 1 ;return pgd_flags (pgd) & _PAGE_PRESENT; }
@@ -900,7 +900,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)/* to find an entry in a page-table-directory. */ static inline p4d_t *p4d_offset (pgd_t *pgd,unsigned long address) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return (p4d_t *)pgd;return (p4d_t *)pgd_page_vaddr (*pgd) +p4d_index (address); }
@@ -909,7 +909,7 @@ static inline int pgd_bad(pgd_t pgd) {unsigned long ignore_flags = _PAGE_USER; -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 0 ;if (IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION ))
@@ -920,7 +920,7 @@ static inline int pgd_bad(pgd_t pgd)static inline int pgd_none (pgd_t pgd) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 0 ;/* * There is no need to do a workaround for the KNL stray
arch/x86/include/asm/pgtable_32_types.h +1 -1
@@ -15,7 +15,7 @@# include <asm/pgtable-2level_types.h> #endif -#define pgtable_l5_enabled 0 +#define pgtable_l5_enabled () 0#define PGDIR_SIZE (1UL << PGDIR_SHIFT)#define PGDIR_MASK (~(PGDIR_SIZE - 1))
arch/x86/include/asm/pgtable_64.h +1 -1
@@ -220,7 +220,7 @@ static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) {pgd_t pgd; -if (pgtable_l5_enabled || !IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION )) { +if (pgtable_l5_enabled () || !IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION )) { *p4dp = p4d;return ; }
arch/x86/include/asm/pgtable_64_types.h +9 -5
@@ -28,12 +28,16 @@ extern unsigned int __pgtable_l5_enabled;* cpu_feature_enabled() is not available in early boot code. * Use variable instead. */ -#define pgtable_l5_enabled __pgtable_l5_enabled +static inline bool pgtable_l5_enabled (void ) +{ +return __pgtable_l5_enabled; +}#else -#define pgtable_l5_enabled cpu_feature_enabled(X86_FEATURE_LA57) +#define pgtable_l5_enabled () cpu_feature_enabled(X86_FEATURE_LA57)#endif /* USE_EARLY_PGTABLE_L5 */ +#else -#define pgtable_l5_enabled 0 +#define pgtable_l5_enabled () 0#endif /* CONFIG_X86_5LEVEL */ extern unsigned int pgdir_shift;
@@ -109,7 +113,7 @@ extern unsigned int ptrs_per_p4d;#define LDT_PGD_ENTRY_L4 -3UL#define LDT_PGD_ENTRY_L5 -112UL -#define LDT_PGD_ENTRY (pgtable_l5_enabled ? LDT_PGD_ENTRY_L5 : LDT_PGD_ENTRY_L4) +#define LDT_PGD_ENTRY (pgtable_l5_enabled() ? LDT_PGD_ENTRY_L5 : LDT_PGD_ENTRY_L4)#define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT)#define __VMALLOC_BASE_L4 0xffffc90000000000UL
@@ -123,7 +127,7 @@ extern unsigned int ptrs_per_p4d;#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT # define VMALLOC_START vmalloc_base -# define VMALLOC_SIZE_TB (pgtable_l5_enabled ? VMALLOC_SIZE_TB_L5 : VMALLOC_SIZE_TB_L4) +# define VMALLOC_SIZE_TB (pgtable_l5_enabled() ? VMALLOC_SIZE_TB_L5 : VMALLOC_SIZE_TB_L4)# define VMEMMAP_START vmemmap_base#else # define VMALLOC_START __VMALLOC_BASE_L4
arch/x86/include/asm/sparsemem.h +2 -2
@@ -27,8 +27,8 @@# endif #else /* CONFIG_X86_32 */ # define SECTION_SIZE_BITS 27/* matt - 128 is convenient right now */ -# define MAX_PHYSADDR_BITS (pgtable_l5_enabled ? 52 : 44) -# define MAX_PHYSMEM_BITS (pgtable_l5_enabled ? 52 : 46) +# define MAX_PHYSADDR_BITS (pgtable_l5_enabled() ? 52 : 44) +# define MAX_PHYSMEM_BITS (pgtable_l5_enabled() ? 52 : 46)#endif #endif /* CONFIG_SPARSEMEM */
arch/x86/kernel/head64.c +1 -1
@@ -271,7 +271,7 @@ int __init __early_make_pgtable(unsigned long address, pmdval_t pmd)* critical -- __PAGE_OFFSET would point us back into the dynamic * range and we might end up looping forever... */ -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ()) p4d_p = pgd_p;else if (pgd) p4d_p = (p4dval_t *)((pgd &PTE_PFN_MASK ) + __START_KERNEL_map - phys_base);
arch/x86/kernel/machine_kexec_64.c +2 -1
@@ -351,7 +351,8 @@ void arch_crash_save_vmcoreinfo(void) {VMCOREINFO_NUMBER (phys_base);VMCOREINFO_SYMBOL (init_top_pgt); -VMCOREINFO_NUMBER (pgtable_l5_enabled); +vmcoreinfo_append_str ("NUMBER(pgtable_l5_enabled)=%d\n" , +pgtable_l5_enabled ());#ifdef CONFIG_NUMA VMCOREINFO_SYMBOL (node_data);
arch/x86/mm/dump_pagetables.c +3 -3
@@ -360,7 +360,7 @@ static inline bool kasan_page_table(struct seq_file *m, struct pg_state *st, void *pt) {if (__pa (pt) ==__pa (kasan_zero_pmd) || - (pgtable_l5_enabled &&__pa (pt) ==__pa (kasan_zero_p4d)) || + (pgtable_l5_enabled () &&__pa (pt) ==__pa (kasan_zero_p4d)) ||__pa (pt) ==__pa (kasan_zero_pud)) {pgprotval_t prot =pte_flags (kasan_zero_pte[0 ]);note_page (m, st,__pgprot (prot),0 ,5 );
@@ -476,8 +476,8 @@ static void walk_p4d_level(struct seq_file *m, struct pg_state *st, pgd_t addr, } } -#define pgd_large (a) (pgtable_l5_enabled ? pgd_large(a) : p4d_large(__p4d(pgd_val(a)))) -#define pgd_none (a) (pgtable_l5_enabled ? pgd_none(a) : p4d_none(__p4d(pgd_val(a)))) +#define pgd_large (a) (pgtable_l5_enabled() ? pgd_large(a) : p4d_large(__p4d(pgd_val(a)))) +#define pgd_none (a) (pgtable_l5_enabled() ? pgd_none(a) : p4d_none(__p4d(pgd_val(a))))static inline bool is_hypervisor_range (int idx) {
arch/x86/mm/fault.c +2 -2
@@ -439,7 +439,7 @@ static noinline int vmalloc_fault(unsigned long address)if (pgd_none (*pgd_k))return -1 ; -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {if (pgd_none (*pgd)) {set_pgd (pgd, *pgd_k);arch_flush_lazy_mmu_mode ();
@@ -454,7 +454,7 @@ static noinline int vmalloc_fault(unsigned long address)if (p4d_none (*p4d_k))return -1 ; -if (p4d_none (*p4d) && !pgtable_l5_enabled) { +if (p4d_none (*p4d) && !pgtable_l5_enabled ()) {set_p4d (p4d, *p4d_k);arch_flush_lazy_mmu_mode (); }else {
arch/x86/mm/ident_map.c +1 -1
@@ -123,7 +123,7 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, result =ident_p4d_init (info, p4d, addr, next);if (result)return result; -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {set_pgd (pgd,__pgd (__pa (p4d) | info->kernpg_flag)); }else {/*
arch/x86/mm/init_64.c +4 -4
@@ -180,7 +180,7 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end)*/ void sync_global_pgds (unsigned long start,unsigned long end) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())sync_global_pgds_l5 (start, end);else sync_global_pgds_l4 (start, end);
@@ -643,7 +643,7 @@ phys_p4d_init(p4d_t *p4d_page, unsigned long paddr, unsigned long paddr_end,unsigned long vaddr = (unsigned long )__va (paddr);int i =p4d_index (vaddr); -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return phys_pud_init ((pud_t *) p4d_page, paddr, paddr_end, page_size_mask);for (; i <PTRS_PER_P4D ; i++, paddr = paddr_next) {
@@ -723,7 +723,7 @@ kernel_physical_mapping_init(unsigned long paddr_start, page_size_mask);spin_lock (&init_mm.page_table_lock); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())pgd_populate (&init_mm, pgd, p4d);else p4d_populate (&init_mm,p4d_offset (pgd, vaddr), (pud_t *) p4d);
@@ -1100,7 +1100,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,* 5-level case we should free them. This code will have to change * to adapt for boot-time switching between 4 and 5 level page tables. */ -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())free_pud_table (pud_base, p4d); }
arch/x86/mm/kasan_init_64.c +4 -4
@@ -180,7 +180,7 @@ static void __init clear_pgds(unsigned long start,* With folded p4d, pgd_clear() is nop, use p4d_clear() * instead. */ -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())pgd_clear (pgd);else p4d_clear (p4d_offset (pgd, start));
@@ -195,7 +195,7 @@ static inline p4d_t *early_p4d_offset(pgd_t *pgd, unsigned long addr) {unsigned long p4d; -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return (p4d_t *)pgd; p4d =__pa_nodebug (pgd_val (*pgd)) &PTE_PFN_MASK ;
@@ -282,7 +282,7 @@ void __init kasan_early_init(void)for (i =0 ; i <PTRS_PER_PUD ; i++) kasan_zero_pud[i] =__pud (pud_val); -for (i =0 ; pgtable_l5_enabled && i <PTRS_PER_P4D ; i++) +for (i =0 ;pgtable_l5_enabled () && i <PTRS_PER_P4D ; i++) kasan_zero_p4d[i] =__p4d (p4d_val);kasan_map_early_shadow (early_top_pgt);
@@ -313,7 +313,7 @@ void __init kasan_init(void)* bunch of things like kernel code, modules, EFI mapping, etc. * We need to take extra steps to not overwrite them. */ -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {void *ptr; ptr = (void *)pgd_page_vaddr (*pgd_offset_k (KASAN_SHADOW_END ));
arch/x86/mm/kaslr.c +4 -4
@@ -78,7 +78,7 @@ void __init kernel_randomize_memory(void)struct rnd_state rand_state;unsigned long remain_entropy; - vaddr_start = pgtable_l5_enabled ? __PAGE_OFFSET_BASE_L5 : __PAGE_OFFSET_BASE_L4; + vaddr_start =pgtable_l5_enabled () ? __PAGE_OFFSET_BASE_L5 : __PAGE_OFFSET_BASE_L4; vaddr = vaddr_start;/*
@@ -124,7 +124,7 @@ void __init kernel_randomize_memory(void)*/ entropy = remain_entropy / (ARRAY_SIZE (kaslr_regions) - i);prandom_bytes_state (&rand_state, &rand,sizeof (rand)); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ()) entropy = (rand % (entropy +1 )) &P4D_MASK ;else entropy = (rand % (entropy +1 )) &PUD_MASK ;
@@ -136,7 +136,7 @@ void __init kernel_randomize_memory(void)* randomization alignment. */ vaddr +=get_padding (&kaslr_regions[i]); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ()) vaddr =round_up (vaddr +1 ,P4D_SIZE );else vaddr =round_up (vaddr +1 ,PUD_SIZE );
@@ -212,7 +212,7 @@ void __meminit init_trampoline(void)return ; } -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())init_trampoline_p4d ();else init_trampoline_pud ();
arch/x86/mm/tlb.c +1 -1
@@ -157,7 +157,7 @@ static void sync_current_stack_to_mm(struct mm_struct *mm)unsigned long sp = current_stack_pointer;pgd_t *pgd =pgd_offset (mm, sp); -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {if (unlikely (pgd_none (*pgd))) {pgd_t *pgd_ref =pgd_offset_k (sp);
arch/x86/platform/efi/efi_64.c +1 -1
@@ -225,7 +225,7 @@ int __init efi_alloc_page_tables(void) pud =pud_alloc (&init_mm, p4d,EFI_VA_END );if (!pud) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())free_page ((unsigned long )pgd_page_vaddr (*pgd));free_pages ((unsigned long )efi_pgd,PGD_ALLOCATION_ORDER );return -ENOMEM ;
arch/x86/power/hibernate_64.c +1 -1
@@ -72,7 +72,7 @@ static int set_up_temporary_text_mapping(pgd_t *pgd)* tables used by the image kernel. */ -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) { p4d = (p4d_t *)get_safe_page (GFP_ATOMIC );if (!p4d)return -ENOMEM ;
Signature · 1 line
2.17.0
Re: [PATCH 3/7] x86/mm: Stop pretending pgtable_l5_enabled is a variable
Quoted 9 lines · Kirill A. Shutemov
pgtable_l5_enabledis defined usingcpu_feature_enabled()but we refer to it as a variable. This is misleading.Make
pgtable_l5_enabled()a function.We cannot literally define it as a function due to circular dependencies between header files. Function-alike macros is close enough.
Signed-off-by Kirill A. Shutemov <[email protected]>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/mm: Stop pretending pgtable_l5_enabled is a variable
In reply to Kirill A. Shutemovx86/mm: Stop pretending pgtable_l5_enabled is a variable
Commit-ID: ed7588d5dc6f5e7202fb9bbeb14d94706ba225d7 Gitweb: https://git.kernel.org/tip/ed7588d5dc6f5e7202fb9bbeb14d94706ba225d7 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:24 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:57 +0200
x86/mm: Stop pretending pgtable_l5_enabled is a variable
pgtable_l5_enabled is defined using cpu_feature_enabled() but we refer to it as a variable. This is misleading.
Make pgtable_l5_enabled() a function.
We cannot literally define it as a function due to circular dependencies between header files. Function-alike macros is close enough.
--- arch/x86/include/asm/page_64_types.h | 2 +- arch/x86/include/asm/paravirt.h | 4 ++-- arch/x86/include/asm/pgalloc.h | 4 ++-- arch/x86/include/asm/pgtable.h | 10 +++++----- arch/x86/include/asm/pgtable_32_types.h | 2 +- arch/x86/include/asm/pgtable_64.h | 2 +- arch/x86/include/asm/pgtable_64_types.h | 14 +++++++++----- arch/x86/include/asm/sparsemem.h | 4 ++-- arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/machine_kexec_64.c | 3 ++- arch/x86/mm/dump_pagetables.c | 6 +++--- arch/x86/mm/fault.c | 4 ++-- arch/x86/mm/ident_map.c | 2 +- arch/x86/mm/init_64.c | 8 ++++---- arch/x86/mm/kasan_init_64.c | 8 ++++---- arch/x86/mm/kaslr.c | 8 ++++---- arch/x86/mm/tlb.c | 2 +- arch/x86/platform/efi/efi_64.c | 2 +- arch/x86/power/hibernate_64.c | 2 +- 19 files changed, 47 insertions(+), 42 deletions(-)
arch/x86/include/asm/page_64_types.h +1 -1
@@ -53,7 +53,7 @@#define __PHYSICAL_MASK_SHIFT 52#ifdef CONFIG_X86_5LEVEL -#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled ? 56 : 47) +#define __VIRTUAL_MASK_SHIFT (pgtable_l5_enabled() ? 56 : 47)#else #define __VIRTUAL_MASK_SHIFT 47#endif
arch/x86/include/asm/paravirt.h +2 -2
@@ -574,14 +574,14 @@ static inline void __set_pgd(pgd_t *pgdp, pgd_t pgd) }#define set_pgd (pgdp, pgdval) do { \ - if (pgtable_l5_enabled) \ + if (pgtable_l5_enabled()) \ __set_pgd(pgdp, pgdval); \ else \ set_p4d((p4d_t *)(pgdp), (p4d_t) { (pgdval).pgd }); \ } while (0)#define pgd_clear (pgdp) do { \ - if (pgtable_l5_enabled) \ + if (pgtable_l5_enabled()) \ set_pgd(pgdp, __pgd(0)); \ } while (0)
arch/x86/include/asm/pgalloc.h +2 -2
@@ -167,7 +167,7 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,#if CONFIG_PGTABLE_LEVELS >4 static inline void pgd_populate (struct mm_struct *mm,pgd_t *pgd,p4d_t *p4d) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return ;paravirt_alloc_p4d (mm,__pa (p4d) >>PAGE_SHIFT );set_pgd (pgd,__pgd (_PAGE_TABLE |__pa (p4d)));
@@ -193,7 +193,7 @@ extern void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d);static inline void __p4d_free_tlb (struct mmu_gather *tlb,p4d_t *p4d,unsigned long address) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())___p4d_free_tlb (tlb, p4d); }
arch/x86/include/asm/pgtable.h +5 -5
@@ -65,7 +65,7 @@ extern pmdval_t early_pmd_flags;#ifndef __PAGETABLE_P4D_FOLDED#define set_pgd (pgdp, pgd) native_set_pgd(pgdp, pgd) -#define pgd_clear (pgd) (pgtable_l5_enabled ? native_pgd_clear(pgd) : 0) +#define pgd_clear (pgd) (pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0)#endif #ifndef set_p4d
@@ -881,7 +881,7 @@ static inline unsigned long p4d_index(unsigned long address)#if CONFIG_PGTABLE_LEVELS >4 static inline int pgd_present (pgd_t pgd) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 1 ;return pgd_flags (pgd) & _PAGE_PRESENT; }
@@ -900,7 +900,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)/* to find an entry in a page-table-directory. */ static inline p4d_t *p4d_offset (pgd_t *pgd,unsigned long address) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return (p4d_t *)pgd;return (p4d_t *)pgd_page_vaddr (*pgd) +p4d_index (address); }
@@ -909,7 +909,7 @@ static inline int pgd_bad(pgd_t pgd) {unsigned long ignore_flags = _PAGE_USER; -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 0 ;if (IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION ))
@@ -920,7 +920,7 @@ static inline int pgd_bad(pgd_t pgd)static inline int pgd_none (pgd_t pgd) { -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return 0 ;/* * There is no need to do a workaround for the KNL stray
arch/x86/include/asm/pgtable_32_types.h +1 -1
@@ -15,7 +15,7 @@# include <asm/pgtable-2level_types.h> #endif -#define pgtable_l5_enabled 0 +#define pgtable_l5_enabled () 0#define PGDIR_SIZE (1UL << PGDIR_SHIFT)#define PGDIR_MASK (~(PGDIR_SIZE - 1))
arch/x86/include/asm/pgtable_64.h +1 -1
@@ -220,7 +220,7 @@ static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) {pgd_t pgd; -if (pgtable_l5_enabled || !IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION )) { +if (pgtable_l5_enabled () || !IS_ENABLED (CONFIG_PAGE_TABLE_ISOLATION )) { *p4dp = p4d;return ; }
arch/x86/include/asm/pgtable_64_types.h +9 -5
@@ -28,12 +28,16 @@ extern unsigned int __pgtable_l5_enabled;* cpu_feature_enabled() is not available in early boot code. * Use variable instead. */ -#define pgtable_l5_enabled __pgtable_l5_enabled +static inline bool pgtable_l5_enabled (void ) +{ +return __pgtable_l5_enabled; +}#else -#define pgtable_l5_enabled cpu_feature_enabled(X86_FEATURE_LA57) +#define pgtable_l5_enabled () cpu_feature_enabled(X86_FEATURE_LA57)#endif /* USE_EARLY_PGTABLE_L5 */ +#else -#define pgtable_l5_enabled 0 +#define pgtable_l5_enabled () 0#endif /* CONFIG_X86_5LEVEL */ extern unsigned int pgdir_shift;
@@ -109,7 +113,7 @@ extern unsigned int ptrs_per_p4d;#define LDT_PGD_ENTRY_L4 -3UL#define LDT_PGD_ENTRY_L5 -112UL -#define LDT_PGD_ENTRY (pgtable_l5_enabled ? LDT_PGD_ENTRY_L5 : LDT_PGD_ENTRY_L4) +#define LDT_PGD_ENTRY (pgtable_l5_enabled() ? LDT_PGD_ENTRY_L5 : LDT_PGD_ENTRY_L4)#define LDT_BASE_ADDR (LDT_PGD_ENTRY << PGDIR_SHIFT)#define __VMALLOC_BASE_L4 0xffffc90000000000UL
@@ -123,7 +127,7 @@ extern unsigned int ptrs_per_p4d;#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT # define VMALLOC_START vmalloc_base -# define VMALLOC_SIZE_TB (pgtable_l5_enabled ? VMALLOC_SIZE_TB_L5 : VMALLOC_SIZE_TB_L4) +# define VMALLOC_SIZE_TB (pgtable_l5_enabled() ? VMALLOC_SIZE_TB_L5 : VMALLOC_SIZE_TB_L4)# define VMEMMAP_START vmemmap_base#else # define VMALLOC_START __VMALLOC_BASE_L4
arch/x86/include/asm/sparsemem.h +2 -2
@@ -27,8 +27,8 @@# endif #else /* CONFIG_X86_32 */ # define SECTION_SIZE_BITS 27/* matt - 128 is convenient right now */ -# define MAX_PHYSADDR_BITS (pgtable_l5_enabled ? 52 : 44) -# define MAX_PHYSMEM_BITS (pgtable_l5_enabled ? 52 : 46) +# define MAX_PHYSADDR_BITS (pgtable_l5_enabled() ? 52 : 44) +# define MAX_PHYSMEM_BITS (pgtable_l5_enabled() ? 52 : 46)#endif #endif /* CONFIG_SPARSEMEM */
arch/x86/kernel/head64.c +1 -1
@@ -279,7 +279,7 @@ again:* critical -- __PAGE_OFFSET would point us back into the dynamic * range and we might end up looping forever... */ -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ()) p4d_p = pgd_p;else if (pgd) p4d_p = (p4dval_t *)((pgd &PTE_PFN_MASK ) + __START_KERNEL_map - phys_base);
arch/x86/kernel/machine_kexec_64.c +2 -1
@@ -354,7 +354,8 @@ void arch_crash_save_vmcoreinfo(void) {VMCOREINFO_NUMBER (phys_base);VMCOREINFO_SYMBOL (init_top_pgt); -VMCOREINFO_NUMBER (pgtable_l5_enabled); +vmcoreinfo_append_str ("NUMBER(pgtable_l5_enabled)=%d\n" , +pgtable_l5_enabled ());#ifdef CONFIG_NUMA VMCOREINFO_SYMBOL (node_data);
arch/x86/mm/dump_pagetables.c +3 -3
@@ -360,7 +360,7 @@ static inline bool kasan_page_table(struct seq_file *m, struct pg_state *st, void *pt) {if (__pa (pt) ==__pa (kasan_zero_pmd) || - (pgtable_l5_enabled &&__pa (pt) ==__pa (kasan_zero_p4d)) || + (pgtable_l5_enabled () &&__pa (pt) ==__pa (kasan_zero_p4d)) ||__pa (pt) ==__pa (kasan_zero_pud)) {pgprotval_t prot =pte_flags (kasan_zero_pte[0 ]);note_page (m, st,__pgprot (prot),0 ,5 );
@@ -476,8 +476,8 @@ static void walk_p4d_level(struct seq_file *m, struct pg_state *st, pgd_t addr, } } -#define pgd_large (a) (pgtable_l5_enabled ? pgd_large(a) : p4d_large(__p4d(pgd_val(a)))) -#define pgd_none (a) (pgtable_l5_enabled ? pgd_none(a) : p4d_none(__p4d(pgd_val(a)))) +#define pgd_large (a) (pgtable_l5_enabled() ? pgd_large(a) : p4d_large(__p4d(pgd_val(a)))) +#define pgd_none (a) (pgtable_l5_enabled() ? pgd_none(a) : p4d_none(__p4d(pgd_val(a))))static inline bool is_hypervisor_range (int idx) {
arch/x86/mm/fault.c +2 -2
@@ -439,7 +439,7 @@ static noinline int vmalloc_fault(unsigned long address)if (pgd_none (*pgd_k))return -1 ; -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {if (pgd_none (*pgd)) {set_pgd (pgd, *pgd_k);arch_flush_lazy_mmu_mode ();
@@ -454,7 +454,7 @@ static noinline int vmalloc_fault(unsigned long address)if (p4d_none (*p4d_k))return -1 ; -if (p4d_none (*p4d) && !pgtable_l5_enabled) { +if (p4d_none (*p4d) && !pgtable_l5_enabled ()) {set_p4d (p4d, *p4d_k);arch_flush_lazy_mmu_mode (); }else {
arch/x86/mm/ident_map.c +1 -1
@@ -123,7 +123,7 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page, result =ident_p4d_init (info, p4d, addr, next);if (result)return result; -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {set_pgd (pgd,__pgd (__pa (p4d) | info->kernpg_flag)); }else {/*
arch/x86/mm/init_64.c +4 -4
@@ -180,7 +180,7 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end)*/ void sync_global_pgds (unsigned long start,unsigned long end) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())sync_global_pgds_l5 (start, end);else sync_global_pgds_l4 (start, end);
@@ -643,7 +643,7 @@ phys_p4d_init(p4d_t *p4d_page, unsigned long paddr, unsigned long paddr_end,unsigned long vaddr = (unsigned long )__va (paddr);int i =p4d_index (vaddr); -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return phys_pud_init ((pud_t *) p4d_page, paddr, paddr_end, page_size_mask);for (; i <PTRS_PER_P4D ; i++, paddr = paddr_next) {
@@ -723,7 +723,7 @@ kernel_physical_mapping_init(unsigned long paddr_start, page_size_mask);spin_lock (&init_mm.page_table_lock); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())pgd_populate (&init_mm, pgd, p4d);else p4d_populate (&init_mm,p4d_offset (pgd, vaddr), (pud_t *) p4d);
@@ -1100,7 +1100,7 @@ remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end,* 5-level case we should free them. This code will have to change * to adapt for boot-time switching between 4 and 5 level page tables. */ -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())free_pud_table (pud_base, p4d); }
arch/x86/mm/kasan_init_64.c +4 -4
@@ -180,7 +180,7 @@ static void __init clear_pgds(unsigned long start,* With folded p4d, pgd_clear() is nop, use p4d_clear() * instead. */ -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())pgd_clear (pgd);else p4d_clear (p4d_offset (pgd, start));
@@ -195,7 +195,7 @@ static inline p4d_t *early_p4d_offset(pgd_t *pgd, unsigned long addr) {unsigned long p4d; -if (!pgtable_l5_enabled) +if (!pgtable_l5_enabled ())return (p4d_t *)pgd; p4d =__pa_nodebug (pgd_val (*pgd)) &PTE_PFN_MASK ;
@@ -282,7 +282,7 @@ void __init kasan_early_init(void)for (i =0 ; i <PTRS_PER_PUD ; i++) kasan_zero_pud[i] =__pud (pud_val); -for (i =0 ; pgtable_l5_enabled && i <PTRS_PER_P4D ; i++) +for (i =0 ;pgtable_l5_enabled () && i <PTRS_PER_P4D ; i++) kasan_zero_p4d[i] =__p4d (p4d_val);kasan_map_early_shadow (early_top_pgt);
@@ -313,7 +313,7 @@ void __init kasan_init(void)* bunch of things like kernel code, modules, EFI mapping, etc. * We need to take extra steps to not overwrite them. */ -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {void *ptr; ptr = (void *)pgd_page_vaddr (*pgd_offset_k (KASAN_SHADOW_END ));
arch/x86/mm/kaslr.c +4 -4
@@ -78,7 +78,7 @@ void __init kernel_randomize_memory(void)struct rnd_state rand_state;unsigned long remain_entropy; - vaddr_start = pgtable_l5_enabled ? __PAGE_OFFSET_BASE_L5 : __PAGE_OFFSET_BASE_L4; + vaddr_start =pgtable_l5_enabled () ? __PAGE_OFFSET_BASE_L5 : __PAGE_OFFSET_BASE_L4; vaddr = vaddr_start;/*
@@ -124,7 +124,7 @@ void __init kernel_randomize_memory(void)*/ entropy = remain_entropy / (ARRAY_SIZE (kaslr_regions) - i);prandom_bytes_state (&rand_state, &rand,sizeof (rand)); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ()) entropy = (rand % (entropy +1 )) &P4D_MASK ;else entropy = (rand % (entropy +1 )) &PUD_MASK ;
@@ -136,7 +136,7 @@ void __init kernel_randomize_memory(void)* randomization alignment. */ vaddr +=get_padding (&kaslr_regions[i]); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ()) vaddr =round_up (vaddr +1 ,P4D_SIZE );else vaddr =round_up (vaddr +1 ,PUD_SIZE );
@@ -212,7 +212,7 @@ void __meminit init_trampoline(void)return ; } -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())init_trampoline_p4d ();else init_trampoline_pud ();
arch/x86/mm/tlb.c +1 -1
@@ -157,7 +157,7 @@ static void sync_current_stack_to_mm(struct mm_struct *mm)unsigned long sp = current_stack_pointer;pgd_t *pgd =pgd_offset (mm, sp); -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {if (unlikely (pgd_none (*pgd))) {pgd_t *pgd_ref =pgd_offset_k (sp);
arch/x86/platform/efi/efi_64.c +1 -1
@@ -225,7 +225,7 @@ int __init efi_alloc_page_tables(void) pud =pud_alloc (&init_mm, p4d,EFI_VA_END );if (!pud) { -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())free_page ((unsigned long )pgd_page_vaddr (*pgd));free_pages ((unsigned long )efi_pgd,PGD_ALLOCATION_ORDER );return -ENOMEM ;
arch/x86/power/hibernate_64.c +1 -1
@@ -72,7 +72,7 @@ static int set_up_temporary_text_mapping(pgd_t *pgd)* tables used by the image kernel. */ -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) { p4d = (p4d_t *)get_safe_page (GFP_ATOMIC );if (!p4d)return -ENOMEM ;
PATCH v5 4/7 x86/mm: Introduce 'no5lvl' kernel parameter
In reply to Kirill A. ShutemovThe 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.
--- 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 | 15 +++++++++++++++ arch/x86/kernel/head64.c | 9 +++++---- 6 files changed, 35 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
@@ -365,6 +365,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
@@ -31,16 +31,23 @@ static char trampoline_save[TRAMPOLINE_32BIT_SIZE];*/ 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
@@ -48,6 +55,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 +15 -0
@@ -1008,6 +1008,21 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)*/ setup_clear_cpu_cap (X86_FEATURE_PCID );#endif + +/* +* Later in the boot process pgtable_l5_enabled() relies on +* cpu_feature_enabled(X86_FEATURE_LA57). If 5-level paging is not +* enabled by this point we need to clear the feature bit to avoid +* false-positives at the later stage. +* +* pgtable_l5_enabled() can be false here for several reasons: +* - 5-level paging is disabled compile-time; +* - it's 32-bit kernel; +* - machine doesn't support 5-level paging; +* - user specified 'no5lvl' in kernel command line. +*/ +if (!pgtable_l5_enabled ()) +setup_clear_cpu_cap (X86_FEATURE_LA57 ); }void __init early_cpu_init (void )
arch/x86/kernel/head64.c +5 -4
@@ -80,10 +80,11 @@ 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 at kernel decomression +* stage. Only check if it has been enabled there. +*/ +if (!(native_read_cr4 () &X86_CR4_LA57 ))return false; *fixup_int (&__pgtable_l5_enabled, physaddr) =1 ;
Signature · 1 line
2.17.0
Re: [PATCH 4/7] x86/mm: Introduce 'no5lvl' kernel parameter
Quoted 7 lines · Kirill A. Shutemov
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]>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/mm: Introduce the 'no5lvl' kernel parameter
In reply to Kirill A. Shutemovx86/mm: Introduce the 'no5lvl' kernel parameter
Commit-ID: 372fddf709041743a93e381556f4c41aad1e28f8 Gitweb: https://git.kernel.org/tip/372fddf709041743a93e381556f4c41aad1e28f8 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:25 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:57 +0200
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.
--- 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 | 15 +++++++++++++++ arch/x86/kernel/head64.c | 9 +++++---- 6 files changed, 35 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
@@ -365,6 +365,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
@@ -31,16 +31,23 @@ static char trampoline_save[TRAMPOLINE_32BIT_SIZE];*/ 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
@@ -48,6 +55,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 +15 -0
@@ -1028,6 +1028,21 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)*/ setup_clear_cpu_cap (X86_FEATURE_PCID );#endif + +/* +* Later in the boot process pgtable_l5_enabled() relies on +* cpu_feature_enabled(X86_FEATURE_LA57). If 5-level paging is not +* enabled by this point we need to clear the feature bit to avoid +* false-positives at the later stage. +* +* pgtable_l5_enabled() can be false here for several reasons: +* - 5-level paging is disabled compile-time; +* - it's 32-bit kernel; +* - machine doesn't support 5-level paging; +* - user specified 'no5lvl' in kernel command line. +*/ +if (!pgtable_l5_enabled ()) +setup_clear_cpu_cap (X86_FEATURE_LA57 ); }void __init early_cpu_init (void )
arch/x86/kernel/head64.c +5 -4
@@ -80,10 +80,11 @@ 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 at kernel decomression +* stage. Only check if it has been enabled there. +*/ +if (!(native_read_cr4 () &X86_CR4_LA57 ))return false; *fixup_int (&__pgtable_l5_enabled, physaddr) =1 ;
PATCH v5 5/7 x86/cpu: Move early cpu initialization into a separate translation unit
In reply to Kirill A. Shutemov__pgtable_l5_enabled shouldn't be needed after system has booted, we can mark it as __initdata, but it requires preparation.
This patch moves early cpu initialization into a separate translation unit. This limits effect of USE_EARLY_PGTABLE_L5 to less code.
Without the change cpu_init() uses __pgtable_l5_enabled. cpu_init() is not __init function and it leads to section mismatch.
--- arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 194 ++++------------------------------- arch/x86/kernel/cpu/cpu.h | 7 ++ arch/x86/kernel/cpu/early.c | 159 ++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 172 deletions(-) create mode 100644 arch/x86/kernel/cpu/early.c
arch/x86/kernel/cpu/Makefile +1 -0
@@ -19,6 +19,7 @@ CFLAGS_common.o := $(nostackp) obj-y := intel_cacheinfo.o scattered.o topology.o obj-y += common.o +obj-y += early.o obj-y += rdrand.o obj-y += match.o obj-y += bugs.o
arch/x86/kernel/cpu/common.c +22 -172
298 lines not on this page · raw message
arch/x86/kernel/cpu/cpu.h +7 -0
@@ -45,8 +45,15 @@ struct _tlb_table {extern const struct cpu_dev *const __x86_cpu_dev_start[], *const __x86_cpu_dev_end[]; +extern const struct cpu_dev *cpu_devs[]; +extern const struct cpu_dev *this_cpu_dev; +extern void get_cpu_cap (struct cpuinfo_x86 *c); +extern void get_cpu_vendor (struct cpuinfo_x86 *c); +extern void get_cpu_address_sizes (struct cpuinfo_x86 *c);extern void cpu_detect_cache_sizes (struct cpuinfo_x86 *c); +extern void identify_cpu_without_cpuid (struct cpuinfo_x86 *c); +extern void filter_cpuid_features (struct cpuinfo_x86 *c,bool warn);unsigned int aperfmperf_get_khz (int cpu);
arch/x86/kernel/cpu/early.c new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.17.0
Re: [PATCH 5/7] x86/cpu: Move early cpu initialization into a separate translation unit
Quoted 10 lines · Kirill A. Shutemov
__pgtable_l5_enabledshouldn't be needed after system has booted, we can mark it as__initdata, but it requires preparation.This patch moves early cpu initialization into a separate translation unit. This limits effect of
USE_EARLY_PGTABLE_L5to less code.Without the change
cpu_init()uses__pgtable_l5_enabled.cpu_init()is not__initfunction and it leads to section mismatch.Signed-off-by Kirill A. Shutemov <[email protected]>
This makes a lot of sense independent of 5level changes.
Kirill A. Shutemov
Reviewed-by Thomas GleixnerRe: [PATCH 5/7] x86/cpu: Move early cpu initialization into a separate translation unit
Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Kirill A. Shutemov
__pgtable_l5_enabledshouldn't be needed after system has booted, we can mark it as__initdata, but it requires preparation.This patch moves early cpu initialization into a separate translation unit. This limits effect of
USE_EARLY_PGTABLE_L5to less code.
Quoted 8 lines
Quoted 4 lines
Without the change
cpu_init()uses__pgtable_l5_enabled.cpu_init()is not__initfunction and it leads to section mismatch.Signed-off-by Kirill A. Shutemov <[email protected]>This makes a lot of sense independent of 5level changes.
Reviewed-by Thomas Gleixner <[email protected]>
Ingo, I've just noticed that this patch wasn't applied.
Below is rebased version. It applies cleanly on current tip/master and Linus' tree.
---------------------8<----------------------------------
Quoted 1 line
From
ff84fea44db72d09890dd69f4afb82060e6633a1Mon Sep 17 00:00:00 2001
From: "Kirill A. Shutemov" <[email protected]>
Date: Fri, 18 May 2018 13:35:26 +0300
Subject: [PATCH] x86/cpu: Move early cpu initialization into a separate
translation unit
__pgtable_l5_enabled shouldn't be needed after system has booted, we can mark it as __initdata, but it requires preparation.
This patch moves early cpu initialization into a separate translation unit. This limits effect of USE_EARLY_PGTABLE_L5 to less code.
Without the change cpu_init() uses __pgtable_l5_enabled. cpu_init() is not __init function and it leads to section mismatch.
--- arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 215 ++++------------------------------- arch/x86/kernel/cpu/cpu.h | 7 ++ arch/x86/kernel/cpu/early.c | 183 +++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 193 deletions(-) create mode 100644 arch/x86/kernel/cpu/early.c
arch/x86/kernel/cpu/Makefile +1 -0
@@ -19,6 +19,7 @@ CFLAGS_common.o := $(nostackp) obj-y := cacheinfo.o scattered.o topology.o obj-y += common.o +obj-y += early.o obj-y += rdrand.o obj-y += match.o obj-y += bugs.o
arch/x86/kernel/cpu/common.c +22 -193
319 lines not on this page · raw message
arch/x86/kernel/cpu/cpu.h +7 -0
@@ -45,8 +45,15 @@ struct _tlb_table {extern const struct cpu_dev *const __x86_cpu_dev_start[], *const __x86_cpu_dev_end[]; +extern const struct cpu_dev *cpu_devs[]; +extern const struct cpu_dev *this_cpu_dev; +extern void get_cpu_cap (struct cpuinfo_x86 *c); +extern void get_cpu_vendor (struct cpuinfo_x86 *c); +extern void get_cpu_address_sizes (struct cpuinfo_x86 *c);extern void cpu_detect_cache_sizes (struct cpuinfo_x86 *c); +extern void identify_cpu_without_cpuid (struct cpuinfo_x86 *c); +extern void filter_cpuid_features (struct cpuinfo_x86 *c,bool warn);extern void init_scattered_cpuid_features (struct cpuinfo_x86 *c); extern u32 get_scattered_cpuid_leaf(unsigned int level, unsigned int sub_leaf,
arch/x86/kernel/cpu/early.c new file +183 -0
183 lines not on this page · raw message
Signature · 1 line
Kirill A. Shutemov
PATCH v5 6/7 x86/mm: Mark p4d_offset() __always_inline
In reply to Kirill A. Shutemov__pgtable_l5_enabled shouldn't be needed after system has booted, we can mark it as __initdata, but it requires preparation.
KASAN initialization code is a user of USE_EARLY_PGTABLE_L5, so all pgtable_l5_enabled() translated to __pgtable_l5_enabled there, including the one in p4d_offset().
It may lead to section mismatch, if a compiler would not inline p4d_offset(), but leave it as a standalone function: p4d_offset() is not marked as __init.
Marking p4d_offset() as __always_inline fixes the issue.
--- arch/x86/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +1 -1
@@ -898,7 +898,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)#define pgd_page (pgd) pfn_to_page(pgd_pfn(pgd))/* to find an entry in a page-table-directory. */ -static inline p4d_t *p4d_offset (pgd_t *pgd,unsigned long address) +static __always_inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) {if (!pgtable_l5_enabled ())return (p4d_t *)pgd;
Signature · 1 line
2.17.0
Re: [PATCH 6/7] x86/mm: Mark p4d_offset() __always_inline
Quoted 7 lines · Kirill A. Shutemov
__pgtable_l5_enabledshouldn't be needed after system has booted, we can mark it as__initdata, but it requires preparation.KASAN initialization code is a user of
USE_EARLY_PGTABLE_L5, so allpgtable_l5_enabled()translated to__pgtable_l5_enabledthere, including the one inp4d_offset().
Quoted 7 lines
It may lead to section mismatch, if a compiler would not inline
p4d_offset(), but leave it as a standalone function:p4d_offset()is not marked as__init.Marking
p4d_offset()as__always_inlinefixes the issue.Signed-off-by Kirill A. Shutemov <[email protected]>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/mm: Mark p4d_offset() __always_inline
In reply to Kirill A. Shutemovx86/mm: Mark p4d_offset() __always_inline
Commit-ID: 1ea66554d3b09ce09c42e6a871899c84a276bb39 Gitweb: https://git.kernel.org/tip/1ea66554d3b09ce09c42e6a871899c84a276bb39 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:27 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:57 +0200
x86/mm: Mark p4d_offset() __always_inline
__pgtable_l5_enabled shouldn't be needed after system has booted, we can mark it as __initdata, but it requires preparation.
KASAN initialization code is a user of USE_EARLY_PGTABLE_L5, so all pgtable_l5_enabled() translated to __pgtable_l5_enabled there, including the one in p4d_offset().
It may lead to section mismatch, if a compiler would not inline p4d_offset(), but leave it as a standalone function: p4d_offset() is not marked as __init.
Marking p4d_offset() as __always_inline fixes the issue.
--- arch/x86/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +1 -1
@@ -898,7 +898,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)#define pgd_page (pgd) pfn_to_page(pgd_pfn(pgd))/* to find an entry in a page-table-directory. */ -static inline p4d_t *p4d_offset (pgd_t *pgd,unsigned long address) +static __always_inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) {if (!pgtable_l5_enabled ())return (p4d_t *)pgd;
PATCH v5 7/7 x86/mm: Mark __pgtable_l5_enabled __initdata
In reply to Kirill A. Shutemov__pgtable_l5_enabled shouldn't be needed after system has booted. All preparation is done. We can now mark it as __initdata.
--- arch/x86/kernel/head64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head64.c +1 -1
@@ -44,7 +44,7 @@ static unsigned int __initdata next_early_pgt;pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);#ifdef CONFIG_X86_5LEVEL -unsigned int __pgtable_l5_enabled__ro_after_init ; +unsigned int __pgtable_l5_enabled__initdata ;unsigned int pgdir_shift__ro_after_init =39 ;EXPORT_SYMBOL (pgdir_shift);unsigned int ptrs_per_p4d__ro_after_init =1 ;
Signature · 1 line
2.17.0
Re: [PATCH 7/7] x86/mm: Mark __pgtable_l5_enabled __initdata
Quoted 4 lines · Kirill A. Shutemov
__pgtable_l5_enabledshouldn't be needed after system has booted. All preparation is done. We can now mark it as__initdata.Signed-off-by Kirill A. Shutemov <[email protected]>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/boot] x86/mm: Mark __pgtable_l5_enabled __initdata
In reply to Kirill A. Shutemovx86/mm: Mark __pgtable_l5_enabled __initdata
Commit-ID: e4e961e36f063484c48bed919013c106d178995d Gitweb: https://git.kernel.org/tip/e4e961e36f063484c48bed919013c106d178995d Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 18 May 2018 13:35:28 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 19 May 2018 11:56:58 +0200
x86/mm: Mark __pgtable_l5_enabled __initdata
__pgtable_l5_enabled shouldn't be needed after system has booted. All preparation is done. We can now mark it as __initdata.
--- arch/x86/kernel/head64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head64.c +1 -1
@@ -44,7 +44,7 @@ static unsigned int __initdata next_early_pgt;pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);#ifdef CONFIG_X86_5LEVEL -unsigned int __pgtable_l5_enabled__ro_after_init ; +unsigned int __pgtable_l5_enabled__initdata ;unsigned int pgdir_shift__ro_after_init =39 ;EXPORT_SYMBOL (pgdir_shift);unsigned int ptrs_per_p4d__ro_after_init =1 ;
Quoted 10 lines · Kirill A. Shutemov
Here's several patches that I would like to queue for v4.18. Please review and consider applying.
In this version I've addressed Thomas' feedback.
Changing
__pgtable_l5_enabledto__initdatais not as trivial as I hoped. It requires few tricks to avoid section mismatch. I'm not sure if it worth the gain. We can keep it__ro_after_init.If you feel it's too invasive, just drop last three patches.
Well done. Thanks for cleaning it up.
Thanks,
tglx