Add support for 4PB virtual address space on hash
v3 cover Add support for 4PB virtual address space on hash
This patch series extended the max virtual address space value from 512TB to 4PB with 64K page size. We do that by allocating one vsid context for each 512TB range. More details of that is explained in patch 3.
Changes from V2:
* Rebased on top of slice_mask series from Nick Piggin
* Fixed segfault when mmap with 512TB hint address
Aneesh Kumar K.V (3):
powerpc/mm: Add support for handling > 512TB address in SLB miss powerpc/mm/hash64: Increase the VA range powerpc/mm/hash: Don't memset pgd table if not needed
arch/powerpc/include/asm/book3s/64/hash-4k.h | 6 ++ arch/powerpc/include/asm/book3s/64/hash-64k.h | 7 +- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 6 +- arch/powerpc/include/asm/book3s/64/mmu.h | 24 +++++ arch/powerpc/include/asm/book3s/64/pgalloc.h | 13 ++- arch/powerpc/include/asm/processor.h | 16 ++- arch/powerpc/kernel/exceptions-64s.S | 12 ++- arch/powerpc/mm/copro_fault.c | 2 +- arch/powerpc/mm/hash_utils_64.c | 4 +- arch/powerpc/mm/init_64.c | 6 -- arch/powerpc/mm/mmu_context_book3s64.c | 17 ++- arch/powerpc/mm/pgtable-hash64.c | 2 +- arch/powerpc/mm/pgtable_64.c | 5 - arch/powerpc/mm/slb.c | 146 ++++++++++++++++++++++++++ arch/powerpc/mm/slb_low.S | 6 +- arch/powerpc/mm/tlb_hash64.c | 2 +- 16 files changed, 245 insertions(+), 29 deletions(-)
Signature · 1 line
2.14.3
PATCH v3 1/3 powerpc/mm: Add support for handling > 512TB address in SLB miss
For address above 512TB we allocate additional mmu context. To make it all easy address above 512TB is handled with IR/DR=1 and with stack frame setup.
We do the additional context allocation in SLB miss handler. If the context is not allocated, we enable interrupts and allocate the context and retry the access which will again result in a SLB miss.
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 6 ++ arch/powerpc/include/asm/book3s/64/hash-64k.h | 5 + arch/powerpc/include/asm/book3s/64/mmu-hash.h | 6 +- arch/powerpc/include/asm/book3s/64/mmu.h | 24 +++++ arch/powerpc/include/asm/processor.h | 7 ++ arch/powerpc/kernel/exceptions-64s.S | 12 ++- arch/powerpc/mm/copro_fault.c | 2 +- arch/powerpc/mm/hash_utils_64.c | 4 +- arch/powerpc/mm/mmu_context_book3s64.c | 17 ++- arch/powerpc/mm/pgtable-hash64.c | 2 +- arch/powerpc/mm/slb.c | 146 ++++++++++++++++++++++++++ arch/powerpc/mm/slb_low.S | 6 +- arch/powerpc/mm/tlb_hash64.c | 2 +- 13 files changed, 224 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +6 -0
@@ -11,6 +11,12 @@#define H_PUD_INDEX_SIZE 9#define H_PGD_INDEX_SIZE 9 +/* +* No of address bits below which we use the default context +* for slb allocation. For 4k this is 64TB. +*/ +#define H_BITS_FIRST_CONTEXT 46 +#ifndef __ASSEMBLY__#define H_PTE_TABLE_SIZE (sizeof(pte_t) << H_PTE_INDEX_SIZE)#define H_PMD_TABLE_SIZE (sizeof(pmd_t) << H_PMD_INDEX_SIZE)
arch/powerpc/include/asm/book3s/64/hash-64k.h +5 -0
@@ -6,6 +6,11 @@#define H_PMD_INDEX_SIZE 10#define H_PUD_INDEX_SIZE 7#define H_PGD_INDEX_SIZE 8 +/* +* No of address bits below which we use the default context +* for slb allocation. For 64k this is 512TB. +*/ +#define H_BITS_FIRST_CONTEXT 49/* * 64k aligned address free up few of the lower bits of RPN for us
arch/powerpc/include/asm/book3s/64/mmu-hash.h +3 -3
@@ -691,8 +691,8 @@ static inline int user_segment_size(unsigned long addr)return MMU_SEGSIZE_256M ; } -static inline unsigned long get_vsid (unsigned long context,unsigned long ea, -int ssize) +static inline unsigned long __get_vsid (unsigned long context,unsigned long ea, +int ssize) {unsigned long va_bits =VA_BITS ;unsigned long vsid_bits;
@@ -744,7 +744,7 @@ static inline unsigned long get_kernel_vsid(unsigned long ea, int ssize)*/ context = (ea >>60 ) -KERNEL_REGION_CONTEXT_OFFSET ; -return get_vsid (context, ea, ssize); +return __get_vsid (context, ea, ssize); }unsigned htab_shift_for_mem_size (unsigned long mem_size);
arch/powerpc/include/asm/book3s/64/mmu.h +24 -0
@@ -92,6 +92,12 @@ struct slice_mask { typedef struct { mm_context_id_t id; + /* + * One context for each 512TB above the first 512TB. + * First 512TB context is saved in id and is also used + * as PIDR. + */ + mm_context_id_t extended_id[(TASK_SIZE_USER64/TASK_CONTEXT_SIZE) - 1]; u16 user_psize; /* page size index */ /* Number of bits in the mm_cpumask */
@@ -193,5 +199,23 @@ extern void radix_init_pseries(void);static inline void radix_init_pseries (void ) { };#endif +static inline int get_esid_context (mm_context_t *ctx,unsigned long ea) +{ +int index = ea >>H_BITS_FIRST_CONTEXT ; + +if (index ==0 ) +return ctx->id; +return ctx->extended_id[--index]; +} + +static inline unsigned long get_user_vsid (mm_context_t *ctx, +unsigned long ea,int ssize) +{ +unsigned long context =get_esid_context (ctx, ea); + +return __get_vsid (context, ea, ssize); +} + +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */
arch/powerpc/include/asm/processor.h +7 -0
@@ -119,9 +119,16 @@ void release_thread(struct task_struct *);*/ #define TASK_SIZE_USER64 TASK_SIZE_512TB#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB +#define TASK_CONTEXT_SIZE TASK_SIZE_512TB#else #define TASK_SIZE_USER64 TASK_SIZE_64TB#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB +/* +* We don't need allocate extended context id for 4K +* page size. We limit max address on this config to +* 64TB. +*/ +#define TASK_CONTEXT_SIZE TASK_SIZE_64TB#endif /*
arch/powerpc/kernel/exceptions-64s.S +8 -4
@@ -620,8 +620,12 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) ld r10,PACA_EXSLB+EX_LR(r13) lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ mtlr r10 + /* + * Large address, check whether we have to allocate new + * contexts. + */ + beq- 8f - beq- 8f /* if bad address, make full stack frame */ bne- cr5,2f /* if unrecoverable exception, oops */
@@ -685,7 +689,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) mr r3,r12 mfspr r11,SPRN_SRR0 mfspr r12,SPRN_SRR1 - LOAD_HANDLER(r10,bad_addr_slb) + LOAD_HANDLER(r10, multi_context_slb) mtspr SPRN_SRR0,r10 ld r10,PACAKMSR(r13) mtspr SPRN_SRR1,r10
@@ -700,7 +704,7 @@ EXC_COMMON_BEGIN(unrecov_slb) bl unrecoverable_exception b 1b -EXC_COMMON_BEGIN(bad_addr_slb) +EXC_COMMON_BEGIN(multi_context_slb) EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB) RECONCILE_IRQ_STATE(r10, r11) ld r3, PACA_EXSLB+EX_DAR(r13)
@@ -710,7 +714,7 @@ EXC_COMMON_BEGIN(bad_addr_slb) std r10, _TRAP(r1) 2: bl save_nvgprs addi r3, r1, STACK_FRAME_OVERHEAD - bl slb_miss_bad_addr + bl handle_multi_context_slb_miss b ret_from_except EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
arch/powerpc/mm/copro_fault.c +1 -1
@@ -112,7 +112,7 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)return 1 ; psize =get_slice_psize (mm, ea); ssize =user_segment_size (ea); - vsid =get_vsid (mm->context.id, ea, ssize); + vsid =get_user_vsid (&mm->context, ea, ssize); vsidkey =SLB_VSID_USER ;break ;case VMALLOC_REGION_ID :
arch/powerpc/mm/hash_utils_64.c +2 -2
@@ -1261,7 +1261,7 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea, } psize =get_slice_psize (mm, ea); ssize =user_segment_size (ea); - vsid =get_vsid (mm->context.id, ea, ssize); + vsid =get_user_vsid (&mm->context, ea, ssize);break ;case VMALLOC_REGION_ID : vsid =get_kernel_vsid (ea, mmu_kernel_ssize);
@@ -1526,7 +1526,7 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,/* Get VSID */ ssize =user_segment_size (ea); - vsid =get_vsid (mm->context.id, ea, ssize); + vsid =get_user_vsid (&mm->context, ea, ssize);if (!vsid)return ;/*
arch/powerpc/mm/mmu_context_book3s64.c +16 -1
@@ -178,6 +178,19 @@ void __destroy_context(int context_id) }EXPORT_SYMBOL_GPL (__destroy_context); +void destroy_extended_context (mm_context_t *ctx) +{ +int index, context_id; + +spin_lock (&mmu_context_lock); +for (index =1 ; index < (TASK_SIZE_USER64 /TASK_CONTEXT_SIZE ); index++) { + context_id = ctx->extended_id[index -1 ]; +if (context_id) +ida_remove (&mmu_context_ida, context_id); + } +spin_unlock (&mmu_context_lock); +} +#ifdef CONFIG_PPC_64K_PAGES static void destroy_pagetable_page (struct mm_struct *mm) {
@@ -213,8 +226,10 @@ void destroy_context(struct mm_struct *mm)#endif if (radix_enabled ())WARN_ON (process_tb[mm->context.id].prtb0 !=0 ); -else +else {subpage_prot_free (mm); +destroy_extended_context (&mm->context); + }destroy_pagetable_page (mm);__destroy_context (mm->context.id); mm->context.id =MMU_NO_CONTEXT ;
arch/powerpc/mm/pgtable-hash64.c +1 -1
@@ -320,7 +320,7 @@ void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr,if (!is_kernel_addr (addr)) { ssize =user_segment_size (addr); - vsid =get_vsid (mm->context.id, addr, ssize); + vsid =get_user_vsid (&mm->context, addr, ssize);WARN_ON (vsid ==0 ); }else { vsid =get_kernel_vsid (addr, mmu_kernel_ssize);
arch/powerpc/mm/slb.c +146 -0
155 lines not on this page · raw message
arch/powerpc/mm/slb_low.S +4 -2
@@ -75,10 +75,12 @@ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA) */ _GLOBAL(slb_allocate) /* - * check for bad kernel/user address + * Check for address range for which we need to handle multi context. For + * the default context we allocate the slb via the fast path. For large + * address we branch out to C-code and look at additional context allocated. * (ea & ~REGION_MASK) >= PGTABLE_RANGE */ - rldicr. r9,r3,4,(63 - H_PGTABLE_EADDR_SIZE - 4) + rldicr. r9,r3,4,(63 - H_BITS_FIRST_CONTEXT - 4) bne- 8f srdi r9,r3,60 /* get region */
arch/powerpc/mm/tlb_hash64.c +1 -1
@@ -89,7 +89,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr,/* Build full vaddr */ if (!is_kernel_addr (addr)) { ssize =user_segment_size (addr); - vsid =get_vsid (mm->context.id, addr, ssize); + vsid =get_user_vsid (&mm->context, addr, ssize); }else { vsid =get_kernel_vsid (addr, mmu_kernel_ssize); ssize = mmu_kernel_ssize;
Signature · 1 line
2.14.3
PATCH v3 2/3 powerpc/mm/hash64: Increase the VA range
In reply to Aneesh Kumar K.VThis patch increase the max virtual address value to 4PB. With 4K page size config we continue to limit ourself to 64TB.
--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/processor.h | 9 ++++++++- arch/powerpc/mm/init_64.c | 6 ------ arch/powerpc/mm/pgtable_64.c | 5 ----- 4 files changed, 9 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +1 -1
@@ -4,7 +4,7 @@#define H_PTE_INDEX_SIZE 8#define H_PMD_INDEX_SIZE 10 -#define H_PUD_INDEX_SIZE 7 +#define H_PUD_INDEX_SIZE 10#define H_PGD_INDEX_SIZE 8/* * No of address bits below which we use the default context
arch/powerpc/include/asm/processor.h +8 -1
@@ -109,6 +109,13 @@ void release_thread(struct task_struct *);#define TASK_SIZE_64TB (0x0000400000000000UL)#define TASK_SIZE_128TB (0x0000800000000000UL)#define TASK_SIZE_512TB (0x0002000000000000UL) +#define TASK_SIZE_1PB (0x0004000000000000UL) +#define TASK_SIZE_2PB (0x0008000000000000UL) +/* +* With 52 bits in the address we can support +* upto 4PB of range. +*/ +#define TASK_SIZE_4PB (0x0010000000000000UL)/* * For now 512TB is only supported with book3s and 64K linux page size.
@@ -117,7 +124,7 @@ void release_thread(struct task_struct *);/* * Max value currently used: */ -#define TASK_SIZE_USER64 TASK_SIZE_512TB +#define TASK_SIZE_USER64 TASK_SIZE_4PB#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB#define TASK_CONTEXT_SIZE TASK_SIZE_512TB#else
arch/powerpc/mm/init_64.c +0 -6
@@ -68,12 +68,6 @@#include "mmu_decl.h" -#ifdef CONFIG_PPC_BOOK3S_64 -#if H_PGTABLE_RANGE >USER_VSID_RANGE -#warning Limited user VSID range means pagetable space is wasted -#endif -#endif /* CONFIG_PPC_BOOK3S_64 */ -phys_addr_t memstart_addr = ~0 ;EXPORT_SYMBOL_GPL (memstart_addr);phys_addr_t kernstart_addr;
arch/powerpc/mm/pgtable_64.c +0 -5
@@ -57,11 +57,6 @@#include "mmu_decl.h" -#ifdef CONFIG_PPC_BOOK3S_64 -#if TASK_SIZE_USER64 > (1UL << (ESID_BITS +SID_SHIFT )) -#error TASK_SIZE_USER64 exceeds user VSID range -#endif -#endif #ifdef CONFIG_PPC_BOOK3S_64 /*
Signature · 1 line
2.14.3
PATCH v3 3/3 powerpc/mm/hash: Don't memset pgd table if not needed
In reply to Aneesh Kumar K.VWe need to zero-out pgd table only if we share the slab cache with pud/pmd level caches. With the support of 4PB, we don't share the slab cache anymore. Instead of removing the code completely hide it within an #ifdef. We don't need to do this with any other page table level, because they all allocate table of double the size and we take of initializing the first half corrrectly during page table zap.
--- arch/powerpc/include/asm/book3s/64/pgalloc.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgalloc.h +12 -1
@@ -80,8 +80,19 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) pgd =kmem_cache_alloc (PGT_CACHE (PGD_INDEX_SIZE ),pgtable_gfp_flags (mm,GFP_KERNEL )); +/* +* With hugetlb, we don't clear the second half of the page table. +* If we share the same slab cache with the pmd or pud level table, +* we need to make sure we zero out the full table on alloc. +* With 4K we don't store slot in the second half. Hence we don't +* need to do this for 4k. +*/ +#if (H_PGD_INDEX_SIZE ==H_PUD_CACHE_INDEX ) || \ + (H_PGD_INDEX_SIZE ==H_PMD_CACHE_INDEX ) +#if defined(CONFIG_HUGETLB_PAGE ) && defined(CONFIG_PPC_64K_PAGES )memset (pgd,0 ,PGD_TABLE_SIZE ); - +#endif +#endif return pgd; }
Signature · 1 line
2.14.3