arm64: dts: rockchip: change N key to home for rk3399 VR product
[firefly-linux-kernel-4.4.55.git] / arch / arm64 / mm / mmap.c
index 7c7be78556387ed548c3c37641cef3be9441ef5a..232f787a088ae8e992c52cba450159a43a900174 100644 (file)
@@ -47,25 +47,20 @@ static int mmap_is_legacy(void)
        return sysctl_legacy_va_layout;
 }
 
-/*
- * Since get_random_int() returns the same value within a 1 jiffy window, we
- * will almost always get the same randomisation for the stack and mmap
- * region. This will mean the relative distance between stack and mmap will be
- * the same.
- *
- * To avoid this we can shift the randomness by 1 bit.
- */
-static unsigned long mmap_rnd(void)
+unsigned long arch_mmap_rnd(void)
 {
-       unsigned long rnd = 0;
-
-       if (current->flags & PF_RANDOMIZE)
-               rnd = (long)get_random_int() & (STACK_RND_MASK >> 1);
+       unsigned long rnd;
 
-       return rnd << (PAGE_SHIFT + 1);
+#ifdef CONFIG_COMPAT
+       if (test_thread_flag(TIF_32BIT))
+               rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1);
+       else
+#endif
+               rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1);
+       return rnd << PAGE_SHIFT;
 }
 
-static unsigned long mmap_base(void)
+static unsigned long mmap_base(unsigned long rnd)
 {
        unsigned long gap = rlimit(RLIMIT_STACK);
 
@@ -74,7 +69,7 @@ static unsigned long mmap_base(void)
        else if (gap > MAX_GAP)
                gap = MAX_GAP;
 
-       return PAGE_ALIGN(STACK_TOP - gap - mmap_rnd());
+       return PAGE_ALIGN(STACK_TOP - gap - rnd);
 }
 
 /*
@@ -83,18 +78,21 @@ static unsigned long mmap_base(void)
  */
 void arch_pick_mmap_layout(struct mm_struct *mm)
 {
+       unsigned long random_factor = 0UL;
+
+       if (current->flags & PF_RANDOMIZE)
+               random_factor = arch_mmap_rnd();
+
        /*
         * Fall back to the standard layout if the personality bit is set, or
         * if the expected stack growth is unlimited:
         */
        if (mmap_is_legacy()) {
-               mm->mmap_base = TASK_UNMAPPED_BASE;
+               mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
                mm->get_unmapped_area = arch_get_unmapped_area;
-               mm->unmap_area = arch_unmap_area;
        } else {
-               mm->mmap_base = mmap_base();
+               mm->mmap_base = mmap_base(random_factor);
                mm->get_unmapped_area = arch_get_unmapped_area_topdown;
-               mm->unmap_area = arch_unmap_area_topdown;
        }
 }
 EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);
@@ -104,7 +102,7 @@ EXPORT_SYMBOL_GPL(arch_pick_mmap_layout);
  * You really shouldn't be using read() or write() on /dev/mem.  This might go
  * away in the future.
  */
-int valid_phys_addr_range(unsigned long addr, size_t size)
+int valid_phys_addr_range(phys_addr_t addr, size_t size)
 {
        if (addr < PHYS_OFFSET)
                return 0;