aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/mm/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390/mm/mmap.c')
-rw-r--r--arch/s390/mm/mmap.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index 6e552af08c76..ea01477b4aa6 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -31,9 +31,6 @@
31#include <linux/security.h> 31#include <linux/security.h>
32#include <asm/pgalloc.h> 32#include <asm/pgalloc.h>
33 33
34unsigned long mmap_rnd_mask;
35static unsigned long mmap_align_mask;
36
37static unsigned long stack_maxrandom_size(void) 34static unsigned long stack_maxrandom_size(void)
38{ 35{
39 if (!(current->flags & PF_RANDOMIZE)) 36 if (!(current->flags & PF_RANDOMIZE))
@@ -62,10 +59,7 @@ static inline int mmap_is_legacy(void)
62 59
63unsigned long arch_mmap_rnd(void) 60unsigned long arch_mmap_rnd(void)
64{ 61{
65 if (is_32bit_task()) 62 return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT;
66 return (get_random_int() & 0x7ff) << PAGE_SHIFT;
67 else
68 return (get_random_int() & mmap_rnd_mask) << PAGE_SHIFT;
69} 63}
70 64
71static unsigned long mmap_base_legacy(unsigned long rnd) 65static unsigned long mmap_base_legacy(unsigned long rnd)
@@ -92,7 +86,6 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92 struct mm_struct *mm = current->mm; 86 struct mm_struct *mm = current->mm;
93 struct vm_area_struct *vma; 87 struct vm_area_struct *vma;
94 struct vm_unmapped_area_info info; 88 struct vm_unmapped_area_info info;
95 int do_color_align;
96 89
97 if (len > TASK_SIZE - mmap_min_addr) 90 if (len > TASK_SIZE - mmap_min_addr)
98 return -ENOMEM; 91 return -ENOMEM;
@@ -108,15 +101,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
108 return addr; 101 return addr;
109 } 102 }
110 103
111 do_color_align = 0;
112 if (filp || (flags & MAP_SHARED))
113 do_color_align = !is_32bit_task();
114
115 info.flags = 0; 104 info.flags = 0;
116 info.length = len; 105 info.length = len;
117 info.low_limit = mm->mmap_base; 106 info.low_limit = mm->mmap_base;
118 info.high_limit = TASK_SIZE; 107 info.high_limit = TASK_SIZE;
119 info.align_mask = do_color_align ? (mmap_align_mask << PAGE_SHIFT) : 0; 108 if (filp || (flags & MAP_SHARED))
109 info.align_mask = MMAP_ALIGN_MASK << PAGE_SHIFT;
110 else
111 info.align_mask = 0;
120 info.align_offset = pgoff << PAGE_SHIFT; 112 info.align_offset = pgoff << PAGE_SHIFT;
121 return vm_unmapped_area(&info); 113 return vm_unmapped_area(&info);
122} 114}
@@ -130,7 +122,6 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
130 struct mm_struct *mm = current->mm; 122 struct mm_struct *mm = current->mm;
131 unsigned long addr = addr0; 123 unsigned long addr = addr0;
132 struct vm_unmapped_area_info info; 124 struct vm_unmapped_area_info info;
133 int do_color_align;
134 125
135 /* requested length too big for entire address space */ 126 /* requested length too big for entire address space */
136 if (len > TASK_SIZE - mmap_min_addr) 127 if (len > TASK_SIZE - mmap_min_addr)
@@ -148,15 +139,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
148 return addr; 139 return addr;
149 } 140 }
150 141
151 do_color_align = 0;
152 if (filp || (flags & MAP_SHARED))
153 do_color_align = !is_32bit_task();
154
155 info.flags = VM_UNMAPPED_AREA_TOPDOWN; 142 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
156 info.length = len; 143 info.length = len;
157 info.low_limit = max(PAGE_SIZE, mmap_min_addr); 144 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
158 info.high_limit = mm->mmap_base; 145 info.high_limit = mm->mmap_base;
159 info.align_mask = do_color_align ? (mmap_align_mask << PAGE_SHIFT) : 0; 146 if (filp || (flags & MAP_SHARED))
147 info.align_mask = MMAP_ALIGN_MASK << PAGE_SHIFT;
148 else
149 info.align_mask = 0;
160 info.align_offset = pgoff << PAGE_SHIFT; 150 info.align_offset = pgoff << PAGE_SHIFT;
161 addr = vm_unmapped_area(&info); 151 addr = vm_unmapped_area(&info);
162 152
@@ -254,35 +244,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
254 mm->get_unmapped_area = s390_get_unmapped_area_topdown; 244 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
255 } 245 }
256} 246}
257
258static int __init setup_mmap_rnd(void)
259{
260 struct cpuid cpu_id;
261
262 get_cpu_id(&cpu_id);
263 switch (cpu_id.machine) {
264 case 0x9672:
265 case 0x2064:
266 case 0x2066:
267 case 0x2084:
268 case 0x2086:
269 case 0x2094:
270 case 0x2096:
271 case 0x2097:
272 case 0x2098:
273 case 0x2817:
274 case 0x2818:
275 case 0x2827:
276 case 0x2828:
277 mmap_rnd_mask = 0x7ffUL;
278 mmap_align_mask = 0UL;
279 break;
280 case 0x2964: /* z13 */
281 default:
282 mmap_rnd_mask = 0x3ff80UL;
283 mmap_align_mask = 0x7fUL;
284 break;
285 }
286 return 0;
287}
288early_initcall(setup_mmap_rnd);