x86: 5-level paging enabling for v4.12
Subsystems (14)
cover x86: 5-level paging enabling for v4.12
Here is v5 of 5-level paging patchset. Please review and consider applying.
== Overview ==
x86-64 is currently limited to 256 TiB of virtual address space and 64 TiB of physical address space. We are already bumping into this limit: some vendors offers servers with 64 TiB of memory today.
To overcome the limitation upcoming hardware will introduce support for 5-level paging[1]. It is a straight-forward extension of the current page table structure adding one more layer of translation.
It bumps the limits to 128 PiB of virtual address space and 4 PiB of physical address space. This "ought to be enough for anybody" ©.
== Patches ==
The patchset is build on top of v4.11-rc2.
Current QEMU upstream git supports 5-level paging. Use "-cpu qemu64,+la57" to enable it.
Patches 1-12:
Convert x86 to properly folded p4d layer using <asm-generic/pgtable-nop4d.h>.
Patches 13-25:
Enabling of real 5-level paging.
CONFIG_X86_5LEVEL=y will enable new paging mode.
Patch 26:
Introduce new prctl(2) handles -- PR_SET_MAX_VADDR and PR_GET_MAX_VADDR.
This aims to address compatibility issue. Only supports x86 for now, but should be useful for other archtectures.
Git:
git://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git la57/v5
== TODO ==
There is still work to do:
- CONFIG_XEN is broken for 5-level paging.
Xen for 5-level paging requires more work to get functional.
Xen on 4-level paging works, so it's not a regression.
- Boot-time switch between 4- and 5-level paging.
We assume that distributions will be keen to avoid returning to the i386 days where we shipped one kernel binary for each page table layout.
As page table format is the same for 4- and 5-level paging it should be possible to have single kernel binary and switch between them at boot-time without too much hassle.
For now I only implemented compile-time switch.
This will implemented with separate patchset.
== Changelong ==
v5:
- Rebased to v4.11-rc2;
- Fix false-positive BUG_ON() in vmalloc_fault() with 4-level paging enabled;
- __xen_pgd_walk(): do not not miss required flushes;
- Fix build with CONFIG_XEN_PVH=y;
v4:
- Rebased to v4.11-rc1;
- Use mmap() hint address to allocate virtual addresss space above 47-bits insteads of prctl() handles.
v3:
- Rebased to v4.10-rc5;
- prctl() handles for large address space opt-in;
- Xen works for 4-level paging;
- EFI boot fixed for both 4- and 5-level paging;
- Hibernation fixed for 4-level paging;
- kexec() fixed;
- Couple of build fixes;
v2:
- Rebased to v4.10-rc1;
- RLIMIT_VADDR proposal;
- Fix virtual map and update documentation;
- Fix few build errors;
- Rework cpuid helpers in boot code;
- Fix espfix code to work with 5-level pages;
[1] https://software.intel.com/sites/default/files/managed/2b/80/5-level_paging_white_paper.pdf
Kirill A. Shutemov (26):
x86: basic changes into headers for 5-level paging
x86: trivial portion of 5-level paging conversion
x86/gup: add 5-level paging support
x86/ident_map: add 5-level paging support
x86/mm: add support of p4d_t in vmalloc_fault()
x86/power: support p4d_t in hibernate code
x86/kexec: support p4d_t
x86/efi: handle p4d in EFI pagetables
x86/mm/pat: handle additional page table
x86/kasan: prepare clear_pgds() to switch to
<asm-generic/pgtable-nop4d.h>
x86/xen: convert __xen_pgd_walk() and xen_cleanmfnmap() to support p4d
x86: convert the rest of the code to support p4d_t
x86: detect 5-level paging support
x86/asm: remove __VIRTUAL_MASK_SHIFT==47 assert
x86/mm: define virtual memory map for 5-level paging x86/paravirt: make paravirt code support 5-level paging x86/mm: basic defines/helpers for CONFIG_X86_5LEVEL x86/dump_pagetables: support 5-level paging
x86/kasan: extend to support 5-level paging
x86/espfix: support 5-level paging
x86/mm: add support of additional page table level during early boot x86/mm: add sync_global_pgds() for configuration with 5-level paging x86/mm: make kernel_physical_mapping_init() support 5-level paging x86/mm: add support for 5-level paging for KASLR
x86: enable 5-level paging support
x86/mm: allow to have userspace mappings above 47-bits
Documentation/x86/x86_64/mm.txt | 33 ++- arch/x86/Kconfig | 6 + arch/x86/boot/compressed/head_64.S | 23 +- arch/x86/boot/cpucheck.c | 9 + arch/x86/boot/cpuflags.c | 12 +- arch/x86/entry/entry_64.S | 7 +- arch/x86/include/asm/disabled-features.h | 8 +- arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/kasan.h | 9 +- arch/x86/include/asm/kexec.h | 1 + arch/x86/include/asm/mpx.h | 9 + arch/x86/include/asm/page_64_types.h | 10 + arch/x86/include/asm/paravirt.h | 65 ++++- arch/x86/include/asm/paravirt_types.h | 17 +- arch/x86/include/asm/pgalloc.h | 37 ++- arch/x86/include/asm/pgtable-2level_types.h | 1 + arch/x86/include/asm/pgtable-3level_types.h | 1 + arch/x86/include/asm/pgtable.h | 85 +++++- arch/x86/include/asm/pgtable_64.h | 29 +- arch/x86/include/asm/pgtable_64_types.h | 27 ++ arch/x86/include/asm/pgtable_types.h | 46 ++- arch/x86/include/asm/processor.h | 9 +- arch/x86/include/asm/required-features.h | 8 +- arch/x86/include/asm/sparsemem.h | 9 +- arch/x86/include/asm/xen/page.h | 8 +- arch/x86/include/uapi/asm/processor-flags.h | 2 + arch/x86/kernel/espfix_64.c | 12 +- arch/x86/kernel/head64.c | 40 ++- arch/x86/kernel/head_64.S | 63 +++- arch/x86/kernel/machine_kexec_32.c | 4 +- arch/x86/kernel/machine_kexec_64.c | 16 +- arch/x86/kernel/paravirt.c | 13 +- arch/x86/kernel/sys_x86_64.c | 28 +- arch/x86/kernel/tboot.c | 6 +- arch/x86/kernel/vm86_32.c | 6 +- arch/x86/mm/dump_pagetables.c | 51 +++- arch/x86/mm/fault.c | 66 ++++- arch/x86/mm/gup.c | 33 ++- arch/x86/mm/hugetlbpage.c | 31 +- arch/x86/mm/ident_map.c | 47 ++- arch/x86/mm/init_32.c | 22 +- arch/x86/mm/init_64.c | 269 ++++++++++++++--- arch/x86/mm/ioremap.c | 3 +- arch/x86/mm/kasan_init_64.c | 41 ++- arch/x86/mm/kaslr.c | 82 ++++-- arch/x86/mm/mmap.c | 4 +- arch/x86/mm/mpx.c | 33 ++- arch/x86/mm/pageattr.c | 56 +++- arch/x86/mm/pgtable.c | 38 ++- arch/x86/mm/pgtable_32.c | 8 +- arch/x86/platform/efi/efi_64.c | 38 ++- arch/x86/power/hibernate_32.c | 7 +- arch/x86/power/hibernate_64.c | 49 +++- arch/x86/realmode/init.c | 2 +- arch/x86/xen/Kconfig | 1 + arch/x86/xen/mmu.c | 435 +++++++++++++++++----------- arch/x86/xen/mmu.h | 1 + arch/x86/xen/xen-pvh.S | 2 +- include/trace/events/xen.h | 28 +- 59 files changed, 1571 insertions(+), 437 deletions(-)
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/26 x86: basic changes into headers for 5-level paging
This patch extends x86 headers to enable 5-level paging support.
It's still based on <asm-generic/5level-fixup.h>. We will get to the point where we can have <asm-generic/pgtable-nop4d.h> later.
--- arch/x86/include/asm/pgtable-2level_types.h | 1 + arch/x86/include/asm/pgtable-3level_types.h | 1 + arch/x86/include/asm/pgtable.h | 26 ++++++++++++++++++++----- arch/x86/include/asm/pgtable_64_types.h | 1 + arch/x86/include/asm/pgtable_types.h | 30 ++++++++++++++++++++++++++++- 5 files changed, 53 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable-2level_types.h +1 -0
@@ -7,6 +7,7 @@typedef unsigned long pteval_t ;typedef unsigned long pmdval_t ;typedef unsigned long pudval_t ; +typedef unsigned long p4dval_t ;typedef unsigned long pgdval_t ;typedef unsigned long pgprotval_t ;
arch/x86/include/asm/pgtable-3level_types.h +1 -0
@@ -7,6 +7,7 @@typedef u64 pteval_t ;typedef u64 pmdval_t ;typedef u64 pudval_t ; +typedef u64 p4dval_t ;typedef u64 pgdval_t ;typedef u64 pgprotval_t ;
arch/x86/include/asm/pgtable.h +21 -5
@@ -179,6 +179,17 @@ static inline unsigned long pud_pfn(pud_t pud)return (pud_val (pud) &pud_pfn_mask (pud)) >>PAGE_SHIFT ; } +static inline unsigned long p4d_pfn (p4d_t p4d) +{ +return (p4d_val (p4d) &p4d_pfn_mask (p4d)) >>PAGE_SHIFT ; +} + +static inline int p4d_large (p4d_t p4d) +{ +/* No 512 GiB pages yet */ +return 0 ; +} +#define pte_page (pte) pfn_to_page(pte_pfn(pte))static inline int pmd_large (pmd_t pte)
@@ -770,6 +781,16 @@ static inline int pud_large(pud_t pud) }#endif /* CONFIG_PGTABLE_LEVELS > 2 */ +static inline unsigned long pud_index (unsigned long address) +{ +return (address >>PUD_SHIFT ) & (PTRS_PER_PUD -1 ); +} + +static inline unsigned long p4d_index (unsigned long address) +{ +return (address >>P4D_SHIFT ) & (PTRS_PER_P4D -1 ); +} +#if CONFIG_PGTABLE_LEVELS >3 static inline int pgd_present (pgd_t pgd) {
@@ -788,11 +809,6 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)#define pgd_page (pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)/* to find an entry in a page-table-directory. */ -static inline unsigned long pud_index (unsigned long address) -{ -return (address >>PUD_SHIFT ) & (PTRS_PER_PUD -1 ); -} -static inline pud_t *pud_offset (pgd_t *pgd,unsigned long address) {return (pud_t *)pgd_page_vaddr (*pgd) +pud_index (address);
arch/x86/include/asm/pgtable_64_types.h +1 -0
@@ -13,6 +13,7 @@typedef unsigned long pteval_t ;typedef unsigned long pmdval_t ;typedef unsigned long pudval_t ; +typedef unsigned long p4dval_t ;typedef unsigned long pgdval_t ;typedef unsigned long pgprotval_t ;
arch/x86/include/asm/pgtable_types.h +29 -1
@@ -272,9 +272,20 @@ static inline pgdval_t pgd_flags(pgd_t pgd)return native_pgd_val (pgd) &PTE_FLAGS_MASK ; } -#if CONFIG_PGTABLE_LEVELS >3 +#if CONFIG_PGTABLE_LEVELS >4 + +#error FIXME + +#else #include <asm-generic/5level-fixup.h> +static inline p4dval_t native_p4d_val (p4d_t p4d) +{ +return native_pgd_val (p4d); +} +#endif + +#if CONFIG_PGTABLE_LEVELS >3 typedef struct {pudval_t pud; }pud_t ;static inline pud_t native_make_pud (pmdval_t val)
@@ -318,6 +329,22 @@ static inline pmdval_t native_pmd_val(pmd_t pmd) }#endif +static inline p4dval_t p4d_pfn_mask (p4d_t p4d) +{ +/* No 512 GiB huge pages yet */ +return PTE_PFN_MASK ; +} + +static inline p4dval_t p4d_flags_mask (p4d_t p4d) +{ +return ~p4d_pfn_mask (p4d); +} + +static inline p4dval_t p4d_flags (p4d_t p4d) +{ +return native_p4d_val (p4d) &p4d_flags_mask (p4d); +} +static inline pudval_t pud_pfn_mask (pud_t pud) {if (native_pud_val (pud) & _PAGE_PSE)
@@ -461,6 +488,7 @@ enum pg_level {PG_LEVEL_4K ,PG_LEVEL_2M ,PG_LEVEL_1G , +PG_LEVEL_512G , PG_LEVEL_NUM };
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/26 x86/ident_map: add 5-level paging support
In reply to Kirill A. ShutemovNothing special: just handle one more level.
--- arch/x86/mm/ident_map.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-)
arch/x86/mm/ident_map.c +40 -7
@@ -45,6 +45,34 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page,return 0 ; } +static int ident_p4d_init (struct x86_mapping_info *info,p4d_t *p4d_page, +unsigned long addr,unsigned long end) +{ +unsigned long next; + +for (; addr < end; addr = next) { +p4d_t *p4d = p4d_page +p4d_index (addr); +pud_t *pud; + + next = (addr &P4D_MASK ) +P4D_SIZE ; +if (next > end) + next = end; + +if (p4d_present (*p4d)) { + pud =pud_offset (p4d,0 ); +ident_pud_init (info, pud, addr, next); +continue ; + } + pud = (pud_t *)info->alloc_pgt_page (info->context); +if (!pud) +return -ENOMEM ; +ident_pud_init (info, pud, addr, next); +set_p4d (p4d,__p4d (__pa (pud) | _KERNPG_TABLE)); + } + +return 0 ; +} +int kernel_ident_mapping_init (struct x86_mapping_info *info,pgd_t *pgd_page,unsigned long pstart,unsigned long pend) {
@@ -55,27 +83,32 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,for (; addr < end; addr = next) {pgd_t *pgd = pgd_page +pgd_index (addr); -pud_t *pud; +p4d_t *p4d; next = (addr &PGDIR_MASK ) +PGDIR_SIZE ;if (next > end) next = end;if (pgd_present (*pgd)) { - pud =pud_offset (pgd,0 ); - result =ident_pud_init (info, pud, addr, next); + p4d =p4d_offset (pgd,0 ); + result =ident_p4d_init (info, p4d, addr, next);if (result)return result;continue ; } - pud = (pud_t *)info->alloc_pgt_page (info->context); -if (!pud) + p4d = (p4d_t *)info->alloc_pgt_page (info->context); +if (!p4d)return -ENOMEM ; - result =ident_pud_init (info, pud, addr, next); + result =ident_p4d_init (info, p4d, addr, next);if (result)return result; -set_pgd (pgd,__pgd (__pa (pud) | _KERNPG_TABLE)); +if (IS_ENABLED (CONFIG_X86_5LEVEL )) { +set_pgd (pgd,__pgd (__pa (p4d) | _KERNPG_TABLE)); + }else { +pud_t *pud =pud_offset (p4d,0 ); +set_pgd (pgd,__pgd (__pa (pud) | _KERNPG_TABLE)); + } }return 0 ;
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/26 x86/mm: add support of p4d_t in vmalloc_fault()
In reply to Kirill A. ShutemovWith 4-level paging copying happens on p4d level, as we have pgd_none() always false when p4d_t folded.
--- arch/x86/mm/fault.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
arch/x86/mm/fault.c +24 -3
@@ -435,6 +435,7 @@ void vmalloc_sync_all(void) static noinline int vmalloc_fault(unsigned long address) {pgd_t *pgd, *pgd_ref; +p4d_t *p4d, *p4d_ref;pud_t *pud, *pud_ref;pmd_t *pmd, *pmd_ref;pte_t *pte, *pte_ref;
@@ -458,17 +459,37 @@ static noinline int vmalloc_fault(unsigned long address)if (pgd_none (*pgd)) {set_pgd (pgd, *pgd_ref);arch_flush_lazy_mmu_mode (); - }else { + }else if (CONFIG_PGTABLE_LEVELS >4 ) { +/* +* With folded p4d, pgd_none() is always false. So pgd may +* point to empty page table entry and pgd_page_vaddr() +* will return garbage. +* +* We will do the correct sanity check on p4d level. +*/ BUG_ON (pgd_page_vaddr (*pgd) !=pgd_page_vaddr (*pgd_ref)); } +/* With 4-level paging copying happens on p4d level. */ + p4d =p4d_offset (pgd, address); + p4d_ref =p4d_offset (pgd_ref, address); +if (p4d_none (*p4d_ref)) +return -1 ; + +if (p4d_none (*p4d)) { +set_p4d (p4d, *p4d_ref); +arch_flush_lazy_mmu_mode (); + }else { +BUG_ON (p4d_pfn (*p4d) !=p4d_pfn (*p4d_ref)); + } +/* * Below here mismatches are bugs because these lower tables * are shared: */ - pud =pud_offset (pgd, address); - pud_ref =pud_offset (pgd_ref, address); + pud =pud_offset (p4d, address); + pud_ref =pud_offset (p4d_ref, address);if (pud_none (*pud_ref))return -1 ;
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/26 x86/power: support p4d_t in hibernate code
In reply to Kirill A. Shutemovset_up_temporary_text_mapping() and relocate_restore_code() require trivial adjustments to handle additional page table level.
--- arch/x86/power/hibernate_64.c | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-)
arch/x86/power/hibernate_64.c +35 -14
@@ -49,6 +49,7 @@ static int set_up_temporary_text_mapping(pgd_t *pgd) {pmd_t *pmd;pud_t *pud; +p4d_t *p4d;/* * The new mapping only has to cover the page containing the image
@@ -63,6 +64,13 @@ static int set_up_temporary_text_mapping(pgd_t *pgd)* the virtual address space after switching over to the original page * tables used by the image kernel. */ + +if (IS_ENABLED (CONFIG_X86_5LEVEL )) { + p4d = (p4d_t *)get_safe_page (GFP_ATOMIC ); +if (!p4d) +return -ENOMEM ; + } + pud = (pud_t *)get_safe_page (GFP_ATOMIC );if (!pud)return -ENOMEM ;
@@ -75,8 +83,15 @@ static int set_up_temporary_text_mapping(pgd_t *pgd) __pmd((jump_address_phys & PMD_MASK) | __PAGE_KERNEL_LARGE_EXEC));set_pud (pud +pud_index (restore_jump_address),__pud (__pa (pmd) | _KERNPG_TABLE)); -set_pgd (pgd +pgd_index (restore_jump_address), -__pgd (__pa (pud) | _KERNPG_TABLE)); +if (IS_ENABLED (CONFIG_X86_5LEVEL )) { +set_p4d (p4d +p4d_index (restore_jump_address), +__p4d (__pa (pud) | _KERNPG_TABLE)); +set_pgd (pgd +pgd_index (restore_jump_address), +__pgd (__pa (p4d) | _KERNPG_TABLE)); + }else { +set_pgd (pgd +pgd_index (restore_jump_address), +__pgd (__pa (pud) | _KERNPG_TABLE)); + }return 0 ; }
@@ -124,7 +139,10 @@ static int set_up_temporary_mappings(void)static int relocate_restore_code (void ) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud; +pmd_t *pmd; +pte_t *pte; relocated_restore_code =get_safe_page (GFP_ATOMIC );if (!relocated_restore_code)
@@ -134,22 +152,25 @@ static int relocate_restore_code(void)/* Make the page containing the relocated code executable */ pgd = (pgd_t *)__va (read_cr3 ()) +pgd_index (relocated_restore_code); - pud =pud_offset (pgd, relocated_restore_code); + p4d =p4d_offset (pgd, relocated_restore_code); +if (p4d_large (*p4d)) { +set_p4d (p4d,__p4d (p4d_val (*p4d) & ~_PAGE_NX)); + goto out; + } + pud =pud_offset (p4d, relocated_restore_code);if (pud_large (*pud)) {set_pud (pud,__pud (pud_val (*pud) & ~_PAGE_NX)); - }else { -pmd_t *pmd =pmd_offset (pud, relocated_restore_code); - -if (pmd_large (*pmd)) { -set_pmd (pmd,__pmd (pmd_val (*pmd) & ~_PAGE_NX)); - }else { -pte_t *pte =pte_offset_kernel (pmd, relocated_restore_code); - -set_pte (pte,__pte (pte_val (*pte) & ~_PAGE_NX)); - } + goto out; + } + pmd =pmd_offset (pud, relocated_restore_code); +if (pmd_large (*pmd)) { +set_pmd (pmd,__pmd (pmd_val (*pmd) & ~_PAGE_NX)); + goto out; } + pte =pte_offset_kernel (pmd, relocated_restore_code); +set_pte (pte,__pte (pte_val (*pte) & ~_PAGE_NX)); +out:__flush_tlb_all (); -return 0 ; }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/26 x86/kexec: support p4d_t
In reply to Kirill A. ShutemovHandle additional page table level in kexec code.
--- arch/x86/include/asm/kexec.h | 1 + arch/x86/kernel/machine_kexec_32.c | 4 +++- arch/x86/kernel/machine_kexec_64.c | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-)
arch/x86/include/asm/kexec.h +1 -0
@@ -164,6 +164,7 @@ struct kimage_arch { }; #else struct kimage_arch { + p4d_t *p4d; pud_t *pud; pmd_t *pmd; pte_t *pte;
arch/x86/kernel/machine_kexec_32.c +3 -1
@@ -103,6 +103,7 @@ static void machine_kexec_page_table_set_one( pgd_t *pgd, pmd_t *pmd, pte_t *pte, unsigned long vaddr, unsigned long paddr) { +p4d_t *p4d;pud_t *pud; pgd +=pgd_index (vaddr);
@@ -110,7 +111,8 @@ static void machine_kexec_page_table_set_one(if (!(pgd_val (*pgd) & _PAGE_PRESENT))set_pgd (pgd,__pgd (__pa (pmd) | _PAGE_PRESENT));#endif - pud =pud_offset (pgd, vaddr); + p4d =p4d_offset (pgd, vaddr); + pud =pud_offset (p4d, vaddr); pmd =pmd_offset (pud, vaddr);if (!(pmd_val (*pmd) & _PAGE_PRESENT))set_pmd (pmd,__pmd (__pa (pte) | _PAGE_TABLE));
arch/x86/kernel/machine_kexec_64.c +12 -2
@@ -36,6 +36,7 @@ static struct kexec_file_ops *kexec_file_loaders[] = {static void free_transition_pgtable (struct kimage *image) { +free_page ((unsigned long )image->arch.p4d);free_page ((unsigned long )image->arch.pud);free_page ((unsigned long )image->arch.pmd);free_page ((unsigned long )image->arch.pte);
@@ -43,6 +44,7 @@ static void free_transition_pgtable(struct kimage *image)static int init_transition_pgtable (struct kimage *image,pgd_t *pgd) { +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -53,13 +55,21 @@ static int init_transition_pgtable(struct kimage *image, pgd_t *pgd) paddr =__pa (page_address (image->control_code_page)+PAGE_SIZE ); pgd +=pgd_index (vaddr);if (!pgd_present (*pgd)) { + p4d = (p4d_t *)get_zeroed_page (GFP_KERNEL ); +if (!p4d) + goto err; + image->arch.p4d = p4d; +set_pgd (pgd,__pgd (__pa (p4d) | _KERNPG_TABLE)); + } + p4d =p4d_offset (pgd, vaddr); +if (!p4d_present (*p4d)) { pud = (pud_t *)get_zeroed_page (GFP_KERNEL );if (!pud) goto err; image->arch.pud = pud; -set_pgd (pgd,__pgd (__pa (pud) | _KERNPG_TABLE)); +set_p4d (p4d,__p4d (__pa (pud) | _KERNPG_TABLE)); } - pud =pud_offset (pgd, vaddr); + pud =pud_offset (p4d, vaddr);if (!pud_present (*pud)) { pmd = (pmd_t *)get_zeroed_page (GFP_KERNEL );if (!pmd)
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/26 x86/efi: handle p4d in EFI pagetables
In reply to Kirill A. ShutemovAllocate additional page table level and change efi_sync_low_kernel_mappings() to make syncing logic work with additional page table level.
--- arch/x86/platform/efi/efi_64.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
arch/x86/platform/efi/efi_64.c +23 -10
@@ -135,6 +135,7 @@ static pgd_t *efi_pgd;int __init efi_alloc_page_tables (void ) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;gfp_t gfp_mask;
@@ -147,15 +148,20 @@ int __init efi_alloc_page_tables(void)return -ENOMEM ; pgd = efi_pgd +pgd_index (EFI_VA_END ); + p4d =p4d_alloc (&init_mm, pgd,EFI_VA_END ); +if (!p4d) { +free_page ((unsigned long )efi_pgd); +return -ENOMEM ; + } - pud =pud_alloc_one (NULL ,0 ); + pud =pud_alloc (&init_mm, p4d,EFI_VA_END );if (!pud) { +if (CONFIG_PGTABLE_LEVELS >4 ) +free_page ((unsigned long )pgd_page_vaddr (*pgd));free_page ((unsigned long )efi_pgd);return -ENOMEM ; } -pgd_populate (NULL , pgd, pud); -return 0 ; }
@@ -190,6 +196,18 @@ void efi_sync_low_kernel_mappings(void) num_entries =pgd_index (EFI_VA_END ) -pgd_index (PAGE_OFFSET );memcpy (pgd_efi, pgd_k,sizeof (pgd_t) * num_entries); +/* The same story as with PGD entries */ +BUILD_BUG_ON (p4d_index (EFI_VA_END ) !=p4d_index (MODULES_END )); +BUILD_BUG_ON ((EFI_VA_START &P4D_MASK ) != (EFI_VA_END &P4D_MASK )); + + pgd_efi = efi_pgd +pgd_index (EFI_VA_END ); + pgd_k =pgd_offset_k (EFI_VA_END ); + p4d_efi =p4d_offset (pgd_efi,0 ); + p4d_k =p4d_offset (pgd_k,0 ); + + num_entries =p4d_index (EFI_VA_END ); +memcpy (p4d_efi, p4d_k,sizeof (p4d_t) * num_entries); +/* * We share all the PUD entries apart from those that map the * EFI regions. Copy around them.
@@ -197,20 +215,15 @@ void efi_sync_low_kernel_mappings(void)BUILD_BUG_ON ((EFI_VA_START & ~PUD_MASK ) !=0 );BUILD_BUG_ON ((EFI_VA_END & ~PUD_MASK ) !=0 ); - pgd_efi = efi_pgd +pgd_index (EFI_VA_END ); - p4d_efi =p4d_offset (pgd_efi,0 ); + p4d_efi =p4d_offset (pgd_efi,EFI_VA_END ); + p4d_k =p4d_offset (pgd_k,EFI_VA_END ); pud_efi =pud_offset (p4d_efi,0 ); - - pgd_k =pgd_offset_k (EFI_VA_END ); - p4d_k =p4d_offset (pgd_k,0 ); pud_k =pud_offset (p4d_k,0 ); num_entries =pud_index (EFI_VA_END );memcpy (pud_efi, pud_k,sizeof (pud_t) * num_entries); - p4d_efi =p4d_offset (pgd_efi,EFI_VA_START ); pud_efi =pud_offset (p4d_efi,EFI_VA_START ); - p4d_k =p4d_offset (pgd_k,EFI_VA_START ); pud_k =pud_offset (p4d_k,EFI_VA_START ); num_entries =PTRS_PER_PUD -pud_index (EFI_VA_START );
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 9/26 x86/mm/pat: handle additional page table
In reply to Kirill A. ShutemovStraight-forward extension of existing code to support additional page table level.
--- arch/x86/mm/pageattr.c | 56 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-)
arch/x86/mm/pageattr.c +41 -15
@@ -346,6 +346,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,pte_t *lookup_address_in_pgd (pgd_t *pgd,unsigned long address,unsigned int *level) { +p4d_t *p4d;pud_t *pud;pmd_t *pmd;
@@ -354,7 +355,15 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,if (pgd_none (*pgd))return NULL ; - pud =pud_offset (pgd, address); + p4d =p4d_offset (pgd, address); +if (p4d_none (*p4d)) +return NULL ; + + *level =PG_LEVEL_512G ; +if (p4d_large (*p4d) || !p4d_present (*p4d)) +return (pte_t *)p4d; + + pud =pud_offset (p4d, address);if (pud_none (*pud))return NULL ;
@@ -406,13 +415,18 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address,pmd_t *lookup_pmd_address (unsigned long address) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud; pgd =pgd_offset_k (address);if (pgd_none (*pgd))return NULL ; - pud =pud_offset (pgd, address); + p4d =p4d_offset (pgd, address); +if (p4d_none (*p4d) ||p4d_large (*p4d) || !p4d_present (*p4d)) +return NULL ; + + pud =pud_offset (p4d, address);if (pud_none (*pud) ||pud_large (*pud) || !pud_present (*pud))return NULL ;
@@ -477,11 +491,13 @@ static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)list_for_each_entry (page, &pgd_list, lru) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd; pgd = (pgd_t *)page_address (page) +pgd_index (address); - pud =pud_offset (pgd, address); + p4d =p4d_offset (pgd, address); + pud =pud_offset (p4d, address); pmd =pmd_offset (pud, address);set_pte_atomic ((pte_t *)pmd, pte); }
@@ -836,9 +852,9 @@ static void unmap_pmd_range(pud_t *pud, unsigned long start, unsigned long end)pud_clear (pud); } -static void unmap_pud_range (pgd_t *pgd,unsigned long start,unsigned long end) +static void unmap_pud_range (p4d_t *p4d,unsigned long start,unsigned long end) { -pud_t *pud =pud_offset (pgd, start); +pud_t *pud =pud_offset (p4d, start);/* * Not on a GB page boundary?
@@ -1004,8 +1020,8 @@ static long populate_pmd(struct cpa_data *cpa,return num_pages; } -static long populate_pud (struct cpa_data *cpa,unsigned long start,pgd_t *pgd, -pgprot_t pgprot) +static int populate_pud (struct cpa_data *cpa,unsigned long start,p4d_t *p4d, +pgprot_t pgprot) {pud_t *pud;unsigned long end;
@@ -1026,7 +1042,7 @@ static long populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd, cur_pages = (pre_end - start) >>PAGE_SHIFT ; cur_pages =min_t (int, (int )cpa->numpages, cur_pages); - pud =pud_offset (pgd, start); + pud =pud_offset (p4d, start);/* * Need a PMD page?
@@ -1047,7 +1063,7 @@ static long populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd,if (cpa->numpages == cur_pages)return cur_pages; - pud =pud_offset (pgd, start); + pud =pud_offset (p4d, start); pud_pgprot =pgprot_4k_2_large (pgprot);/*
@@ -1067,7 +1083,7 @@ static long populate_pud(struct cpa_data *cpa, unsigned long start, pgd_t *pgd,if (start < end) {long tmp; - pud =pud_offset (pgd, start); + pud =pud_offset (p4d, start);if (pud_none (*pud))if (alloc_pmd_page (pud))return -1 ;
@@ -1090,33 +1106,43 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr) {pgprot_t pgprot =__pgprot (_KERNPG_TABLE);pud_t *pud =NULL ;/* shut up gcc */ +p4d_t *p4d;pgd_t *pgd_entry;long ret; pgd_entry = cpa->pgd +pgd_index (addr); +if (pgd_none (*pgd_entry)) { + p4d = (p4d_t *)get_zeroed_page (GFP_KERNEL | __GFP_NOTRACK); +if (!p4d) +return -1 ; + +set_pgd (pgd_entry,__pgd (__pa (p4d) | _KERNPG_TABLE)); + } +/* -* Allocate a PUD page and hand it down for mapping. +* Allocate a P4D page and hand it down for mapping. */ -if (pgd_none (*pgd_entry)) { + p4d =p4d_offset (pgd_entry, addr); +if (p4d_none (*p4d)) { pud = (pud_t *)get_zeroed_page (GFP_KERNEL | __GFP_NOTRACK);if (!pud)return -1 ; -set_pgd (pgd_entry,__pgd (__pa (pud) | _KERNPG_TABLE)); +set_p4d (p4d,__p4d (__pa (pud) | _KERNPG_TABLE)); }pgprot_val (pgprot) &= ~pgprot_val (cpa->mask_clr);pgprot_val (pgprot) |=pgprot_val (cpa->mask_set); - ret =populate_pud (cpa, addr, pgd_entry, pgprot); + ret =populate_pud (cpa, addr, p4d, pgprot);if (ret <0 ) {/* * Leave the PUD page in place in case some other CPU or thread * already found it, but remove any useless entries we just * added to it. */ -unmap_pud_range (pgd_entry, addr, +unmap_pud_range (p4d, addr, addr + (cpa->numpages <<PAGE_SHIFT ));return ret; }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/26 x86/kasan: prepare clear_pgds() to switch to <asm-generic/pgtable-nop4d.h>
In reply to Kirill A. ShutemovWith folded p4d, pgd_clear() is nop. Change clear_pgds() to use p4d_clear() instead.
--- arch/x86/mm/kasan_init_64.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/x86/mm/kasan_init_64.c +9 -2
@@ -32,8 +32,15 @@ static int __init map_range(struct range *range)static void __init clear_pgds (unsigned long start,unsigned long end) { -for (; start < end; start +=PGDIR_SIZE ) -pgd_clear (pgd_offset_k (start)); +pgd_t *pgd; + +for (; start < end; start +=PGDIR_SIZE ) { + pgd =pgd_offset_k (start); +if (CONFIG_PGTABLE_LEVELS <5 ) +p4d_clear (p4d_offset (pgd, start)); +else +pgd_clear (pgd); + } }static void __init kasan_map_early_shadow (pgd_t *pgd)
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 11/26 x86/xen: convert __xen_pgd_walk() and xen_cleanmfnmap() to support p4d
In reply to Kirill A. ShutemovSplit these helpers few per-level functions and add p4d support.
--- arch/x86/xen/mmu.c | 245 ++++++++++++++++++++++++++++++++--------------------- arch/x86/xen/mmu.h | 1 + 2 files changed, 150 insertions(+), 96 deletions(-)
arch/x86/xen/mmu.c +149 -96
@@ -593,6 +593,64 @@ static void xen_set_pgd(pgd_t *ptr, pgd_t val) }#endif /* CONFIG_PGTABLE_LEVELS == 4 */ +static int xen_pmd_walk (struct mm_struct *mm,pmd_t *pmd, +int (*func)(struct mm_struct *mm,struct page *,enum pt_level ), +bool last,unsigned long limit) +{ +int i, nr, flush =0 ; + + nr = last ?pmd_index (limit) +1 :PTRS_PER_PMD ; +for (i =0 ; i < nr; i++) { +if (!pmd_none (pmd[i])) + flush |= (*func)(mm,pmd_page (pmd[i]),PT_PTE ); + } +return flush; +} + +static int xen_pud_walk (struct mm_struct *mm,pud_t *pud, +int (*func)(struct mm_struct *mm,struct page *,enum pt_level ), +bool last,unsigned long limit) +{ +int i, nr, flush =0 ; + + nr = last ?pud_index (limit) +1 :PTRS_PER_PUD ; +for (i =0 ; i < nr; i++) { +pmd_t *pmd; + +if (pud_none (pud[i])) +continue ; + + pmd =pmd_offset (&pud[i],0 ); +if (PTRS_PER_PMD >1 ) + flush |= (*func)(mm,virt_to_page (pmd),PT_PMD ); + flush |=xen_pmd_walk (mm, pmd, func, + last && i == nr -1 , limit); + } +return flush; +} + +static int xen_p4d_walk (struct mm_struct *mm,p4d_t *p4d, +int (*func)(struct mm_struct *mm,struct page *,enum pt_level ), +bool last,unsigned long limit) +{ +int i, nr, flush =0 ; + + nr = last ?p4d_index (limit) +1 :PTRS_PER_P4D ; +for (i =0 ; i < nr; i++) { +pud_t *pud; + +if (p4d_none (p4d[i])) +continue ; + + pud =pud_offset (&p4d[i],0 ); +if (PTRS_PER_PUD >1 ) + flush |= (*func)(mm,virt_to_page (pud),PT_PUD ); + flush |=xen_pud_walk (mm, pud, func, + last && i == nr -1 , limit); + } +return flush; +} +/* * (Yet another) pagetable walker. This one is intended for pinning a * pagetable. This means that it walks a pagetable and calls the
@@ -613,10 +671,8 @@ static int __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd, enum pt_level), unsigned long limit) { -int flush =0 ; +int i, nr, flush =0 ;unsigned hole_low, hole_high; -unsigned pgdidx_limit, pudidx_limit, pmdidx_limit; -unsigned pgdidx, pudidx, pmdidx;/* The limit is the last byte to be touched */ limit--;
@@ -633,65 +689,22 @@ static int __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd, hole_low =pgd_index (USER_LIMIT ); hole_high =pgd_index (PAGE_OFFSET ); - pgdidx_limit =pgd_index (limit); -#if PTRS_PER_PUD >1 - pudidx_limit =pud_index (limit); -#else - pudidx_limit =0 ; -#endif -#if PTRS_PER_PMD >1 - pmdidx_limit =pmd_index (limit); -#else - pmdidx_limit =0 ; -#endif - -for (pgdidx =0 ; pgdidx <= pgdidx_limit; pgdidx++) { -pud_t *pud; + nr =pgd_index (limit) +1 ; +for (i =0 ; i < nr; i++) { +p4d_t *p4d; -if (pgdidx >= hole_low && pgdidx < hole_high) +if (i >= hole_low && i < hole_high)continue ; -if (!pgd_val (pgd[pgdidx])) +if (pgd_none (pgd[i]))continue ; - pud =pud_offset (&pgd[pgdidx],0 ); - -if (PTRS_PER_PUD >1 )/* not folded */ - flush |= (*func)(mm,virt_to_page (pud),PT_PUD ); - -for (pudidx =0 ; pudidx <PTRS_PER_PUD ; pudidx++) { -pmd_t *pmd; - -if (pgdidx == pgdidx_limit && - pudidx > pudidx_limit) - goto out; - -if (pud_none (pud[pudidx])) -continue ; - - pmd =pmd_offset (&pud[pudidx],0 ); - -if (PTRS_PER_PMD >1 )/* not folded */ - flush |= (*func)(mm,virt_to_page (pmd),PT_PMD ); - -for (pmdidx =0 ; pmdidx <PTRS_PER_PMD ; pmdidx++) { -struct page *pte; - -if (pgdidx == pgdidx_limit && - pudidx == pudidx_limit && - pmdidx > pmdidx_limit) - goto out; - -if (pmd_none (pmd[pmdidx])) -continue ; - - pte =pmd_page (pmd[pmdidx]); - flush |= (*func)(mm, pte,PT_PTE ); - } - } + p4d =p4d_offset (&pgd[i],0 ); +if (PTRS_PER_P4D >1 ) + flush |= (*func)(mm,virt_to_page (p4d),PT_P4D ); + flush |=xen_p4d_walk (mm, p4d, func, i == nr -1 , limit); } -out:/* Do the top level last, so that the callbacks can use it as a cue to do final things like tlb flushes. */ flush |= (*func)(mm,virt_to_page (pgd),PT_PGD );
@@ -1150,57 +1163,97 @@ static void __init xen_cleanmfnmap_free_pgtbl(void *pgtbl, bool unpin)xen_free_ro_pages (pa,PAGE_SIZE ); } +static void __init xen_cleanmfnmap_pmd (pmd_t *pmd,bool unpin) +{ +unsigned long pa; +pte_t *pte_tbl; +int i; + +if (pmd_large (*pmd)) { + pa =pmd_val (*pmd) &PHYSICAL_PAGE_MASK ; +xen_free_ro_pages (pa,PMD_SIZE ); +return ; + } + + pte_tbl =pte_offset_kernel (pmd,0 ); +for (i =0 ; i <PTRS_PER_PTE ; i++) { +if (pte_none (pte_tbl[i])) +continue ; + pa =pte_pfn (pte_tbl[i]) <<PAGE_SHIFT ; +xen_free_ro_pages (pa,PAGE_SIZE ); + } +set_pmd (pmd,__pmd (0 )); +xen_cleanmfnmap_free_pgtbl (pte_tbl, unpin); +} + +static void __init xen_cleanmfnmap_pud (pud_t *pud,bool unpin) +{ +unsigned long pa; +pmd_t *pmd_tbl; +int i; + +if (pud_large (*pud)) { + pa =pud_val (*pud) &PHYSICAL_PAGE_MASK ; +xen_free_ro_pages (pa,PUD_SIZE ); +return ; + } + + pmd_tbl =pmd_offset (pud,0 ); +for (i =0 ; i <PTRS_PER_PMD ; i++) { +if (pmd_none (pmd_tbl[i])) +continue ; +xen_cleanmfnmap_pmd (pmd_tbl + i, unpin); + } +set_pud (pud,__pud (0 )); +xen_cleanmfnmap_free_pgtbl (pmd_tbl, unpin); +} + +static void __init xen_cleanmfnmap_p4d (p4d_t *p4d,bool unpin) +{ +unsigned long pa; +pud_t *pud_tbl; +int i; + +if (p4d_large (*p4d)) { + pa =p4d_val (*p4d) &PHYSICAL_PAGE_MASK ; +xen_free_ro_pages (pa,P4D_SIZE ); +return ; + } + + pud_tbl =pud_offset (p4d,0 ); +for (i =0 ; i <PTRS_PER_PUD ; i++) { +if (pud_none (pud_tbl[i])) +continue ; +xen_cleanmfnmap_pud (pud_tbl + i, unpin); + } +set_p4d (p4d,__p4d (0 )); +xen_cleanmfnmap_free_pgtbl (pud_tbl, unpin); +} +/* * Since it is well isolated we can (and since it is perhaps large we should) * also free the page tables mapping the initial P->M table. */ static void __init xen_cleanmfnmap (unsigned long vaddr) { -unsigned long va = vaddr &PMD_MASK ; -unsigned long pa; -pgd_t *pgd =pgd_offset_k (va); -pud_t *pud_page =pud_offset (pgd,0 ); -pud_t *pud; -pmd_t *pmd; -pte_t *pte; +pgd_t *pgd; +p4d_t *p4d;unsigned int i;bool unpin; unpin = (vaddr ==2 *PGDIR_SIZE ); -set_pgd (pgd,__pgd (0 )); -do { - pud = pud_page +pud_index (va); -if (pud_none (*pud)) { - va +=PUD_SIZE ; - }else if (pud_large (*pud)) { - pa =pud_val (*pud) &PHYSICAL_PAGE_MASK ; -xen_free_ro_pages (pa,PUD_SIZE ); - va +=PUD_SIZE ; - }else { - pmd =pmd_offset (pud, va); -if (pmd_large (*pmd)) { - pa =pmd_val (*pmd) &PHYSICAL_PAGE_MASK ; -xen_free_ro_pages (pa,PMD_SIZE ); - }else if (!pmd_none (*pmd)) { - pte =pte_offset_kernel (pmd, va); -set_pmd (pmd,__pmd (0 )); -for (i =0 ; i <PTRS_PER_PTE ; ++i) { -if (pte_none (pte[i])) -break ; - pa =pte_pfn (pte[i]) <<PAGE_SHIFT ; -xen_free_ro_pages (pa,PAGE_SIZE ); - } -xen_cleanmfnmap_free_pgtbl (pte, unpin); - } - va +=PMD_SIZE ; -if (pmd_index (va)) -continue ; -set_pud (pud,__pud (0 )); -xen_cleanmfnmap_free_pgtbl (pmd, unpin); - } - - }while (pud_index (va) ||pmd_index (va)); -xen_cleanmfnmap_free_pgtbl (pud_page, unpin); + vaddr &=PMD_MASK ; + pgd =pgd_offset_k (vaddr); + p4d =p4d_offset (pgd,0 ); +for (i =0 ; i <PTRS_PER_P4D ; i++) { +if (p4d_none (p4d[i])) +continue ; +xen_cleanmfnmap_p4d (p4d + i, unpin); + } +if (IS_ENABLED (CONFIG_X86_5LEVEL )) { +set_pgd (pgd,__pgd (0 )); +xen_cleanmfnmap_free_pgtbl (p4d, unpin); + } }static void __init xen_pagetable_p2m_free (void )
arch/x86/xen/mmu.h +1 -0
@@ -5,6 +5,7 @@enum pt_level {PT_PGD , +PT_P4D ,PT_PUD ,PT_PMD ,PT_PTE
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 12/26 x86: convert the rest of the code to support p4d_t
In reply to Kirill A. ShutemovThis patch converts x86 to use proper folding of new page table level with <asm-generic/pgtable-nop4d.h>.
That's a bit of kitchen sink, but I don't see how to split it further.
--- arch/x86/include/asm/paravirt.h | 33 +++++- arch/x86/include/asm/paravirt_types.h | 12 ++- arch/x86/include/asm/pgalloc.h | 35 ++++++- arch/x86/include/asm/pgtable.h | 59 ++++++++++- arch/x86/include/asm/pgtable_64.h | 12 ++- arch/x86/include/asm/pgtable_types.h | 10 +- arch/x86/include/asm/xen/page.h | 8 +- arch/x86/kernel/paravirt.c | 10 +- arch/x86/mm/init_64.c | 183 +++++++++++++++++++++++++++------- arch/x86/xen/mmu.c | 152 ++++++++++++++++------------ include/trace/events/xen.h | 28 +++--- 11 files changed, 401 insertions(+), 141 deletions(-)
arch/x86/include/asm/paravirt.h +28 -5
@@ -536,7 +536,7 @@ static inline void set_pud(pud_t *pudp, pud_t pud)PVOP_VCALL2 (pv_mmu_ops.set_pud, pudp, val); } -#if CONFIG_PGTABLE_LEVELS ==4 +#if CONFIG_PGTABLE_LEVELS >=4 static inline pud_t __pud (pudval_t val) {pudval_t ret;
@@ -565,6 +565,32 @@ static inline pudval_t pud_val(pud_t pud)return ret; } +static inline void pud_clear (pud_t *pudp) +{ +set_pud (pudp,__pud (0 )); +} + +static inline void set_p4d (p4d_t *p4dp,p4d_t p4d) +{ +p4dval_t val =native_p4d_val (p4d); + +if (sizeof (p4dval_t) >sizeof (long )) +PVOP_VCALL3 (pv_mmu_ops.set_p4d, p4dp, + val, (u64 )val >>32 ); +else +PVOP_VCALL2 (pv_mmu_ops.set_p4d, p4dp, + val); +} + +static inline void p4d_clear (p4d_t *p4dp) +{ +set_p4d (p4dp,__p4d (0 )); +} + +#if CONFIG_PGTABLE_LEVELS >=5 + +#error FIXME +static inline void set_pgd (pgd_t *pgdp,pgd_t pgd) {pgdval_t val =native_pgd_val (pgd);
@@ -582,10 +608,7 @@ static inline void pgd_clear(pgd_t *pgdp)set_pgd (pgdp,__pgd (0 )); } -static inline void pud_clear (pud_t *pudp) -{ -set_pud (pudp,__pud (0 )); -} +#endif /* CONFIG_PGTABLE_LEVELS == 5 */ #endif /* CONFIG_PGTABLE_LEVELS == 4 */
arch/x86/include/asm/paravirt_types.h +9 -3
@@ -279,12 +279,18 @@ struct pv_mmu_ops {struct paravirt_callee_save pmd_val;struct paravirt_callee_save make_pmd; -#if CONFIG_PGTABLE_LEVELS ==4 +#if CONFIG_PGTABLE_LEVELS >=4 struct paravirt_callee_save pud_val;struct paravirt_callee_save make_pud; -void (*set_pgd)(pgd_t *pudp,pgd_t pgdval); -#endif /* CONFIG_PGTABLE_LEVELS == 4 */ +void (*set_p4d)(p4d_t *p4dp,p4d_t p4dval); + +#if CONFIG_PGTABLE_LEVELS >=5 +#error FIXME +#endif /* CONFIG_PGTABLE_LEVELS >= 5 */ + +#endif /* CONFIG_PGTABLE_LEVELS >= 4 */ +#endif /* CONFIG_PGTABLE_LEVELS >= 3 */ struct pv_lazy_ops lazy_mode;
arch/x86/include/asm/pgalloc.h +33 -2
@@ -121,10 +121,10 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)#endif /* CONFIG_X86_PAE */ #if CONFIG_PGTABLE_LEVELS >3 -static inline void pgd_populate (struct mm_struct *mm,pgd_t *pgd,pud_t *pud) +static inline void p4d_populate (struct mm_struct *mm,p4d_t *p4d,pud_t *pud) {paravirt_alloc_pud (mm,__pa (pud) >>PAGE_SHIFT ); -set_pgd (pgd,__pgd (_PAGE_TABLE |__pa (pud))); +set_p4d (p4d,__p4d (_PAGE_TABLE |__pa (pud))); }static inline pud_t *pud_alloc_one (struct mm_struct *mm,unsigned long addr)
@@ -150,6 +150,37 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,___pud_free_tlb (tlb, pud); } +#if CONFIG_PGTABLE_LEVELS >4 +static inline void pgd_populate (struct mm_struct *mm,pgd_t *pgd,p4d_t *p4d) +{ +paravirt_alloc_p4d (mm,__pa (p4d) >>PAGE_SHIFT ); +set_pgd (pgd,__pgd (_PAGE_TABLE |__pa (p4d))); +} + +static inline p4d_t *p4d_alloc_one (struct mm_struct *mm,unsigned long addr) +{ +gfp_t gfp =GFP_KERNEL_ACCOUNT ; + +if (mm == &init_mm) + gfp &= ~__GFP_ACCOUNT; +return (p4d_t *)get_zeroed_page (gfp); +} + +static inline void p4d_free (struct mm_struct *mm,p4d_t *p4d) +{ +BUG_ON ((unsigned long )p4d & (PAGE_SIZE -1 )); +free_page ((unsigned long )p4d); +} + +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) +{ +___p4d_free_tlb (tlb, p4d); +} + +#endif /* CONFIG_PGTABLE_LEVELS > 4 */ #endif /* CONFIG_PGTABLE_LEVELS > 3 */ #endif /* CONFIG_PGTABLE_LEVELS > 2 */
arch/x86/include/asm/pgtable.h +54 -5
105 lines not on this page · raw message
arch/x86/include/asm/pgtable_64.h +11 -1
@@ -41,9 +41,9 @@ extern void paging_init(void);struct mm_struct ; +void set_pte_vaddr_p4d (p4d_t *p4d_page,unsigned long vaddr,pte_t new_pte);void set_pte_vaddr_pud (pud_t *pud_page,unsigned long vaddr,pte_t new_pte); -static inline void native_pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {
@@ -121,6 +121,16 @@ static inline pud_t native_pudp_get_and_clear(pud_t *xp)#endif } +static inline void native_set_p4d (p4d_t *p4dp,p4d_t p4d) +{ + *p4dp = p4d; +} + +static inline void native_p4d_clear (p4d_t *p4d) +{ +native_set_p4d (p4d, (p4d_t ) { .pgd =native_make_pgd (0 )}); +} +static inline void native_set_pgd (pgd_t *pgdp,pgd_t pgd) { *pgdp = pgd;
arch/x86/include/asm/pgtable_types.h +4 -6
@@ -277,11 +277,11 @@ static inline pgdval_t pgd_flags(pgd_t pgd)#error FIXME#else -#include <asm-generic/5level-fixup.h> +#include <asm-generic/pgtable-nop4d.h> static inline p4dval_t native_p4d_val (p4d_t p4d) { -return native_pgd_val (p4d); +return native_pgd_val (p4d.pgd); }#endif
@@ -298,12 +298,11 @@ static inline pudval_t native_pud_val(pud_t pud) return pud.pud; }#else -#define __ARCH_USE_5LEVEL_HACK#include <asm-generic/pgtable-nopud.h> static inline pudval_t native_pud_val (pud_t pud) { -return native_pgd_val (pud.pgd); +return native_pgd_val (pud.p4d.pgd); }#endif
@@ -320,12 +319,11 @@ static inline pmdval_t native_pmd_val(pmd_t pmd) return pmd.pmd; }#else -#define __ARCH_USE_5LEVEL_HACK#include <asm-generic/pgtable-nopmd.h> static inline pmdval_t native_pmd_val (pmd_t pmd) { -return native_pgd_val (pmd.pud.pgd); +return native_pgd_val (pmd.pud.p4d.pgd); }#endif
arch/x86/include/asm/xen/page.h +6 -2
@@ -279,13 +279,17 @@ static inline pte_t __pte_ma(pteval_t x)#define pmd_val_ma (v) ((v).pmd)#ifdef __PAGETABLE_PUD_FOLDED -#define pud_val_ma (v) ((v).pgd.pgd) +#define pud_val_ma (v) ((v).p4d.pgd.pgd)#else #define pud_val_ma (v) ((v).pud)#endif #define __pmd_ma (x) ((pmd_t) { (x) } ) -#define pgd_val_ma (x) ((x).pgd) +#ifdef __PAGETABLE_P4D_FOLDED +#define p4d_val_ma (x) ((x).pgd.pgd) +#else +#define p4d_val_ma (x) ((x).p4d) +#endif void xen_set_domain_pte (pte_t *ptep,pte_t pteval,unsigned domid);
arch/x86/kernel/paravirt.c +7 -3
@@ -430,12 +430,16 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = { .pmd_val = PTE_IDENT, .make_pmd = PTE_IDENT, -#if CONFIG_PGTABLE_LEVELS ==4 +#if CONFIG_PGTABLE_LEVELS >=4 .pud_val = PTE_IDENT, .make_pud = PTE_IDENT, - .set_pgd = native_set_pgd, -#endif + .set_p4d = native_set_p4d, + +#if CONFIG_PGTABLE_LEVELS >=5 +#error FIXME +#endif /* CONFIG_PGTABLE_LEVELS >= 4 */ +#endif /* CONFIG_PGTABLE_LEVELS >= 4 */ #endif /* CONFIG_PGTABLE_LEVELS >= 3 */ .pte_val = PTE_IDENT,
arch/x86/mm/init_64.c +145 -38
345 lines not on this page · raw message
arch/x86/xen/mmu.c +90 -62
261 lines not on this page · raw message
include/trace/events/xen.h +14 -14
@@ -241,21 +241,21 @@ TRACE_EVENT(xen_mmu_set_pud, (int)sizeof(pudval_t) * 2, (unsigned long long)__entry->pudval) ); -TRACE_EVENT (xen_mmu_set_pgd, - TP_PROTO(pgd_t *pgdp, pgd_t *user_pgdp, pgd_t pgdval), -TP_ARGS (pgdp, user_pgdp, pgdval), +TRACE_EVENT (xen_mmu_set_p4d, + TP_PROTO(p4d_t *p4dp, p4d_t *user_p4dp, p4d_t p4dval), +TP_ARGS (p4dp, user_p4dp, p4dval),TP_STRUCT__entry ( - __field(pgd_t *, pgdp) - __field(pgd_t *, user_pgdp) -__field (pgdval_t, pgdval) - ), - TP_fast_assign(__entry->pgdp = pgdp; - __entry->user_pgdp = user_pgdp; - __entry->pgdval = pgdval.pgd), -TP_printk ("pgdp %p user_pgdp %p pgdval %0*llx (raw %0*llx)" , - __entry->pgdp, __entry->user_pgdp, - (int )sizeof (pgdval_t) *2 , (unsigned long long )pgd_val (native_make_pgd (__entry->pgdval)), - (int )sizeof (pgdval_t) *2 , (unsigned long long )__entry->pgdval) + __field(p4d_t *, p4dp) + __field(p4d_t *, user_p4dp) +__field (p4dval_t, p4dval) + ), + TP_fast_assign(__entry->p4dp = p4dp; + __entry->user_p4dp = user_p4dp; + __entry->p4dval =p4d_val (p4dval)), +TP_printk ("p4dp %p user_p4dp %p p4dval %0*llx (raw %0*llx)" , + __entry->p4dp, __entry->user_p4dp, + (int )sizeof (p4dval_t) *2 , (unsigned long long )pgd_val (native_make_pgd (__entry->p4dval)), + (int )sizeof (p4dval_t) *2 , (unsigned long long )__entry->p4dval) ); TRACE_EVENT(xen_mmu_pud_clear,
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 13/26 x86: detect 5-level paging support
In reply to Kirill A. Shutemov5-level paging support is required from hardware when compiled with CONFIG_X86_5LEVEL=y. We may implement runtime switch support later.
--- arch/x86/boot/cpucheck.c | 9 +++++++++ arch/x86/boot/cpuflags.c | 12 ++++++++++-- arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/include/asm/required-features.h | 8 +++++++- 4 files changed, 33 insertions(+), 4 deletions(-)
arch/x86/boot/cpucheck.c +9 -0
@@ -44,6 +44,15 @@ static const u32 req_flags[NCAPINTS] =0 ,/* REQUIRED_MASK5 not implemented in this file */ REQUIRED_MASK6 ,0 ,/* REQUIRED_MASK7 not implemented in this file */ +0 ,/* REQUIRED_MASK8 not implemented in this file */ +0 ,/* REQUIRED_MASK9 not implemented in this file */ +0 ,/* REQUIRED_MASK10 not implemented in this file */ +0 ,/* REQUIRED_MASK11 not implemented in this file */ +0 ,/* REQUIRED_MASK12 not implemented in this file */ +0 ,/* REQUIRED_MASK13 not implemented in this file */ +0 ,/* REQUIRED_MASK14 not implemented in this file */ +0 ,/* REQUIRED_MASK15 not implemented in this file */ + REQUIRED_MASK16, };#define A32 (a, b, c, d) (((d) << 24)+((c) << 16)+((b) << 8)+(a))
arch/x86/boot/cpuflags.c +10 -2
@@ -70,16 +70,19 @@ int has_eflag(unsigned long mask)# define EBX_REG "=b"#endif -static inline void cpuid (u32 id,u32 *a,u32 *b,u32 *c,u32 *d) +static inline void cpuid_count (u32 id,u32 count, +u32 *a,u32 *b,u32 *c,u32 *d) { asmvolatile (".ifnc %%ebx,%3 ; movl %%ebx,%3 ; .endif \n\t" "cpuid \n\t" ".ifnc %%ebx,%3 ; xchgl %%ebx,%3 ; .endif \n\t" : "=a" (*a), "=c" (*c), "=d" (*d), EBX_REG (*b) - :"a" (id) + :"a" (id),"c" (count) ); } +#define cpuid (id, a, b, c, d) cpuid_count(id, 0, a, b, c, d) +void get_cpuflags (void ) {u32 max_intel_level, max_amd_level;
@@ -108,6 +111,11 @@ void get_cpuflags(void) cpu.model += ((tfms >>16 ) &0xf ) <<4 ; } +if (max_intel_level >=0x00000007 ) { +cpuid_count (0x00000007 ,0 , &ignored, &ignored, + &cpu.flags[16 ], &ignored); + } +cpuid (0x80000000 , &max_amd_level, &ignored, &ignored, &ignored);
arch/x86/include/asm/disabled-features.h +7 -1
@@ -36,6 +36,12 @@# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */ +#ifdef CONFIG_X86_5LEVEL +#define DISABLE_LA57 0 +#else +#define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31)) +#endif +/* * Make sure to add features to the correct mask */
@@ -55,7 +61,7 @@#define DISABLED_MASK13 0#define DISABLED_MASK14 0#define DISABLED_MASK15 0 -#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE) +#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57)#define DISABLED_MASK17 0#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
arch/x86/include/asm/required-features.h +7 -1
@@ -53,6 +53,12 @@# define NEED_MOVBE 0#endif +#ifdef CONFIG_X86_5LEVEL +# define NEED_LA57 (1<<(X86_FEATURE_LA57 & 31)) +#else +# define NEED_LA57 0 +#endif +#ifdef CONFIG_X86_64 #ifdef CONFIG_PARAVIRT /* Paravirtualized systems may not have PSE or PGE available */
@@ -98,7 +104,7 @@#define REQUIRED_MASK13 0#define REQUIRED_MASK14 0#define REQUIRED_MASK15 0 -#define REQUIRED_MASK16 0 +#define REQUIRED_MASK16 (NEED_LA57)#define REQUIRED_MASK17 0#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 14/26 x86/asm: remove __VIRTUAL_MASK_SHIFT==47 assert
In reply to Kirill A. ShutemovWe don't need it anymore. 17be0aec74fb ("x86/asm/entry/64: Implement better check for canonical addresses") made canonical address check generic wrt. address width.
--- arch/x86/entry/entry_64.S | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/entry/entry_64.S +2 -5
@@ -265,12 +265,9 @@ return_from_SYSCALL_64: * * If width of "canonical tail" ever becomes variable, this will need * to be updated to remain correct on both old and new CPUs. + * + * Change top 16 bits to be the sign-extension of 47th bit */ - .ifne __VIRTUAL_MASK_SHIFT - 47 - .error "virtual address width changed -- SYSRET checks need update" - .endif - - /* Change top 16 bits to be the sign-extension of 47th bit */ shl $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx sar $(64 - (__VIRTUAL_MASK_SHIFT+1)), %rcx
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 15/26 x86/mm: define virtual memory map for 5-level paging
In reply to Kirill A. ShutemovThe first part of memory map (up to %esp fixup) simply scales existing map for 4-level paging by factor of 9 -- number of bits addressed by additional page table level.
The rest of the map is uncahnged.
--- Documentation/x86/x86_64/mm.txt | 33 ++++++++++++++++++++++++++++++--- arch/x86/Kconfig | 1 + arch/x86/include/asm/kasan.h | 9 ++++++--- arch/x86/include/asm/page_64_types.h | 10 ++++++++++ arch/x86/include/asm/pgtable_64_types.h | 6 ++++++ arch/x86/include/asm/sparsemem.h | 9 +++++++-- 6 files changed, 60 insertions(+), 8 deletions(-)
Documentation/x86/x86_64/mm.txt +30 -3
@@ -4,7 +4,7 @@ Virtual memory map with 4 level page tables: 0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm -hole caused by [48:63] sign extension +hole caused by [47:63] sign extension ffff800000000000 - ffff87ffffffffff (=43 bits) guard hole, reserved for hypervisor ffff880000000000 - ffffc7ffffffffff (=64 TB) direct mapping of all phys. memory ffffc80000000000 - ffffc8ffffffffff (=40 bits) hole
@@ -23,12 +23,39 @@ ffffffffa0000000 - ffffffffff5fffff (=1526 MB) module mapping space ffffffffff600000 - ffffffffffdfffff (=8 MB) vsyscalls ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole +Virtual memory map with 5 level page tables: + +0000000000000000 - 00ffffffffffffff (=56 bits) user space, different per mm +hole caused by [56:63] sign extension +ff00000000000000 - ff0fffffffffffff (=52 bits) guard hole, reserved for hypervisor +ff10000000000000 - ff8fffffffffffff (=55 bits) direct mapping of all phys. memory +ff90000000000000 - ff91ffffffffffff (=49 bits) hole +ff92000000000000 - ffd1ffffffffffff (=54 bits) vmalloc/ioremap space +ffd2000000000000 - ffd3ffffffffffff (=49 bits) hole +ffd4000000000000 - ffd5ffffffffffff (=49 bits) virtual memory map (512TB) +... unused hole ... +ffd8000000000000 - fff7ffffffffffff (=53 bits) kasan shadow memory (8PB) +... unused hole ... +fffe000000000000 - fffe007fffffffff (=39 bits) %esp fixup stacks +... unused hole ... +ffffffef00000000 - fffffffeffffffff (=64 GB) EFI region mapping space +... unused hole ... +ffffffff80000000 - ffffffff9fffffff (=512 MB) kernel text mapping, from phys 0 +ffffffffa0000000 - ffffffffff5fffff (=1526 MB) module mapping space +ffffffffff600000 - ffffffffffdfffff (=8 MB) vsyscalls +ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole + +Architecture defines a 64-bit virtual address. Implementations can support +less. Currently supported are 48- and 57-bit virtual addresses. Bits 63 +through to the most-significant implemented bit are set to either all ones +or all zero. This causes hole between user space and kernel addresses. + The direct mapping covers all memory in the system up to the highest memory address (this means in some cases it can also include PCI memory holes). -vmalloc space is lazily synchronized into the different PML4 pages of -the processes using the page fault handler, with init_level4_pgt as +vmalloc space is lazily synchronized into the different PML4/PML5 pages of +the processes using the page fault handler, with init_top_pgt as reference. Current X86-64 implementations support up to 46 bits of address space (64 TB),
arch/x86/Kconfig +1 -0
@@ -290,6 +290,7 @@ config ARCH_SUPPORTS_DEBUG_PAGEALLOC config KASAN_SHADOW_OFFSET hex depends on KASAN + default 0xdff8000000000000 if X86_5LEVEL default 0xdffffc0000000000 config HAVE_INTEL_TXT
arch/x86/include/asm/kasan.h +6 -3
@@ -11,9 +11,12 @@* 'kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT */ #define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ - (0xffff800000000000ULL >> 3)) -/* 47 bits for kernel address -> (47 - 3) bits for shadow */ -#define KASAN_SHADOW_END (KASAN_SHADOW_START + (1ULL << (47 - 3))) + ((-1UL << __VIRTUAL_MASK_SHIFT) >> 3)) +/* +* 47 bits for kernel address -> (47 - 3) bits for shadow +* 56 bits for kernel address -> (56 - 3) bits for shadow +*/ +#define KASAN_SHADOW_END (KASAN_SHADOW_START + (1ULL << (__VIRTUAL_MASK_SHIFT - 3)))#ifndef __ASSEMBLY__
arch/x86/include/asm/page_64_types.h +10 -0
@@ -36,7 +36,12 @@* hypervisor to fit. Choosing 16 slots here is arbitrary, but it's * what Xen requires. */ +#ifdef CONFIG_X86_5LEVEL +#define __PAGE_OFFSET_BASE _AC(0xff10000000000000, UL) +#else #define __PAGE_OFFSET_BASE _AC(0xffff880000000000, UL) +#endif +#ifdef CONFIG_RANDOMIZE_MEMORY #define __PAGE_OFFSET page_offset_base#else
@@ -46,8 +51,13 @@#define __START_KERNEL_map _AC(0xffffffff80000000, UL)/* See Documentation/x86/x86_64/mm.txt for a description of the memory map. */ +#ifdef CONFIG_X86_5LEVEL +#define __PHYSICAL_MASK_SHIFT 52 +#define __VIRTUAL_MASK_SHIFT 56 +#else #define __PHYSICAL_MASK_SHIFT 46#define __VIRTUAL_MASK_SHIFT 47 +#endif /* * Kernel image size is limited to 1GiB due to the fixmap living in the
arch/x86/include/asm/pgtable_64_types.h +6 -0
@@ -56,9 +56,15 @@ typedef struct { pteval_t pte; } pte_t;/* See Documentation/x86/x86_64/mm.txt for a description of the memory map. */ #define MAXMEM _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL) +#ifdef CONFIG_X86_5LEVEL +#define VMALLOC_SIZE_TB _AC(16384, UL) +#define __VMALLOC_BASE _AC(0xff92000000000000, UL) +#define __VMEMMAP_BASE _AC(0xffd4000000000000, UL) +#else #define VMALLOC_SIZE_TB _AC(32, UL)#define __VMALLOC_BASE _AC(0xffffc90000000000, UL)#define __VMEMMAP_BASE _AC(0xffffea0000000000, UL) +#endif #ifdef CONFIG_RANDOMIZE_MEMORY #define VMALLOC_START vmalloc_base#define VMEMMAP_START vmemmap_base
arch/x86/include/asm/sparsemem.h +7 -2
@@ -26,8 +26,13 @@# endif #else /* CONFIG_X86_32 */ # define SECTION_SIZE_BITS 27/* matt - 128 is convenient right now */ -# define MAX_PHYSADDR_BITS 44 -# define MAX_PHYSMEM_BITS 46 +# ifdef CONFIG_X86_5LEVEL +# define MAX_PHYSADDR_BITS 52 +# define MAX_PHYSMEM_BITS 52 +# else +# define MAX_PHYSADDR_BITS 44 +# define MAX_PHYSMEM_BITS 46 +# endif #endif #endif /* CONFIG_SPARSEMEM */
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 16/26 x86/paravirt: make paravirt code support 5-level paging
In reply to Kirill A. ShutemovAdd operations to allocate/release p4ds. Xen requires more work.
--- arch/x86/include/asm/paravirt.h | 44 +++++++++++++++++++++++++++++++---- arch/x86/include/asm/paravirt_types.h | 7 +++++- arch/x86/include/asm/pgalloc.h | 2 ++ arch/x86/kernel/paravirt.c | 9 +++++-- 4 files changed, 55 insertions(+), 7 deletions(-)
arch/x86/include/asm/paravirt.h +40 -4
@@ -357,6 +357,16 @@ static inline void paravirt_release_pud(unsigned long pfn)PVOP_VCALL1 (pv_mmu_ops.release_pud, pfn); } +static inline void paravirt_alloc_p4d (struct mm_struct *mm,unsigned long pfn) +{ +PVOP_VCALL2 (pv_mmu_ops.alloc_p4d, mm, pfn); +} + +static inline void paravirt_release_p4d (unsigned long pfn) +{ +PVOP_VCALL1 (pv_mmu_ops.release_p4d, pfn); +} +static inline void pte_update (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {
@@ -582,14 +592,35 @@ static inline void set_p4d(p4d_t *p4dp, p4d_t p4d) val); } -static inline void p4d_clear (p4d_t *p4dp) +#if CONFIG_PGTABLE_LEVELS >=5 + +static inline p4d_t __p4d (p4dval_t val) { -set_p4d (p4dp,__p4d (0 )); +p4dval_t ret; + +if (sizeof (p4dval_t) >sizeof (long )) + ret =PVOP_CALLEE2 (p4dval_t, pv_mmu_ops.make_p4d, + val, (u64 )val >>32 ); +else + ret =PVOP_CALLEE1 (p4dval_t, pv_mmu_ops.make_p4d, + val); + +return (p4d_t ) { ret }; } -#if CONFIG_PGTABLE_LEVELS >=5 +static inline p4dval_t p4d_val (p4d_t p4d) +{ +p4dval_t ret; + +if (sizeof (p4dval_t) >sizeof (long )) + ret =PVOP_CALLEE2 (p4dval_t, pv_mmu_ops.p4d_val, + p4d.p4d, (u64 )p4d.p4d >>32 ); +else + ret =PVOP_CALLEE1 (p4dval_t, pv_mmu_ops.p4d_val, + p4d.p4d); -#error FIXME +return ret; +}static inline void set_pgd (pgd_t *pgdp,pgd_t pgd) {
@@ -610,6 +641,11 @@ static inline void pgd_clear(pgd_t *pgdp)#endif /* CONFIG_PGTABLE_LEVELS == 5 */ +static inline void p4d_clear (p4d_t *p4dp) +{ +set_p4d (p4dp,__p4d (0 )); +} +#endif /* CONFIG_PGTABLE_LEVELS == 4 */ #endif /* CONFIG_PGTABLE_LEVELS >= 3 */
arch/x86/include/asm/paravirt_types.h +6 -1
@@ -238,9 +238,11 @@ struct pv_mmu_ops {void (*alloc_pte)(struct mm_struct *mm,unsigned long pfn);void (*alloc_pmd)(struct mm_struct *mm,unsigned long pfn);void (*alloc_pud)(struct mm_struct *mm,unsigned long pfn); +void (*alloc_p4d)(struct mm_struct *mm,unsigned long pfn);void (*release_pte)(unsigned long pfn);void (*release_pmd)(unsigned long pfn);void (*release_pud)(unsigned long pfn); +void (*release_p4d)(unsigned long pfn);/* Pagetable manipulation functions */ void (*set_pte)(pte_t *ptep,pte_t pteval);
@@ -286,7 +288,10 @@ struct pv_mmu_ops {void (*set_p4d)(p4d_t *p4dp,p4d_t p4dval);#if CONFIG_PGTABLE_LEVELS >=5 -#error FIXME +struct paravirt_callee_save p4d_val; +struct paravirt_callee_save make_p4d; + +void (*set_pgd)(pgd_t *pgdp,pgd_t pgdval);#endif /* CONFIG_PGTABLE_LEVELS >= 5 */ #endif /* CONFIG_PGTABLE_LEVELS >= 4 */
arch/x86/include/asm/pgalloc.h +2 -0
@@ -17,9 +17,11 @@ static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn) {static inline void paravirt_alloc_pmd_clone (unsigned long pfn,unsigned long clonepfn,unsigned long start,unsigned long count) {}static inline void paravirt_alloc_pud (struct mm_struct *mm,unsigned long pfn) {} +static inline void paravirt_alloc_p4d (struct mm_struct *mm,unsigned long pfn) {}static inline void paravirt_release_pte (unsigned long pfn) {}static inline void paravirt_release_pmd (unsigned long pfn) {}static inline void paravirt_release_pud (unsigned long pfn) {} +static inline void paravirt_release_p4d (unsigned long pfn) {}#endif /*
arch/x86/kernel/paravirt.c +7 -2
@@ -405,9 +405,11 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = { .alloc_pte = paravirt_nop, .alloc_pmd = paravirt_nop, .alloc_pud = paravirt_nop, + .alloc_p4d = paravirt_nop, .release_pte = paravirt_nop, .release_pmd = paravirt_nop, .release_pud = paravirt_nop, + .release_p4d = paravirt_nop, .set_pte = native_set_pte, .set_pte_at = native_set_pte_at,
@@ -437,8 +439,11 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = { .set_p4d = native_set_p4d,#if CONFIG_PGTABLE_LEVELS >=5 -#error FIXME -#endif /* CONFIG_PGTABLE_LEVELS >= 4 */ + .p4d_val = PTE_IDENT, + .make_p4d = PTE_IDENT, + + .set_pgd = native_set_pgd, +#endif /* CONFIG_PGTABLE_LEVELS >= 5 */ #endif /* CONFIG_PGTABLE_LEVELS >= 4 */ #endif /* CONFIG_PGTABLE_LEVELS >= 3 */
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 17/26 x86/mm: basic defines/helpers for CONFIG_X86_5LEVEL
In reply to Kirill A. ShutemovExtends pagetable headers to support new paging mode.
--- arch/x86/include/asm/pgtable_64.h | 11 +++++++++++ arch/x86/include/asm/pgtable_64_types.h | 20 +++++++++++++++++++ arch/x86/include/asm/pgtable_types.h | 10 +++++++++- arch/x86/mm/pgtable.c | 34 ++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable_64.h +11 -0
@@ -35,6 +35,13 @@ extern void paging_init(void);#define pud_ERROR (e) \ pr_err("%s:%d: bad pud %p(%016lx)\n", \ __FILE__, __LINE__, &(e), pud_val(e)) + +#if CONFIG_PGTABLE_LEVELS >=5 +#define p4d_ERROR (e) \ + pr_err("%s:%d: bad p4d %p(%016lx)\n", \ + __FILE__, __LINE__, &(e), p4d_val(e)) +#endif +#define pgd_ERROR (e) \ pr_err("%s:%d: bad pgd %p(%016lx)\n", \ __FILE__, __LINE__, &(e), pgd_val(e))
@@ -128,7 +135,11 @@ static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d)static inline void native_p4d_clear (p4d_t *p4d) { +#ifdef CONFIG_X86_5LEVEL +native_set_p4d (p4d,native_make_p4d (0 )); +#else native_set_p4d (p4d, (p4d_t ) { .pgd =native_make_pgd (0 )}); +#endif }static inline void native_set_pgd (pgd_t *pgdp,pgd_t pgd)
arch/x86/include/asm/pgtable_64_types.h +20 -0
@@ -23,12 +23,32 @@ typedef struct { pteval_t pte; } pte_t;#define SHARED_KERNEL_PMD 0 +#ifdef CONFIG_X86_5LEVEL + +/* +* PGDIR_SHIFT determines what a top-level page table entry can map +*/ +#define PGDIR_SHIFT 48 +#define PTRS_PER_PGD 512 + +/* +* 4rd level page in 5-level paging case +*/ +#define P4D_SHIFT 39 +#define PTRS_PER_P4D 512 +#define P4D_SIZE (_AC(1, UL) << P4D_SHIFT) +#define P4D_MASK (~(P4D_SIZE - 1)) + +#else /* CONFIG_X86_5LEVEL */ +/* * PGDIR_SHIFT determines what a top-level page table entry can map */ #define PGDIR_SHIFT 39#define PTRS_PER_PGD 512 +#endif /* CONFIG_X86_5LEVEL */ +/* * 3rd level page */
arch/x86/include/asm/pgtable_types.h +9 -1
@@ -273,9 +273,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd) }#if CONFIG_PGTABLE_LEVELS >4 +typedef struct {p4dval_t p4d; }p4d_t ; -#error FIXME +static inline p4d_t native_make_p4d (pudval_t val) +{ +return (p4d_t ) { val }; +} +static inline p4dval_t native_p4d_val (p4d_t p4d) +{ +return p4d.p4d; +}#else #include <asm-generic/pgtable-nop4d.h>
arch/x86/mm/pgtable.c +33 -1
@@ -81,6 +81,14 @@ void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud)paravirt_release_pud (__pa (pud) >>PAGE_SHIFT );tlb_remove_page (tlb,virt_to_page (pud)); } + +#if CONFIG_PGTABLE_LEVELS >4 +void ___p4d_free_tlb (struct mmu_gather *tlb,p4d_t *p4d) +{ +paravirt_release_p4d (__pa (p4d) >>PAGE_SHIFT ); +tlb_remove_page (tlb,virt_to_page (p4d)); +} +#endif /* CONFIG_PGTABLE_LEVELS > 4 */ #endif /* CONFIG_PGTABLE_LEVELS > 3 */ #endif /* CONFIG_PGTABLE_LEVELS > 2 */
@@ -120,7 +128,7 @@ static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd)references from swapper_pg_dir. */ if (CONFIG_PGTABLE_LEVELS ==2 || (CONFIG_PGTABLE_LEVELS ==3 &&SHARED_KERNEL_PMD ) || -CONFIG_PGTABLE_LEVELS ==4 ) { +CONFIG_PGTABLE_LEVELS >=4 ) {clone_pgd_range (pgd +KERNEL_PGD_BOUNDARY , swapper_pg_dir +KERNEL_PGD_BOUNDARY ,KERNEL_PGD_PTRS );
@@ -582,6 +590,30 @@ void native_set_fixmap(enum fixed_addresses idx, phys_addr_t phys, }#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +#ifdef CONFIG_X86_5LEVEL +/** +* p4d_set_huge - setup kernel P4D mapping +* +* No 512GB pages yet -- always return 0 +* +* Returns 1 on success and 0 on failure. +*/ +int p4d_set_huge (p4d_t *p4d,phys_addr_t addr,pgprot_t prot) +{ +return 0 ; +} + +/** +* p4d_clear_huge - clear kernel P4D mapping when it is set +* +* No 512GB pages yet -- always return 0 +*/ +int p4d_clear_huge (p4d_t *p4d) +{ +return 0 ; +} +#endif +/** * pud_set_huge - setup kernel PUD mapping *
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 18/26 x86/dump_pagetables: support 5-level paging
In reply to Kirill A. ShutemovSimple extension to support one more page table level.
--- arch/x86/mm/dump_pagetables.c | 49 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-)
arch/x86/mm/dump_pagetables.c +42 -7
@@ -110,7 +110,8 @@ static struct addr_marker address_markers[] = {#define PTE_LEVEL_MULT (PAGE_SIZE)#define PMD_LEVEL_MULT (PTRS_PER_PTE * PTE_LEVEL_MULT)#define PUD_LEVEL_MULT (PTRS_PER_PMD * PMD_LEVEL_MULT) -#define PGD_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT) +#define P4D_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT) +#define PGD_LEVEL_MULT (PTRS_PER_PUD * P4D_LEVEL_MULT) #define pt_dump_seq_printf(m, to_dmesg, fmt, args...) \ ({ \
@@ -347,7 +348,7 @@ static bool pud_already_checked(pud_t *prev_pud, pud_t *pud, bool checkwx)return checkwx && prev_pud && (pud_val (*prev_pud) ==pud_val (*pud)); } -static void walk_pud_level (struct seq_file *m,struct pg_state *st,pgd_t addr, +static void walk_pud_level (struct seq_file *m,struct pg_state *st,p4d_t addr,unsigned long P ) {int i;
@@ -355,7 +356,7 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st, pgd_t addr,pgprotval_t prot;pud_t *prev_pud =NULL ; - start = (pud_t *)pgd_page_vaddr (addr); + start = (pud_t *)p4d_page_vaddr (addr);for (i =0 ; i <PTRS_PER_PUD ; i++) { st->current_address =normalize_addr (P + i *PUD_LEVEL_MULT );
@@ -377,9 +378,43 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st, pgd_t addr, }#else -#define walk_pud_level (m,s,a,p) walk_pmd_level(m,s,__pud(pgd_val(a)),p) -#define pgd_large (a) pud_large(__pud(pgd_val(a))) -#define pgd_none (a) pud_none(__pud(pgd_val(a))) +#define walk_pud_level (m,s,a,p) walk_pmd_level(m,s,__pud(p4d_val(a)),p) +#define p4d_large (a) pud_large(__pud(p4d_val(a))) +#define p4d_none (a) pud_none(__pud(p4d_val(a))) +#endif + +#if PTRS_PER_P4D >1 + +static void walk_p4d_level (struct seq_file *m,struct pg_state *st,pgd_t addr, +unsigned long P ) +{ +int i; +p4d_t *start; +pgprotval_t prot; + + start = (p4d_t *)pgd_page_vaddr (addr); + +for (i =0 ; i <PTRS_PER_P4D ; i++) { + st->current_address =normalize_addr (P + i *P4D_LEVEL_MULT ); +if (!p4d_none (*start)) { +if (p4d_large (*start) || !p4d_present (*start)) { + prot =p4d_flags (*start); +note_page (m, st,__pgprot (prot),2 ); + }else { +walk_pud_level (m, st, *start, +P + i *P4D_LEVEL_MULT ); + } + }else +note_page (m, st,__pgprot (0 ),2 ); + + start++; + } +} + +#else +#define walk_p4d_level (m,s,a,p) walk_pud_level(m,s,__p4d(pgd_val(a)),p) +#define pgd_large (a) p4d_large(__p4d(pgd_val(a))) +#define pgd_none (a) p4d_none(__p4d(pgd_val(a)))#endif static inline bool is_hypervisor_range (int idx)
@@ -424,7 +459,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd, prot =pgd_flags (*start);note_page (m, &st,__pgprot (prot),1 ); }else { -walk_pud_level (m, &st, *start, +walk_p4d_level (m, &st, *start, i *PGD_LEVEL_MULT ); } }else
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 19/26 x86/kasan: extend to support 5-level paging
In reply to Kirill A. ShutemovThis patch bring support for non-folded additional page table level.
--- arch/x86/mm/kasan_init_64.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/x86/mm/kasan_init_64.c +16 -2
@@ -50,8 +50,18 @@ static void __init kasan_map_early_shadow(pgd_t *pgd)unsigned long end =KASAN_SHADOW_END ;for (i =pgd_index (start); start < end; i++) { - pgd[i] =__pgd (__pa_nodebug (kasan_zero_pud) - | _KERNPG_TABLE); +switch (CONFIG_PGTABLE_LEVELS ) { +case 4 : + pgd[i] =__pgd (__pa_nodebug (kasan_zero_pud) | + _KERNPG_TABLE); +break ; +case 5 : + pgd[i] =__pgd (__pa_nodebug (kasan_zero_p4d) | + _KERNPG_TABLE); +break ; +default : +BUILD_BUG (); + } start +=PGDIR_SIZE ; } }
@@ -79,6 +89,7 @@ void __init kasan_early_init(void)pteval_t pte_val =__pa_nodebug (kasan_zero_page) | __PAGE_KERNEL;pmdval_t pmd_val =__pa_nodebug (kasan_zero_pte) | _KERNPG_TABLE;pudval_t pud_val =__pa_nodebug (kasan_zero_pmd) | _KERNPG_TABLE; +p4dval_t p4d_val =__pa_nodebug (kasan_zero_pud) | _KERNPG_TABLE;for (i =0 ; i <PTRS_PER_PTE ; i++) kasan_zero_pte[i] =__pte (pte_val);
@@ -89,6 +100,9 @@ void __init kasan_early_init(void)for (i =0 ; i <PTRS_PER_PUD ; i++) kasan_zero_pud[i] =__pud (pud_val); +for (i =0 ;CONFIG_PGTABLE_LEVELS >=5 && i <PTRS_PER_P4D ; i++) + kasan_zero_p4d[i] =__p4d (p4d_val); +kasan_map_early_shadow (early_level4_pgt);kasan_map_early_shadow (init_level4_pgt); }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 20/26 x86/espfix: support 5-level paging
In reply to Kirill A. ShutemovWe don't need extra virtual address space for ESPFIX, so it stays within one PUD page table for both 4- and 5-level paging.
--- arch/x86/kernel/espfix_64.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arch/x86/kernel/espfix_64.c +7 -5
@@ -50,11 +50,11 @@#define ESPFIX_STACKS_PER_PAGE (PAGE_SIZE/ESPFIX_STACK_SIZE)/* There is address space for how many espfix pages? */ -#define ESPFIX_PAGE_SPACE (1UL << (PGDIR_SHIFT-PAGE_SHIFT-16)) +#define ESPFIX_PAGE_SPACE (1UL << (P4D_SHIFT-PAGE_SHIFT-16))#define ESPFIX_MAX_CPUS (ESPFIX_STACKS_PER_PAGE * ESPFIX_PAGE_SPACE)#if CONFIG_NR_CPUS >ESPFIX_MAX_CPUS -# error "Need more than one PGD for the ESPFIX hack" +# error "Need more virtual address space for the ESPFIX hack"#endif #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
@@ -121,11 +121,13 @@ static void init_espfix_random(void)void __init init_espfix_bsp (void ) { -pgd_t *pgd_p; +pgd_t *pgd; +p4d_t *p4d;/* Install the espfix pud into the kernel page directory */ - pgd_p = &init_level4_pgt[pgd_index (ESPFIX_BASE_ADDR )]; -pgd_populate (&init_mm, pgd_p, (pud_t *)espfix_pud_page); + pgd = &init_level4_pgt[pgd_index (ESPFIX_BASE_ADDR )]; + p4d =p4d_alloc (&init_mm, pgd,ESPFIX_BASE_ADDR ); +p4d_populate (&init_mm, p4d, espfix_pud_page);/* Randomize the locations */ init_espfix_random ();
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 21/26 x86/mm: add support of additional page table level during early boot
In reply to Kirill A. ShutemovThis patch adds support for 5-level paging during early boot. It generalizes boot for 4- and 5-level paging on 64-bit systems with compile-time switch between them.
--- arch/x86/boot/compressed/head_64.S | 23 +++++++++-- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable_64.h | 6 ++- arch/x86/include/uapi/asm/processor-flags.h | 2 + arch/x86/kernel/espfix_64.c | 2 +- arch/x86/kernel/head64.c | 40 +++++++++++++----- arch/x86/kernel/head_64.S | 63 +++++++++++++++++++++-------- arch/x86/kernel/machine_kexec_64.c | 2 +- arch/x86/mm/dump_pagetables.c | 2 +- arch/x86/mm/kasan_init_64.c | 12 +++--- arch/x86/realmode/init.c | 2 +- arch/x86/xen/mmu.c | 38 ++++++++++------- arch/x86/xen/xen-pvh.S | 2 +- 13 files changed, 136 insertions(+), 60 deletions(-)
arch/x86/boot/compressed/head_64.S +19 -4
@@ -122,9 +122,12 @@ ENTRY(startup_32) addl %ebp, gdt+2(%ebp) lgdt gdt(%ebp) - /* Enable PAE mode */ + /* Enable PAE and LA57 mode */ movl %cr4, %eax orl $X86_CR4_PAE, %eax +#ifdef CONFIG_X86_5LEVEL + orl $X86_CR4_LA57, %eax +#endif movl %eax, %cr4 /*
@@ -136,13 +139,24 @@ ENTRY(startup_32) movl $(BOOT_INIT_PGT_SIZE/4), %ecx rep stosl + xorl %edx, %edx + + /* Build Top Level */ + leal pgtable(%ebx,%edx,1), %edi + leal 0x1007 (%edi), %eax + movl %eax, 0(%edi) + +#ifdef CONFIG_X86_5LEVEL /* Build Level 4 */ - leal pgtable + 0(%ebx), %edi + addl $0x1000, %edx + leal pgtable(%ebx,%edx), %edi leal 0x1007 (%edi), %eax movl %eax, 0(%edi) +#endif /* Build Level 3 */ - leal pgtable + 0x1000(%ebx), %edi + addl $0x1000, %edx + leal pgtable(%ebx,%edx), %edi leal 0x1007(%edi), %eax movl $4, %ecx 1: movl %eax, 0x00(%edi)
@@ -152,7 +166,8 @@ ENTRY(startup_32) jnz 1b /* Build Level 2 */ - leal pgtable + 0x2000(%ebx), %edi + addl $0x1000, %edx + leal pgtable(%ebx,%edx), %edi movl $0x00000183, %eax movl $2048, %ecx 1: movl %eax, 0(%edi)
arch/x86/include/asm/pgtable.h +1 -1
@@ -917,7 +917,7 @@ extern pgd_t trampoline_pgd_entry;static inline void __meminit init_trampoline_default (void ) {/* Default trampoline pgd value */ - trampoline_pgd_entry = init_level4_pgt[pgd_index (__PAGE_OFFSET)]; + trampoline_pgd_entry = init_top_pgt[pgd_index (__PAGE_OFFSET)]; }# ifdef CONFIG_RANDOMIZE_MEMORY void __meminit init_trampoline (void );
arch/x86/include/asm/pgtable_64.h +4 -2
@@ -14,15 +14,17 @@#include <linux/bitops.h> #include <linux/threads.h> +extern p4d_t level4_kernel_pgt[512 ]; +extern p4d_t level4_ident_pgt[512 ];extern pud_t level3_kernel_pgt[512 ];extern pud_t level3_ident_pgt[512 ];extern pmd_t level2_kernel_pgt[512 ];extern pmd_t level2_fixmap_pgt[512 ];extern pmd_t level2_ident_pgt[512 ];extern pte_t level1_fixmap_pgt[512 ]; -extern pgd_t init_level4_pgt[]; +extern pgd_t init_top_pgt[]; -#define swapper_pg_dir init_level4_pgt +#define swapper_pg_dir init_top_pgtextern void paging_init (void );
arch/x86/include/uapi/asm/processor-flags.h +2 -0
@@ -104,6 +104,8 @@#define X86_CR4_OSFXSR _BITUL(X86_CR4_OSFXSR_BIT)#define X86_CR4_OSXMMEXCPT_BIT 10/* enable unmasked SSE exceptions */ #define X86_CR4_OSXMMEXCPT _BITUL(X86_CR4_OSXMMEXCPT_BIT) +#define X86_CR4_LA57_BIT 12/* enable 5-level page tables */ +#define X86_CR4_LA57 _BITUL(X86_CR4_LA57_BIT)#define X86_CR4_VMXE_BIT 13/* enable VMX virtualization */ #define X86_CR4_VMXE _BITUL(X86_CR4_VMXE_BIT)#define X86_CR4_SMXE_BIT 14/* enable safer mode (TXT) */
arch/x86/kernel/espfix_64.c +1 -1
@@ -125,7 +125,7 @@ void __init init_espfix_bsp(void)p4d_t *p4d;/* Install the espfix pud into the kernel page directory */ - pgd = &init_level4_pgt[pgd_index (ESPFIX_BASE_ADDR )]; + pgd = &init_top_pgt[pgd_index (ESPFIX_BASE_ADDR )]; p4d =p4d_alloc (&init_mm, pgd,ESPFIX_BASE_ADDR );p4d_populate (&init_mm, p4d, espfix_pud_page);
arch/x86/kernel/head64.c +29 -11
@@ -32,7 +32,7 @@/* * Manage page tables very early on. */ -extern pgd_t early_level4_pgt[PTRS_PER_PGD ]; +extern pgd_t early_top_pgt[PTRS_PER_PGD ];extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES ][PTRS_PER_PMD ];static unsigned int __initdata next_early_pgt =2 ;pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);
@@ -40,9 +40,9 @@ pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);/* Wipe all early page tables except for the kernel symbol map */ static void __init reset_early_page_tables (void ) { -memset (early_level4_pgt,0 ,sizeof (pgd_t)*(PTRS_PER_PGD -1 )); +memset (early_top_pgt,0 ,sizeof (pgd_t)*(PTRS_PER_PGD -1 )); next_early_pgt =0 ; -write_cr3 (__pa_nodebug (early_level4_pgt)); +write_cr3 (__pa_nodebug (early_top_pgt)); }/* Create a new PMD entry */
@@ -50,15 +50,16 @@ int __init early_make_pgtable(unsigned long address) {unsigned long physaddr = address - __PAGE_OFFSET;pgdval_t pgd, *pgd_p; +p4dval_t p4d, *p4d_p;pudval_t pud, *pud_p;pmdval_t pmd, *pmd_p;/* Invalid address or early pgt is done ? */ -if (physaddr >=MAXMEM ||read_cr3 () !=__pa_nodebug (early_level4_pgt)) +if (physaddr >=MAXMEM ||read_cr3 () !=__pa_nodebug (early_top_pgt))return -1 ; again: - pgd_p = &early_level4_pgt[pgd_index (address)].pgd; + pgd_p = &early_top_pgt[pgd_index (address)].pgd; pgd = *pgd_p;/*
@@ -66,8 +67,25 @@ int __init early_make_pgtable(unsigned long address)* critical -- __PAGE_OFFSET would point us back into the dynamic * range and we might end up looping forever... */ -if (pgd) - pud_p = (pudval_t *)((pgd &PTE_PFN_MASK ) + __START_KERNEL_map - phys_base); +if (!IS_ENABLED (CONFIG_X86_5LEVEL )) + p4d_p = pgd_p; +else if (pgd) + p4d_p = (p4dval_t *)((pgd &PTE_PFN_MASK ) + __START_KERNEL_map - phys_base); +else { +if (next_early_pgt >=EARLY_DYNAMIC_PAGE_TABLES ) { +reset_early_page_tables (); + goto again; + } + + p4d_p = (p4dval_t *)early_dynamic_pgts[next_early_pgt++]; +memset (p4d_p,0 ,sizeof (*p4d_p) *PTRS_PER_P4D ); + *pgd_p = (pgdval_t )p4d_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE; + } + p4d_p +=p4d_index (address); + p4d = *p4d_p; + +if (p4d) + pud_p = (pudval_t *)((p4d &PTE_PFN_MASK ) + __START_KERNEL_map - phys_base);else {if (next_early_pgt >=EARLY_DYNAMIC_PAGE_TABLES ) {reset_early_page_tables ();
@@ -76,7 +94,7 @@ int __init early_make_pgtable(unsigned long address) pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];memset (pud_p,0 ,sizeof (*pud_p) *PTRS_PER_PUD ); - *pgd_p = (pgdval_t )pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE; + *p4d_p = (p4dval_t )pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE; } pud_p +=pud_index (address); pud = *pud_p;
@@ -155,7 +173,7 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)clear_bss (); -clear_page (init_level4_pgt); +clear_page (init_top_pgt);kasan_early_init ();
@@ -170,8 +188,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)*/ load_ucode_bsp (); -/* set init_level4_pgt kernel high mapping*/ - init_level4_pgt[511 ] = early_level4_pgt[511 ]; +/* set init_top_pgt kernel high mapping*/ + init_top_pgt[511 ] = early_top_pgt[511 ];x86_64_start_reservations (real_mode_data); }
arch/x86/kernel/head_64.S +47 -16
137 lines not on this page · raw message
arch/x86/kernel/machine_kexec_64.c +1 -1
@@ -342,7 +342,7 @@ void machine_kexec(struct kimage *image)void arch_crash_save_vmcoreinfo (void ) {VMCOREINFO_NUMBER (phys_base); -VMCOREINFO_SYMBOL (init_level4_pgt); +VMCOREINFO_SYMBOL (init_top_pgt);#ifdef CONFIG_NUMA VMCOREINFO_SYMBOL (node_data);
arch/x86/mm/dump_pagetables.c +1 -1
@@ -435,7 +435,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd, bool checkwx) {#ifdef CONFIG_X86_64 -pgd_t *start = (pgd_t *) &init_level4_pgt; +pgd_t *start = (pgd_t *) &init_top_pgt;#else pgd_t *start = swapper_pg_dir;#endif
arch/x86/mm/kasan_init_64.c +6 -6
@@ -10,7 +10,7 @@#include <asm/tlbflush.h> #include <asm/sections.h> -extern pgd_t early_level4_pgt[PTRS_PER_PGD ]; +extern pgd_t early_top_pgt[PTRS_PER_PGD ];extern struct range pfn_mapped[E820_X_MAX ];static int __init map_range (struct range *range)
@@ -103,8 +103,8 @@ void __init kasan_early_init(void)for (i =0 ;CONFIG_PGTABLE_LEVELS >=5 && i <PTRS_PER_P4D ; i++) kasan_zero_p4d[i] =__p4d (p4d_val); -kasan_map_early_shadow (early_level4_pgt); -kasan_map_early_shadow (init_level4_pgt); +kasan_map_early_shadow (early_top_pgt); +kasan_map_early_shadow (init_top_pgt); }void __init kasan_init (void )
@@ -115,8 +115,8 @@ void __init kasan_init(void)register_die_notifier (&kasan_die_notifier);#endif -memcpy (early_level4_pgt, init_level4_pgt,sizeof (early_level4_pgt)); -load_cr3 (early_level4_pgt); +memcpy (early_top_pgt, init_top_pgt,sizeof (early_top_pgt)); +load_cr3 (early_top_pgt);__flush_tlb_all ();clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );
@@ -142,7 +142,7 @@ void __init kasan_init(void)kasan_populate_zero_shadow (kasan_mem_to_shadow ((void *)MODULES_END ), (void *)KASAN_SHADOW_END ); -load_cr3 (init_level4_pgt); +load_cr3 (init_top_pgt);__flush_tlb_all ();/*
arch/x86/realmode/init.c +1 -1
@@ -102,7 +102,7 @@ static void __init setup_real_mode(void) trampoline_pgd = (u64 *)__va (real_mode_header->trampoline_pgd); trampoline_pgd[0 ] = trampoline_pgd_entry.pgd; - trampoline_pgd[511 ] = init_level4_pgt[511 ].pgd; + trampoline_pgd[511 ] = init_top_pgt[511 ].pgd;#endif }
arch/x86/xen/mmu.c +23 -15
@@ -97,7 +97,11 @@ static RESERVE_BRK_ARRAY(pte_t, level1_ident_pgt, LEVEL1_IDENT_ENTRIES);#endif #ifdef CONFIG_X86_64 /* l3 pud for userspace vsyscall mapping */ -static pud_t level3_user_vsyscall[PTRS_PER_PUD] __page_aligned_bss; +#if CONFIG_PGTABLE_LEVELS ==5 +static p4d_t user_vsyscall[PTRS_PER_P4D] __page_aligned_bss; +#else +static pud_t user_vsyscall[PTRS_PER_PUD] __page_aligned_bss; +#endif #endif /* CONFIG_X86_64 */ /*
@@ -504,7 +508,7 @@ __visible pmd_t xen_make_pmd(pmdval_t pmd) }PV_CALLEE_SAVE_REGS_THUNK (xen_make_pmd); -#if CONFIG_PGTABLE_LEVELS ==4 +#if CONFIG_PGTABLE_LEVELS >=4 __visible pudval_t xen_pud_val(pud_t pud) {return pte_mfn_to_pfn (pud.pud);
@@ -1531,8 +1535,8 @@ static void xen_write_cr3(unsigned long cr3)* At the start of the day - when Xen launches a guest, it has already * built pagetables for the guest. We diligently look over them * in xen_setup_kernel_pagetable and graft as appropriate them in the -* init_level4_pgt and its friends. Then when we are happy we load -* the new init_level4_pgt - and continue on. +* init_top_pgt and its friends. Then when we are happy we load +* the new init_top_pgt - and continue on. * * The generic code starts (start_kernel) and 'init_mem_mapping' sets * up the rest of the pagetables. When it has completed it loads the cr3.
@@ -1585,7 +1589,7 @@ static int xen_pgd_alloc(struct mm_struct *mm)if (user_pgd !=NULL ) {#ifdef CONFIG_X86_VSYSCALL_EMULATION user_pgd[pgd_index (VSYSCALL_ADDR )] = -__pgd (__pa (level3_user_vsyscall) | _PAGE_TABLE); +__pgd (__pa (user_vsyscall) | _PAGE_TABLE);#endif ret =0 ; }
@@ -1975,13 +1979,13 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn) pt_end = pt_base + xen_start_info->nr_pt_frames;/* Zap identity mapping */ - init_level4_pgt[0 ] =__pgd (0 ); + init_top_pgt[0 ] =__pgd (0 );if (!xen_feature (XENFEAT_auto_translated_physmap)) {/* Pre-constructed entries are in pfn, so convert to mfn */ /* L4[272] -> level3_ident_pgt * L4[511] -> level3_kernel_pgt */ -convert_pfn_mfn (init_level4_pgt); +convert_pfn_mfn (init_top_pgt);/* L3_i[0] -> level2_ident_pgt */ convert_pfn_mfn (level3_ident_pgt);
@@ -2012,14 +2016,14 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)/* Copy the initial P->M table mappings if necessary. */ i =pgd_index (xen_start_info->mfn_list);if (i && i <pgd_index (__START_KERNEL_map)) - init_level4_pgt[i] = ((pgd_t *)xen_start_info->pt_base)[i]; + init_top_pgt[i] = ((pgd_t *)xen_start_info->pt_base)[i];if (!xen_feature (XENFEAT_auto_translated_physmap)) {/* Make pagetable pieces RO */ -set_page_prot (init_level4_pgt,PAGE_KERNEL_RO ); +set_page_prot (init_top_pgt,PAGE_KERNEL_RO );set_page_prot (level3_ident_pgt,PAGE_KERNEL_RO );set_page_prot (level3_kernel_pgt,PAGE_KERNEL_RO ); -set_page_prot (level3_user_vsyscall,PAGE_KERNEL_RO ); +set_page_prot (user_vsyscall,PAGE_KERNEL_RO );set_page_prot (level2_ident_pgt,PAGE_KERNEL_RO );set_page_prot (level2_kernel_pgt,PAGE_KERNEL_RO );set_page_prot (level2_fixmap_pgt,PAGE_KERNEL_RO );
@@ -2027,7 +2031,7 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)/* Pin down new L4 */ pin_pagetable_pfn (MMUEXT_PIN_L4_TABLE , -PFN_DOWN (__pa_symbol (init_level4_pgt))); +PFN_DOWN (__pa_symbol (init_top_pgt)));/* Unpin Xen-provided one */ pin_pagetable_pfn (MMUEXT_UNPIN_TABLE ,PFN_DOWN (__pa (pgd)));
@@ -2038,10 +2042,10 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)* pgd. */ xen_mc_batch (); -__xen_write_cr3 (true,__pa (init_level4_pgt)); +__xen_write_cr3 (true,__pa (init_top_pgt));xen_mc_issue (PARAVIRT_LAZY_CPU ); }else -native_write_cr3 (__pa (init_level4_pgt)); +native_write_cr3 (__pa (init_top_pgt));/* We can't that easily rip out L3 and L2, as the Xen pagetables are * set out this way: [L4], [L1], [L2], [L3], [L1], [L1] ... for
@@ -2446,7 +2450,11 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)pagetable vsyscall mapping. */ if (idx ==VSYSCALL_PAGE ) {unsigned long vaddr =__fix_to_virt (idx); -set_pte_vaddr_pud (level3_user_vsyscall, vaddr, pte); +#if CONFIG_PGTABLE_LEVELS ==5 +set_pte_vaddr_p4d (user_vsyscall, vaddr, pte); +#else +set_pte_vaddr_pud (user_vsyscall, vaddr, pte); +#endif }#endif }
@@ -2477,7 +2485,7 @@ static void __init xen_post_allocator_init(void)#ifdef CONFIG_X86_64 pv_mmu_ops.write_cr3 = &xen_write_cr3; -SetPagePinned (virt_to_page (level3_user_vsyscall)); +SetPagePinned (virt_to_page (user_vsyscall));#endif xen_mark_init_mm_pinned (); }
arch/x86/xen/xen-pvh.S +1 -1
@@ -87,7 +87,7 @@ ENTRY(pvh_start_xen) wrmsr /* Enable pre-constructed page tables. */ - mov $_pa(init_level4_pgt), %eax + mov $_pa(init_top_pgt), %eax mov %eax, %cr3 mov $(X86_CR0_PG | X86_CR0_PE), %eax mov %eax, %cr0
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 22/26 x86/mm: add sync_global_pgds() for configuration with 5-level paging
In reply to Kirill A. ShutemovThis basically restores slightly modified version of original sync_global_pgds() which we had before foldedl p4d was introduced.
The only modification is protection against 'address' overflow.
--- arch/x86/mm/init_64.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
arch/x86/mm/init_64.c +37 -0
@@ -92,6 +92,42 @@ __setup("noexec32=", nonx32_setup);* When memory was added make sure all the processes MM have * suitable PGD entries in the local PGD level page. */ +#ifdef CONFIG_X86_5LEVEL +void sync_global_pgds (unsigned long start,unsigned long end) +{ +unsigned long address; + +for (address = start; address <= end && address >= start; + address +=PGDIR_SIZE ) { +const pgd_t *pgd_ref =pgd_offset_k (address); +struct page *page; + +if (pgd_none (*pgd_ref)) +continue ; + +spin_lock (&pgd_lock); +list_for_each_entry (page, &pgd_list, lru) { +pgd_t *pgd; +spinlock_t *pgt_lock; + + pgd = (pgd_t *)page_address (page) +pgd_index (address); +/* the pgt_lock only for Xen */ + pgt_lock = &pgd_page_get_mm (page)->page_table_lock; +spin_lock (pgt_lock); + +if (!pgd_none (*pgd_ref) && !pgd_none (*pgd)) +BUG_ON (pgd_page_vaddr (*pgd) + !=pgd_page_vaddr (*pgd_ref)); + +if (pgd_none (*pgd)) +set_pgd (pgd, *pgd_ref); + +spin_unlock (pgt_lock); + } +spin_unlock (&pgd_lock); + } +} +#else void sync_global_pgds (unsigned long start,unsigned long end) {unsigned long address;
@@ -135,6 +171,7 @@ void sync_global_pgds(unsigned long start, unsigned long end) spin_unlock(&pgd_lock); } } +#endif /* * NOTE: This function is marked __ref because it calls __init function
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 23/26 x86/mm: make kernel_physical_mapping_init() support 5-level paging
In reply to Kirill A. ShutemovProperly populate addition pagetable level if CONFIG_X86_5LEVEL is enabled.
--- arch/x86/mm/init_64.c | 71 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 9 deletions(-)
arch/x86/mm/init_64.c +62 -9
@@ -622,6 +622,58 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,return paddr_last; } +static unsigned long __meminit +phys_p4d_init (p4d_t *p4d_page,unsigned long paddr,unsigned long paddr_end, +unsigned long page_size_mask) +{ +unsigned long paddr_next, paddr_last = paddr_end; +unsigned long vaddr = (unsigned long )__va (paddr); +int i =p4d_index (vaddr); + +if (!IS_ENABLED (CONFIG_X86_5LEVEL )) +return phys_pud_init ((pud_t *) p4d_page, paddr, paddr_end, page_size_mask); + +for (; i <PTRS_PER_P4D ; i++, paddr = paddr_next) { +p4d_t *p4d; +pud_t *pud; + + vaddr = (unsigned long )__va (paddr); + p4d = p4d_page +p4d_index (vaddr); + paddr_next = (paddr &P4D_MASK ) +P4D_SIZE ; + +if (paddr >= paddr_end) { +if (!after_bootmem && + !e820_any_mapped (paddr &P4D_MASK , paddr_next, +E820_RAM ) && + !e820_any_mapped (paddr &P4D_MASK , paddr_next, +E820_RESERVED_KERN )) { +set_p4d (p4d,__p4d (0 )); + } +continue ; + } + +if (!p4d_none (*p4d)) { + pud =pud_offset (p4d,0 ); + paddr_last =phys_pud_init (pud, paddr, + paddr_end, + page_size_mask); +__flush_tlb_all (); +continue ; + } + + pud =alloc_low_page (); + paddr_last =phys_pud_init (pud, paddr, paddr_end, + page_size_mask); + +spin_lock (&init_mm.page_table_lock); +p4d_populate (&init_mm, p4d, pud); +spin_unlock (&init_mm.page_table_lock); + } +__flush_tlb_all (); + +return paddr_last; +} +/* * Create page table mapping for the physical memory for specific physical * addresses. The virtual and physical addresses have to be aligned on PMD level
@@ -643,26 +695,27 @@ kernel_physical_mapping_init(unsigned long paddr_start,for (; vaddr < vaddr_end; vaddr = vaddr_next) {pgd_t *pgd =pgd_offset_k (vaddr);p4d_t *p4d; -pud_t *pud; vaddr_next = (vaddr &PGDIR_MASK ) +PGDIR_SIZE ; -BUILD_BUG_ON (pgd_none (*pgd)); - p4d =p4d_offset (pgd, vaddr); -if (p4d_val (*p4d)) { - pud = (pud_t *)p4d_page_vaddr (*p4d); - paddr_last =phys_pud_init (pud,__pa (vaddr), +if (pgd_val (*pgd)) { + p4d = (p4d_t *)pgd_page_vaddr (*pgd); + paddr_last =phys_p4d_init (p4d,__pa (vaddr),__pa (vaddr_end), page_size_mask);continue ; } - pud =alloc_low_page (); - paddr_last =phys_pud_init (pud,__pa (vaddr),__pa (vaddr_end), + p4d =alloc_low_page (); + paddr_last =phys_p4d_init (p4d,__pa (vaddr),__pa (vaddr_end), page_size_mask);spin_lock (&init_mm.page_table_lock); -p4d_populate (&init_mm, p4d, pud); +if (IS_ENABLED (CONFIG_X86_5LEVEL )) +pgd_populate (&init_mm, pgd, p4d); +else +p4d_populate (&init_mm,p4d_offset (pgd, vaddr), + (pud_t *) p4d);spin_unlock (&init_mm.page_table_lock); pgd_changed = true; }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 24/26 x86/mm: add support for 5-level paging for KASLR
In reply to Kirill A. ShutemovWith 5-level paging randomization happens on P4D level instead of PUD.
Maximum amount of physical memory also bumped to 52-bits for 5-level paging.
--- arch/x86/mm/kaslr.c | 82 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 19 deletions(-)
arch/x86/mm/kaslr.c +63 -19
@@ -6,12 +6,12 @@* * Entropy is generated using the KASLR early boot functions now shared in * the lib directory (originally written by Kees Cook). Randomization is -* done on PGD & PUD page table levels to increase possible addresses. The -* physical memory mapping code was adapted to support PUD level virtual -* addresses. This implementation on the best configuration provides 30,000 -* possible virtual addresses in average for each memory region. An additional -* low memory page is used to ensure each CPU can start with a PGD aligned -* virtual address (for realmode). +* done on PGD & P4D/PUD page table levels to increase possible addresses. +* The physical memory mapping code was adapted to support P4D/PUD level +* virtual addresses. This implementation on the best configuration provides +* 30,000 possible virtual addresses in average for each memory region. +* An additional low memory page is used to ensure each CPU can start with +* a PGD aligned virtual address (for realmode). * * The order of each memory region is not changed. The feature looks at * the available space for the regions based on different configuration
@@ -70,7 +70,8 @@ static __initdata struct kaslr_memory_region {unsigned long *base;unsigned long size_tb; } kaslr_regions[] = { - { &page_offset_base, 64/* Maximum */ }, + { &page_offset_base, + 1 << (__PHYSICAL_MASK_SHIFT - TB_SHIFT) /* Maximum */ }, { &vmalloc_base, VMALLOC_SIZE_TB }, { &vmemmap_base, 1 }, };
@@ -142,7 +143,10 @@ void __init kernel_randomize_memory(void)*/ entropy = remain_entropy / (ARRAY_SIZE (kaslr_regions) - i);prandom_bytes_state (&rand_state, &rand,sizeof (rand)); - entropy = (rand % (entropy +1 )) &PUD_MASK ; +if (IS_ENABLED (CONFIG_X86_5LEVEL )) + entropy = (rand % (entropy +1 )) &P4D_MASK ; +else + entropy = (rand % (entropy +1 )) &PUD_MASK ; vaddr += entropy; *kaslr_regions[i].base = vaddr;
@@ -151,27 +155,21 @@ void __init kernel_randomize_memory(void)* randomization alignment. */ vaddr +=get_padding (&kaslr_regions[i]); - vaddr =round_up (vaddr +1 ,PUD_SIZE ); +if (IS_ENABLED (CONFIG_X86_5LEVEL )) + vaddr =round_up (vaddr +1 ,P4D_SIZE ); +else + vaddr =round_up (vaddr +1 ,PUD_SIZE ); remain_entropy -= entropy; } } -/* -* Create PGD aligned trampoline table to allow real mode initialization -* of additional CPUs. Consume only 1 low memory page. -*/ -void __meminit init_trampoline (void ) +static void __meminit init_trampoline_pud (void ) {unsigned long paddr, paddr_next;pgd_t *pgd;pud_t *pud_page, *pud_page_tramp;int i; -if (!kaslr_memory_enabled ()) { -init_trampoline_default (); -return ; - } - pud_page_tramp =alloc_low_page (); paddr =0 ;
@@ -192,3 +190,49 @@ void __meminit init_trampoline(void)set_pgd (&trampoline_pgd_entry,__pgd (_KERNPG_TABLE |__pa (pud_page_tramp))); } + +static void __meminit init_trampoline_p4d (void ) +{ +unsigned long paddr, paddr_next; +pgd_t *pgd; +p4d_t *p4d_page, *p4d_page_tramp; +int i; + + p4d_page_tramp =alloc_low_page (); + + paddr =0 ; + pgd =pgd_offset_k ((unsigned long )__va (paddr)); + p4d_page = (p4d_t *)pgd_page_vaddr (*pgd); + +for (i =p4d_index (paddr); i <PTRS_PER_P4D ; i++, paddr = paddr_next) { +p4d_t *p4d, *p4d_tramp; +unsigned long vaddr = (unsigned long )__va (paddr); + + p4d_tramp = p4d_page_tramp +p4d_index (paddr); + p4d = p4d_page +p4d_index (vaddr); + paddr_next = (paddr &P4D_MASK ) +P4D_SIZE ; + + *p4d_tramp = *p4d; + } + +set_pgd (&trampoline_pgd_entry, +__pgd (_KERNPG_TABLE |__pa (p4d_page_tramp))); +} + +/* +* Create PGD aligned trampoline table to allow real mode initialization +* of additional CPUs. Consume only 1 low memory page. +*/ +void __meminit init_trampoline (void ) +{ + +if (!kaslr_memory_enabled ()) { +init_trampoline_default (); +return ; + } + +if (IS_ENABLED (CONFIG_X86_5LEVEL )) +init_trampoline_p4d (); +else +init_trampoline_pud (); +}
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 25/26 x86: enable 5-level paging support
In reply to Kirill A. ShutemovMost of things are in place and we can enable support of 5-level paging.
Enabling XEN with 5-level paging requires more work. The patch makes XEN dependent on !X86_5LEVEL.
--- arch/x86/Kconfig | 5 +++++ arch/x86/xen/Kconfig | 1 + 2 files changed, 6 insertions(+)
arch/x86/Kconfig +5 -0
@@ -317,6 +317,7 @@ config FIX_EARLYCON_MEM config PGTABLE_LEVELS int + default 5 if X86_5LEVEL default 4 if X86_64 default 3 if X86_PAE default 2
@@ -1381,6 +1382,10 @@ config X86_PAE has the cost of more pagetable lookup overhead, and also consumes more pagetable space per process. +config X86_5LEVEL + bool "Enable 5-level page tables support" + depends on X86_64 + config ARCH_PHYS_ADDR_T_64BIT def_bool y depends on X86_64 || X86_PAE
arch/x86/xen/Kconfig +1 -0
@@ -5,6 +5,7 @@ config XEN bool "Xen guest support" depends on PARAVIRT + depends on !X86_5LEVEL select PARAVIRT_CLOCK select XEN_HAVE_PVMMU select XEN_HAVE_VPMU
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 26/26 x86/mm: allow to have userspace mappings above 47-bits
In reply to Kirill A. ShutemovOn x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without MAP_FIXED) above 47-bits.
If hint address set above 47-bit, but MAP_FIXED is not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 47-bit window.
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
One important case we need to handle here is interaction with MPX. MPX (without MAWA( extension cannot handle addresses above 47-bit, so we need to make sure that MPX cannot be enabled we already have VMA above the boundary and forbid creating such VMAs once MPX is enabled.
--- arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/mpx.h | 9 +++++++++ arch/x86/include/asm/processor.h | 9 ++++++--- arch/x86/kernel/sys_x86_64.c | 28 +++++++++++++++++++++++++++- arch/x86/mm/hugetlbpage.c | 31 +++++++++++++++++++++++++++---- arch/x86/mm/mmap.c | 4 ++-- arch/x86/mm/mpx.c | 33 ++++++++++++++++++++++++++++++++- 7 files changed, 104 insertions(+), 12 deletions(-)
arch/x86/include/asm/elf.h +1 -1
@@ -250,7 +250,7 @@ extern int force_personality32;the loader. We need to make sure that it is out of the way of the program that it will "exec", and that there is sufficient room for the brk. */ -#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) +#define ELF_ET_DYN_BASE (DEFAULT_MAP_WINDOW / 3 * 2)/* This yields a mask that user programs can use to figure out what instruction set this CPU supports. This could be done in user space,
arch/x86/include/asm/mpx.h +9 -0
@@ -73,6 +73,9 @@ static inline void mpx_mm_init(struct mm_struct *mm) }void mpx_notify_unmap (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long start,unsigned long end); + +unsigned long mpx_unmapped_area_check (unsigned long addr,unsigned long len, +unsigned long flags);#else static inline siginfo_t *mpx_generate_siginfo (struct pt_regs *regs) {
@@ -94,6 +97,12 @@ static inline void mpx_notify_unmap(struct mm_struct *mm, unsigned long start, unsigned long end) { } + +static inline unsigned long mpx_unmapped_area_check (unsigned long addr, +unsigned long len,unsigned long flags) +{ +return addr; +}#endif /* CONFIG_X86_INTEL_MPX */ #endif /* _ASM_X86_MPX_H */
arch/x86/include/asm/processor.h +6 -3
@@ -799,6 +799,7 @@ static inline void spin_lock_prefetch(const void *x)*/ #define TASK_SIZE PAGE_OFFSET#define TASK_SIZE_MAX TASK_SIZE +#define DEFAULT_MAP_WINDOW TASK_SIZE#define STACK_TOP TASK_SIZE#define STACK_TOP_MAX STACK_TOP
@@ -838,7 +839,9 @@ static inline void spin_lock_prefetch(const void *x)* particular problem by preventing anything from being mapped * at the maximum canonical address. */ -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE) +#define TASK_SIZE_MAX ((1UL << __VIRTUAL_MASK_SHIFT) - PAGE_SIZE) + +#define DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE)/* This decides where the kernel will search for a free chunk of vm * space during mmap's.
@@ -851,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)#define TASK_SIZE_OF (child) ((test_tsk_thread_flag(child, TIF_ADDR32)) ? \ IA32_PAGE_OFFSET : TASK_SIZE_MAX) -#define STACK_TOP TASK_SIZE +#define STACK_TOP DEFAULT_MAP_WINDOW#define STACK_TOP_MAX TASK_SIZE_MAX#define INIT_THREAD { \
@@ -873,7 +876,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,* This decides where the kernel will search for a free chunk of vm * space during mmap's. */ -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 3))#define KSTK_EIP (task) (task_pt_regs(task)->ip)
arch/x86/kernel/sys_x86_64.c +27 -1
@@ -19,6 +19,7 @@#include <asm/ia32.h> #include <asm/syscalls.h> +#include <asm/mpx.h> /* * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
@@ -129,6 +130,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,struct vm_unmapped_area_info info;unsigned long begin, end; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +if (flags &MAP_FIXED )return addr;
@@ -148,7 +153,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.flags =0 ; info.length = len; info.low_limit = begin; - info.high_limit = end; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit =min (end,TASK_SIZE ); +else + info.high_limit =min (end,DEFAULT_MAP_WINDOW ); + info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;if (filp) {
@@ -168,6 +182,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,unsigned long addr = addr0;struct vm_unmapped_area_info info; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +/* requested length too big for entire address space */ if (len >TASK_SIZE )return -ENOMEM ;
@@ -192,6 +210,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; + info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;if (filp) {
arch/x86/mm/hugetlbpage.c +27 -4
@@ -16,6 +16,7 @@#include <asm/tlb.h> #include <asm/tlbflush.h> #include <asm/pgalloc.h> +#include <asm/mpx.h> #if 0 /* This is just for testing */ struct page *
@@ -83,24 +84,41 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file, info.flags =0 ; info.length = len; info.low_limit = current->mm->mmap_legacy_base; - info.high_limit =TASK_SIZE ; + info.high_limit =DEFAULT_MAP_WINDOW ; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit =TASK_SIZE ; +else + info.high_limit =DEFAULT_MAP_WINDOW ; + info.align_mask =PAGE_MASK & ~huge_page_mask (h); info.align_offset =0 ;return vm_unmapped_area (&info); }static unsigned long hugetlb_get_unmapped_area_topdown (struct file *file, -unsigned long addr0,unsigned long len, +unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags) {struct hstate *h =hstate_file (file);struct vm_unmapped_area_info info; -unsigned long addr; info.flags =VM_UNMAPPED_AREA_TOPDOWN ; info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit = current->mm->mmap_base; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; + info.align_mask =PAGE_MASK & ~huge_page_mask (h); info.align_offset =0 ; addr =vm_unmapped_area (&info);
@@ -115,7 +133,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,VM_BUG_ON (addr != -ENOMEM ); info.flags =0 ; info.low_limit =TASK_UNMAPPED_BASE ; - info.high_limit =TASK_SIZE ; + info.high_limit =DEFAULT_MAP_WINDOW ; addr =vm_unmapped_area (&info); }
@@ -132,6 +150,11 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,if (len & ~huge_page_mask (h))return -EINVAL ; + + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +if (len >TASK_SIZE )return -ENOMEM ;
arch/x86/mm/mmap.c +2 -2
@@ -53,7 +53,7 @@ static unsigned long stack_maxrandom_size(void)* Leave an at least ~128 MB hole with possible stack randomization. */ #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size()) -#define MAX_GAP (TASK_SIZE/6*5) +#define MAX_GAP (DEFAULT_MAP_WINDOW/6*5)static int mmap_is_legacy (void ) {
@@ -91,7 +91,7 @@ static unsigned long mmap_base(unsigned long rnd)else if (gap >MAX_GAP ) gap =MAX_GAP ; -return PAGE_ALIGN (TASK_SIZE - gap - rnd); +return PAGE_ALIGN (DEFAULT_MAP_WINDOW - gap - rnd); }/*
arch/x86/mm/mpx.c +32 -1
@@ -355,10 +355,19 @@ int mpx_enable_management(void)*/ bd_base =mpx_get_bounds_dir ();down_write (&mm->mmap_sem); + +/* MPX doesn't support addresses above 47-bits yet. */ +if (find_vma (mm,DEFAULT_MAP_WINDOW )) { +pr_warn_once ("%s (%d): MPX cannot handle addresses " +"above 47-bits. Disabling." , + current->comm, current->pid); + ret = -ENXIO ; + goto out; + } mm->context.bd_addr = bd_base;if (mm->context.bd_addr ==MPX_INVALID_BOUNDS_DIR ) ret = -ENXIO ; - +out:up_write (&mm->mmap_sem);return ret; }
@@ -1038,3 +1047,25 @@ void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,if (ret)force_sig (SIGSEGV , current); } + +/* MPX cannot handle addresses above 47-bits yet. */ +unsigned long mpx_unmapped_area_check (unsigned long addr,unsigned long len, +unsigned long flags) +{ +if (!kernel_managing_mpx_tables (current->mm)) +return addr; +if (addr + len <=DEFAULT_MAP_WINDOW ) +return addr; +if (flags &MAP_FIXED ) +return -ENOMEM ; + +/* +* Requested len is larger than whole area we're allowed to map in. +* Resetting hinting address wouldn't do much good -- fail early. +*/ +if (len >DEFAULT_MAP_WINDOW ) +return -ENOMEM ; + +/* Look for unmap area within DEFAULT_MAP_WINDOW */ +return 0 ; +}
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/26 x86/gup: add 5-level paging support
In reply to Kirill A. ShutemovIt's simply extension for one more page table level.
--- arch/x86/mm/gup.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
arch/x86/mm/gup.c +27 -6
@@ -76,9 +76,9 @@ static void undo_dev_pagemap(int *nr, int nr_start, struct page **pages) }/* -* 'pteval' can come from a pte, pmd or pud. We only check +* 'pteval' can come from a pte, pmd, pud or p4d. We only check * _PAGE_PRESENT, _PAGE_USER, and _PAGE_RW in here which are the -* same value on all 3 types. +* same value on all 4 types. */ static inline int pte_allows_gup (unsigned long pteval,int write) {
@@ -295,13 +295,13 @@ static noinline int gup_huge_pud(pud_t pud, unsigned long addr,return 1 ; } -static int gup_pud_range (pgd_t pgd,unsigned long addr,unsigned long end, +static int gup_pud_range (p4d_t p4d,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr) {unsigned long next;pud_t *pudp; - pudp =pud_offset (&pgd, addr); + pudp =pud_offset (&p4d, addr); do { pud_t pud = *pudp;
@@ -320,6 +320,27 @@ static int gup_pud_range(pgd_t pgd, unsigned long addr, unsigned long end,return 1 ; } +static int gup_p4d_range (pgd_t pgd,unsigned long addr,unsigned long end, +int write,struct page **pages,int *nr) +{ +unsigned long next; +p4d_t *p4dp; + + p4dp =p4d_offset (&pgd, addr); +do { +p4d_t p4d = *p4dp; + + next =p4d_addr_end (addr, end); +if (p4d_none (p4d)) +return 0 ; +BUILD_BUG_ON (p4d_large (p4d)); +if (!gup_pud_range (p4d, addr, next, write, pages, nr)) +return 0 ; + }while (p4dp++, addr = next, addr != end); + +return 1 ; +} +/* * Like get_user_pages_fast() except its IRQ-safe in that it won't fall * back to the regular GUP.
@@ -368,7 +389,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, next =pgd_addr_end (addr, end);if (pgd_none (pgd))break ; -if (!gup_pud_range (pgd, addr, next, write, pages, &nr)) +if (!gup_p4d_range (pgd, addr, next, write, pages, &nr))break ; }while (pgdp++, addr = next, addr != end);local_irq_restore (flags);
@@ -440,7 +461,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, next =pgd_addr_end (addr, end);if (pgd_none (pgd)) goto slow; -if (!gup_pud_range (pgd, addr, next, write, pages, &nr)) +if (!gup_p4d_range (pgd, addr, next, write, pages, &nr)) goto slow; }while (pgdp++, addr = next, addr != end);local_irq_enable ();
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/26 x86: trivial portion of 5-level paging conversion
In reply to Kirill A. ShutemovThis patch covers simple cases only.
--- arch/x86/kernel/tboot.c | 6 +++++- arch/x86/kernel/vm86_32.c | 6 +++++- arch/x86/mm/fault.c | 39 +++++++++++++++++++++++++++++++++------ arch/x86/mm/init_32.c | 22 ++++++++++++++++------ arch/x86/mm/ioremap.c | 3 ++- arch/x86/mm/pgtable.c | 4 +++- arch/x86/mm/pgtable_32.c | 8 +++++++- arch/x86/platform/efi/efi_64.c | 13 +++++++++---- arch/x86/power/hibernate_32.c | 7 +++++-- 9 files changed, 85 insertions(+), 23 deletions(-)
arch/x86/kernel/tboot.c +5 -1
@@ -118,12 +118,16 @@ static int map_tboot_page(unsigned long vaddr, unsigned long pfn, pgprot_t prot) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte; pgd =pgd_offset (&tboot_mm, vaddr); - pud =pud_alloc (&tboot_mm, pgd, vaddr); + p4d =p4d_alloc (&tboot_mm, pgd, vaddr); +if (!p4d) +return -1 ; + pud =pud_alloc (&tboot_mm, p4d, vaddr);if (!pud)return -1 ; pmd =pmd_alloc (&tboot_mm, pud, vaddr);
arch/x86/kernel/vm86_32.c +5 -1
@@ -164,6 +164,7 @@ static void mark_screen_rdonly(struct mm_struct *mm)struct vm_area_struct *vma;spinlock_t *ptl;pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -173,7 +174,10 @@ static void mark_screen_rdonly(struct mm_struct *mm) pgd =pgd_offset (mm,0xA0000 );if (pgd_none_or_clear_bad (pgd)) goto out; - pud =pud_offset (pgd,0xA0000 ); + p4d =p4d_offset (pgd,0xA0000 ); +if (p4d_none_or_clear_bad (p4d)) + goto out; + pud =pud_offset (p4d,0xA0000 );if (pud_none_or_clear_bad (pud)) goto out; pmd =pmd_offset (pud,0xA0000 );
arch/x86/mm/fault.c +33 -6
@@ -253,6 +253,7 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) {unsigned index =pgd_index (address);pgd_t *pgd_k; +p4d_t *p4d, *p4d_k;pud_t *pud, *pud_k;pmd_t *pmd, *pmd_k;
@@ -265,10 +266,15 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)/* * set_pgd(pgd, *pgd_k); here would be useless on PAE * and redundant with the set_pmd() on non-PAE. As would -* set_pud. +* set_p4d/set_pud. */ - pud =pud_offset (pgd, address); - pud_k =pud_offset (pgd_k, address); + p4d =p4d_offset (pgd, address); + p4d_k =p4d_offset (pgd_k, address); +if (!p4d_present (*p4d_k)) +return NULL ; + + pud =pud_offset (p4d, address); + pud_k =pud_offset (p4d_k, address);if (!pud_present (*pud_k))return NULL ;
@@ -384,6 +390,8 @@ static void dump_pagetable(unsigned long address) {pgd_t *base =__va (read_cr3 ());pgd_t *pgd = &base[pgd_index (address)]; +p4d_t *p4d; +pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -392,7 +400,9 @@ static void dump_pagetable(unsigned long address)if (!low_pfn (pgd_val (*pgd) >>PAGE_SHIFT ) || !pgd_present (*pgd)) goto out;#endif - pmd =pmd_offset (pud_offset (pgd, address), address); + p4d =p4d_offset (pgd, address); + pud =pud_offset (p4d, address); + pmd =pmd_offset (pud, address);printk (KERN_CONT "*pde = %0*Lx " ,sizeof (*pmd) *2 , (u64 )pmd_val (*pmd));/*
@@ -526,6 +536,7 @@ static void dump_pagetable(unsigned long address) {pgd_t *base =__va (read_cr3 () &PHYSICAL_PAGE_MASK );pgd_t *pgd = base +pgd_index (address); +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -538,7 +549,15 @@ static void dump_pagetable(unsigned long address)if (!pgd_present (*pgd)) goto out; - pud =pud_offset (pgd, address); + p4d =p4d_offset (pgd, address); +if (bad_address (p4d)) + goto bad; + +printk ("P4D %lx " ,p4d_val (*p4d)); +if (!p4d_present (*p4d) ||p4d_large (*p4d)) + goto out; + + pud =pud_offset (p4d, address);if (bad_address (pud)) goto bad;
@@ -1082,6 +1101,7 @@ static noinline int spurious_fault(unsigned long error_code, unsigned long address) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -1104,7 +1124,14 @@ spurious_fault(unsigned long error_code, unsigned long address)if (!pgd_present (*pgd))return 0 ; - pud =pud_offset (pgd, address); + p4d =p4d_offset (pgd, address); +if (!p4d_present (*p4d)) +return 0 ; + +if (p4d_large (*p4d)) +return spurious_fault_check (error_code, (pte_t *) p4d); + + pud =pud_offset (p4d, address);if (!pud_present (*pud))return 0 ;
arch/x86/mm/init_32.c +16 -6
@@ -67,6 +67,7 @@ bool __read_mostly __vmalloc_start_set = false;*/ static pmd_t *__init one_md_table_init (pgd_t *pgd) { +p4d_t *p4d;pud_t *pud;pmd_t *pmd_table;
@@ -75,13 +76,15 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd) pmd_table = (pmd_t *)alloc_low_page ();paravirt_alloc_pmd (&init_mm,__pa (pmd_table) >>PAGE_SHIFT );set_pgd (pgd,__pgd (__pa (pmd_table) | _PAGE_PRESENT)); - pud =pud_offset (pgd,0 ); + p4d =p4d_offset (pgd,0 ); + pud =pud_offset (p4d,0 );BUG_ON (pmd_table !=pmd_offset (pud,0 )); return pmd_table; }#endif - pud =pud_offset (pgd,0 ); + p4d =p4d_offset (pgd,0 ); + pud =pud_offset (p4d,0 ); pmd_table =pmd_offset (pud,0 );return pmd_table;
@@ -390,8 +393,11 @@ pte_t *kmap_pte;static inline pte_t *kmap_get_fixmap_pte (unsigned long vaddr) { -return pte_offset_kernel (pmd_offset (pud_offset (pgd_offset_k (vaddr), - vaddr), vaddr), vaddr); +pgd_t *pgd =pgd_offset_k (vaddr); +p4d_t *p4d =p4d_offset (pgd, vaddr); +pud_t *pud =pud_offset (p4d, vaddr); +pmd_t *pmd =pmd_offset (pud, vaddr); +return pte_offset_kernel (pmd, vaddr); }static void __init kmap_init (void )
@@ -410,6 +416,7 @@ static void __init permanent_kmaps_init(pgd_t *pgd_base) {unsigned long vaddr;pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -418,7 +425,8 @@ static void __init permanent_kmaps_init(pgd_t *pgd_base)page_table_range_init (vaddr, vaddr +PAGE_SIZE *LAST_PKMAP , pgd_base); pgd = swapper_pg_dir +pgd_index (vaddr); - pud =pud_offset (pgd, vaddr); + p4d =p4d_offset (pgd, vaddr); + pud =pud_offset (p4d, vaddr); pmd =pmd_offset (pud, vaddr); pte =pte_offset_kernel (pmd, vaddr); pkmap_page_table = pte;
@@ -450,6 +458,7 @@ void __init native_pagetable_init(void) {unsigned long pfn, va;pgd_t *pgd, *base = swapper_pg_dir; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -469,7 +478,8 @@ void __init native_pagetable_init(void)if (!pgd_present (*pgd))break ; - pud =pud_offset (pgd, va); + p4d =p4d_offset (pgd, va); + pud =pud_offset (p4d, va); pmd =pmd_offset (pud, va);if (!pmd_present (*pmd))break ;
arch/x86/mm/ioremap.c +2 -1
@@ -425,7 +425,8 @@ static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)/* Don't assume we're using swapper_pg_dir at this point */ pgd_t *base =__va (read_cr3 ());pgd_t *pgd = &base[pgd_index (addr)]; -pud_t *pud =pud_offset (pgd, addr); +p4d_t *p4d =p4d_offset (pgd, addr); +pud_t *pud =pud_offset (p4d, addr);pmd_t *pmd =pmd_offset (pud, addr);return pmd;
arch/x86/mm/pgtable.c +3 -1
@@ -261,13 +261,15 @@ static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)static void pgd_prepopulate_pmd (struct mm_struct *mm,pgd_t *pgd,pmd_t *pmds[]) { +p4d_t *p4d;pud_t *pud;int i;if (PREALLOCATED_PMDS ==0 )/* Work around gcc-3.4.x bug */ return ; - pud =pud_offset (pgd,0 ); + p4d =p4d_offset (pgd,0 ); + pud =pud_offset (p4d,0 );for (i =0 ; i <PREALLOCATED_PMDS ; i++, pud++) {pmd_t *pmd = pmds[i];
arch/x86/mm/pgtable_32.c +7 -1
@@ -26,6 +26,7 @@ unsigned int __VMALLOC_RESERVE = 128 << 20;void set_pte_vaddr (unsigned long vaddr,pte_t pteval) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -35,7 +36,12 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)BUG ();return ; } - pud =pud_offset (pgd, vaddr); + p4d =p4d_offset (pgd, vaddr); +if (p4d_none (*p4d)) { +BUG (); +return ; + } + pud =pud_offset (p4d, vaddr);if (pud_none (*pud)) {BUG ();return ;
arch/x86/platform/efi/efi_64.c +9 -4
@@ -166,6 +166,7 @@ void efi_sync_low_kernel_mappings(void) {unsigned num_entries;pgd_t *pgd_k, *pgd_efi; +p4d_t *p4d_k, *p4d_efi;pud_t *pud_k, *pud_efi;if (efi_enabled (EFI_OLD_MEMMAP ))
@@ -197,16 +198,20 @@ void efi_sync_low_kernel_mappings(void)BUILD_BUG_ON ((EFI_VA_END & ~PUD_MASK ) !=0 ); pgd_efi = efi_pgd +pgd_index (EFI_VA_END ); - pud_efi =pud_offset (pgd_efi,0 ); + p4d_efi =p4d_offset (pgd_efi,0 ); + pud_efi =pud_offset (p4d_efi,0 ); pgd_k =pgd_offset_k (EFI_VA_END ); - pud_k =pud_offset (pgd_k,0 ); + p4d_k =p4d_offset (pgd_k,0 ); + pud_k =pud_offset (p4d_k,0 ); num_entries =pud_index (EFI_VA_END );memcpy (pud_efi, pud_k,sizeof (pud_t) * num_entries); - pud_efi =pud_offset (pgd_efi,EFI_VA_START ); - pud_k =pud_offset (pgd_k,EFI_VA_START ); + p4d_efi =p4d_offset (pgd_efi,EFI_VA_START ); + pud_efi =pud_offset (p4d_efi,EFI_VA_START ); + p4d_k =p4d_offset (pgd_k,EFI_VA_START ); + pud_k =pud_offset (p4d_k,EFI_VA_START ); num_entries =PTRS_PER_PUD -pud_index (EFI_VA_START );memcpy (pud_efi, pud_k,sizeof (pud_t) * num_entries);
arch/x86/power/hibernate_32.c +5 -2
@@ -32,6 +32,7 @@ pgd_t *resume_pg_dir;*/ static pmd_t *resume_one_md_table_init (pgd_t *pgd) { +p4d_t *p4d;pud_t *pud;pmd_t *pmd_table;
@@ -41,11 +42,13 @@ static pmd_t *resume_one_md_table_init(pgd_t *pgd)return NULL ;set_pgd (pgd,__pgd (__pa (pmd_table) | _PAGE_PRESENT)); - pud =pud_offset (pgd,0 ); + p4d =p4d_offset (pgd,0 ); + pud =pud_offset (p4d,0 );BUG_ON (pmd_table !=pmd_offset (pud,0 ));#else - pud =pud_offset (pgd,0 ); + p4d =p4d_offset (pgd,0 ); + pud =pud_offset (p4d,0 ); pmd_table =pmd_offset (pud,0 );#endif
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 21/26] x86/mm: add support of additional page table level during early boot
In reply to Kirill A. ShutemovQuoted 5 lines · Kirill A. Shutemov
This patch adds support for 5-level paging during early boot. It generalizes boot for 4- and 5-level paging on 64-bit systems with compile-time switch between them.
Signed-off-by Kirill A. Shutemov <[email protected]>
Quoted 8 lines
--- arch/x86/boot/compressed/head_64.S | 23 +++++++++-- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable_64.h | 6 ++- arch/x86/include/uapi/asm/processor-flags.h | 2 + arch/x86/kernel/espfix_64.c | 2 +- arch/x86/kernel/head64.c | 40 +++++++++++++----- arch/x86/kernel/head_64.S | 63 +++++++++++++++++++++--------
Ok, here I'd like to have a C version instead of further complicating an already complex assembly version...
I.e. the existing setup code should be converted to C in one patch, and then another patch should add 5-level paging support to the C code.
See how this was done for the 32-bit setup code already:
5a7670ee23f2 x86/boot/32: Convert the 32-bit pgtable setup code from assembly to C
Also, please split it up into per boot path and topic, i.e. have a sparate patch for the Xen bits, the KASAN bits, the kexec extension, etc.
Thanks,
Ingo
Re: [PATCH 22/26] x86/mm: add sync_global_pgds() for configuration with 5-level paging
In reply to Kirill A. ShutemovQuoted 2 lines · Kirill A. Shutemov
This basically restores slightly modified version of original
sync_global_pgds()which we had before foldedl p4d was introduced.
Please read your changelogs, I saw several typos/grammar mistakes in earlier patches. The one here is:
s/foldedl/folded
arch/x86/mm/init_64.c __setup("noexec32=", nonx32_setup); · line 101
Quoted 2 lines
arch/x86/mm/init_64.c +2
-0+for (address = start; address <= end && address >= start; + address +=PGDIR_SIZE ) {
Please don't address col80 checkpatch warnings by breaking the line in such an ugly way! Find another method, or just leave it slightly longer than 80 cols.
This one could probably be solved by:
s/address/addr
... which is the canonical variable name for such iterations anyway.
arch/x86/mm/init_64.c __setup("noexec32=", nonx32_setup); · line 114
Quoted 1 line
arch/x86/mm/init_64.c +1
-0+/* the pgt_lock only for Xen */
Please use whole sentences in comments, and please capitalize them properly.
I.e. here:
/* We acquire the pgt_lock only for Xen: */
arch/x86/mm/init_64.c __setup("noexec32=", nonx32_setup); · line 120
Quoted 2 lines
arch/x86/mm/init_64.c +2
-0+BUG_ON (pgd_page_vaddr (*pgd) + !=pgd_page_vaddr (*pgd_ref));
Ugly col80 artifact ...
Please review the rest of the series for similar patterns as well, and please only post 5-10 patches in the next submission - we'll review and apply them step by step.
Thanks,
Ingo
Dmitry Vyukov
reviewerRe: [PATCH 19/26] x86/kasan: extend to support 5-level paging
In reply to Kirill A. ShutemovQuoted 4 lines · Kirill A. Shutemov
This patch bring support for non-folded additional page table level.
Signed-off-by Kirill A. Shutemov <[email protected]>Cc Dmitry Vyukov <[email protected]
+Andrey Ryabinin
Quoted 50 lines
--- arch/x86/mm/kasan_init_64.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)arch/x86/mm/kasan_init_64.c +16
-3@@ -50,8 +50,18 @@ static void __init kasan_map_early_shadow(pgd_t *pgd)unsigned long end =KASAN_SHADOW_END ;for (i =pgd_index (start); start < end; i++) { - pgd[i] =__pgd (__pa_nodebug (kasan_zero_pud) - | _KERNPG_TABLE); +switch (CONFIG_PGTABLE_LEVELS ) { +case 4 : + pgd[i] =__pgd (__pa_nodebug (kasan_zero_pud) | + _KERNPG_TABLE); +break ; +case 5 : + pgd[i] =__pgd (__pa_nodebug (kasan_zero_p4d) | + _KERNPG_TABLE); +break ; +default : +BUILD_BUG (); + } start +=PGDIR_SIZE ; } }@@ -79,6 +89,7 @@ void __init kasan_early_init(void)pteval_t pte_val =__pa_nodebug (kasan_zero_page) | __PAGE_KERNEL;pmdval_t pmd_val =__pa_nodebug (kasan_zero_pte) | _KERNPG_TABLE;pudval_t pud_val =__pa_nodebug (kasan_zero_pmd) | _KERNPG_TABLE; +p4dval_t p4d_val =__pa_nodebug (kasan_zero_pud) | _KERNPG_TABLE;for (i =0 ; i <PTRS_PER_PTE ; i++) kasan_zero_pte[i] =__pte (pte_val);@@ -89,6 +100,9 @@ void __init kasan_early_init(void)for (i =0 ; i <PTRS_PER_PUD ; i++) kasan_zero_pud[i] =__pud (pud_val); +for (i =0 ;CONFIG_PGTABLE_LEVELS >=5 && i <PTRS_PER_P4D ; i++) + kasan_zero_p4d[i] =__p4d (p4d_val); +kasan_map_early_shadow (early_level4_pgt);kasan_map_early_shadow (init_level4_pgt); } --2.11.0
Quoted 20 lines · Kirill A. Shutemov
Kirill A. Shutemov (26):
x86: basic changes into headers for 5-level paging
x86: trivial portion of 5-level paging conversion
x86/gup: add 5-level paging support
x86/ident_map: add 5-level paging support
x86/mm: add support ofp4d_tinvmalloc_fault()
x86/power: supportp4d_tin hibernate code
x86/kexec: supportp4d_t
x86/efi: handle p4d in EFI pagetables
x86/mm/pat: handle additional page table
x86/kasan: prepareclear_pgds()to switch to
<asm-generic/pgtable-nop4d.h>
x86/xen: convert__xen_pgd_walk()andxen_cleanmfnmap()to support p4d
x86: convert the rest of the code to supportp4d_t
x86: detect 5-level paging support
x86/asm: remove __VIRTUAL_MASK_SHIFT==47 assert
x86/mm: define virtual memory map for 5-level paging x86/paravirt: make paravirt code support 5-level paging x86/mm: basic defines/helpers forCONFIG_X86_5LEVELx86/dump_pagetables: support 5-level paging
Quoted 8 lines
x86/kasan: extend to support 5-level paging
x86/espfix: support 5-level paging
x86/mm: add support of additional page table level during early boot x86/mm: addsync_global_pgds()for configuration with 5-level paging x86/mm: makekernel_physical_mapping_init()support 5-level paging x86/mm: add support for 5-level paging for KASLR
x86: enable 5-level paging support
x86/mm: allow to have userspace mappings above 47-bits
Since we are cleaning up the series anyway, please fix the patch titles as well:
- Please try to find the proper subsystem marker instead of a generic 'x86: ' prefix. For example:
x86: basic changes into headers for 5-level paging
... can be prefixed with "x86/headers: ..." or "x86/mm: ..."
- Please always start the titles with verbs, to make it easy to parse shortlogs and git oneliner logs quickly. I.e. instead of:
x86: basic changes into headers for 5-level paging
Use something like:
x86/mm: Apply basic changes into headers for 5-level paging
- Please capitalize them consistently, i.e. "x86/subsystem: Verb ...", with the verb in upper case.
- Also, please _read_ the titles and the changelogs, for example "basic changes into headers" is not a valid, easy to parse English sentence...
I.e. applying all these 4 principles to the first line turns it from:
x86: basic changes into headers for 5-level paging
... into something much more informative and easier to read:
x86/mm: Extend headers with basic definitions to support 5-level paging
Please do this for all the other patches as well - almost all of them have one deficiency or some other, several have multiple such deficiencnies.
Ok?
Thanks,
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Kirill A. ShutemovQuoted 12 lines · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.
Quoted 9 lines
If hint address set above 47-bit, but
MAP_FIXEDis not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 47-bit window.This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
So if I have done a successful mmap which returned > 128TB what should a following mmap(0,...) return ? Should that now search the *full* address space or below 128TB ?
-aneesh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
Quoted 19 lines · Aneesh Kumar K.V
Quoted 17 lines · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.If hint address set above 47-bit, but
MAP_FIXEDis not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 47-bit window.
Quoted 8 lines
Quoted 4 lines
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?
No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
Quoted 29 lines · Kirill A. Shutemov
Quoted 19 lines · Aneesh Kumar K.V
Quoted 17 lines · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.If hint address set above 47-bit, but
MAP_FIXEDis not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 47-bit window.Quoted 8 lines
Quoted 4 lines
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?
Quoted 6 lines
No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
What is the epectation when the hint addr is below 128TB but addr + len > 128TB ? Should such mmap request fail ?
-aneesh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
On Mar 19, 2017 09:25, "Aneesh Kumar K.V" <[email protected]> wrote:
Quoted 9 lines · Kirill A. Shutemov
Quoted 8 lines · Aneesh Kumar K.V
Quoted 6 lines · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.If hint address set above 47-bit, but
MAP_FIXEDis not specified, we
try
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather
than
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
from 47-bit window.
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?
Quoted 6 lines
No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
What is the epectation when the hint addr is below 128TB but addr + len > 128TB ? Should such mmap request fail ?
Yes, I believe so.
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Aneesh Kumar K.VQuoted 33 lines · Aneesh Kumar K.V
Quoted 31 lines · Kirill A. Shutemov
Quoted 19 lines · Aneesh Kumar K.V
Quoted 17 lines · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address space. Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 5-level paging and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.If hint address set above 47-bit, but
MAP_FIXEDis not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 47-bit window.Quoted 8 lines
Quoted 4 lines
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?No, I don't think so. And this implementation doesn't do this.
Quoted 7 lines
Quoted 4 lines
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
What is the epectation when the hint addr is below 128TB but addr + len > 128TB ? Should such mmap request fail ?
Considering that we have stack at the top (around 128TB) we may not be able to get a free area for such a request. But I guess the idea here is that if hint address is below 128TB, we behave as though our TASK_SIZE is 128TB ? Is that correct ?
-aneesh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Kirill A. Shutemov"Kirill A. Shutemov" <[email protected]> writes:
@@ -168,6 +182,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
Quoted 12 lines
arch/x86/kernel/sys_x86_64.c +4
-0unsigned long addr = addr0;struct vm_unmapped_area_info info; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +/* requested length too big for entire address space */ if (len >TASK_SIZE )return -ENOMEM ;@@ -192,6 +210,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len;
arch/x86/kernel/sys_x86_64.c arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, · line 220
Quoted 10 lines
arch/x86/kernel/sys_x86_64.c +8
-0info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; +
Is this ok for 32 bit application ?
arch/x86/kernel/sys_x86_64.c arch_get_unmapped_area(struct file *filp, unsigned long addr, · line 168
Quoted 3 lines
arch/x86/kernel/sys_x86_64.c +0
-0info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;if (filp) {
-aneesh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Aneesh Kumar K.VQuoted 6 lines · Aneesh Kumar K.V
Quoted 5 lines · Kirill A. Shutemov
Quoted 3 lines · Aneesh Kumar K.V
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?
Quoted 8 lines
Quoted 5 lines
No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
What is the epectation when the hint addr is below 128TB but addr + len > 128TB ? Should such mmap request fail ?
Yeah I think that makes sense, it retains the existing behaviour unless the hint itself is >= 128TB.
cheers
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
[email protected]
reviewerRe: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Kirill A. ShutemovQuoted 56 lines · Kirill A. Shutemov
On Mar 19, 2017 09:25, "Aneesh Kumar K.V"
<[email protected]>
wrote:Quoted 4 lines · Kirill A. Shutemov
Quoted 3 lines · Aneesh Kumar K.V
Quoted 1 line · Kirill A. Shutemov
On x86, 5-level paging enables 56-bit userspace virtual address
space.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Not all user space is ready to handle wide addresses. It's known
that
Quoted 1 line
Quoted 1 line
Quoted 1 line
at least some JIT compilers use higher bits in pointers to encode
their
Quoted 1 line
Quoted 1 line
Quoted 1 line
information. It collides with valid pointers with 5-level paging
and
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
leads to crashes.
To mitigate this, we are not going to allocate virtual address
space
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
above 47-bit by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without
MAP_FIXED) above 47-bits.If hint address set above 47-bit, but
MAP_FIXEDis not specified,we
tryQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space,
rather
thanQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
from 47-bit window.
This approach helps to easily make application's memory allocator
aware
Quoted 1 line
Quoted 1 line
Quoted 1 line
about large address space without manually tracking allocated
virtual
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
address space.
So if I have done a successful mmap which returned > 128TB what
should a
Quoted 1 line
Quoted 1 line
following
mmap(0,...)return ? Should that now search the *full*address
Quoted 6 lines
Quoted 1 line
space or below 128TB ?
No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other
part
Quoted 2 lines
of the process requested high address.
Quoted 6 lines
What is the epectation when the hint addr is below 128TB but addr + len
Quoted 1 line
128TB ? Should such mmap request fail ?
Yes, I believe so.
This *better* be conditional on some kind of settable limit. Having a barrier in the middle of the address space for no apparent reason to "clean" software is insane.
Signature · 7 lines
Sent from my Android device with K-9 Mail. Please excuse my brevity. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
Quoted 10 lines · On Mon, Mar 20, 2017 at 11:08:41AM -0700, [email protected] wrote:
Quoted 5 lines · Kirill A. Shutemov
Quoted 2 lines · Aneesh Kumar K.V
What is the epectation when the hint addr is below 128TB but addr + len 128TB ? Should such mmap request fail ?
Yes, I believe so.
This *better* be conditional on some kind of settable limit. Having a barrier in the middle of the address space for no apparent reason to "clean" software is insane.
I disagree with Kirill here. If addr+len > 128TB, I think we should assume the application is 57-bit aware.
Specifying hint addresses is such a rare thing to do anyway.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to [email protected]Quoted 3 lines · On Mon, Mar 20, 2017 at 11:08:41AM -0700, [email protected] wrote:
This *better* be conditional on some kind of settable limit. Having a barrier in the middle of the address space for no apparent reason to "clean" software is insane.
I had the same argument (on your side) before, but if you look on numbers it's far from the middle of address space. The barrier is around 0.2% from the start 56-bit address space.
And it's we have vdso/vvar/stack just below the barier anyway.
I don't think we would loose much if wouldn't not allow VMA to sit across it.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Aneesh Kumar K.VQuoted 11 lines · Aneesh Kumar K.V
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
So if I have done a successful mmap which returned > 128TB what should a following
mmap(0,...)return ? Should that now search the *full* address space or below 128TB ?No, I don't think so. And this implementation doesn't do this.
It's safer this way: if an library can't handle high addresses, it's better not to switch it automagically to full address space if other part of the process requested high address.
Quoted 7 lines
Quoted 2 lines
What is the epectation when the hint addr is below 128TB but addr + len > 128TB ? Should such mmap request fail ?
Considering that we have stack at the top (around 128TB) we may not be able to get a free area for such a request. But I guess the idea here is that if hint address is below 128TB, we behave as though our
TASK_SIZEis 128TB ? Is that correct ?
Right.
Signature · 1 line
Kirill A. Shutemov
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
In reply to Aneesh Kumar K.VQuoted 18 lines · Aneesh Kumar K.V
"Kirill A. Shutemov" <[email protected]> writes:
@@ -168,6 +182,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,Quoted 16 lines
arch/x86/kernel/sys_x86_64.c +6
-0unsigned long addr = addr0;struct vm_unmapped_area_info info; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +/* requested length too big for entire address space */ if (len >TASK_SIZE )return -ENOMEM ;@@ -192,6 +210,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; + +/*
Quoted 8 lines
arch/x86/kernel/sys_x86_64.c arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, · line 220
Quoted 6 lines
arch/x86/kernel/sys_x86_64.c +6
-0+* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; +Is this ok for 32 bit application ?
DEFAULT_MAP_WINDOW is equal to TASK_SIZE on 32-bit, so it's nop and will be compile out.
Signature · 1 line
Kirill A. Shutemov
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
Quoted 28 lines · Kirill A. Shutemov
Quoted 18 lines · Aneesh Kumar K.V
"Kirill A. Shutemov" <[email protected]> writes:
@@ -168,6 +182,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,Quoted 16 lines
arch/x86/kernel/sys_x86_64.c +6
-0unsigned long addr = addr0;struct vm_unmapped_area_info info; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +/* requested length too big for entire address space */ if (len >TASK_SIZE )return -ENOMEM ;@@ -192,6 +210,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; + +/* Quoted 8 lines
arch/x86/kernel/sys_x86_64.c arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, · line 220
Quoted 6 lines
arch/x86/kernel/sys_x86_64.c +6
-0+* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; +Is this ok for 32 bit application ?
Quoted 3 lines
DEFAULT_MAP_WINDOWis equal toTASK_SIZEon 32-bit, so it's nop and will be compile out.
That is not about CONFIG_X86_32 but about 32 bit application on a 64 bit kernel. I guess we will never find addr > DEFAULT_MAP_WINDOW with a 32 bit app ?
-aneesh
Re: [PATCH 26/26] x86/mm: allow to have userspace mappings above 47-bits
Quoted 31 lines · Aneesh Kumar K.V
Quoted 28 lines · Kirill A. Shutemov
Quoted 26 lines · Aneesh Kumar K.V
"Kirill A. Shutemov" <[email protected]> writes:
@@ -168,6 +182,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,Quoted 12 lines
arch/x86/kernel/sys_x86_64.c +4
-0unsigned long addr = addr0;struct vm_unmapped_area_info info; + addr =mpx_unmapped_area_check (addr, len, flags); +if (IS_ERR_VALUE (addr)) +return addr; +/* requested length too big for entire address space */ if (len >TASK_SIZE )return -ENOMEM ;@@ -192,6 +210,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len;arch/x86/kernel/sys_x86_64.c arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, · line 220
Quoted 10 lines
arch/x86/kernel/sys_x86_64.c +8
-0info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; + +/* +* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area +* in the full address space. +*/ +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit +=TASK_SIZE -DEFAULT_MAP_WINDOW ; +Is this ok for 32 bit application ?
Quoted 7 lines
Quoted 3 lines
DEFAULT_MAP_WINDOWis equal toTASK_SIZEon 32-bit, so it's nop and will be compile out.That is not about
CONFIG_X86_32but about 32 bit application on a 64 bit kernel. I guess we will never find addr >DEFAULT_MAP_WINDOWwith a 32 bit app ?
I have local change to avoid this within 32-bit syscall, but I'll need to recheck everthing.
Signature · 1 line
Kirill A. Shutemov
Re: [PATCH 21/26] x86/mm: add support of additional page table level during early boot
In reply to Ingo MolnarQuoted 17 lines · Ingo Molnar
Quoted 5 lines · Kirill A. Shutemov
This patch adds support for 5-level paging during early boot. It generalizes boot for 4- and 5-level paging on 64-bit systems with compile-time switch between them.
Signed-off-by Kirill A. Shutemov <[email protected]>Quoted 8 lines
--- arch/x86/boot/compressed/head_64.S | 23 +++++++++-- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable_64.h | 6 ++- arch/x86/include/uapi/asm/processor-flags.h | 2 + arch/x86/kernel/espfix_64.c | 2 +- arch/x86/kernel/head64.c | 40 +++++++++++++----- arch/x86/kernel/head_64.S | 63 +++++++++++++++++++++--------
Quoted 2 lines
Ok, here I'd like to have a C version instead of further complicating an already complex assembly version...
Just head up: I work on this.
It's great deal of frustration (I can't really read assembly), but I'm slowly moving forward.
Most of logic in startup_64 in arch/x86/kernel/head_64.S is converted to C. Dealing with secondary_startup_64 now.
Not sure if it's possible to convert code inarch/x86/boot/compressed/head_64.S to C.
Assembly code there is in 32-bit mode, but if we move it to C it will compiled as 64-bit. I've tried to put it in separate translation unit and compile with -m32, but then link phase breaks as object files have different types.
Any suggestion how I can get out of the situation?
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 21/26] x86/mm: add support of additional page table level during early boot
Quoted 21 lines · Kirill A. Shutemov
Quoted 17 lines · Ingo Molnar
Quoted 5 lines · Kirill A. Shutemov
This patch adds support for 5-level paging during early boot. It generalizes boot for 4- and 5-level paging on 64-bit systems with compile-time switch between them.
Signed-off-by Kirill A. Shutemov <[email protected]>Quoted 8 lines
--- arch/x86/boot/compressed/head_64.S | 23 +++++++++-- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/asm/pgtable_64.h | 6 ++- arch/x86/include/uapi/asm/processor-flags.h | 2 + arch/x86/kernel/espfix_64.c | 2 +- arch/x86/kernel/head64.c | 40 +++++++++++++----- arch/x86/kernel/head_64.S | 63 +++++++++++++++++++++--------Quoted 2 lines
Ok, here I'd like to have a C version instead of further complicating an already complex assembly version...
Quoted 7 lines
Just head up: I work on this.
It's great deal of frustration (I can't really read assembly), but I'm slowly moving forward.
Most of logic in
startup_64inarch/x86/kernel/head_64.Sis converted to C. Dealing withsecondary_startup_64now.
I'm stuck with secondary_startup_64 too. Stack breaks as soon as we switch to new page tables when onlining secondary CPUs. I don't know how to get around this.
Would it be sufficient if I only convert startup_64 in arch/x86/kernel/head_64.S to C?
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>