Commit 9b11c791 authored by Martin Schwidefsky's avatar Martin Schwidefsky

s390/mm: simplify arch_get_unmapped_area[_topdown]

With TASK_SIZE now reflecting the maximum size of the address space for
a process the code for arch_get_unmapped_area[_topdown] can be simplified.
Just let the logic pick a suitable address and deal with the page table
upgrade after the address has been selected.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent ee71d16d
...@@ -89,32 +89,43 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, ...@@ -89,32 +89,43 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct vm_unmapped_area_info info; struct vm_unmapped_area_info info;
int rc;
if (len > mm->context.asce_limit - mmap_min_addr) if (len > TASK_SIZE - mmap_min_addr)
return -ENOMEM; return -ENOMEM;
if (flags & MAP_FIXED) if (flags & MAP_FIXED)
return addr; goto check_asce_limit;
if (addr) { if (addr) {
addr = PAGE_ALIGN(addr); addr = PAGE_ALIGN(addr);
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
if (mm->context.asce_limit - len >= addr && if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
addr >= mmap_min_addr &&
(!vma || addr + len <= vma->vm_start)) (!vma || addr + len <= vma->vm_start))
return addr; goto check_asce_limit;
} }
info.flags = 0; info.flags = 0;
info.length = len; info.length = len;
info.low_limit = mm->mmap_base; info.low_limit = mm->mmap_base;
info.high_limit = mm->context.asce_limit; info.high_limit = TASK_SIZE;
if (filp || (flags & MAP_SHARED)) if (filp || (flags & MAP_SHARED))
info.align_mask = MMAP_ALIGN_MASK << PAGE_SHIFT; info.align_mask = MMAP_ALIGN_MASK << PAGE_SHIFT;
else else
info.align_mask = 0; info.align_mask = 0;
info.align_offset = pgoff << PAGE_SHIFT; info.align_offset = pgoff << PAGE_SHIFT;
return vm_unmapped_area(&info); addr = vm_unmapped_area(&info);
if (addr & ~PAGE_MASK)
return addr;
check_asce_limit:
if (addr + len > current->mm->context.asce_limit) {
rc = crst_table_upgrade(mm);
if (rc)
return (unsigned long) rc;
}
return addr;
} }
unsigned long unsigned long
...@@ -126,22 +137,22 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, ...@@ -126,22 +137,22 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
unsigned long addr = addr0; unsigned long addr = addr0;
struct vm_unmapped_area_info info; struct vm_unmapped_area_info info;
int rc;
/* requested length too big for entire address space */ /* requested length too big for entire address space */
if (len > mm->context.asce_limit - mmap_min_addr) if (len > TASK_SIZE - mmap_min_addr)
return -ENOMEM; return -ENOMEM;
if (flags & MAP_FIXED) if (flags & MAP_FIXED)
return addr; goto check_asce_limit;
/* requesting a specific address */ /* requesting a specific address */
if (addr) { if (addr) {
addr = PAGE_ALIGN(addr); addr = PAGE_ALIGN(addr);
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
if (mm->context.asce_limit - len >= addr && if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
addr >= mmap_min_addr &&
(!vma || addr + len <= vma->vm_start)) (!vma || addr + len <= vma->vm_start))
return addr; goto check_asce_limit;
} }
info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.flags = VM_UNMAPPED_AREA_TOPDOWN;
...@@ -165,58 +176,22 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, ...@@ -165,58 +176,22 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
VM_BUG_ON(addr != -ENOMEM); VM_BUG_ON(addr != -ENOMEM);
info.flags = 0; info.flags = 0;
info.low_limit = TASK_UNMAPPED_BASE; info.low_limit = TASK_UNMAPPED_BASE;
info.high_limit = mm->context.asce_limit; info.high_limit = TASK_SIZE;
addr = vm_unmapped_area(&info); addr = vm_unmapped_area(&info);
if (addr & ~PAGE_MASK)
return addr;
} }
return addr; check_asce_limit:
} if (addr + len > current->mm->context.asce_limit) {
static unsigned long
s390_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff, unsigned long flags)
{
struct mm_struct *mm = current->mm;
unsigned long area;
int rc;
area = arch_get_unmapped_area(filp, addr, len, pgoff, flags);
if (!(area & ~PAGE_MASK))
return area;
if (area == -ENOMEM && !is_compat_task() &&
current->mm->context.asce_limit < TASK_SIZE_MAX) {
/* Upgrade the page table to 4 levels and retry. */
rc = crst_table_upgrade(mm); rc = crst_table_upgrade(mm);
if (rc) if (rc)
return (unsigned long) rc; return (unsigned long) rc;
area = arch_get_unmapped_area(filp, addr, len, pgoff, flags);
} }
return area;
}
static unsigned long
s390_get_unmapped_area_topdown(struct file *filp, const unsigned long addr,
const unsigned long len, const unsigned long pgoff,
const unsigned long flags)
{
struct mm_struct *mm = current->mm;
unsigned long area;
int rc;
area = arch_get_unmapped_area_topdown(filp, addr, len, pgoff, flags); return addr;
if (!(area & ~PAGE_MASK))
return area;
if (area == -ENOMEM && !is_compat_task() &&
current->mm->context.asce_limit < TASK_SIZE_MAX) {
/* Upgrade the page table to 4 levels and retry. */
rc = crst_table_upgrade(mm);
if (rc)
return (unsigned long) rc;
area = arch_get_unmapped_area_topdown(filp, addr, len,
pgoff, flags);
}
return area;
} }
/* /*
* This function, called very early during the creation of a new * This function, called very early during the creation of a new
* process VM image, sets up which VM layout function to use: * process VM image, sets up which VM layout function to use:
...@@ -234,9 +209,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm) ...@@ -234,9 +209,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
*/ */
if (mmap_is_legacy()) { if (mmap_is_legacy()) {
mm->mmap_base = mmap_base_legacy(random_factor); mm->mmap_base = mmap_base_legacy(random_factor);
mm->get_unmapped_area = s390_get_unmapped_area; mm->get_unmapped_area = arch_get_unmapped_area;
} else { } else {
mm->mmap_base = mmap_base(random_factor); mm->mmap_base = mmap_base(random_factor);
mm->get_unmapped_area = s390_get_unmapped_area_topdown; mm->get_unmapped_area = arch_get_unmapped_area_topdown;
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment