powerpc/mm: Switch TASK_SIZE check to use mm->task_size
Subsystems (3)
RFC PATCH 1/3 powerpc/mm: Switch TASK_SIZE check to use mm->task_size
--- arch/powerpc/mm/hugetlbpage-radix.c | 4 ++-- arch/powerpc/mm/mmap.c | 12 ++++++------ arch/powerpc/mm/slice.c | 6 +++--- arch/powerpc/mm/subpage-prot.c | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-)
arch/powerpc/mm/hugetlbpage-radix.c +2 -2
@@ -52,7 +52,7 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,if (len & ~huge_page_mask (h))return -EINVAL ; -if (len >TASK_SIZE ) +if (len > mm->task_size)return -ENOMEM ;if (flags &MAP_FIXED ) {
@@ -64,7 +64,7 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,if (addr) { addr =ALIGN (addr,huge_page_size (h)); vma =find_vma (mm, addr); -if (TASK_SIZE - len >= addr && +if (mm->task_size - len >= addr && (!vma || addr + len <= vma->vm_start))return addr; }
arch/powerpc/mm/mmap.c +6 -6
@@ -97,7 +97,7 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr,struct vm_area_struct *vma;struct vm_unmapped_area_info info; -if (len >TASK_SIZE - mmap_min_addr) +if (len > mm->task_size - mmap_min_addr)return -ENOMEM ;if (flags &MAP_FIXED )
@@ -106,7 +106,7 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr,if (addr) { addr =PAGE_ALIGN (addr); vma =find_vma (mm, addr); -if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && +if (mm->task_size - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vma->vm_start))return addr; }
@@ -114,7 +114,7 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr, info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; - info.high_limit =TASK_SIZE ; + info.high_limit = mm->task_size; info.align_mask =0 ;return vm_unmapped_area (&info); }
@@ -132,7 +132,7 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,struct vm_unmapped_area_info info;/* requested length too big for entire address space */ -if (len >TASK_SIZE - mmap_min_addr) +if (len > mm->task_size - mmap_min_addr)return -ENOMEM ;if (flags &MAP_FIXED )
@@ -142,7 +142,7 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,if (addr) { addr =PAGE_ALIGN (addr); vma =find_vma (mm, addr); -if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && +if (mm->task_size - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vma->vm_start))return addr; }
@@ -164,7 +164,7 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,VM_BUG_ON (addr != -ENOMEM ); info.flags =0 ; info.low_limit =TASK_UNMAPPED_BASE ; - info.high_limit =TASK_SIZE ; + info.high_limit = mm->task_size; addr =vm_unmapped_area (&info); }
arch/powerpc/mm/slice.c +3 -3
@@ -277,7 +277,7 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, info.align_offset =0 ; addr =TASK_UNMAPPED_BASE ; -while (addr <TASK_SIZE ) { +while (addr < mm->task_size) { info.low_limit = addr;if (!slice_scan_available (addr, available,1 , &addr))continue ;
@@ -289,8 +289,8 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,* Check if we need to reduce the range, or if we can * extend it to cover the next available slice. */ -if (addr >=TASK_SIZE ) - addr =TASK_SIZE ; +if (addr >= mm->task_size) + addr = mm->task_size;else if (slice_scan_available (addr, available,1 , &next_end)) { addr = next_end; goto next_slice;
arch/powerpc/mm/subpage-prot.c +2 -1
@@ -197,7 +197,8 @@ long sys_subpage_prot(unsigned long addr, unsigned long len, u32 __user *map)/* Check parameters */ if ((addr & ~PAGE_MASK ) || (len & ~PAGE_MASK ) || - addr >=TASK_SIZE || len >=TASK_SIZE || addr + len >TASK_SIZE ) + addr >= mm->task_size || len >= mm->task_size || + addr + len > mm->task_size)return -EINVAL ;if (is_hugepage_only_range (mm, addr, len))
Signature · 1 line
2.7.4
RFC PATCH 2/3 mm: Let arch choose the initial value of task size
As we start supporting larger address space (>128TB), we want to give architecture a control on max task size of an application which is different from the TASK_SIZE. For ex: ppc64 needs to track the base page size of a segment and it is copied from mm_context_t to PACA on each context switch. If we know that application has not used an address range above 128TB we only need to copy details about 128TB range to PACA. This will help in improving context switch performance by avoiding larger copy operation.
--- fs/exec.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/exec.c +9 -1
@@ -1308,6 +1308,14 @@ void would_dump(struct linux_binprm *bprm, struct file *file) }EXPORT_SYMBOL (would_dump); +#ifndef arch_init_task_size +static inline void arch_init_task_size (void ) +{ + current->mm->task_size =TASK_SIZE ; +} +#define arch_init_task_size arch_init_task_size +#endif +void setup_new_exec (struct linux_binprm * bprm) {arch_pick_mmap_layout (current->mm);
@@ -1327,7 +1335,7 @@ void setup_new_exec(struct linux_binprm * bprm)* depend on TIF_32BIT which is only updated in flush_thread() on * some architectures like powerpc */ - current->mm->task_size =TASK_SIZE ; +arch_init_task_size ();/* install the new credentials */ if (!uid_eq(bprm->cred->uid, current_euid()) ||
Signature · 1 line
2.7.4
RFC PATCH 3/3 powerpc/mm: Enable mappings above 128TB
In reply to Aneesh Kumar K.VNot all user space application is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. It collides with valid pointers with 512TB addresses and leads to crashes.
To mitigate this, we are not going to allocate virtual address space above 128TB by default.
But userspace can ask for allocation from full address space by specifying hint address (with or without MAP_FIXED) above 128TB.
If hint address set above 128TB, but MAP_FIXED is not specified, we try to look for unmapped area by specified address. If it's already occupied, we look for unmapped area in *full* address space, rather than from 128TB window.
This approach helps to easily make application's memory allocator aware about large address space without manually tracking allocated virtual address space.
This is going to be a per mmap decision. ie, we can have some mmaps with larger addresses and other that do not.
A sample memory layout looks like below.
10000000-10010000 r-xp 00000000 fc:00 9057045 /home/max_addr_512TB 10010000-10020000 r--p 00000000 fc:00 9057045 /home/max_addr_512TB 10020000-10030000 rw-p 00010000 fc:00 9057045 /home/max_addr_512TB 10029630000-10029660000 rw-p 00000000 00:00 0 [heap] 7fff834a0000-7fff834b0000 rw-p 00000000 00:00 0 7fff834b0000-7fff83670000 r-xp 00000000 fc:00 9177190 /lib/powerpc64le-linux-gnu/libc-2.23.so 7fff83670000-7fff83680000 r--p 001b0000 fc:00 9177190 /lib/powerpc64le-linux-gnu/libc-2.23.so 7fff83680000-7fff83690000 rw-p 001c0000 fc:00 9177190 /lib/powerpc64le-linux-gnu/libc-2.23.so 7fff83690000-7fff836a0000 rw-p 00000000 00:00 0 7fff836a0000-7fff836c0000 r-xp 00000000 00:00 0 [vdso] 7fff836c0000-7fff83700000 r-xp 00000000 fc:00 9177193 /lib/powerpc64le-linux-gnu/ld-2.23.so 7fff83700000-7fff83710000 r--p 00030000 fc:00 9177193 /lib/powerpc64le-linux-gnu/ld-2.23.so 7fff83710000-7fff83720000 rw-p 00040000 fc:00 9177193 /lib/powerpc64le-linux-gnu/ld-2.23.so 7fffdccf0000-7fffdcd20000 rw-p 00000000 00:00 0 [stack]
1000000000000-1000000010000 rw-p 00000000 00:00 0
1ffff83710000-1ffff83720000 rw-p 00000000 00:00 0
--- arch/powerpc/include/asm/processor.h | 18 ++++++++---- arch/powerpc/mm/hugetlbpage-radix.c | 7 +++++ arch/powerpc/mm/mmap.c | 32 +++++++++++++-------- arch/powerpc/mm/slice.c | 55 ++++++++++++++++++++++++++++-------- 4 files changed, 84 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/processor.h +13 -5
@@ -114,9 +114,11 @@ void release_thread(struct task_struct *);/* * MAx value currently used: */ -#define TASK_SIZE_USER64 TASK_SIZE_128TB +#define TASK_SIZE_USER64 TASK_SIZE_512TB +#define DEFAULT_MAP_WINDOW TASK_SIZE_128TB#else -#define TASK_SIZE_USER64 TASK_SIZE_64TB +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#define DEFAULT_MAP_WINDOW TASK_SIZE_64TB#endif /*
@@ -128,12 +130,18 @@ void release_thread(struct task_struct *);#define TASK_SIZE_OF (tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ TASK_SIZE_USER32 : TASK_SIZE_USER64)#define TASK_SIZE TASK_SIZE_OF(current) +/* +* We want to track current task size in mm->task_size not the max possible +* task size. +*/ +#define arch_init_task_size () (test_tsk_thread_flag(current, TIF_32BIT) ? \ + TASK_SIZE_USER32 : DEFAULT_MAP_WINDOW)/* This decides where the kernel will search for a free chunk of vm * space during mmap's. */ #define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) -#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4)) +#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))#define TASK_UNMAPPED_BASE ((is_32bit_task()) ? \ TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
@@ -141,13 +149,13 @@ void release_thread(struct task_struct *);#ifdef __powerpc64__ -#define STACK_TOP_USER64 TASK_SIZE_USER64 +#define STACK_TOP_USER64 DEFAULT_MAP_WINDOW#define STACK_TOP_USER32 TASK_SIZE_USER32#define STACK_TOP (is_32bit_task() ? \ STACK_TOP_USER32 : STACK_TOP_USER64) -#define STACK_TOP_MAX STACK_TOP_USER64 +#define STACK_TOP_MAX TASK_SIZE_USER64#else /* __powerpc64__ */
arch/powerpc/mm/hugetlbpage-radix.c +7 -0
@@ -50,6 +50,9 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,struct hstate *h =hstate_file (file);struct vm_unmapped_area_info info; +if (unlikely (addr > mm->task_size)) + mm->task_size =TASK_SIZE ; +if (len & ~huge_page_mask (h))return -EINVAL ;if (len > mm->task_size)
@@ -78,5 +81,9 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, info.high_limit = current->mm->mmap_base; info.align_mask =PAGE_MASK & ~huge_page_mask (h); info.align_offset =0 ; + +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit += mm->task_size -DEFAULT_MAP_WINDOW ; +return vm_unmapped_area (&info); }
arch/powerpc/mm/mmap.c +21 -11
@@ -79,7 +79,7 @@ static inline unsigned long mmap_base(unsigned long rnd)else if (gap >MAX_GAP ) gap =MAX_GAP ; -return PAGE_ALIGN (TASK_SIZE - gap - rnd); +return PAGE_ALIGN (DEFAULT_MAP_WINDOW - gap - rnd); }#ifdef CONFIG_PPC_RADIX_MMU
@@ -97,6 +97,9 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr,struct vm_area_struct *vma;struct vm_unmapped_area_info info; +if (unlikely (addr > mm->task_size)) + mm->task_size =TASK_SIZE ; +if (len > mm->task_size - mmap_min_addr)return -ENOMEM ;
@@ -114,8 +117,13 @@ radix__arch_get_unmapped_area(struct file *filp, unsigned long addr, info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; - info.high_limit = mm->task_size; info.align_mask =0 ; + +if (unlikely (addr >DEFAULT_MAP_WINDOW )) + info.high_limit = mm->task_size; +else + info.high_limit =DEFAULT_MAP_WINDOW ; +return vm_unmapped_area (&info); }
@@ -131,6 +139,9 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,unsigned long addr = addr0;struct vm_unmapped_area_info info; +if (unlikely (addr > mm->task_size)) + mm->task_size =TASK_SIZE ; +/* requested length too big for entire address space */ if (len > mm->task_size - mmap_min_addr)return -ENOMEM ;
@@ -152,7 +163,14 @@ radix__arch_get_unmapped_area_topdown(struct file *filp, info.low_limit =max (PAGE_SIZE , mmap_min_addr); info.high_limit = mm->mmap_base; info.align_mask =0 ; + +if (addr >DEFAULT_MAP_WINDOW ) + info.high_limit += mm->task_size -DEFAULT_MAP_WINDOW ; + addr =vm_unmapped_area (&info); +if (!(addr & ~PAGE_MASK )) +return addr; +VM_BUG_ON (addr != -ENOMEM );/* * A failed mmap() very likely causes application failure,
@@ -160,15 +178,7 @@ radix__arch_get_unmapped_area_topdown(struct file *filp,* can happen with large stack limits and large mmap() * allocations. */ -if (addr & ~PAGE_MASK ) { -VM_BUG_ON (addr != -ENOMEM ); - info.flags =0 ; - info.low_limit =TASK_UNMAPPED_BASE ; - info.high_limit = mm->task_size; - addr =vm_unmapped_area (&info); - } - -return addr; +return radix__arch_get_unmapped_area (filp, addr0, len, pgoff, flags); } static void radix__arch_pick_mmap_layout(struct mm_struct *mm,
arch/powerpc/mm/slice.c +43 -12
124 lines not on this page · raw message
Signature · 1 line
2.7.4