MIPS: Add 48-bit VA space (and 4-level page tables) for 4K pages.
PATCH 1/1 MIPS: Add 48-bit VA space (and 4-level page tables) for 4K pages.
From: Alex Belits <[email protected]>
Some users must have 4K pages while needing a 48-bit VA space size. The cleanest way do do this is to go to a 4-level page table for this case. Each page table level using order-0 pages adds 9 bits to the VA size (at 4K pages, so for four levels we get 9 * 4 + 12 == 48-bits.
For the 4K page size case only we add support functions for the PUD level of the page table tree, also the TLB exception handlers get an extra level of tree walk.
[[email protected]] Forward port to v4.10
--- arch/mips/Kconfig | 13 +++--- arch/mips/include/asm/pgalloc.h | 26 +++++++++++ arch/mips/include/asm/pgtable-64.h | 88 +++++++++++++++++++++++++++++++++++--- arch/mips/mm/init.c | 3 ++ arch/mips/mm/pgtable-64.c | 33 ++++++++++++-- arch/mips/mm/tlbex.c | 22 ++++++++++ 6 files changed, 172 insertions(+), 13 deletions(-)
arch/mips/Kconfig +8 -5
@@ -2113,10 +2113,13 @@ config MIPS_VA_BITS_48 bool "48 bits virtual memory" depends on 64BIT help - Support a maximum at least 48 bits of application virtual memory. - Default is 40 bits or less, depending on the CPU. - This option result in a small memory overhead for page tables. - This option is only supported with 16k and 64k page sizes. + Support a maximum at least 48 bits of application virtual + memory. Default is 40 bits or less, depending on the CPU. + For page sizes 16k and above, this option results in a small + memory overhead for page tables. For 4k page size, a fourth + level of page tables is added which imposes both a memory + overhead as well as slower TLB fault handling. + If unsure, say N. choice
@@ -2126,7 +2129,6 @@ choice config PAGE_SIZE_4KB bool "4kB" depends on !CPU_LOONGSON2 && !CPU_LOONGSON3 - depends on !MIPS_VA_BITS_48 help This option select the standard 4kB Linux page size. On some R3000-family processors this is the only available page size. Using
@@ -2977,6 +2979,7 @@ config HAVE_LATENCYTOP_SUPPORT config PGTABLE_LEVELS int + default 4 if PAGE_SIZE_4KB && MIPS_VA_BITS_48 default 3 if 64BIT && !PAGE_SIZE_64KB default 2
arch/mips/include/asm/pgalloc.h +26 -0
@@ -124,6 +124,32 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)#endif +#ifndef __PAGETABLE_PUD_FOLDED + +static inline pud_t *pud_alloc_one (struct mm_struct *mm,unsigned long address) +{ +pud_t *pud; + + pud = (pud_t *)__get_free_pages (GFP_KERNEL |__GFP_REPEAT,PUD_ORDER ); +if (pud) +pud_init ((unsigned long )pud, (unsigned long )invalid_pmd_table); +return pud; +} + +static inline void pud_free (struct mm_struct *mm,pud_t *pud) +{ +free_pages ((unsigned long )pud,PUD_ORDER ); +} + +static inline void pgd_populate (struct mm_struct *mm,pgd_t *pgd,pud_t *pud) +{ +set_pgd (pgd,__pgd ((unsigned long )pud)); +} + +#define __pud_free_tlb (tlb, x, addr) pud_free((tlb)->mm, x) + +#endif /* __PAGETABLE_PUD_FOLDED */ +#define check_pgt_cache () do { } while (0)extern void pagetable_init (void );
arch/mips/include/asm/pgtable-64.h +83 -5
138 lines not on this page · raw message
arch/mips/mm/init.c +3 -0
@@ -536,6 +536,9 @@ unsigned long pgd_current[NR_CPUS];* it in the linker script. */ pgd_t swapper_pg_dir[_PTRS_PER_PGD] __section(.bss..swapper_pg_dir); +#ifndef __PAGETABLE_PUD_FOLDED +pud_t invalid_pud_table[PTRS_PER_PUD] __page_aligned_bss; +#endif #ifndef __PAGETABLE_PMD_FOLDED pmd_t invalid_pmd_table[PTRS_PER_PMD] __page_aligned_bss;#endif
arch/mips/mm/pgtable-64.c +30 -3
@@ -18,10 +18,12 @@ void pgd_init(unsigned long page)unsigned long *p, *end;unsigned long entry; -#ifdef __PAGETABLE_PMD_FOLDED - entry = (unsigned long )invalid_pte_table; -#else +#if !defined(__PAGETABLE_PUD_FOLDED) + entry = (unsigned long )invalid_pud_table; +#elif !defined(__PAGETABLE_PMD_FOLDED) entry = (unsigned long )invalid_pmd_table; +#else + entry = (unsigned long )invalid_pte_table;#endif p = (unsigned long *) page;
@@ -62,6 +64,28 @@ void pmd_init(unsigned long addr, unsigned long pagetable) }#endif +#ifndef __PAGETABLE_PUD_FOLDED +void pud_init (unsigned long addr,unsigned long pagetable) +{ +unsigned long *p, *end; + + p = (unsigned long *)addr; + end = p +PTRS_PER_PUD ; + +do { + p[0 ] = pagetable; + p[1 ] = pagetable; + p[2 ] = pagetable; + p[3 ] = pagetable; + p[4 ] = pagetable; + p +=8 ; + p[-3 ] = pagetable; + p[-2 ] = pagetable; + p[-1 ] = pagetable; + }while (p != end); +} +#endif +pmd_t mk_pmd (struct page *page,pgprot_t prot) {pmd_t pmd;
@@ -85,6 +109,9 @@ void __init pagetable_init(void)/* Initialize the entire pgd. */ pgd_init ((unsigned long )swapper_pg_dir); +#ifndef __PAGETABLE_PUD_FOLDED +pud_init ((unsigned long )invalid_pud_table, (unsigned long )invalid_pmd_table); +#endif #ifndef __PAGETABLE_PMD_FOLDEDpmd_init ((unsigned long )invalid_pmd_table, (unsigned long )invalid_pte_table);#endif
arch/mips/mm/tlbex.c +22 -0
@@ -851,6 +851,13 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,uasm_i_andi (p, tmp, tmp, (PTRS_PER_PGD -1 )<<3 );uasm_i_daddu (p, ptr, ptr, tmp);/* add in pgd offset */ +#ifndef __PAGETABLE_PUD_FOLDED +uasm_i_dmfc0 (p, tmp,C0_BADVADDR );/* get faulting address */ +uasm_i_ld (p, ptr,0 , ptr);/* get pud pointer */ +uasm_i_dsrl_safe (p, tmp, tmp,PUD_SHIFT -3 );/* get pud offset in bytes */ +uasm_i_andi (p, tmp, tmp, (PTRS_PER_PUD -1 ) <<3 ); +uasm_i_daddu (p, ptr, ptr, tmp);/* add in pud offset */ +#endif #ifndef __PAGETABLE_PMD_FOLDEDuasm_i_dmfc0 (p, tmp,C0_BADVADDR );/* get faulting address */ uasm_i_ld (p, ptr,0 , ptr);/* get pmd pointer */
@@ -1167,6 +1174,21 @@ build_fast_tlb_refill_handler (u32 **p, struct uasm_label **l,uasm_i_ld (p,LOC_PTEP ,0 , ptr);/* get pmd pointer */ } +#ifndef __PAGETABLE_PUD_FOLDED +/* get pud offset in bytes */ +uasm_i_dsrl_safe (p, scratch, tmp,PUD_SHIFT -3 ); +uasm_i_andi (p, scratch, scratch, (PTRS_PER_PUD -1 ) <<3 ); + +if (use_lwx_insns ()) { +UASM_i_LWX (p, ptr, scratch, ptr); + }else { +uasm_i_daddu (p, ptr, ptr, scratch);/* add in pmd offset */ +UASM_i_LW (p, ptr,0 , ptr); + } +/* ptr contains a pointer to PMD entry */ +/* tmp contains the address */ +#endif +#ifndef __PAGETABLE_PMD_FOLDED/* get pmd offset in bytes */ uasm_i_dsrl_safe (p, scratch, tmp,PMD_SHIFT -3 );
Signature · 1 line
2.9.3
Quoted 7 lines · David Daney
From: Alex Belits <[email protected]>
Some users must have 4K pages while needing a 48-bit VA space size. The cleanest way do do this is to go to a 4-level page table for this case. Each page table level using order-0 pages adds 9 bits to the VA size (at 4K pages, so for four levels we get 9 * 4 + 12 == 48-bits.
Quoted 7 lines
For the 4K page size case only we add support functions for the PUD level of the page table tree, also the TLB exception handlers get an extra level of tree walk.
Signed-off-by Alex Belits <[email protected]>[[email protected]] Forward port to v4.10
Signed-off-by David Daney <[email protected]>
Thanks folks, queued for 4.12.
While the need for 48-bit address space is not so surprising, the need for the combination of 4K pages and 48-bit address space is!
I had some minor merge conflicts so it would be good if you could take
a look if https://git.linux-mips.org/cgit/ralf/upstream-sfr.git/commit/?id=afba1896993a0b74aa2ad3076d594e455b3af301
looks good.
Ralf