powerpc/mm/hash: Handle mmap_min_addr correctly in get_unmapped_area topdown search
authorAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Tue, 26 Feb 2019 04:39:35 +0000 (10:09 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 26 Feb 2019 05:26:29 +0000 (16:26 +1100)
When doing top-down search the low_limit is not PAGE_SIZE but rather
max(PAGE_SIZE, mmap_min_addr). This handle cases in which mmap_min_addr >
PAGE_SIZE.

Fixes: fba2369e6ceb ("mm: use vm_unmapped_area() on powerpc architecture")
Reviewed-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/slice.c

index 06898c13901de85cda6b50a3677b38325f685dd8..aec91dbcdc0b47bef604eeb802cd40e999a48f7c 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/export.h>
 #include <linux/hugetlb.h>
 #include <linux/sched/mm.h>
+#include <linux/security.h>
 #include <asm/mman.h>
 #include <asm/mmu.h>
 #include <asm/copro.h>
@@ -377,6 +378,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
        int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
        unsigned long addr, found, prev;
        struct vm_unmapped_area_info info;
+       unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr);
 
        info.flags = VM_UNMAPPED_AREA_TOPDOWN;
        info.length = len;
@@ -393,7 +395,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
        if (high_limit > DEFAULT_MAP_WINDOW)
                addr += mm->context.slb_addr_limit - DEFAULT_MAP_WINDOW;
 
-       while (addr > PAGE_SIZE) {
+       while (addr > min_addr) {
                info.high_limit = addr;
                if (!slice_scan_available(addr - 1, available, 0, &addr))
                        continue;
@@ -405,8 +407,8 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
                 * Check if we need to reduce the range, or if we can
                 * extend it to cover the previous available slice.
                 */
-               if (addr < PAGE_SIZE)
-                       addr = PAGE_SIZE;
+               if (addr < min_addr)
+                       addr = min_addr;
                else if (slice_scan_available(addr - 1, available, 0, &prev)) {
                        addr = prev;
                        goto prev_slice;
@@ -528,7 +530,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
                addr = _ALIGN_UP(addr, page_size);
                slice_dbg(" aligned addr=%lx\n", addr);
                /* Ignore hint if it's too large or overlaps a VMA */
-               if (addr > high_limit - len ||
+               if (addr > high_limit - len || addr < mmap_min_addr ||
                    !slice_area_is_free(mm, addr, len))
                        addr = 0;
        }