powerpc/mm/ppc64: Add 128TB support
Subsystems (2)
v3 cover powerpc/mm/ppc64: Add 128TB support
This patch series increase the effective virtual address range of applications from 64TB to 128TB. We do that by supporting a 68 bit virtual address. On platforms that can only do 65 bit virtual address we limit the max contexts to a 16bit value instead of 19.
The patch series also switch the page table layout such that we can do 512TB effective address. But we still limit the TASK_SIZE to 128TB. This was done to make sure we don't break applications that make assumption regarding the max address returned by the OS. We can switch to 128TB without a linux personality value because other architectures do 128TB as max address.
Changes from V2:
* Handle hugepage size correctly.
Aneesh Kumar K.V (10):
powerpc/mm/slice: Convert slice_mask high slice to a bitmap powerpc/mm/slice: Update the function prototype powerpc/mm/hash: Move kernel context to the starting of context range powerpc/mm/hash: Support 68 bit VA
powerpc/mm: Move copy_mm_to_paca to paca.c
powerpc/mm: Remove redundant TASK_SIZE_USER64 checks powerpc/mm/slice: Use mm task_size as max value of slice index powerpc/mm/hash: Increase VA range to 128TB powerpc/mm/slice: Move slice_mask struct definition to slice.c powerpc/mm/slice: Update slice mask printing to use bitmap printing.
arch/powerpc/include/asm/book3s/64/hash-4k.h | 2 +- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 160 ++++++++++++--------- arch/powerpc/include/asm/mmu.h | 19 ++- arch/powerpc/include/asm/mmu_context.h | 2 +- arch/powerpc/include/asm/paca.h | 18 +-- arch/powerpc/include/asm/page_64.h | 14 -- arch/powerpc/include/asm/processor.h | 22 ++- arch/powerpc/kernel/paca.c | 26 ++++ arch/powerpc/kvm/book3s_64_mmu_host.c | 10 +- arch/powerpc/mm/hash_utils_64.c | 9 +- arch/powerpc/mm/init_64.c | 4 - arch/powerpc/mm/mmu_context_book3s64.c | 96 +++++++++---- arch/powerpc/mm/pgtable_64.c | 5 - arch/powerpc/mm/slb.c | 2 +- arch/powerpc/mm/slb_low.S | 74 ++++++---- arch/powerpc/mm/slice.c | 195 +++++++++++++++----------- 17 files changed, 394 insertions(+), 266 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/10 powerpc/mm/slice: Convert slice_mask high slice to a bitmap
In followup patch we want to increase the va range which will result in us requiring high_slices to have more than 64 bits. To enable this convert high_slices to bitmap. We keep the number bits same in this patch and later change that to higher value
--- arch/powerpc/include/asm/page_64.h | 15 ++--- arch/powerpc/mm/slice.c | 110 +++++++++++++++++++++++++------------ 2 files changed, 80 insertions(+), 45 deletions(-)
arch/powerpc/include/asm/page_64.h +6 -9
@@ -98,19 +98,16 @@ extern u64 ppc64_pft_size;#define GET_LOW_SLICE_INDEX (addr) ((addr) >> SLICE_LOW_SHIFT)#define GET_HIGH_SLICE_INDEX (addr) ((addr) >> SLICE_HIGH_SHIFT) +#ifndef __ASSEMBLY__/* -* 1 bit per slice and we have one slice per 1TB -* Right now we support only 64TB. -* IF we change this we will have to change the type -* of high_slices +* One bit per slice. We have lower slices which cover 256MB segments +* upto 4G range. That gets us 16 low slices. For the rest we track slices +* in 1TB size. +* 64 below is actually SLICE_NUM_HIGH to fixup complie errros */ -#define SLICE_MASK_SIZE 8 - -#ifndef __ASSEMBLY__ -struct slice_mask {u16 low_slices; -u64 high_slices; + DECLARE_BITMAP(high_slices, 64); };struct mm_struct ;
arch/powerpc/mm/slice.c +74 -36
238 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 2/10 powerpc/mm/slice: Update the function prototype
In reply to Aneesh Kumar K.VThis avoid copying the slice_mask struct as function return value
--- arch/powerpc/mm/slice.c | 62 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 34 deletions(-)
arch/powerpc/mm/slice.c +28 -34
@@ -75,20 +75,19 @@ static void slice_print_mask(const char *label, struct slice_mask mask) {}#endif -static struct slice_mask slice_range_to_mask (unsigned long start, -unsigned long len) +static void slice_range_to_mask (unsigned long start,unsigned long len, +struct slice_mask *ret) {unsigned long end = start + len -1 ; -struct slice_mask ret; - ret.low_slices =0 ; -bitmap_zero (ret.high_slices,SLICE_NUM_HIGH ); + ret->low_slices =0 ; +bitmap_zero (ret->high_slices,SLICE_NUM_HIGH );if (start <SLICE_LOW_TOP ) {unsigned long mend =min (end,SLICE_LOW_TOP );unsigned long mstart =min (start,SLICE_LOW_TOP ); - ret.low_slices = (1u << (GET_LOW_SLICE_INDEX (mend) +1 )) + ret->low_slices = (1u << (GET_LOW_SLICE_INDEX (mend) +1 )) - (1u <<GET_LOW_SLICE_INDEX (mstart)); }
@@ -97,9 +96,8 @@ static struct slice_mask slice_range_to_mask(unsigned long start,unsigned long align_end =ALIGN (end, (1UL <<SLICE_HIGH_SHIFT ));unsigned long count =GET_HIGH_SLICE_INDEX (align_end) - start_index; -bitmap_set (ret.high_slices, start_index, count); +bitmap_set (ret->high_slices, start_index, count); } -return ret; } static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
@@ -133,53 +131,47 @@ static int slice_high_has_vma(struct mm_struct *mm, unsigned long slice)return !slice_area_is_free (mm, start, end - start); } -static struct slice_mask slice_mask_for_free (struct mm_struct *mm) +static void slice_mask_for_free (struct mm_struct *mm,struct slice_mask *ret) { -struct slice_mask ret;unsigned long i; - ret.low_slices =0 ; -bitmap_zero (ret.high_slices,SLICE_NUM_HIGH ); + ret->low_slices =0 ; +bitmap_zero (ret->high_slices,SLICE_NUM_HIGH );for (i =0 ; i <SLICE_NUM_LOW ; i++)if (!slice_low_has_vma (mm, i)) - ret.low_slices |=1u << i; + ret->low_slices |=1u << i;if (mm->task_size <=SLICE_LOW_TOP ) -return ret; +return ;for (i =0 ; i <SLICE_NUM_HIGH ; i++)if (!slice_high_has_vma (mm, i)) -__set_bit (i, ret.high_slices); - -return ret; +__set_bit (i, ret->high_slices); } -static struct slice_mask slice_mask_for_size (struct mm_struct *mm,int psize) +static void slice_mask_for_size (struct mm_struct *mm,int psize,struct slice_mask *ret) {unsigned char *hpsizes;int index, mask_index; -struct slice_mask ret;unsigned long i;u64 lpsizes; - ret.low_slices =0 ; -bitmap_zero (ret.high_slices,SLICE_NUM_HIGH ); + ret->low_slices =0 ; +bitmap_zero (ret->high_slices,SLICE_NUM_HIGH ); lpsizes = mm->context.low_slices_psize;for (i =0 ; i <SLICE_NUM_LOW ; i++)if (((lpsizes >> (i *4 )) &0xf ) == psize) - ret.low_slices |=1u << i; + ret->low_slices |=1u << i; hpsizes = mm->context.high_slices_psize;for (i =0 ; i <SLICE_NUM_HIGH ; i++) { mask_index = i &0x1 ; index = i >>1 ;if (((hpsizes[index] >> (mask_index *4 )) &0xf ) == psize) -__set_bit (i, ret.high_slices); +__set_bit (i, ret->high_slices); } - -return ret; }static int slice_check_fit (struct slice_mask mask,struct slice_mask available)
@@ -461,7 +453,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,/* First make up a "good" mask of slices that have the right size * already */ - good_mask =slice_mask_for_size (mm, psize); +slice_mask_for_size (mm, psize, &good_mask);slice_print_mask (" good_mask" , good_mask);/*
@@ -486,7 +478,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,#ifdef CONFIG_PPC_64K_PAGES /* If we support combo pages, we can allow 64k pages in 4k slices */ if (psize ==MMU_PAGE_64K ) { - compat_mask =slice_mask_for_size (mm,MMU_PAGE_4K ); +slice_mask_for_size (mm,MMU_PAGE_4K , &compat_mask);if (fixed)slice_or_mask (&good_mask, &compat_mask); }
@@ -495,7 +487,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,/* First check hint if it's valid or if we have MAP_FIXED */ if (addr !=0 || fixed) {/* Build a mask for the requested range */ - mask =slice_range_to_mask (addr, len); +slice_range_to_mask (addr, len, &mask);slice_print_mask (" mask" , mask);/* Check if we fit in the good mask. If we do, we just return,
@@ -522,7 +514,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,/* We don't fit in the good mask, check what other slices are * empty and thus can be converted */ - potential_mask =slice_mask_for_free (mm); +slice_mask_for_free (mm, &potential_mask);slice_or_mask (&potential_mask, &good_mask);slice_print_mask (" potential" , potential_mask);
@@ -565,7 +557,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,if (addr == -ENOMEM )return -ENOMEM ; - mask =slice_range_to_mask (addr, len); +slice_range_to_mask (addr, len, &mask);slice_dbg (" found potential area at 0x%lx\n" , addr);slice_print_mask (" mask" , mask);
@@ -697,9 +689,11 @@ void slice_set_user_psize(struct mm_struct *mm, unsigned int psize)void slice_set_range_psize (struct mm_struct *mm,unsigned long start,unsigned long len,unsigned int psize) { -struct slice_mask mask =slice_range_to_mask (start, len); +struct slice_mask mask;VM_BUG_ON (radix_enabled ()); + +slice_range_to_mask (start, len, &mask);slice_convert (mm, mask, psize); }
@@ -732,13 +726,13 @@ int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,if (radix_enabled ())return 0 ; - mask =slice_range_to_mask (addr, len); - available =slice_mask_for_size (mm, psize); +slice_range_to_mask (addr, len, &mask); +slice_mask_for_size (mm, psize, &available);#ifdef CONFIG_PPC_64K_PAGES /* We need to account for 4k slices too */ if (psize ==MMU_PAGE_64K ) {struct slice_mask compat_mask; - compat_mask =slice_mask_for_size (mm,MMU_PAGE_4K ); +slice_mask_for_size (mm,MMU_PAGE_4K , &compat_mask);slice_or_mask (&available, &compat_mask); }#endif
Signature · 1 line
2.7.4
PATCH v3 3/10 powerpc/mm/hash: Move kernel context to the starting of context range
In reply to Aneesh Kumar K.VWith current kernel, we use the top 4 context for the kernel. Kernel VSIDs are built using these top context values and effective segemnt ID. In the following patches, we want to increase the max effective address to 512TB. We achieve that by increasing the effective segments IDs there by increasing virtual address range.
We will be switching to a 68bit virtual address in the following patch. But for platforms like p4 and p5, which only support a 65 bit va, we want to limit the virtual addrress to a 65 bit value. We do that by limiting the context bits to 16 instead of 19. That means we will have different max context values on different platforms.
To make this simpler. we move the kernel context to the starting of the range.
--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 39 ++++++------ arch/powerpc/include/asm/mmu_context.h | 2 +- arch/powerpc/kvm/book3s_64_mmu_host.c | 2 +- arch/powerpc/mm/hash_utils_64.c | 5 -- arch/powerpc/mm/mmu_context_book3s64.c | 88 ++++++++++++++++++--------- arch/powerpc/mm/slb_low.S | 20 ++---- 6 files changed, 84 insertions(+), 72 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu-hash.h +18 -21
@@ -493,10 +493,10 @@ extern void slb_set_size(u16 size);* For user processes max context id is limited to ((1ul << 19) - 5) * for kernel space, we use the top 4 context ids to map address as below * NOTE: each context only support 64TB now. -* 0x7fffc - [ 0xc000000000000000 - 0xc0003fffffffffff ] -* 0x7fffd - [ 0xd000000000000000 - 0xd0003fffffffffff ] -* 0x7fffe - [ 0xe000000000000000 - 0xe0003fffffffffff ] -* 0x7ffff - [ 0xf000000000000000 - 0xf0003fffffffffff ] +* 0x00000 - [ 0xc000000000000000 - 0xc0003fffffffffff ] +* 0x00001 - [ 0xd000000000000000 - 0xd0003fffffffffff ] +* 0x00002 - [ 0xe000000000000000 - 0xe0003fffffffffff ] +* 0x00003 - [ 0xf000000000000000 - 0xf0003fffffffffff ] * * The proto-VSIDs are then scrambled into real VSIDs with the * multiplicative hash:
@@ -510,15 +510,9 @@ extern void slb_set_size(u16 size);* robust scattering in the hash table (at least based on some initial * results). * -* We also consider VSID 0 special. We use VSID 0 for slb entries mapping -* bad address. This enables us to consolidate bad address handling in -* hash_page. -* * We also need to avoid the last segment of the last context, because that * would give a protovsid of 0x1fffffffff. That will result in a VSID 0 -* because of the modulo operation in vsid scramble. But the vmemmap -* (which is what uses region 0xf) will never be close to 64TB in size -* (it's 56 bytes per page of system memory). +* because of the modulo operation in vsid scramble. */ #define CONTEXT_BITS 19
@@ -530,12 +524,15 @@ extern void slb_set_size(u16 size);/* * 256MB segment * The proto-VSID space has 2^(CONTEX_BITS + ESID_BITS) - 1 segments -* available for user + kernel mapping. The top 4 contexts are used for +* available for user + kernel mapping. The bottom 4 contexts are used for * kernel mapping. Each segment contains 2^28 bytes. Each -* context maps 2^46 bytes (64TB) so we can support 2^19-1 contexts -* (19 == 37 + 28 - 46). +* context maps 2^46 bytes (64TB). +* +* We also need to avoid the last segment of the last context, because that +* would give a protovsid of 0x1fffffffff. That will result in a VSID 0 +* because of the modulo operation in vsid scramble. */ -#define MAX_USER_CONTEXT ((ASM_CONST(1) << CONTEXT_BITS) - 5) +#define MAX_USER_CONTEXT ((ASM_CONST(1) << CONTEXT_BITS) - 2)/* * This should be computed such that protovosid * vsid_mulitplier
@@ -671,19 +668,19 @@ static inline unsigned long get_vsid(unsigned long context, unsigned long ea,* This is only valid for addresses >= PAGE_OFFSET * * For kernel space, we use the top 4 context ids to map address as below -* 0x7fffc - [ 0xc000000000000000 - 0xc0003fffffffffff ] -* 0x7fffd - [ 0xd000000000000000 - 0xd0003fffffffffff ] -* 0x7fffe - [ 0xe000000000000000 - 0xe0003fffffffffff ] -* 0x7ffff - [ 0xf000000000000000 - 0xf0003fffffffffff ] +* 0x00000 - [ 0xc000000000000000 - 0xc0003fffffffffff ] +* 0x00001 - [ 0xd000000000000000 - 0xd0003fffffffffff ] +* 0x00002 - [ 0xe000000000000000 - 0xe0003fffffffffff ] +* 0x00003 - [ 0xf000000000000000 - 0xf0003fffffffffff ] */ static inline unsigned long get_kernel_vsid (unsigned long ea,int ssize) {unsigned long context;/* -* kernel take the top 4 context from the available range +* kernel take the first 4 context from the available range */ - context = (MAX_USER_CONTEXT ) + ((ea >>60 ) -0xc ) +1 ; + context = (ea >>60 ) -0xc ;return get_vsid (context, ea, ssize); }
arch/powerpc/include/asm/mmu_context.h +1 -1
@@ -51,7 +51,7 @@ static inline void switch_mmu_context(struct mm_struct *prev, return switch_slb(tsk, next); } -extern int __init_new_context (void ); +extern int hash__get_new_context (void );extern void __destroy_context (int context_id);static inline void mmu_context_init (void ) { }#else
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -1
@@ -390,7 +390,7 @@ int kvmppc_mmu_init(struct kvm_vcpu *vcpu)struct kvmppc_vcpu_book3s *vcpu3s =to_book3s (vcpu);int err; - err =__init_new_context (); + err =hash__get_new_context ();if (err <0 )return -1 ; vcpu3s->context_id[0 ] = err;
arch/powerpc/mm/hash_utils_64.c +0 -5
@@ -255,11 +255,6 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,unsigned long vpn =hpt_vpn (vaddr, vsid, ssize);unsigned long tprot = prot; -/* -* If we hit a bad address return error. -*/ -if (!vsid) -return -1 ;/* Make kernel text executable */ if (overlaps_kernel_text (vaddr, vaddr + step)) tprot &= ~HPTE_R_N ;
arch/powerpc/mm/mmu_context_book3s64.c +59 -29
127 lines not on this page · raw message
arch/powerpc/mm/slb_low.S +5 -15
@@ -45,13 +45,6 @@ _GLOBAL(slb_allocate_realmode) /* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */ blt cr7,0f /* user or kernel? */ - /* kernel address: proto-VSID = ESID */ - /* WARNING - MAGIC: we don't use the VSID 0xfffffffff, but - * this code will generate the protoVSID 0xfffffffff for the - * top segment. That's ok, the scramble below will translate - * it to VSID 0, which is reserved as a bad VSID - one which - * will never have any pages in it. */ - /* Check if hitting the linear mapping or some other kernel space */ bne cr7,1f
@@ -63,12 +56,10 @@ _GLOBAL(slb_allocate_realmode) slb_miss_kernel_load_linear: li r11,0 /* - * context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1 + * context = (ea >> 60) - 0xc * r9 = region id. */ - addis r9,r9,(MAX_USER_CONTEXT - 0xc + 1)@ha - addi r9,r9,(MAX_USER_CONTEXT - 0xc + 1)@l - + subi r9,r9,0xc BEGIN_FTR_SECTION b slb_finish_load
@@ -77,9 +68,9 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT) 1: #ifdef CONFIG_SPARSEMEM_VMEMMAP - /* Check virtual memmap region. To be patches at kernel boot */ cmpldi cr0,r9,0xf bne 1f +/* Check virtual memmap region. To be patched at kernel boot */ .globl slb_miss_kernel_load_vmemmap slb_miss_kernel_load_vmemmap: li r11,0
@@ -102,11 +93,10 @@ slb_miss_kernel_load_io: li r11,0 6: /* - * context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1 + * context = (ea >> 60) - 0xc * r9 = region id. */ - addis r9,r9,(MAX_USER_CONTEXT - 0xc + 1)@ha - addi r9,r9,(MAX_USER_CONTEXT - 0xc + 1)@l + subi r9,r9,0xc BEGIN_FTR_SECTION b slb_finish_load
Signature · 1 line
2.7.4
PATCH v3 4/10 powerpc/mm/hash: Support 68 bit VA
In reply to Aneesh Kumar K.VInorder to support large effective address range (512TB), we want to increase the virtual address bits to 68. But we do have platforms like p4 and p5 that can only do 65 bit VA. We support those platforms by limiting context bits on them to 16.
The protovsid -> vsid conversion is verified to work with both 65 and 68 bit va values. I also documented the restrictions in a table format as part of code comments.
--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 123 ++++++++++++++++---------- arch/powerpc/include/asm/mmu.h | 19 ++-- arch/powerpc/kvm/book3s_64_mmu_host.c | 8 +- arch/powerpc/mm/mmu_context_book3s64.c | 8 +- arch/powerpc/mm/slb_low.S | 54 +++++++++-- 5 files changed, 150 insertions(+), 62 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu-hash.h +78 -45
@@ -39,6 +39,7 @@/* Bits in the SLB VSID word */ #define SLB_VSID_SHIFT 12 +#define SLB_VSID_SHIFT_256M 12#define SLB_VSID_SHIFT_1T 24#define SLB_VSID_SSIZE_SHIFT 62#define SLB_VSID_B ASM_CONST(0xc000000000000000)
@@ -515,9 +516,19 @@ extern void slb_set_size(u16 size);* because of the modulo operation in vsid scramble. */ +/* +* Max Va bits we support as of now is 68 bits. We want 19 bit +* context ID. +* Restrictions: +* GPU has restrictions of not able to access beyond 128TB +* (47 bit effective address). We also cannot do more than 20bit PID. +* For p4 and p5 which can only do 65 bit VA, we restrict our CONTEXT_BITS +* to 16 bits (ie, we can only have 2^16 pids at the same time). +*/ +#define VA_BITS 68#define CONTEXT_BITS 19 -#define ESID_BITS 18 -#define ESID_BITS_1T 6 +#define ESID_BITS (VA_BITS - (SID_SHIFT + CONTEXT_BITS)) +#define ESID_BITS_1T (VA_BITS - (SID_SHIFT_1T + CONTEXT_BITS))#define ESID_BITS_MASK ((1 << ESID_BITS) - 1)#define ESID_BITS_1T_MASK ((1 << ESID_BITS_1T) - 1)
@@ -526,62 +537,54 @@ extern void slb_set_size(u16 size);* The proto-VSID space has 2^(CONTEX_BITS + ESID_BITS) - 1 segments * available for user + kernel mapping. The bottom 4 contexts are used for * kernel mapping. Each segment contains 2^28 bytes. Each -* context maps 2^46 bytes (64TB). +* context maps 2^49 bytes (512TB). * * We also need to avoid the last segment of the last context, because that * would give a protovsid of 0x1fffffffff. That will result in a VSID 0 * because of the modulo operation in vsid scramble. */ #define MAX_USER_CONTEXT ((ASM_CONST(1) << CONTEXT_BITS) - 2) +/* +* For platforms that support on 65bit VA we limit the context bits +*/ +#define MAX_USER_CONTEXT_65BIT_VA ((ASM_CONST(1) << (65 - (SID_SHIFT + ESID_BITS))) - 2)/* * This should be computed such that protovosid * vsid_mulitplier * doesn't overflow 64 bits. It should also be co-prime to vsid_modulus +* We also need to make sure that number of bits in divisor is less +* than twice the number of protovsid bits for our modulus optmization to work. +* The below table shows the current values used. +* +* |-------+------------+----------------+------------+--------------| +* | | Prime Bits | VSID_BITS_65VA | Total Bits | 2* VSID_BITS | +* |-------+------------+----------------+------------+--------------| +* | 1T | 24 | 25 | 49 | 50 | +* |-------+------------+----------------+------------+--------------| +* | 256MB | 24 | 37 | 61 | 74 | +* |-------+------------+----------------+------------+--------------| +* +* |-------+------------+----------------+------------+--------------| +* | | Prime Bits | VSID_BITS_68VA | Total Bits | 2* VSID_BITS | +* |-------+------------+----------------+------------+--------------| +* | 1T | 24 | 28 | 52 | 56 | +* |-------+------------+----------------+------------+--------------| +* | 256MB | 24 | 40 | 64 | 80 | +* |-------+------------+----------------+------------+--------------| +* */ #define VSID_MULTIPLIER_256M ASM_CONST(12538073)/* 24-bit prime */ -#define VSID_BITS_256M (CONTEXT_BITS + ESID_BITS) +#define VSID_BITS_256M (VA_BITS - SID_SHIFT)#define VSID_MODULUS_256M ((1UL<<VSID_BITS_256M)-1) +#define VSID_BITS_65_256M (65 - SID_SHIFT)#define VSID_MULTIPLIER_1T ASM_CONST(12538073)/* 24-bit prime */ -#define VSID_BITS_1T (CONTEXT_BITS + ESID_BITS_1T) +#define VSID_BITS_1T (VA_BITS - SID_SHIFT_1T)#define VSID_MODULUS_1T ((1UL<<VSID_BITS_1T)-1) - +#define VSID_BITS_65_1T (65 - SID_SHIFT_1T)#define USER_VSID_RANGE (1UL << (ESID_BITS + SID_SHIFT)) -/* -* This macro generates asm code to compute the VSID scramble -* function. Used in slb_allocate() and do_stab_bolted. The function -* computed is: (protovsid*VSID_MULTIPLIER) % VSID_MODULUS -* -* rt = register containing the proto-VSID and into which the -* VSID will be stored -* rx = scratch register (clobbered) -* -* - rt and rx must be different registers -* - The answer will end up in the low VSID_BITS bits of rt. The higher -* bits may contain other garbage, so you may need to mask the -* result. -*/ -#define ASM_VSID_SCRAMBLE(rt, rx, size) \ - lis rx,VSID_MULTIPLIER_##size@h; \ - ori rx,rx,VSID_MULTIPLIER_##size@l; \ - mulld rt,rt,rx; /* rt = rt * MULTIPLIER */ \ - \ - srdi rx,rt,VSID_BITS_##size; \ - clrldi rt,rt,(64-VSID_BITS_##size); \ - add rt,rt,rx;/* add high and low bits */ \ -/* NOTE: explanation based on VSID_BITS_##size = 36 \ -* Now, r3 == VSID (mod 2^36-1), and lies between 0 and \ -* 2^36-1+2^28-1. That in particular means that if r3 >= \ -* 2^36-1, then r3+1 has the 2^36 bit set. So, if r3+1 has \ -* the bit clear, r3 already has the answer we want, if it \ -* doesn't, the answer is the low 36 bits of r3+1. So in all \ -* cases the answer is the low 36 bits of (r3 + ((r3+1) >> 36))*/ \ - addi rx,rt,1; \ - srdi rx,rx,VSID_BITS_##size; /* extract 2^VSID_BITS bit */ \ - add rt,rt,rx -/* 4 bits per slice and we have one slice per 1TB */ #define SLICE_ARRAY_SIZE (H_PGTABLE_RANGE >> 41)
@@ -629,7 +632,7 @@ static inline void subpage_prot_init_new_context(struct mm_struct *mm) { }#define vsid_scramble (protovsid, size) \ ((((protovsid) * VSID_MULTIPLIER_##size) % VSID_MODULUS_##size)) -#else /* 1 */ +/* simplified form avoiding mod operation */ #define vsid_scramble (protovsid, size) \ ({ \ unsigned long x; \
@@ -637,6 +640,21 @@ static inline void subpage_prot_init_new_context(struct mm_struct *mm) { } x = (x >> VSID_BITS_##size) + (x & VSID_MODULUS_##size); \ (x + ((x+1) >> VSID_BITS_##size)) & VSID_MODULUS_##size; \ }) + +#else /* 1 */ +static inline unsigned long vsid_scramble (unsigned long protovsid, +unsigned long vsid_multiplier,int vsid_bits) +{ +unsigned long vsid; +unsigned long vsid_modulus = ((1UL << vsid_bits) -1 ); +/* +* We have same multipler for both 256 and 1T segements now +*/ + vsid = protovsid * vsid_multiplier; + vsid = (vsid >> vsid_bits) + (vsid & vsid_modulus); +return (vsid + ((vsid +1 ) >> vsid_bits)) & vsid_modulus; +} +#endif /* 1 */ /* Returns the segment size indicator for a user address */
@@ -651,17 +669,32 @@ static inline int user_segment_size(unsigned long addr)static inline unsigned long get_vsid (unsigned long context,unsigned long ea,int ssize) { +unsigned long va_bits =VA_BITS ; +unsigned long vsid_bits; +unsigned long protovsid; +/* * Bad address. We return VSID 0 for that */ if ((ea & ~REGION_MASK ) >=H_PGTABLE_RANGE )return 0 ; -if (ssize ==MMU_SEGSIZE_256M ) -return vsid_scramble ((context <<ESID_BITS ) - | ((ea >> SID_SHIFT) & ESID_BITS_MASK), 256M); -return vsid_scramble ((context <<ESID_BITS_1T ) - | ((ea >> SID_SHIFT_1T) & ESID_BITS_1T_MASK), 1T); +if (!mmu_has_feature (MMU_FTR_68_BIT_VA )) + va_bits =65 ; + +if (ssize ==MMU_SEGSIZE_256M ) { + vsid_bits = va_bits -SID_SHIFT ; + protovsid = (context <<ESID_BITS ) | + ((ea >>SID_SHIFT ) &ESID_BITS_MASK ); +return vsid_scramble (protovsid, +VSID_MULTIPLIER_256M , vsid_bits); + } +/* 1T segment */ + vsid_bits = va_bits -SID_SHIFT_1T ; + protovsid = (context <<ESID_BITS_1T ) | + ((ea >>SID_SHIFT_1T ) &ESID_BITS_1T_MASK ); +return vsid_scramble (protovsid, +VSID_MULTIPLIER_1T , vsid_bits); }/*
arch/powerpc/include/asm/mmu.h +13 -6
@@ -29,6 +29,10 @@*/ /* +* Support for 68 bit VA space. We added that from ISA 2.05 +*/ +#define MMU_FTR_68_BIT_VA ASM_CONST(0x00002000) +/* * Kernel read only support. * We added the ppp value 0b110 in ISA 2.04. */
@@ -109,10 +113,10 @@#define MMU_FTRS_POWER4 MMU_FTRS_DEFAULT_HPTE_ARCH_V2#define MMU_FTRS_PPC970 MMU_FTRS_POWER4 | MMU_FTR_TLBIE_CROP_VA#define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE -#define MMU_FTRS_POWER6 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER7 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER8 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER9 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO +#define MMU_FTRS_POWER6 MMU_FTRS_POWER5 | MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA +#define MMU_FTRS_POWER7 MMU_FTRS_POWER6 +#define MMU_FTRS_POWER8 MMU_FTRS_POWER6 +#define MMU_FTRS_POWER9 MMU_FTRS_POWER6#define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \ MMU_FTR_CI_LARGE_PAGE#define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
@@ -136,7 +140,7 @@ enum { MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE | MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA | - MMU_FTR_KERNEL_RO | + MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA |#ifdef CONFIG_PPC_RADIX_MMU MMU_FTR_TYPE_RADIX |#endif
@@ -290,7 +294,10 @@ static inline bool early_radix_enabled(void)#define MMU_PAGE_16G 14#define MMU_PAGE_64G 15 -/* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 */ +/* +* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 +* Also we need to change he type of mm_context.low/high_slices_psize. +*/ #define MMU_PAGE_COUNT 16#ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kvm/book3s_64_mmu_host.c +7 -1
@@ -229,6 +229,7 @@ void kvmppc_mmu_unmap_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)static struct kvmppc_sid_map *create_sid_map (struct kvm_vcpu *vcpu,u64 gvsid) { +unsigned long vsid_bits =VSID_BITS_65_256M ;struct kvmppc_sid_map *map;struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);u16 sid_map_mask;
@@ -257,7 +258,12 @@ static struct kvmppc_sid_map *create_sid_map(struct kvm_vcpu *vcpu, u64 gvsid)kvmppc_mmu_pte_flush (vcpu,0 ,0 );kvmppc_mmu_flush_segments (vcpu); } - map->host_vsid = vsid_scramble(vcpu_book3s->proto_vsid_next++, 256M); + +if (mmu_has_feature (MMU_FTR_68_BIT_VA )) + vsid_bits =VSID_BITS_256M ; + + map->host_vsid =vsid_scramble (vcpu_book3s->proto_vsid_next++, +VSID_MULTIPLIER_256M , vsid_bits); map->guest_vsid = gvsid; map->valid = true;
arch/powerpc/mm/mmu_context_book3s64.c +7 -1
@@ -33,6 +33,12 @@ static DEFINE_IDA(mmu_context_ida);int hash__get_new_context (void ) {int index, err; +unsigned long max_user_context; + +if (mmu_has_feature (MMU_FTR_68_BIT_VA )) + max_user_context =MAX_USER_CONTEXT ; +else + max_user_context =MAX_USER_CONTEXT_65BIT_VA ; again:if (!ida_pre_get (&mmu_context_ida,GFP_KERNEL ))
@@ -50,7 +56,7 @@ int hash__get_new_context(void)else if (err)return err; -if (index >MAX_USER_CONTEXT ) { +if (index > max_user_context) {spin_lock (&mmu_context_lock);ida_remove (&mmu_context_ida, index);spin_unlock (&mmu_context_lock);
arch/powerpc/mm/slb_low.S +45 -9
76 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 5/10 powerpc/mm: Move copy_mm_to_paca to paca.c
In reply to Aneesh Kumar K.VWe will be updating this later to use struct mm_struct. Move this so that function finds the definition of struct mm_struct;
--- arch/powerpc/include/asm/paca.h | 18 +----------------- arch/powerpc/kernel/paca.c | 19 +++++++++++++++++++ arch/powerpc/mm/hash_utils_64.c | 4 ++-- arch/powerpc/mm/slb.c | 2 +- arch/powerpc/mm/slice.c | 2 +- 5 files changed, 24 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/paca.h +1 -17
@@ -207,23 +207,7 @@ struct paca_struct {#endif }; -#ifdef CONFIG_PPC_BOOK3S -static inline void copy_mm_to_paca (mm_context_t *context) -{ -get_paca ()->mm_ctx_id = context->id; -#ifdef CONFIG_PPC_MM_SLICES -get_paca ()->mm_ctx_low_slices_psize = context->low_slices_psize; -memcpy (&get_paca ()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); -#else -get_paca ()->mm_ctx_user_psize = context->user_psize; -get_paca ()->mm_ctx_sllp = context->sllp; -#endif -} -#else -static inline void copy_mm_to_paca (mm_context_t *context){} -#endif - +extern void copy_mm_to_paca (struct mm_struct *mm);extern struct paca_struct *paca;extern void initialise_paca (struct paca_struct *new_paca,int cpu);extern void setup_paca (struct paca_struct *new_paca);
arch/powerpc/kernel/paca.c +19 -0
@@ -244,3 +244,22 @@ void __init free_unused_pacas(void)free_lppacas (); } + +void copy_mm_to_paca (struct mm_struct *mm) +{ +#ifdef CONFIG_PPC_BOOK3S +mm_context_t *context = &mm->context; + +get_paca ()->mm_ctx_id = context->id; +#ifdef CONFIG_PPC_MM_SLICES +get_paca ()->mm_ctx_low_slices_psize = context->low_slices_psize; +memcpy (&get_paca ()->mm_ctx_high_slices_psize, + &context->high_slices_psize,SLICE_ARRAY_SIZE ); +#else /* CONFIG_PPC_MM_SLICES */ +get_paca ()->mm_ctx_user_psize = context->user_psize; +get_paca ()->mm_ctx_sllp = context->sllp; +#endif +#else /* CONFIG_PPC_BOOK3S */ +return ; +#endif +}
arch/powerpc/mm/hash_utils_64.c +2 -2
@@ -1084,7 +1084,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)copro_flush_all_slbs (mm);if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) { -copy_mm_to_paca (&mm->context); +copy_mm_to_paca (mm);slb_flush_and_rebolt (); } }
@@ -1156,7 +1156,7 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm, {if (user_region) {if (psize !=get_paca_psize (ea)) { -copy_mm_to_paca (&mm->context); +copy_mm_to_paca (mm);slb_flush_and_rebolt (); } } else if (get_paca()->vmalloc_sllp !=
arch/powerpc/mm/slb.c +1 -1
@@ -227,7 +227,7 @@ void switch_slb(struct task_struct *tsk, struct mm_struct *mm) asmvolatile ("slbie %0" : :"r" (slbie_data));get_paca ()->slb_cache_ptr =0 ; -copy_mm_to_paca (&mm->context); +copy_mm_to_paca (mm);/* * preload some userspace segments into the SLB.
arch/powerpc/mm/slice.c +1 -1
@@ -193,7 +193,7 @@ static void slice_flush_segments(void *parm)if (mm != current->active_mm)return ; -copy_mm_to_paca (¤t->active_mm->context); +copy_mm_to_paca (current->active_mm);local_irq_save (flags);slb_flush_and_rebolt ();
Signature · 1 line
2.7.4
PATCH v3 6/10 powerpc/mm: Remove redundant TASK_SIZE_USER64 checks
In reply to Aneesh Kumar K.VThe check against VSID range is implied when we check task size against hash and radix pgtable range[1], because we make sure page table range cannot exceed vsid range.
[1] BUILD_BUG_ON(TASK_SIZE_USER64 > H_PGTABLE_RANGE); BUILD_BUG_ON(TASK_SIZE_USER64 > RADIX_PGTABLE_RANGE);
The check for smaller task size is also removed here, because the follow up patch will support a tasksize smaller than pgtable range.
--- arch/powerpc/mm/init_64.c | 4 ---- arch/powerpc/mm/pgtable_64.c | 5 ----- 2 files changed, 9 deletions(-)
arch/powerpc/mm/init_64.c +0 -4
@@ -69,10 +69,6 @@#if H_PGTABLE_RANGE >USER_VSID_RANGE #warning Limited user VSID range means pagetable space is wasted#endif - -#if (TASK_SIZE_USER64 <H_PGTABLE_RANGE ) && (TASK_SIZE_USER64 <USER_VSID_RANGE ) -#warning TASK_SIZE is smaller than it needs to be. -#endif #endif /* CONFIG_PPC_STD_MMU_64 */ phys_addr_t memstart_addr = ~0 ;
arch/powerpc/mm/pgtable_64.c +0 -5
@@ -55,11 +55,6 @@#include "mmu_decl.h" -#ifdef CONFIG_PPC_STD_MMU_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.7.4
PATCH v3 7/10 powerpc/mm/slice: Use mm task_size as max value of slice index
In reply to Aneesh Kumar K.VIn the followup patch, we will increase the slice array sice to handle 512TB range, but will limit the task size to 128TB. Avoid doing uncessary computation and avoid doing slice mask related operation above task_size.
--- arch/powerpc/mm/slice.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
arch/powerpc/mm/slice.c +12 -10
@@ -145,7 +145,7 @@ static void slice_mask_for_free(struct mm_struct *mm, struct slice_mask *ret)if (mm->task_size <=SLICE_LOW_TOP )return ; -for (i =0 ; i <SLICE_NUM_HIGH ; i++) +for (i =0 ; i <GET_HIGH_SLICE_INDEX (mm->task_size); i++)if (!slice_high_has_vma (mm, i))__set_bit (i, ret->high_slices); }
@@ -166,7 +166,7 @@ static void slice_mask_for_size(struct mm_struct *mm, int psize, struct slice_ma ret->low_slices |=1u << i; hpsizes = mm->context.high_slices_psize; -for (i =0 ; i <SLICE_NUM_HIGH ; i++) { +for (i =0 ; i <GET_HIGH_SLICE_INDEX (mm->task_size); i++) { mask_index = i &0x1 ; index = i >>1 ;if (((hpsizes[index] >> (mask_index *4 )) &0xf ) == psize)
@@ -174,15 +174,17 @@ static void slice_mask_for_size(struct mm_struct *mm, int psize, struct slice_ma } } -static int slice_check_fit (struct slice_mask mask,struct slice_mask available) +static int slice_check_fit (struct mm_struct *mm, +struct slice_mask mask,struct slice_mask available) {DECLARE_BITMAP (result,SLICE_NUM_HIGH ); +unsigned long slice_count =GET_HIGH_SLICE_INDEX (mm->task_size);bitmap_and (result, mask.high_slices, - available.high_slices,SLICE_NUM_HIGH ); + available.high_slices, slice_count);return (mask.low_slices & available.low_slices) == mask.low_slices && -bitmap_equal (result, mask.high_slices,SLICE_NUM_HIGH ); +bitmap_equal (result, mask.high_slices, slice_count); }static void slice_flush_segments (void *parm)
@@ -226,7 +228,7 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psiz mm->context.low_slices_psize = lpsizes; hpsizes = mm->context.high_slices_psize; -for (i =0 ; i <SLICE_NUM_HIGH ; i++) { +for (i =0 ; i <GET_HIGH_SLICE_INDEX (mm->task_size); i++) { mask_index = i &0x1 ; index = i >>1 ;if (test_bit (i, mask.high_slices))
@@ -493,7 +495,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,/* Check if we fit in the good mask. If we do, we just return, * nothing else to do */ -if (slice_check_fit (mask, good_mask)) { +if (slice_check_fit (mm, mask, good_mask)) {slice_dbg (" fits good !\n" );return addr; }
@@ -518,7 +520,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,slice_or_mask (&potential_mask, &good_mask);slice_print_mask (" potential" , potential_mask); -if ((addr !=0 || fixed) &&slice_check_fit (mask, potential_mask)) { +if ((addr !=0 || fixed) &&slice_check_fit (mm, mask, potential_mask)) {slice_dbg (" fits potential !\n" ); goto convert; }
@@ -666,7 +668,7 @@ void slice_set_user_psize(struct mm_struct *mm, unsigned int psize) mm->context.low_slices_psize = lpsizes; hpsizes = mm->context.high_slices_psize; -for (i =0 ; i <SLICE_NUM_HIGH ; i++) { +for (i =0 ; i <GET_HIGH_SLICE_INDEX (mm->task_size); i++) { mask_index = i &0x1 ; index = i >>1 ;if (((hpsizes[index] >> (mask_index *4 )) &0xf ) == old_psize)
@@ -743,6 +745,6 @@ int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,slice_print_mask (" mask" , mask);slice_print_mask (" available" , available);#endif - return !slice_check_fit(mask, available); + return !slice_check_fit(mm, mask, available); }#endif
Signature · 1 line
2.7.4
PATCH v3 8/10 powerpc/mm/hash: Increase VA range to 128TB
In reply to Aneesh Kumar K.VWe update the hash linux page table layout such that we can support 512TB. But we limit the TASK_SIZE to 128TB. We can switch to 128TB by default without conditional because that is the max virtual address supported by other architectures. We will later add a mechanism to on-demand increase the application's effective address range to 512TB.
Having the page table layout changed to accommodate 512TB makes testing large memory configuration easier with less code changes to kernel
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 2 +- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/page_64.h | 2 +- arch/powerpc/include/asm/processor.h | 22 ++++++++++++++++++---- arch/powerpc/kernel/paca.c | 9 ++++++++- arch/powerpc/mm/slice.c | 2 ++ 6 files changed, 31 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +1 -1
@@ -8,7 +8,7 @@#define H_PTE_INDEX_SIZE 9#define H_PMD_INDEX_SIZE 7#define H_PUD_INDEX_SIZE 9 -#define H_PGD_INDEX_SIZE 9 +#define H_PGD_INDEX_SIZE 12#ifndef __ASSEMBLY__#define H_PTE_TABLE_SIZE (sizeof(pte_t) << H_PTE_INDEX_SIZE)
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 5#define H_PUD_INDEX_SIZE 5 -#define H_PGD_INDEX_SIZE 12 +#define H_PGD_INDEX_SIZE 15/* * 64k aligned address free up few of the lower bits of RPN for us
arch/powerpc/include/asm/page_64.h +1 -1
@@ -107,7 +107,7 @@ extern u64 ppc64_pft_size;*/ struct slice_mask {u16 low_slices; - DECLARE_BITMAP(high_slices, 64); + DECLARE_BITMAP(high_slices, 512); };struct mm_struct ;
arch/powerpc/include/asm/processor.h +18 -4
@@ -102,11 +102,25 @@ void release_thread(struct task_struct *);#endif #ifdef CONFIG_PPC64 -/* 64-bit user address space is 46-bits (64TB user VM) */ -#define TASK_SIZE_USER64 (0x0000400000000000UL) +/* +* 64-bit user address space can have multiple limits +* For now supported values are: +*/ +#define TASK_SIZE_64TB (0x0000400000000000UL) +#define TASK_SIZE_128TB (0x0000800000000000UL) +#define TASK_SIZE_512TB (0x0002000000000000UL) -/* -* 32-bit user address space is 4GB - 1 page +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* MAx value currently used: +*/ +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif + +/* +* 32-bit user address space is 4GB - 1 page * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT */ #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
arch/powerpc/kernel/paca.c +8 -1
@@ -253,8 +253,15 @@ void copy_mm_to_paca(struct mm_struct *mm)get_paca ()->mm_ctx_id = context->id;#ifdef CONFIG_PPC_MM_SLICES get_paca ()->mm_ctx_low_slices_psize = context->low_slices_psize; +/* +* We support upto 128TB for now. Hence copy only 128/2 bytes. +* Later when we support tasks with different max effective +* address, we can optimize this based on mm->task_size. +*/ +BUILD_BUG_ON (TASK_SIZE_USER64 !=TASK_SIZE_128TB );memcpy (&get_paca ()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); + &context->high_slices_psize,TASK_SIZE_128TB >>41 ); +#else /* CONFIG_PPC_MM_SLICES */ get_paca ()->mm_ctx_user_psize = context->user_psize;get_paca ()->mm_ctx_sllp = context->sllp;
arch/powerpc/mm/slice.c +2 -0
@@ -412,6 +412,8 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,struct mm_struct *mm = current->mm;unsigned long newaddr; +/* Make sure high_slices bitmap size is same as we expected */ +BUILD_BUG_ON (512 !=SLICE_NUM_HIGH );/* * init different masks */
Signature · 1 line
2.7.4
PATCH v3 9/10 powerpc/mm/slice: Move slice_mask struct definition to slice.c
In reply to Aneesh Kumar K.VThis structure definition need not be in a header since this is used only by slice.c file. So move it to slice.c. This also allow us to use SLICE_NUM_HIGH instead of 512 and also helps in getting rid of one BUILD_BUG_ON().
I also switch the low_slices type to u64 from u16. This doesn't have an impact on size of struct due to padding added with u16 type. This helps in using bitmap printing function for printing slice mask.
--- arch/powerpc/include/asm/page_64.h | 11 ----------- arch/powerpc/mm/slice.c | 13 ++++++++++--- 2 files changed, 10 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/page_64.h +0 -11
@@ -99,17 +99,6 @@ extern u64 ppc64_pft_size;#define GET_HIGH_SLICE_INDEX (addr) ((addr) >> SLICE_HIGH_SHIFT)#ifndef __ASSEMBLY__ -/* -* One bit per slice. We have lower slices which cover 256MB segments -* upto 4G range. That gets us 16 low slices. For the rest we track slices -* in 1TB size. -* 64 below is actually SLICE_NUM_HIGH to fixup complie errros -*/ -struct slice_mask { -u16 low_slices; - DECLARE_BITMAP(high_slices, 512); -}; -struct mm_struct ; extern unsigned long slice_get_unmapped_area(unsigned long addr,
arch/powerpc/mm/slice.c +10 -3
@@ -37,7 +37,16 @@#include <asm/hugetlb.h> static DEFINE_SPINLOCK (slice_convert_lock); - +/* +* One bit per slice. We have lower slices which cover 256MB segments +* upto 4G range. That gets us 16 low slices. For the rest we track slices +* in 1TB size. +* 64 below is actually SLICE_NUM_HIGH to fixup complie errros +*/ +struct slice_mask { +u64 low_slices; + DECLARE_BITMAP(high_slices, SLICE_NUM_HIGH); +};#ifdef DEBUG int _slice_debug =1 ;
@@ -412,8 +421,6 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,struct mm_struct *mm = current->mm;unsigned long newaddr; -/* Make sure high_slices bitmap size is same as we expected */ -BUILD_BUG_ON (512 !=SLICE_NUM_HIGH );/* * init different masks */
Signature · 1 line
2.7.4
PATCH v3 10/10 powerpc/mm/slice: Update slice mask printing to use bitmap printing.
In reply to Aneesh Kumar K.VWe now get output like below which is much better.
[ 0.935306] good_mask low_slice: 0-15 [ 0.935360] good_mask high_slice: 0-511
Compared to
[ 0.953414] good_mask:1111111111111111 - 1111111111111.........
I also fixed an error with slice_dbg printing.
--- arch/powerpc/mm/slice.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)
arch/powerpc/mm/slice.c +7 -23
@@ -53,29 +53,13 @@ int _slice_debug = 1;static void slice_print_mask (const char *label,struct slice_mask mask) { -char *p, buf[SLICE_NUM_LOW +3 +SLICE_NUM_HIGH +1 ]; -int i; -if (!_slice_debug)return ; - p = buf; -for (i =0 ; i <SLICE_NUM_LOW ; i++) - *(p++) = (mask.low_slices & (1 << i)) ?'1' :'0' ; - *(p++) =' ' ; - *(p++) ='-' ; - *(p++) =' ' ; -for (i =0 ; i <SLICE_NUM_HIGH ; i++) { -if (test_bit (i, mask.high_slices)) - *(p++) ='1' ; -else - *(p++) ='0' ; - } - *(p++) =0 ; - -printk (KERN_DEBUG "%s:%s\n" , label, buf); +pr_devel ("%s low_slice: %*pbl\n" , label, (int )SLICE_NUM_LOW , &mask.low_slices); +pr_devel ("%s high_slice: %*pbl\n" , label, (int )SLICE_NUM_HIGH , mask.high_slices); } -#define slice_dbg(fmt...) do { if (_slice_debug) pr_debug(fmt); } while(0) +#define slice_dbg(fmt...) do { if (_slice_debug) pr_devel(fmt); } while (0)#else
@@ -247,8 +231,8 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psiz }slice_dbg (" lsps=%lx, hsps=%lx\n" , - mm->context.low_slices_psize, - mm->context.high_slices_psize); + (unsigned long )mm->context.low_slices_psize, + (unsigned long )mm->context.high_slices_psize);spin_unlock_irqrestore (&slice_convert_lock, flags);
@@ -690,8 +674,8 @@ void slice_set_user_psize(struct mm_struct *mm, unsigned int psize)slice_dbg (" lsps=%lx, hsps=%lx\n" , - mm->context.low_slices_psize, - mm->context.high_slices_psize); + (unsigned long )mm->context.low_slices_psize, + (unsigned long )mm->context.high_slices_psize); bail:spin_unlock_irqrestore (&slice_convert_lock, flags);
Signature · 1 line
2.7.4
Re: [PATCH V3 01/10] powerpc/mm/slice: Convert slice_mask high slice to a bitmap
In reply to Aneesh Kumar K.VQuoted 7 lines · Aneesh Kumar K.V
In followup patch we want to increase the va range which will result in us requiring
high_slicesto have more than 64 bits. To enable this converthigh_slicesto bitmap. We keep the number bits same in this patch and later change that to higher valueSigned-off-by Aneesh Kumar K.V <[email protected]>---
For consistency it would be nice to have low_slices represented similarly as well.
Re: [PATCH V3 02/10] powerpc/mm/slice: Update the function prototype
In reply to Aneesh Kumar K.VQuoted 4 lines · Aneesh Kumar K.V
This avoid copying the
slice_maskstruct as function return valueSigned-off-by Aneesh Kumar K.V <[email protected]>---
Makes sense, since we are no longer restricted to u64
Re: [PATCH V3 03/10] powerpc/mm/hash: Move kernel context to the starting of context range
In reply to Aneesh Kumar K.VQuoted 11 lines · Aneesh Kumar K.V
With current kernel, we use the top 4 context for the kernel. Kernel VSIDs are built using these top context values and effective segemnt ID. In the following patches, we want to increase the max effective address to 512TB. We achieve that by increasing the effective segments IDs there by increasing virtual address range.
We will be switching to a 68bit virtual address in the following patch. But for platforms like p4 and p5, which only support a 65 bit va, we want to limit the virtual addrress to a 65 bit value. We do that by limiting the context bits to 16 instead of 19. That means we will have different max context values on different platforms.
Quoted 4 lines
To make this simpler. we move the kernel context to the starting of the range.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
Re: [PATCH V3 01/10] powerpc/mm/slice: Convert slice_mask high slice to a bitmap
In reply to Balbir SinghQuoted 10 lines · Balbir Singh
Quoted 7 lines · Aneesh Kumar K.V
In followup patch we want to increase the va range which will result in us requiring
high_slicesto have more than 64 bits. To enable this converthigh_slicesto bitmap. We keep the number bits same in this patch and later change that to higher valueSigned-off-by Aneesh Kumar K.V <[email protected]>---
For consistency it would be nice to have
low_slicesrepresented similarly as well.
That will need converting lot of low_slices update to bitmap api with no real benefit
Quoted 2 lines
Acked-by Balbir Singh <[email protected]>
-aneesh
Re: [PATCH V3 04/10] powerpc/mm/hash: Support 68 bit VA
In reply to Aneesh Kumar K.VQuoted 9 lines · Aneesh Kumar K.V
Inorder to support large effective address range (512TB), we want to increase the virtual address bits to 68. But we do have platforms like p4 and p5 that can only do 65 bit VA. We support those platforms by limiting context bits on them to 16.
The protovsid -> vsid conversion is verified to work with both 65 and 68 bit va values. I also documented the restrictions in a table format as part of code comments.
Quoted 7 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>---
/*
* This should be computed such that protovosid *vsid_mulitplier
* doesn't overflow 64 bits. It should also be co-prime tovsid_modulus
+ * We also need to make sure that number of bits in divisor is less
+ * than twice the number of protovsid bits for our modulus optmization to work.
Could you please explain why?
I am also beginning to wonder if we need the modulus optimization. On my compiler (a * b) % (2^n - 1) generated reasonable code with just one multiplication and a few shifts and boolean operations.
Quoted 53 lines
+ * The below table shows the current values used.
+ *+ * |-------+------------+----------------+------------+--------------| + * | | Prime Bits | VSID_BITS_65VA | Total Bits | 2* VSID_BITS | + * |-------+------------+----------------+------------+--------------| + * | 1T | 24 | 25 | 49 | 50 | + * |-------+------------+----------------+------------+--------------| + * | 256MB | 24 | 37 | 61 | 74 | + * |-------+------------+----------------+------------+--------------| + * + * |-------+------------+----------------+------------+--------------| + * | | Prime Bits | VSID_BITS_68VA | Total Bits | 2* VSID_BITS | + * |-------+------------+----------------+------------+--------------| + * | 1T | 24 | 28 | 52 | 56 | + * |-------+------------+----------------+------------+--------------| + * | 256MB | 24 | 40 | 64 | 80 | + * |-------+------------+----------------+------------+--------------|+ *
*/
#defineVSID_MULTIPLIER_256MASM_CONST(12538073)/* 24-bit prime */arch/powerpc/include/asm/book3s/64/mmu-hash.h +4
-22-#define VSID_BITS_256M (CONTEXT_BITS + ESID_BITS) +#define VSID_BITS_256M (VA_BITS - SID_SHIFT)#define VSID_MODULUS_256M ((1UL<<VSID_BITS_256M)-1) +#define VSID_BITS_65_256M (65 - SID_SHIFT)#define VSID_MULTIPLIER_1T ASM_CONST(12538073)/* 24-bit prime */ -#define VSID_BITS_1T (CONTEXT_BITS + ESID_BITS_1T) +#define VSID_BITS_1T (VA_BITS - SID_SHIFT_1T)#define VSID_MODULUS_1T ((1UL<<VSID_BITS_1T)-1) - +#define VSID_BITS_65_1T (65 - SID_SHIFT_1T)#define USER_VSID_RANGE (1UL << (ESID_BITS + SID_SHIFT)) -/* -* This macro generates asm code to compute the VSID scramble -* function. Used in slb_allocate() and do_stab_bolted. The function -* computed is: (protovsid*VSID_MULTIPLIER) % VSID_MODULUS -* -* rt = register containing the proto-VSID and into which the -* VSID will be stored -* rx = scratch register (clobbered) -* -* - rt and rx must be different registers -* - The answer will end up in the low VSID_BITS bits of rt. The higher -* bits may contain other garbage, so you may need to mask the -* result. -*/ -#define ASM_VSID_SCRAMBLE (rt, rx, size) \ - lis rx,VSID_MULTIPLIER_##size@h; \ - ori rx,rx,VSID_MULTIPLIER_##size@l; \ - mulld rt,rt,rx;/* rt = rt * MULTIPLIER */ \ - \
arch/powerpc/include/asm/book3s/64/mmu-hash.h extern void slb_set_size(u16 size); · line 580
Quoted 10 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +0
-10- srdi rx,rt,VSID_BITS_##size; \ - clrldi rt,rt,(64-VSID_BITS_##size); \ - add rt,rt,rx;/* add high and low bits */ \ -/* NOTE: explanation based on VSID_BITS_##size = 36 \ -* Now, r3 == VSID (mod 2^36-1), and lies between 0 and \ -* 2^36-1+2^28-1. That in particular means that if r3 >= \ -* 2^36-1, then r3+1 has the 2^36 bit set. So, if r3+1 has \ -* the bit clear, r3 already has the answer we want, if it \ -* doesn't, the answer is the low 36 bits of r3+1. So in all \ -* cases the answer is the low 36 bits of (r3 + ((r3+1) >> 36))*/ \
I see that this comment is lost in the new definition, could we please retain it.
Quoted 38 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +15
-5- addi rx,rt,1; \ - srdi rx,rx,VSID_BITS_##size; /* extract 2^VSID_BITS bit */ \ - add rt,rt,rx -/* 4 bits per slice and we have one slice per 1TB */ #define SLICE_ARRAY_SIZE (H_PGTABLE_RANGE >> 41)@@ -629,7 +632,7 @@ static inline void subpage_prot_init_new_context(struct mm_struct *mm) { }#define vsid_scramble (protovsid, size) \ ((((protovsid) * VSID_MULTIPLIER_##size) % VSID_MODULUS_##size)) -#else /* 1 */ +/* simplified form avoiding mod operation */ #define vsid_scramble (protovsid, size) \ ({ \ unsigned long x; \@@ -637,6 +640,21 @@ static inline void subpage_prot_init_new_context(struct mm_struct *mm) { } x = (x >> VSID_BITS_##size) + (x & VSID_MODULUS_##size); \ (x + ((x+1) >> VSID_BITS_##size)) & VSID_MODULUS_##size; \ }) + +static inline unsigned long vsid_scramble (unsigned long protovsid, +unsigned long vsid_multiplier,int vsid_bits) +{ +unsigned long vsid; +unsigned long vsid_modulus = ((1UL << vsid_bits) -1 ); +/* +* We have same multipler for both 256 and 1T segements now +*/ + vsid = protovsid * vsid_multiplier; + vsid = (vsid >> vsid_bits) + (vsid & vsid_modulus); +return (vsid + ((vsid +1 ) >> vsid_bits)) & vsid_modulus; +} +#endif /* 1 */ /* Returns the segment size indicator for a user address */
arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long addr) · line 672
Quoted 4 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1
-0@@ -651,17 +669,32 @@ static inline int user_segment_size(unsigned long addr)static inline unsigned long get_vsid (unsigned long context,unsigned long ea,int ssize) { +unsigned long va_bits =VA_BITS ;
Is there a reason to convert the constant into unsigned long?
Quoted 20 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +9
-5+unsigned long vsid_bits; +unsigned long protovsid; +/* * Bad address. We return VSID 0 for that */ if ((ea & ~REGION_MASK ) >=H_PGTABLE_RANGE )return 0 ; -if (ssize ==MMU_SEGSIZE_256M ) -return vsid_scramble ((context <<ESID_BITS ) - | ((ea >> SID_SHIFT) & ESID_BITS_MASK), 256M); -return vsid_scramble ((context <<ESID_BITS_1T ) - | ((ea >> SID_SHIFT_1T) & ESID_BITS_1T_MASK), 1T); +if (!mmu_has_feature (MMU_FTR_68_BIT_VA )) + va_bits =65 ; + +if (ssize ==MMU_SEGSIZE_256M ) { + vsid_bits = va_bits -SID_SHIFT ; + protovsid = (context << ESID_BITS) |
arch/powerpc/include/asm/book3s/64/mmu-hash.h static inline int user_segment_size(unsigned long addr) · line 697
Quoted 10 lines
arch/powerpc/include/asm/book3s/64/mmu-hash.h +10
-0+ ((ea >>SID_SHIFT ) &ESID_BITS_MASK ); +return vsid_scramble (protovsid, +VSID_MULTIPLIER_256M , vsid_bits); + } +/* 1T segment */ + vsid_bits = va_bits -SID_SHIFT_1T ; + protovsid = (context <<ESID_BITS_1T ) | + ((ea >>SID_SHIFT_1T ) &ESID_BITS_1T_MASK ); +return vsid_scramble (protovsid, +VSID_MULTIPLIER_1T , vsid_bits);
We seem to be passing an unsigned long to a prototype above that expects an int
Quoted 143 lines
(quoted diff) +0
-0} /*arch/powerpc/include/asm/mmu.h +13
-6@@ -29,6 +29,10 @@*/ /* +* Support for 68 bit VA space. We added that from ISA 2.05 +*/ +#define MMU_FTR_68_BIT_VA ASM_CONST(0x00002000) +/* * Kernel read only support. * We added the ppp value 0b110 in ISA 2.04. */ @@ -109,10 +113,10 @@#define MMU_FTRS_POWER4 MMU_FTRS_DEFAULT_HPTE_ARCH_V2#define MMU_FTRS_PPC970 MMU_FTRS_POWER4 | MMU_FTR_TLBIE_CROP_VA#define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE -#define MMU_FTRS_POWER6 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER7 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER8 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO -#define MMU_FTRS_POWER9 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO +#define MMU_FTRS_POWER6 MMU_FTRS_POWER5 | MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA +#define MMU_FTRS_POWER7 MMU_FTRS_POWER6 +#define MMU_FTRS_POWER8 MMU_FTRS_POWER6 +#define MMU_FTRS_POWER9 MMU_FTRS_POWER6#define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \ MMU_FTR_CI_LARGE_PAGE#define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \@@ -136,7 +140,7 @@ enum { MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE | MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA | - MMU_FTR_KERNEL_RO | + MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA |#ifdef CONFIG_PPC_RADIX_MMU MMU_FTR_TYPE_RADIX |#endif @@ -290,7 +294,10 @@ static inline bool early_radix_enabled(void)#define MMU_PAGE_16G 14#define MMU_PAGE_64G 15 -/* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 */ +/* +* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 +* Also we need to change he type of mm_context.low/high_slices_psize. +*/ #define MMU_PAGE_COUNT 16#ifdef CONFIG_PPC_BOOK3S_64 arch/powerpc/kvm/book3s_64_mmu_host.c +7
-1@@ -229,6 +229,7 @@ void kvmppc_mmu_unmap_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)static struct kvmppc_sid_map *create_sid_map (struct kvm_vcpu *vcpu,u64 gvsid) { +unsigned long vsid_bits =VSID_BITS_65_256M ;struct kvmppc_sid_map *map;struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);u16 sid_map_mask;@@ -257,7 +258,12 @@ static struct kvmppc_sid_map *create_sid_map(struct kvm_vcpu *vcpu, u64 gvsid)kvmppc_mmu_pte_flush (vcpu,0 ,0 );kvmppc_mmu_flush_segments (vcpu); } - map->host_vsid = vsid_scramble(vcpu_book3s->proto_vsid_next++, 256M); + +if (mmu_has_feature (MMU_FTR_68_BIT_VA )) + vsid_bits =VSID_BITS_256M ; + + map->host_vsid =vsid_scramble (vcpu_book3s->proto_vsid_next++, +VSID_MULTIPLIER_256M , vsid_bits); map->guest_vsid = gvsid; map->valid = true;arch/powerpc/mm/mmu_context_book3s64.c +7
-1@@ -33,6 +33,12 @@ static DEFINE_IDA(mmu_context_ida);int hash__get_new_context (void ) {int index, err; +unsigned long max_user_context; + +if (mmu_has_feature (MMU_FTR_68_BIT_VA )) + max_user_context =MAX_USER_CONTEXT ; +else + max_user_context =MAX_USER_CONTEXT_65BIT_VA ; again:if (!ida_pre_get (&mmu_context_ida,GFP_KERNEL ))@@ -50,7 +56,7 @@ int hash__get_new_context(void)else if (err)return err; -if (index >MAX_USER_CONTEXT ) { +if (index > max_user_context) {spin_lock (&mmu_context_lock);ida_remove (&mmu_context_ida, index);spin_unlock (&mmu_context_lock);arch/powerpc/mm/slb_low.S +29
-0@@ -23,6 +23,48 @@ #include <asm/pgtable.h> #include <asm/firmware.h> +/* + * This macro generates asm code to compute the VSID scramble + * function. Used in slb_allocate() and do_stab_bolted. The function + * computed is: (protovsid*VSID_MULTIPLIER) % VSID_MODULUS + * + * rt = register containing the proto-VSID and into which the + * VSID will be stored + * rx = scratch register (clobbered) + * rf = flags + * + * - rt and rx must be different registers + * - The answer will end up in the low VSID_BITS bits of rt. The higher + * bits may contain other garbage, so you may need to mask the + * result. + */ +#define ASM_VSID_SCRAMBLE(rt, rx, rf, size) \ + lis rx,VSID_MULTIPLIER_##size@h; \ + ori rx,rx,VSID_MULTIPLIER_##size@l; \ + mulld rt,rt,rx; /* rt = rt * MULTIPLIER */ \ +/* \ + * powermac get slb fault before feature fixup, so make 65 bit part \ + * the default part of feature fixup \ + */ \ +BEGIN_MMU_FTR_SECTION \ + srdi rx,rt,VSID_BITS_65_##size; \ + clrldi rt,rt,(64-VSID_BITS_65_##size); \ + add rt,rt,rx; \ + addi rx,rt,1; \ + srdi rx,rx,VSID_BITS_65_##size; \
arch/powerpc/mm/slb_low.S line 64
Quoted 10 lines
arch/powerpc/mm/slb_low.S +10
-0+ add rt,rt,rx; \ + rldimi rf,rt,SLB_VSID_SHIFT_##size,(64 - (SLB_VSID_SHIFT_##size + VSID_BITS_65_##size)); \ +MMU_FTR_SECTION_ELSE \ + srdi rx,rt,VSID_BITS_##size; \ + clrldi rt,rt,(64-VSID_BITS_##size); \ + add rt,rt,rx; /* add high and low bits */ \ + addi rx,rt,1; \ + srdi rx,rx,VSID_BITS_##size; /* extract 2^VSID_BITS bit */ \ + add rt,rt,rx; \ + rldimi rf,rt,SLB_VSID_SHIFT_##size,(64 - (SLB_VSID_SHIFT_##size + VSID_BITS_##size)); \
Don't like this bit, it does more than scramble, it adds the flags to the generated scramble bits, could we please revisit what ASM_VSID_SCRAMBLE should do?
Otherwise,
Balbir
Re: [PATCH V3 01/10] powerpc/mm/slice: Convert slice_mask high slice to a bitmap
In reply to Aneesh Kumar K.VQuoted 9 lines · Aneesh Kumar K.V
Quoted 6 lines · Balbir Singh
Quoted 5 lines · Aneesh Kumar K.V
In followup patch we want to increase the va range which will result in us requiring
high_slicesto have more than 64 bits. To enable this converthigh_slicesto bitmap. We keep the number bits same in this patch and later change that to higher value
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>---
For consistency it would be nice to have
low_slicesrepresented similarly as well.That will need converting lot of
low_slicesupdate to bitmap api with no real benefit
Consistency and not having our own bitmap implementation :) Anways, I am not too held up on it.
Quoted 5 lines
Quoted 2 lines
Acked-by Balbir Singh <[email protected]>-aneesh
Re: [PATCH V3 06/10] powerpc/mm: Remove redundant TASK_SIZE_USER64 checks
In reply to Aneesh Kumar K.VQuoted 4 lines · Aneesh Kumar K.V
The check against VSID range is implied when we check task size against hash and radix pgtable range[1], because we make sure page table range cannot exceed vsid range.
Quoted 8 lines
[1]
BUILD_BUG_ON(TASK_SIZE_USER64 > H_PGTABLE_RANGE);BUILD_BUG_ON(TASK_SIZE_USER64 > RADIX_PGTABLE_RANGE);The check for smaller task size is also removed here, because the follow up patch will support a tasksize smaller than pgtable range.
Signed-off-by Aneesh Kumar K.V <[email protected]>---
Re: [PATCH V3 10/10] powerpc/mm/slice: Update slice mask printing to use bitmap printing.
In reply to Aneesh Kumar K.VQuoted 5 lines · Aneesh Kumar K.V
We now get output like below which is much better.
[ 0.935306] good_mask low_slice: 0-15 [ 0.935360] good_mask high_slice: 0-511
Quoted 8 lines
Compared to
[ 0.953414] good_mask:1111111111111111 - 1111111111111.........I also fixed an error with
slice_dbgprinting.Signed-off-by Aneesh Kumar K.V <[email protected]>---
Yep, like this much better
Re: [PATCH V3 09/10] powerpc/mm/slice: Move slice_mask struct definition to slice.c
In reply to Aneesh Kumar K.VHello,
Quoted 50 lines · On Sun, 19 Feb 2017 15:37:16 +0530 "Aneesh Kumar K.V"…
This structure definition need not be in a header since this is used only by
slice.cfile. So move it toslice.c. This also allow us to useSLICE_NUM_HIGHinstead of 512 and also helps in getting rid of oneBUILD_BUG_ON().I also switch the
low_slicestype to u64 from u16. This doesn't have an impact on size of struct due to padding added with u16 type. This helps in using bitmap printing function for printing slice mask.Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/page_64.h | 11 ----------- arch/powerpc/mm/slice.c | 13 ++++++++++--- 2 files changed, 10 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/arch/powerpc/include/asm/page_64.hindex9b60e9455c6e..3ecfc2734b50100644 ---a/arch/powerpc/include/asm/page_64.h
+++b/arch/powerpc/include/asm/page_64.harch/powerpc/include/asm/page_64.h +0
-3@@ -99,17 +99,6 @@ extern u64 ppc64_pft_size;#define GET_HIGH_SLICE_INDEX (addr) ((addr) >> SLICE_HIGH_SHIFT)#ifndef __ASSEMBLY__ -/* -* One bit per slice. We have lower slices which cover 256MB segments -* upto 4G range. That gets us 16 low slices. For the rest we track slices
- * in 1TB size.
- * 64 below is actuallySLICE_NUM_HIGHto fixup complie errros
- */arch/powerpc/include/asm/page_64.h +0
-5-struct slice_mask { -u16 low_slices; - DECLARE_BITMAP(high_slices, 512); -}; -struct mm_struct ; extern unsigned long slice_get_unmapped_area(unsigned long addr,arch/powerpc/mm/slice.c +3
-1@@ -37,7 +37,16 @@#include <asm/hugetlb.h> static DEFINE_SPINLOCK (slice_convert_lock); - +/* +* One bit per slice. We have lower slices which cover 256MB segments +* upto 4G range. That gets us 16 low slices. For the rest we track
Quoted 3 lines
slices
+ * in 1TB size.
+ * 64 below is actuallySLICE_NUM_HIGHto fixup complie errros*
Please remove the above line which no longer applies for multiple reasons.
Also consider swapping this and the previous patch.
Thanks
Michal
Quoted 18 lines
+ */
arch/powerpc/mm/slice.c +4
-2+struct slice_mask { +u64 low_slices; + DECLARE_BITMAP(high_slices, SLICE_NUM_HIGH); +};#ifdef DEBUG int _slice_debug =1 ;@@ -412,8 +421,6 @@ unsigned long slice_get_unmapped_area(unsignedlong addr, unsigned long len, struct mm_struct *mm = current->mm; unsigned long newaddr; -/* Make sure high_slices bitmap size is same as we expected */ -BUILD_BUG_ON (512 !=SLICE_NUM_HIGH );/* * init different masks */
Re: [PATCH V3 08/10] powerpc/mm/hash: Increase VA range to 128TB
In reply to Aneesh Kumar K.VHello,
Quoted 105 lines · On Sun, 19 Feb 2017 15:37:15 +0530 "Aneesh Kumar K.V"…
We update the hash linux page table layout such that we can support 512TB. But we limit the
TASK_SIZEto 128TB. We can switch to 128TB by default without conditional because that is the max virtual address supported by other architectures. We will later add a mechanism to on-demand increase the application's effective address range to 512TB.Having the page table layout changed to accommodate 512TB makes testing large memory configuration easier with less code changes to kernel
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 2 +- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/page_64.h | 2 +- arch/powerpc/include/asm/processor.h | 22 ++++++++++++++++++---- arch/powerpc/kernel/paca.c | 9 ++++++++- arch/powerpc/mm/slice.c | 2 ++ 6 files changed, 31 insertions(+), 8 deletions(-)(quoted diff) +0
-0
b/arch/powerpc/include/asm/book3s/64/hash-4k.hindex0c4e470571ca..b4b5e6b671ca100644 ---a/arch/powerpc/include/asm/book3s/64/hash-4k.h+++b/arch/powerpc/include/asm/book3s/64/hash-4k.h@@ -8,7 +8,7 @@#define H_PTE_INDEX_SIZE 9 #define H_PMD_INDEX_SIZE 7 #define H_PUD_INDEX_SIZE 9arch/powerpc/include/asm/book3s/64/hash-4k.h +1
-1-#define H_PGD_INDEX_SIZE 9 +#define H_PGD_INDEX_SIZE 12#ifndef __ASSEMBLY__#define H_PTE_TABLE_SIZE (sizeof(pte_t) << H_PTE_INDEX_SIZE)(quoted diff) +0
-0
b/arch/powerpc/include/asm/book3s/64/hash-64k.hindexb39f0b86405e..682c4eb28fa4100644 ---a/arch/powerpc/include/asm/book3s/64/hash-64k.h+++b/arch/powerpc/include/asm/book3s/64/hash-64k.h@@ -4,7 +4,7 @@#define H_PTE_INDEX_SIZE 8 #define H_PMD_INDEX_SIZE 5 #define H_PUD_INDEX_SIZE 5arch/powerpc/include/asm/book3s/64/hash-64k.h +1
-1-#define H_PGD_INDEX_SIZE 12 +#define H_PGD_INDEX_SIZE 15/* * 64k aligned address free up few of the lower bits of RPN for us (quoted diff) +0
-0
b/arch/powerpc/include/asm/page_64.hindex7f72659b7999..9b60e9455c6e100644 ---a/arch/powerpc/include/asm/page_64.h
+++b/arch/powerpc/include/asm/page_64.harch/powerpc/include/asm/page_64.h +1
-1@@ -107,7 +107,7 @@ extern u64 ppc64_pft_size;*/ struct slice_mask {u16 low_slices; - DECLARE_BITMAP(high_slices, 64); + DECLARE_BITMAP(high_slices, 512); };struct mm_struct ;(quoted diff) +0
-0
b/arch/powerpc/include/asm/processor.hindex1ba814436c73..1d4e34f9004d100644 ---a/arch/powerpc/include/asm/processor.h+++b/arch/powerpc/include/asm/processor.h@@ -102,11 +102,25 @@ voidrelease_thread(struct task_struct *); #endif#ifdef
CONFIG_PPC64arch/powerpc/include/asm/processor.h +18
-4-/* 64-bit user address space is 46-bits (64TB user VM) */ -#define TASK_SIZE_USER64 (0x0000400000000000UL) +/* +* 64-bit user address space can have multiple limits +* For now supported values are: +*/ +#define TASK_SIZE_64TB (0x0000400000000000UL) +#define TASK_SIZE_128TB (0x0000800000000000UL) +#define TASK_SIZE_512TB (0x0002000000000000UL) -/* -* 32-bit user address space is 4GB - 1 page +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* MAx value currently used: +*/ +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif + +/* +* 32-bit user address space is 4GB - 1 page * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT */
#defineTASK_SIZE_USER32(0x0000000100000000UL- (1*PAGE_SIZE))arch/powerpc/kernel/paca.c +2
-0@@ -253,8 +253,15 @@ void copy_mm_to_paca(struct mm_struct *mm)get_paca ()->mm_ctx_id = context->id;#ifdef CONFIG_PPC_MM_SLICES get_paca ()->mm_ctx_low_slices_psize = context->low_slices_psize; +/* +* We support upto 128TB for now. Hence copy only 128/2 bytes.
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm) · line 261
Quoted 4 lines
arch/powerpc/kernel/paca.c +4
-0+* Later when we support tasks with different max effective +* address, we can optimize this based on mm->task_size. +*/ +BUILD_BUG_ON (TASK_SIZE_USER64 !=TASK_SIZE_128TB );
Can this be handled by KConfig?
Above I see
arch/powerpc/kernel/paca.c
Quoted 5 lines
arch/powerpc/kernel/paca.c +5
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif
and
Quoted 2 lines
#ifdef
CONFIG_PPC_MM_SLICESILD_BUG_ON(TASK_SIZE_USER64 != TASK_SIZE_128TB)
which boils down to
#ifndef CONFIG_PPC_BOOK3S_64
#ifdef CONFIG_PPC_MM_SLICES
#error TASK_SIZE_USER64 != TASK_SIZE_128TB
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm) · line 263
Quoted 3 lines
arch/powerpc/kernel/paca.c +1
-1memcpy (&get_paca ()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); + &context->high_slices_psize,TASK_SIZE_128TB >>41 );
Can we avoid magic numbers, please?
Thanks
Michal
Quoted 18 lines
arch/powerpc/kernel/paca.c +1
-0+#else /* CONFIG_PPC_MM_SLICES */ get_paca ()->mm_ctx_user_psize = context->user_psize;get_paca ()->mm_ctx_sllp = context->sllp;arch/powerpc/mm/slice.c +2
-0@@ -412,6 +412,8 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, struct mm_struct *mm = current->mm;unsigned long newaddr; +/* Make sure high_slices bitmap size is same as we expected */ +BUILD_BUG_ON (512 !=SLICE_NUM_HIGH );/* * init different masks */
Re: [PATCH V3 08/10] powerpc/mm/hash: Increase VA range to 128TB
Quoted 16 lines · Michal Such=C3=A1nek <[email protected]> writes:
Hello,
Quoted 11 lines · On Sun, 19 Feb 2017 15:37:15 +0530 "Aneesh Kumar K.V"…
We update the hash linux page table layout such that we can support 512TB. But we limit the
TASK_SIZEto 128TB. We can switch to 128TB by default without conditional because that is the max virtual address supported by other architectures. We will later add a mechanism to on-demand increase the application's effective address range to 512TB. =20
Having the page table layout changed to accommodate 512TB makes testing large memory configuration easier with less code changes to kernel
=20Signed-off-by Aneesh Kumar K.V <[email protected]>
....
Quoted 10 lines
index
b64daf124fee..c7ca70dc3ba5100644Quoted 9 lines
arch/powerpc/kernel/paca.c +2
-0@@ -253,8 +253,15 @@ void copy_mm_to_paca(struct mm_struct *mm) get_paca()->mm_ctx_id =3D context->id;#ifdef CONFIG_PPC_MM_SLICES get_paca()->mm_ctx_low_slices_psize =3D context->low_slices_psize; +/* +* We support upto 128TB for now. Hence copy only 128/2
Quoted 8 lines
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm)
Quoted 5 lines
bytes.
arch/powerpc/kernel/paca.c +4
-0+* Later when we support tasks with different max effective +* address, we can optimize this based on mm->task_size. +*/ + BUILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB);Can this be handled by KConfig?
Above I see=20
I am reworking the series so that we depend on mm->task_size. Will send a new version soon.
Quoted 15 lines
arch/powerpc/kernel/paca.c
Quoted 5 lines
arch/powerpc/kernel/paca.c +5
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif and=20
Quoted 2 lines
#ifdef
CONFIG_PPC_MM_SLICESILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB)which boils down to
#ifndefCONFIG_PPC_BOOK3S_64
#ifdefCONFIG_PPC_MM_SLICES
#errorTASK_SIZE_USER64!=3DTASK_SIZE_128TB
Quoted 6 lines
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm) · line 263
Quoted 3 lines
arch/powerpc/kernel/paca.c +1
-1memcpy (&get_paca ()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); + &context->high_slices_psize,TASK_SIZE_128TB >>41 );Can we avoid magic numbers, please?
Since array is 4 bytes per each TB which is documented else where. Considering we are just converting max range there, do we need that as a macro ?
-aneesh
Re: [PATCH V3 08/10] powerpc/mm/hash: Increase VA range to 128TB
Quoted 60 lines · Aneesh Kumar K.V
Quoted 16 lines · Michal Such=C3=A1nek <[email protected]> writes:
Hello,
Quoted 11 lines · On Sun, 19 Feb 2017 15:37:15 +0530 "Aneesh Kumar K.V"…
We update the hash linux page table layout such that we can support 512TB. But we limit the
TASK_SIZEto 128TB. We can switch to 128TB by default without conditional because that is the max virtual address supported by other architectures. We will later add a mechanism to on-demand increase the application's effective address range to 512TB. =20
Having the page table layout changed to accommodate 512TB makes testing large memory configuration easier with less code changes to kernel
=20Signed-off-by Aneesh Kumar K.V <[email protected]>....
Quoted 10 lines
index
b64daf124fee..c7ca70dc3ba5100644Quoted 9 lines
arch/powerpc/kernel/paca.c +2
-0@@ -253,8 +253,15 @@ void copy_mm_to_paca(struct mm_struct *mm) get_paca()->mm_ctx_id =3D context->id;#ifdef CONFIG_PPC_MM_SLICES get_paca()->mm_ctx_low_slices_psize =3D context->low_slices_psize; +/* +* We support upto 128TB for now. Hence copy only 128/2 Quoted 8 lines
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm)
Quoted 5 lines
bytes.
arch/powerpc/kernel/paca.c +4
-0+* Later when we support tasks with different max effective +* address, we can optimize this based on mm->task_size. +*/ + BUILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB);Can this be handled by KConfig?
Above I see=20I am reworking the series so that we depend on
mm->task_size. Will send a new version soon.Quoted 15 lines
arch/powerpc/kernel/paca.c
Quoted 5 lines
arch/powerpc/kernel/paca.c +5
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif and=20
Quoted 2 lines
#ifdef
CONFIG_PPC_MM_SLICESILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB)which boils down to
#ifndefCONFIG_PPC_BOOK3S_64
#ifdefCONFIG_PPC_MM_SLICES
#errorTASK_SIZE_USER64!=3DTASK_SIZE_128TB
Quoted 8 lines
Quoted 6 lines
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm) · line 263
Quoted 3 lines
arch/powerpc/kernel/paca.c +1
-1memcpy (&get_paca ()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); + &context->high_slices_psize,TASK_SIZE_128TB >>41 );Can we avoid magic numbers, please?
Since array is 4 bytes per each TB which is documented else where.
4 bits per teach TB.
-aneesh
Re: [PATCH V3 08/10] powerpc/mm/hash: Increase VA range to 128TB
Quoted 73 lines · On Mon, 06 Mar 2017 09:07:48 +0530 "Aneesh Kumar K.V"…
"Aneesh Kumar K.V" <[email protected]> writes:
=20Quoted 71 lines
Michal Such=C3=A1nek <[email protected]> writes:
=20Quoted 18 lines
Hello,
On Sun, 19 Feb 2017 15:37:15 +0530
"Aneesh Kumar K.V" <[email protected]> wrote:
=20Quoted 13 lines
We update the hash linux page table layout such that we can support 512TB. But we limit the
TASK_SIZEto 128TB. We can switch to 128TB by default without conditional because that is the max virtual address supported by other architectures. We will later add a mechanism to on-demand increase the application's effective address range to 512TB.
=20
Having the page table layout changed to accommodate 512TB makes testing large memory configuration easier with less code changes to kernel
=20
Signed-off-by: Aneesh Kumar K.V <[email protected]> =20....
=20Quoted 11 lines
index
b64daf124fee..c7ca70dc3ba5100644 =20Quoted 10 lines
arch/powerpc/kernel/paca.c +2
-0@@ -253,8 +253,15 @@ void copy_mm_to_paca(struct mm_struct *mm) get_paca()->mm_ctx_id =3D context->id;#ifdef CONFIG_PPC_MM_SLICES get_paca()->mm_ctx_low_slices_psize =3D context->low_slices_psize; +/* +* We support upto 128TB for now. Hence copy only 128/2 bytes.
Quoted 8 lines
arch/powerpc/kernel/paca.c void copy_mm_to_paca(struct mm_struct *mm)
Quoted 5 lines
arch/powerpc/kernel/paca.c +1
-0+* Later when we support tasks with different max effective
arch/powerpc/kernel/paca.c +3
-0+* address, we can optimize this based on mm->task_size. +*/ + BUILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB); =20Can this be handled by KConfig?
Above I see =20I am reworking the series so that we depend on
mm->task_size. Will send a new version soon.=20
Quoted 22 lines
arch/powerpc/kernel/paca.c
Quoted 5 lines
arch/powerpc/kernel/paca.c +5
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define TASK_SIZE_USER64 TASK_SIZE_128TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#endif =20and =20
Quoted 2 lines
#ifdef
CONFIG_PPC_MM_SLICESILD_BUG_ON(TASK_SIZE_USER64 !=3D TASK_SIZE_128TB)=20which boils down to
#ifndefCONFIG_PPC_BOOK3S_64
#ifdefCONFIG_PPC_MM_SLICES
#errorTASK_SIZE_USER64!=3DTASK_SIZE_128TB=20
Quoted 4 lines
arch/powerpc/kernel/paca.c +1
-1memcpy(&get_paca()->mm_ctx_high_slices_psize, - &context->high_slices_psize,SLICE_ARRAY_SIZE ); + &context->high_slices_psize, TASK_SIZE_128TB >>41); =20
Can we avoid magic numbers, please?
=20
Quoted 4 lines
Quoted 1 line
Since array is 4 bytes per each TB which is documented else where. =20
=20
4 bits per teach TB.
=20
It is certainly nicer to have a macro for it. You can then see what the number is from the macro name or grep it and find the definition and the explanation.
Thanks
Michal