diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/s390/mm |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/s390/mm')
-rw-r--r-- | arch/s390/mm/Makefile | 7 | ||||
-rw-r--r-- | arch/s390/mm/cmm.c | 443 | ||||
-rw-r--r-- | arch/s390/mm/extmem.c | 588 | ||||
-rw-r--r-- | arch/s390/mm/fault.c | 586 | ||||
-rw-r--r-- | arch/s390/mm/init.c | 310 | ||||
-rw-r--r-- | arch/s390/mm/ioremap.c | 138 | ||||
-rw-r--r-- | arch/s390/mm/mmap.c | 86 |
7 files changed, 2158 insertions, 0 deletions
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile new file mode 100644 index 000000000000..aa9a42b6e62d --- /dev/null +++ b/arch/s390/mm/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # | ||
2 | # Makefile for the linux s390-specific parts of the memory manager. | ||
3 | # | ||
4 | |||
5 | obj-y := init.o fault.o ioremap.o extmem.o mmap.o | ||
6 | obj-$(CONFIG_CMM) += cmm.o | ||
7 | |||
diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c new file mode 100644 index 000000000000..d30cdb4248a9 --- /dev/null +++ b/arch/s390/mm/cmm.c | |||
@@ -0,0 +1,443 @@ | |||
1 | /* | ||
2 | * arch/s390/mm/cmm.c | ||
3 | * | ||
4 | * S390 version | ||
5 | * Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation | ||
6 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) | ||
7 | * | ||
8 | * Collaborative memory management interface. | ||
9 | */ | ||
10 | |||
11 | #include <linux/config.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/fs.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/sysctl.h> | ||
18 | #include <linux/ctype.h> | ||
19 | |||
20 | #include <asm/pgalloc.h> | ||
21 | #include <asm/uaccess.h> | ||
22 | |||
23 | #include "../../../drivers/s390/net/smsgiucv.h" | ||
24 | |||
25 | #define CMM_NR_PAGES ((PAGE_SIZE / sizeof(unsigned long)) - 2) | ||
26 | |||
27 | struct cmm_page_array { | ||
28 | struct cmm_page_array *next; | ||
29 | unsigned long index; | ||
30 | unsigned long pages[CMM_NR_PAGES]; | ||
31 | }; | ||
32 | |||
33 | static long cmm_pages = 0; | ||
34 | static long cmm_timed_pages = 0; | ||
35 | static volatile long cmm_pages_target = 0; | ||
36 | static volatile long cmm_timed_pages_target = 0; | ||
37 | static long cmm_timeout_pages = 0; | ||
38 | static long cmm_timeout_seconds = 0; | ||
39 | |||
40 | static struct cmm_page_array *cmm_page_list = 0; | ||
41 | static struct cmm_page_array *cmm_timed_page_list = 0; | ||
42 | |||
43 | static unsigned long cmm_thread_active = 0; | ||
44 | static struct work_struct cmm_thread_starter; | ||
45 | static wait_queue_head_t cmm_thread_wait; | ||
46 | static struct timer_list cmm_timer; | ||
47 | |||
48 | static void cmm_timer_fn(unsigned long); | ||
49 | static void cmm_set_timer(void); | ||
50 | |||
51 | static long | ||
52 | cmm_strtoul(const char *cp, char **endp) | ||
53 | { | ||
54 | unsigned int base = 10; | ||
55 | |||
56 | if (*cp == '0') { | ||
57 | base = 8; | ||
58 | cp++; | ||
59 | if ((*cp == 'x' || *cp == 'X') && isxdigit(cp[1])) { | ||
60 | base = 16; | ||
61 | cp++; | ||
62 | } | ||
63 | } | ||
64 | return simple_strtoul(cp, endp, base); | ||
65 | } | ||
66 | |||
67 | static long | ||
68 | cmm_alloc_pages(long pages, long *counter, struct cmm_page_array **list) | ||
69 | { | ||
70 | struct cmm_page_array *pa; | ||
71 | unsigned long page; | ||
72 | |||
73 | pa = *list; | ||
74 | while (pages) { | ||
75 | page = __get_free_page(GFP_NOIO); | ||
76 | if (!page) | ||
77 | break; | ||
78 | if (!pa || pa->index >= CMM_NR_PAGES) { | ||
79 | /* Need a new page for the page list. */ | ||
80 | pa = (struct cmm_page_array *) | ||
81 | __get_free_page(GFP_NOIO); | ||
82 | if (!pa) { | ||
83 | free_page(page); | ||
84 | break; | ||
85 | } | ||
86 | pa->next = *list; | ||
87 | pa->index = 0; | ||
88 | *list = pa; | ||
89 | } | ||
90 | diag10(page); | ||
91 | pa->pages[pa->index++] = page; | ||
92 | (*counter)++; | ||
93 | pages--; | ||
94 | } | ||
95 | return pages; | ||
96 | } | ||
97 | |||
98 | static void | ||
99 | cmm_free_pages(long pages, long *counter, struct cmm_page_array **list) | ||
100 | { | ||
101 | struct cmm_page_array *pa; | ||
102 | unsigned long page; | ||
103 | |||
104 | pa = *list; | ||
105 | while (pages) { | ||
106 | if (!pa || pa->index <= 0) | ||
107 | break; | ||
108 | page = pa->pages[--pa->index]; | ||
109 | if (pa->index == 0) { | ||
110 | pa = pa->next; | ||
111 | free_page((unsigned long) *list); | ||
112 | *list = pa; | ||
113 | } | ||
114 | free_page(page); | ||
115 | (*counter)--; | ||
116 | pages--; | ||
117 | } | ||
118 | } | ||
119 | |||
120 | static int | ||
121 | cmm_thread(void *dummy) | ||
122 | { | ||
123 | int rc; | ||
124 | |||
125 | daemonize("cmmthread"); | ||
126 | while (1) { | ||
127 | rc = wait_event_interruptible(cmm_thread_wait, | ||
128 | (cmm_pages != cmm_pages_target || | ||
129 | cmm_timed_pages != cmm_timed_pages_target)); | ||
130 | if (rc == -ERESTARTSYS) { | ||
131 | /* Got kill signal. End thread. */ | ||
132 | clear_bit(0, &cmm_thread_active); | ||
133 | cmm_pages_target = cmm_pages; | ||
134 | cmm_timed_pages_target = cmm_timed_pages; | ||
135 | break; | ||
136 | } | ||
137 | if (cmm_pages_target > cmm_pages) { | ||
138 | if (cmm_alloc_pages(1, &cmm_pages, &cmm_page_list)) | ||
139 | cmm_pages_target = cmm_pages; | ||
140 | } else if (cmm_pages_target < cmm_pages) { | ||
141 | cmm_free_pages(1, &cmm_pages, &cmm_page_list); | ||
142 | } | ||
143 | if (cmm_timed_pages_target > cmm_timed_pages) { | ||
144 | if (cmm_alloc_pages(1, &cmm_timed_pages, | ||
145 | &cmm_timed_page_list)) | ||
146 | cmm_timed_pages_target = cmm_timed_pages; | ||
147 | } else if (cmm_timed_pages_target < cmm_timed_pages) { | ||
148 | cmm_free_pages(1, &cmm_timed_pages, | ||
149 | &cmm_timed_page_list); | ||
150 | } | ||
151 | if (cmm_timed_pages > 0 && !timer_pending(&cmm_timer)) | ||
152 | cmm_set_timer(); | ||
153 | } | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | static void | ||
158 | cmm_start_thread(void) | ||
159 | { | ||
160 | kernel_thread(cmm_thread, 0, 0); | ||
161 | } | ||
162 | |||
163 | static void | ||
164 | cmm_kick_thread(void) | ||
165 | { | ||
166 | if (!test_and_set_bit(0, &cmm_thread_active)) | ||
167 | schedule_work(&cmm_thread_starter); | ||
168 | wake_up(&cmm_thread_wait); | ||
169 | } | ||
170 | |||
171 | static void | ||
172 | cmm_set_timer(void) | ||
173 | { | ||
174 | if (cmm_timed_pages_target <= 0 || cmm_timeout_seconds <= 0) { | ||
175 | if (timer_pending(&cmm_timer)) | ||
176 | del_timer(&cmm_timer); | ||
177 | return; | ||
178 | } | ||
179 | if (timer_pending(&cmm_timer)) { | ||
180 | if (mod_timer(&cmm_timer, jiffies + cmm_timeout_seconds*HZ)) | ||
181 | return; | ||
182 | } | ||
183 | cmm_timer.function = cmm_timer_fn; | ||
184 | cmm_timer.data = 0; | ||
185 | cmm_timer.expires = jiffies + cmm_timeout_seconds*HZ; | ||
186 | add_timer(&cmm_timer); | ||
187 | } | ||
188 | |||
189 | static void | ||
190 | cmm_timer_fn(unsigned long ignored) | ||
191 | { | ||
192 | long pages; | ||
193 | |||
194 | pages = cmm_timed_pages_target - cmm_timeout_pages; | ||
195 | if (pages < 0) | ||
196 | cmm_timed_pages_target = 0; | ||
197 | else | ||
198 | cmm_timed_pages_target = pages; | ||
199 | cmm_kick_thread(); | ||
200 | cmm_set_timer(); | ||
201 | } | ||
202 | |||
203 | void | ||
204 | cmm_set_pages(long pages) | ||
205 | { | ||
206 | cmm_pages_target = pages; | ||
207 | cmm_kick_thread(); | ||
208 | } | ||
209 | |||
210 | long | ||
211 | cmm_get_pages(void) | ||
212 | { | ||
213 | return cmm_pages; | ||
214 | } | ||
215 | |||
216 | void | ||
217 | cmm_add_timed_pages(long pages) | ||
218 | { | ||
219 | cmm_timed_pages_target += pages; | ||
220 | cmm_kick_thread(); | ||
221 | } | ||
222 | |||
223 | long | ||
224 | cmm_get_timed_pages(void) | ||
225 | { | ||
226 | return cmm_timed_pages; | ||
227 | } | ||
228 | |||
229 | void | ||
230 | cmm_set_timeout(long pages, long seconds) | ||
231 | { | ||
232 | cmm_timeout_pages = pages; | ||
233 | cmm_timeout_seconds = seconds; | ||
234 | cmm_set_timer(); | ||
235 | } | ||
236 | |||
237 | static inline int | ||
238 | cmm_skip_blanks(char *cp, char **endp) | ||
239 | { | ||
240 | char *str; | ||
241 | |||
242 | for (str = cp; *str == ' ' || *str == '\t'; str++); | ||
243 | *endp = str; | ||
244 | return str != cp; | ||
245 | } | ||
246 | |||
247 | #ifdef CONFIG_CMM_PROC | ||
248 | /* These will someday get removed. */ | ||
249 | #define VM_CMM_PAGES 1111 | ||
250 | #define VM_CMM_TIMED_PAGES 1112 | ||
251 | #define VM_CMM_TIMEOUT 1113 | ||
252 | |||
253 | static struct ctl_table cmm_table[]; | ||
254 | |||
255 | static int | ||
256 | cmm_pages_handler(ctl_table *ctl, int write, struct file *filp, | ||
257 | void *buffer, size_t *lenp, loff_t *ppos) | ||
258 | { | ||
259 | char buf[16], *p; | ||
260 | long pages; | ||
261 | int len; | ||
262 | |||
263 | if (!*lenp || (*ppos && !write)) { | ||
264 | *lenp = 0; | ||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | if (write) { | ||
269 | len = *lenp; | ||
270 | if (copy_from_user(buf, buffer, | ||
271 | len > sizeof(buf) ? sizeof(buf) : len)) | ||
272 | return -EFAULT; | ||
273 | buf[sizeof(buf) - 1] = '\0'; | ||
274 | cmm_skip_blanks(buf, &p); | ||
275 | pages = cmm_strtoul(p, &p); | ||
276 | if (ctl == &cmm_table[0]) | ||
277 | cmm_set_pages(pages); | ||
278 | else | ||
279 | cmm_add_timed_pages(pages); | ||
280 | } else { | ||
281 | if (ctl == &cmm_table[0]) | ||
282 | pages = cmm_get_pages(); | ||
283 | else | ||
284 | pages = cmm_get_timed_pages(); | ||
285 | len = sprintf(buf, "%ld\n", pages); | ||
286 | if (len > *lenp) | ||
287 | len = *lenp; | ||
288 | if (copy_to_user(buffer, buf, len)) | ||
289 | return -EFAULT; | ||
290 | } | ||
291 | *lenp = len; | ||
292 | *ppos += len; | ||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | static int | ||
297 | cmm_timeout_handler(ctl_table *ctl, int write, struct file *filp, | ||
298 | void *buffer, size_t *lenp, loff_t *ppos) | ||
299 | { | ||
300 | char buf[64], *p; | ||
301 | long pages, seconds; | ||
302 | int len; | ||
303 | |||
304 | if (!*lenp || (*ppos && !write)) { | ||
305 | *lenp = 0; | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | if (write) { | ||
310 | len = *lenp; | ||
311 | if (copy_from_user(buf, buffer, | ||
312 | len > sizeof(buf) ? sizeof(buf) : len)) | ||
313 | return -EFAULT; | ||
314 | buf[sizeof(buf) - 1] = '\0'; | ||
315 | cmm_skip_blanks(buf, &p); | ||
316 | pages = cmm_strtoul(p, &p); | ||
317 | cmm_skip_blanks(p, &p); | ||
318 | seconds = cmm_strtoul(p, &p); | ||
319 | cmm_set_timeout(pages, seconds); | ||
320 | } else { | ||
321 | len = sprintf(buf, "%ld %ld\n", | ||
322 | cmm_timeout_pages, cmm_timeout_seconds); | ||
323 | if (len > *lenp) | ||
324 | len = *lenp; | ||
325 | if (copy_to_user(buffer, buf, len)) | ||
326 | return -EFAULT; | ||
327 | } | ||
328 | *lenp = len; | ||
329 | *ppos += len; | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | static struct ctl_table cmm_table[] = { | ||
334 | { | ||
335 | .ctl_name = VM_CMM_PAGES, | ||
336 | .procname = "cmm_pages", | ||
337 | .mode = 0600, | ||
338 | .proc_handler = &cmm_pages_handler, | ||
339 | }, | ||
340 | { | ||
341 | .ctl_name = VM_CMM_TIMED_PAGES, | ||
342 | .procname = "cmm_timed_pages", | ||
343 | .mode = 0600, | ||
344 | .proc_handler = &cmm_pages_handler, | ||
345 | }, | ||
346 | { | ||
347 | .ctl_name = VM_CMM_TIMEOUT, | ||
348 | .procname = "cmm_timeout", | ||
349 | .mode = 0600, | ||
350 | .proc_handler = &cmm_timeout_handler, | ||
351 | }, | ||
352 | { .ctl_name = 0 } | ||
353 | }; | ||
354 | |||
355 | static struct ctl_table cmm_dir_table[] = { | ||
356 | { | ||
357 | .ctl_name = CTL_VM, | ||
358 | .procname = "vm", | ||
359 | .maxlen = 0, | ||
360 | .mode = 0555, | ||
361 | .child = cmm_table, | ||
362 | }, | ||
363 | { .ctl_name = 0 } | ||
364 | }; | ||
365 | #endif | ||
366 | |||
367 | #ifdef CONFIG_CMM_IUCV | ||
368 | #define SMSG_PREFIX "CMM" | ||
369 | static void | ||
370 | cmm_smsg_target(char *msg) | ||
371 | { | ||
372 | long pages, seconds; | ||
373 | |||
374 | if (!cmm_skip_blanks(msg + strlen(SMSG_PREFIX), &msg)) | ||
375 | return; | ||
376 | if (strncmp(msg, "SHRINK", 6) == 0) { | ||
377 | if (!cmm_skip_blanks(msg + 6, &msg)) | ||
378 | return; | ||
379 | pages = cmm_strtoul(msg, &msg); | ||
380 | cmm_skip_blanks(msg, &msg); | ||
381 | if (*msg == '\0') | ||
382 | cmm_set_pages(pages); | ||
383 | } else if (strncmp(msg, "RELEASE", 7) == 0) { | ||
384 | if (!cmm_skip_blanks(msg + 7, &msg)) | ||
385 | return; | ||
386 | pages = cmm_strtoul(msg, &msg); | ||
387 | cmm_skip_blanks(msg, &msg); | ||
388 | if (*msg == '\0') | ||
389 | cmm_add_timed_pages(pages); | ||
390 | } else if (strncmp(msg, "REUSE", 5) == 0) { | ||
391 | if (!cmm_skip_blanks(msg + 5, &msg)) | ||
392 | return; | ||
393 | pages = cmm_strtoul(msg, &msg); | ||
394 | if (!cmm_skip_blanks(msg, &msg)) | ||
395 | return; | ||
396 | seconds = cmm_strtoul(msg, &msg); | ||
397 | cmm_skip_blanks(msg, &msg); | ||
398 | if (*msg == '\0') | ||
399 | cmm_set_timeout(pages, seconds); | ||
400 | } | ||
401 | } | ||
402 | #endif | ||
403 | |||
404 | struct ctl_table_header *cmm_sysctl_header; | ||
405 | |||
406 | static int | ||
407 | cmm_init (void) | ||
408 | { | ||
409 | #ifdef CONFIG_CMM_PROC | ||
410 | cmm_sysctl_header = register_sysctl_table(cmm_dir_table, 1); | ||
411 | #endif | ||
412 | #ifdef CONFIG_CMM_IUCV | ||
413 | smsg_register_callback(SMSG_PREFIX, cmm_smsg_target); | ||
414 | #endif | ||
415 | INIT_WORK(&cmm_thread_starter, (void *) cmm_start_thread, 0); | ||
416 | init_waitqueue_head(&cmm_thread_wait); | ||
417 | init_timer(&cmm_timer); | ||
418 | return 0; | ||
419 | } | ||
420 | |||
421 | static void | ||
422 | cmm_exit(void) | ||
423 | { | ||
424 | cmm_free_pages(cmm_pages, &cmm_pages, &cmm_page_list); | ||
425 | cmm_free_pages(cmm_timed_pages, &cmm_timed_pages, &cmm_timed_page_list); | ||
426 | #ifdef CONFIG_CMM_PROC | ||
427 | unregister_sysctl_table(cmm_sysctl_header); | ||
428 | #endif | ||
429 | #ifdef CONFIG_CMM_IUCV | ||
430 | smsg_unregister_callback(SMSG_PREFIX, cmm_smsg_target); | ||
431 | #endif | ||
432 | } | ||
433 | |||
434 | module_init(cmm_init); | ||
435 | module_exit(cmm_exit); | ||
436 | |||
437 | EXPORT_SYMBOL(cmm_set_pages); | ||
438 | EXPORT_SYMBOL(cmm_get_pages); | ||
439 | EXPORT_SYMBOL(cmm_add_timed_pages); | ||
440 | EXPORT_SYMBOL(cmm_get_timed_pages); | ||
441 | EXPORT_SYMBOL(cmm_set_timeout); | ||
442 | |||
443 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c new file mode 100644 index 000000000000..648deed17e25 --- /dev/null +++ b/arch/s390/mm/extmem.c | |||
@@ -0,0 +1,588 @@ | |||
1 | /* | ||
2 | * File...........: arch/s390/mm/extmem.c | ||
3 | * Author(s)......: Carsten Otte <cotte@de.ibm.com> | ||
4 | * Rob M van der Heij <rvdheij@nl.ibm.com> | ||
5 | * Steven Shultz <shultzss@us.ibm.com> | ||
6 | * Bugreports.to..: <Linux390@de.ibm.com> | ||
7 | * (C) IBM Corporation 2002-2004 | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/string.h> | ||
12 | #include <linux/spinlock.h> | ||
13 | #include <linux/list.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/bootmem.h> | ||
17 | #include <asm/page.h> | ||
18 | #include <asm/ebcdic.h> | ||
19 | #include <asm/errno.h> | ||
20 | #include <asm/extmem.h> | ||
21 | #include <asm/cpcmd.h> | ||
22 | #include <linux/ctype.h> | ||
23 | |||
24 | #define DCSS_DEBUG /* Debug messages on/off */ | ||
25 | |||
26 | #define DCSS_NAME "extmem" | ||
27 | #ifdef DCSS_DEBUG | ||
28 | #define PRINT_DEBUG(x...) printk(KERN_DEBUG DCSS_NAME " debug:" x) | ||
29 | #else | ||
30 | #define PRINT_DEBUG(x...) do {} while (0) | ||
31 | #endif | ||
32 | #define PRINT_INFO(x...) printk(KERN_INFO DCSS_NAME " info:" x) | ||
33 | #define PRINT_WARN(x...) printk(KERN_WARNING DCSS_NAME " warning:" x) | ||
34 | #define PRINT_ERR(x...) printk(KERN_ERR DCSS_NAME " error:" x) | ||
35 | |||
36 | |||
37 | #define DCSS_LOADSHR 0x00 | ||
38 | #define DCSS_LOADNSR 0x04 | ||
39 | #define DCSS_PURGESEG 0x08 | ||
40 | #define DCSS_FINDSEG 0x0c | ||
41 | #define DCSS_LOADNOLY 0x10 | ||
42 | #define DCSS_SEGEXT 0x18 | ||
43 | #define DCSS_FINDSEGA 0x0c | ||
44 | |||
45 | struct qrange { | ||
46 | unsigned int start; // 3byte start address, 1 byte type | ||
47 | unsigned int end; // 3byte end address, 1 byte reserved | ||
48 | }; | ||
49 | |||
50 | struct qout64 { | ||
51 | int segstart; | ||
52 | int segend; | ||
53 | int segcnt; | ||
54 | int segrcnt; | ||
55 | struct qrange range[6]; | ||
56 | }; | ||
57 | |||
58 | struct qin64 { | ||
59 | char qopcode; | ||
60 | char rsrv1[3]; | ||
61 | char qrcode; | ||
62 | char rsrv2[3]; | ||
63 | char qname[8]; | ||
64 | unsigned int qoutptr; | ||
65 | short int qoutlen; | ||
66 | }; | ||
67 | |||
68 | struct dcss_segment { | ||
69 | struct list_head list; | ||
70 | char dcss_name[8]; | ||
71 | unsigned long start_addr; | ||
72 | unsigned long end; | ||
73 | atomic_t ref_count; | ||
74 | int do_nonshared; | ||
75 | unsigned int vm_segtype; | ||
76 | struct qrange range[6]; | ||
77 | int segcnt; | ||
78 | }; | ||
79 | |||
80 | static DEFINE_SPINLOCK(dcss_lock); | ||
81 | static struct list_head dcss_list = LIST_HEAD_INIT(dcss_list); | ||
82 | static char *segtype_string[] = { "SW", "EW", "SR", "ER", "SN", "EN", "SC", | ||
83 | "EW/EN-MIXED" }; | ||
84 | |||
85 | extern struct { | ||
86 | unsigned long addr, size, type; | ||
87 | } memory_chunk[MEMORY_CHUNKS]; | ||
88 | |||
89 | /* | ||
90 | * Create the 8 bytes, ebcdic VM segment name from | ||
91 | * an ascii name. | ||
92 | */ | ||
93 | static void inline | ||
94 | dcss_mkname(char *name, char *dcss_name) | ||
95 | { | ||
96 | int i; | ||
97 | |||
98 | for (i = 0; i < 8; i++) { | ||
99 | if (name[i] == '\0') | ||
100 | break; | ||
101 | dcss_name[i] = toupper(name[i]); | ||
102 | }; | ||
103 | for (; i < 8; i++) | ||
104 | dcss_name[i] = ' '; | ||
105 | ASCEBC(dcss_name, 8); | ||
106 | } | ||
107 | |||
108 | |||
109 | /* | ||
110 | * search all segments in dcss_list, and return the one | ||
111 | * namend *name. If not found, return NULL. | ||
112 | */ | ||
113 | static struct dcss_segment * | ||
114 | segment_by_name (char *name) | ||
115 | { | ||
116 | char dcss_name[9]; | ||
117 | struct list_head *l; | ||
118 | struct dcss_segment *tmp, *retval = NULL; | ||
119 | |||
120 | assert_spin_locked(&dcss_lock); | ||
121 | dcss_mkname (name, dcss_name); | ||
122 | list_for_each (l, &dcss_list) { | ||
123 | tmp = list_entry (l, struct dcss_segment, list); | ||
124 | if (memcmp(tmp->dcss_name, dcss_name, 8) == 0) { | ||
125 | retval = tmp; | ||
126 | break; | ||
127 | } | ||
128 | } | ||
129 | return retval; | ||
130 | } | ||
131 | |||
132 | |||
133 | /* | ||
134 | * Perform a function on a dcss segment. | ||
135 | */ | ||
136 | static inline int | ||
137 | dcss_diag (__u8 func, void *parameter, | ||
138 | unsigned long *ret1, unsigned long *ret2) | ||
139 | { | ||
140 | unsigned long rx, ry; | ||
141 | int rc; | ||
142 | |||
143 | rx = (unsigned long) parameter; | ||
144 | ry = (unsigned long) func; | ||
145 | __asm__ __volatile__( | ||
146 | #ifdef CONFIG_ARCH_S390X | ||
147 | " sam31\n" // switch to 31 bit | ||
148 | " diag %0,%1,0x64\n" | ||
149 | " sam64\n" // switch back to 64 bit | ||
150 | #else | ||
151 | " diag %0,%1,0x64\n" | ||
152 | #endif | ||
153 | " ipm %2\n" | ||
154 | " srl %2,28\n" | ||
155 | : "+d" (rx), "+d" (ry), "=d" (rc) : : "cc" ); | ||
156 | *ret1 = rx; | ||
157 | *ret2 = ry; | ||
158 | return rc; | ||
159 | } | ||
160 | |||
161 | static inline int | ||
162 | dcss_diag_translate_rc (int vm_rc) { | ||
163 | if (vm_rc == 44) | ||
164 | return -ENOENT; | ||
165 | return -EIO; | ||
166 | } | ||
167 | |||
168 | |||
169 | /* do a diag to get info about a segment. | ||
170 | * fills start_address, end and vm_segtype fields | ||
171 | */ | ||
172 | static int | ||
173 | query_segment_type (struct dcss_segment *seg) | ||
174 | { | ||
175 | struct qin64 *qin = kmalloc (sizeof(struct qin64), GFP_DMA); | ||
176 | struct qout64 *qout = kmalloc (sizeof(struct qout64), GFP_DMA); | ||
177 | |||
178 | int diag_cc, rc, i; | ||
179 | unsigned long dummy, vmrc; | ||
180 | |||
181 | if ((qin == NULL) || (qout == NULL)) { | ||
182 | rc = -ENOMEM; | ||
183 | goto out_free; | ||
184 | } | ||
185 | |||
186 | /* initialize diag input parameters */ | ||
187 | qin->qopcode = DCSS_FINDSEGA; | ||
188 | qin->qoutptr = (unsigned long) qout; | ||
189 | qin->qoutlen = sizeof(struct qout64); | ||
190 | memcpy (qin->qname, seg->dcss_name, 8); | ||
191 | |||
192 | diag_cc = dcss_diag (DCSS_SEGEXT, qin, &dummy, &vmrc); | ||
193 | |||
194 | if (diag_cc > 1) { | ||
195 | rc = dcss_diag_translate_rc (vmrc); | ||
196 | goto out_free; | ||
197 | } | ||
198 | |||
199 | if (qout->segcnt > 6) { | ||
200 | rc = -ENOTSUPP; | ||
201 | goto out_free; | ||
202 | } | ||
203 | |||
204 | if (qout->segcnt == 1) { | ||
205 | seg->vm_segtype = qout->range[0].start & 0xff; | ||
206 | } else { | ||
207 | /* multi-part segment. only one type supported here: | ||
208 | - all parts are contiguous | ||
209 | - all parts are either EW or EN type | ||
210 | - maximum 6 parts allowed */ | ||
211 | unsigned long start = qout->segstart >> PAGE_SHIFT; | ||
212 | for (i=0; i<qout->segcnt; i++) { | ||
213 | if (((qout->range[i].start & 0xff) != SEG_TYPE_EW) && | ||
214 | ((qout->range[i].start & 0xff) != SEG_TYPE_EN)) { | ||
215 | rc = -ENOTSUPP; | ||
216 | goto out_free; | ||
217 | } | ||
218 | if (start != qout->range[i].start >> PAGE_SHIFT) { | ||
219 | rc = -ENOTSUPP; | ||
220 | goto out_free; | ||
221 | } | ||
222 | start = (qout->range[i].end >> PAGE_SHIFT) + 1; | ||
223 | } | ||
224 | seg->vm_segtype = SEG_TYPE_EWEN; | ||
225 | } | ||
226 | |||
227 | /* analyze diag output and update seg */ | ||
228 | seg->start_addr = qout->segstart; | ||
229 | seg->end = qout->segend; | ||
230 | |||
231 | memcpy (seg->range, qout->range, 6*sizeof(struct qrange)); | ||
232 | seg->segcnt = qout->segcnt; | ||
233 | |||
234 | rc = 0; | ||
235 | |||
236 | out_free: | ||
237 | if (qin) kfree(qin); | ||
238 | if (qout) kfree(qout); | ||
239 | return rc; | ||
240 | } | ||
241 | |||
242 | /* | ||
243 | * check if the given segment collides with guest storage. | ||
244 | * returns 1 if this is the case, 0 if no collision was found | ||
245 | */ | ||
246 | static int | ||
247 | segment_overlaps_storage(struct dcss_segment *seg) | ||
248 | { | ||
249 | int i; | ||
250 | |||
251 | for (i=0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) { | ||
252 | if (memory_chunk[i].type != 0) | ||
253 | continue; | ||
254 | if ((memory_chunk[i].addr >> 20) > (seg->end >> 20)) | ||
255 | continue; | ||
256 | if (((memory_chunk[i].addr + memory_chunk[i].size - 1) >> 20) | ||
257 | < (seg->start_addr >> 20)) | ||
258 | continue; | ||
259 | return 1; | ||
260 | } | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * check if segment collides with other segments that are currently loaded | ||
266 | * returns 1 if this is the case, 0 if no collision was found | ||
267 | */ | ||
268 | static int | ||
269 | segment_overlaps_others (struct dcss_segment *seg) | ||
270 | { | ||
271 | struct list_head *l; | ||
272 | struct dcss_segment *tmp; | ||
273 | |||
274 | assert_spin_locked(&dcss_lock); | ||
275 | list_for_each(l, &dcss_list) { | ||
276 | tmp = list_entry(l, struct dcss_segment, list); | ||
277 | if ((tmp->start_addr >> 20) > (seg->end >> 20)) | ||
278 | continue; | ||
279 | if ((tmp->end >> 20) < (seg->start_addr >> 20)) | ||
280 | continue; | ||
281 | if (seg == tmp) | ||
282 | continue; | ||
283 | return 1; | ||
284 | } | ||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * check if segment exceeds the kernel mapping range (detected or set via mem=) | ||
290 | * returns 1 if this is the case, 0 if segment fits into the range | ||
291 | */ | ||
292 | static inline int | ||
293 | segment_exceeds_range (struct dcss_segment *seg) | ||
294 | { | ||
295 | int seg_last_pfn = (seg->end) >> PAGE_SHIFT; | ||
296 | if (seg_last_pfn > max_pfn) | ||
297 | return 1; | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | /* | ||
302 | * get info about a segment | ||
303 | * possible return values: | ||
304 | * -ENOSYS : we are not running on VM | ||
305 | * -EIO : could not perform query diagnose | ||
306 | * -ENOENT : no such segment | ||
307 | * -ENOTSUPP: multi-part segment cannot be used with linux | ||
308 | * -ENOSPC : segment cannot be used (overlaps with storage) | ||
309 | * -ENOMEM : out of memory | ||
310 | * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h | ||
311 | */ | ||
312 | int | ||
313 | segment_type (char* name) | ||
314 | { | ||
315 | int rc; | ||
316 | struct dcss_segment seg; | ||
317 | |||
318 | if (!MACHINE_IS_VM) | ||
319 | return -ENOSYS; | ||
320 | |||
321 | dcss_mkname(name, seg.dcss_name); | ||
322 | rc = query_segment_type (&seg); | ||
323 | if (rc < 0) | ||
324 | return rc; | ||
325 | return seg.vm_segtype; | ||
326 | } | ||
327 | |||
328 | /* | ||
329 | * real segment loading function, called from segment_load | ||
330 | */ | ||
331 | static int | ||
332 | __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long *end) | ||
333 | { | ||
334 | struct dcss_segment *seg = kmalloc(sizeof(struct dcss_segment), | ||
335 | GFP_DMA); | ||
336 | int dcss_command, rc, diag_cc; | ||
337 | |||
338 | if (seg == NULL) { | ||
339 | rc = -ENOMEM; | ||
340 | goto out; | ||
341 | } | ||
342 | dcss_mkname (name, seg->dcss_name); | ||
343 | rc = query_segment_type (seg); | ||
344 | if (rc < 0) | ||
345 | goto out_free; | ||
346 | if (segment_exceeds_range(seg)) { | ||
347 | PRINT_WARN ("segment_load: not loading segment %s - exceeds" | ||
348 | " kernel mapping range\n",name); | ||
349 | rc = -ERANGE; | ||
350 | goto out_free; | ||
351 | } | ||
352 | if (segment_overlaps_storage(seg)) { | ||
353 | PRINT_WARN ("segment_load: not loading segment %s - overlaps" | ||
354 | " storage\n",name); | ||
355 | rc = -ENOSPC; | ||
356 | goto out_free; | ||
357 | } | ||
358 | if (segment_overlaps_others(seg)) { | ||
359 | PRINT_WARN ("segment_load: not loading segment %s - overlaps" | ||
360 | " other segments\n",name); | ||
361 | rc = -EBUSY; | ||
362 | goto out_free; | ||
363 | } | ||
364 | if (do_nonshared) | ||
365 | dcss_command = DCSS_LOADNSR; | ||
366 | else | ||
367 | dcss_command = DCSS_LOADNOLY; | ||
368 | |||
369 | diag_cc = dcss_diag(dcss_command, seg->dcss_name, | ||
370 | &seg->start_addr, &seg->end); | ||
371 | if (diag_cc > 1) { | ||
372 | PRINT_WARN ("segment_load: could not load segment %s - " | ||
373 | "diag returned error (%ld)\n",name,seg->end); | ||
374 | rc = dcss_diag_translate_rc (seg->end); | ||
375 | dcss_diag(DCSS_PURGESEG, seg->dcss_name, | ||
376 | &seg->start_addr, &seg->end); | ||
377 | goto out_free; | ||
378 | } | ||
379 | seg->do_nonshared = do_nonshared; | ||
380 | atomic_set(&seg->ref_count, 1); | ||
381 | list_add(&seg->list, &dcss_list); | ||
382 | rc = seg->vm_segtype; | ||
383 | *addr = seg->start_addr; | ||
384 | *end = seg->end; | ||
385 | if (do_nonshared) | ||
386 | PRINT_INFO ("segment_load: loaded segment %s range %p .. %p " | ||
387 | "type %s in non-shared mode\n", name, | ||
388 | (void*)seg->start_addr, (void*)seg->end, | ||
389 | segtype_string[seg->vm_segtype]); | ||
390 | else | ||
391 | PRINT_INFO ("segment_load: loaded segment %s range %p .. %p " | ||
392 | "type %s in shared mode\n", name, | ||
393 | (void*)seg->start_addr, (void*)seg->end, | ||
394 | segtype_string[seg->vm_segtype]); | ||
395 | goto out; | ||
396 | out_free: | ||
397 | kfree (seg); | ||
398 | out: | ||
399 | return rc; | ||
400 | } | ||
401 | |||
402 | /* | ||
403 | * this function loads a DCSS segment | ||
404 | * name : name of the DCSS | ||
405 | * do_nonshared : 0 indicates that the dcss should be shared with other linux images | ||
406 | * 1 indicates that the dcss should be exclusive for this linux image | ||
407 | * addr : will be filled with start address of the segment | ||
408 | * end : will be filled with end address of the segment | ||
409 | * return values: | ||
410 | * -ENOSYS : we are not running on VM | ||
411 | * -EIO : could not perform query or load diagnose | ||
412 | * -ENOENT : no such segment | ||
413 | * -ENOTSUPP: multi-part segment cannot be used with linux | ||
414 | * -ENOSPC : segment cannot be used (overlaps with storage) | ||
415 | * -EBUSY : segment can temporarily not be used (overlaps with dcss) | ||
416 | * -ERANGE : segment cannot be used (exceeds kernel mapping range) | ||
417 | * -EPERM : segment is currently loaded with incompatible permissions | ||
418 | * -ENOMEM : out of memory | ||
419 | * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h | ||
420 | */ | ||
421 | int | ||
422 | segment_load (char *name, int do_nonshared, unsigned long *addr, | ||
423 | unsigned long *end) | ||
424 | { | ||
425 | struct dcss_segment *seg; | ||
426 | int rc; | ||
427 | |||
428 | if (!MACHINE_IS_VM) | ||
429 | return -ENOSYS; | ||
430 | |||
431 | spin_lock (&dcss_lock); | ||
432 | seg = segment_by_name (name); | ||
433 | if (seg == NULL) | ||
434 | rc = __segment_load (name, do_nonshared, addr, end); | ||
435 | else { | ||
436 | if (do_nonshared == seg->do_nonshared) { | ||
437 | atomic_inc(&seg->ref_count); | ||
438 | *addr = seg->start_addr; | ||
439 | *end = seg->end; | ||
440 | rc = seg->vm_segtype; | ||
441 | } else { | ||
442 | *addr = *end = 0; | ||
443 | rc = -EPERM; | ||
444 | } | ||
445 | } | ||
446 | spin_unlock (&dcss_lock); | ||
447 | return rc; | ||
448 | } | ||
449 | |||
450 | /* | ||
451 | * this function modifies the shared state of a DCSS segment. note that | ||
452 | * name : name of the DCSS | ||
453 | * do_nonshared : 0 indicates that the dcss should be shared with other linux images | ||
454 | * 1 indicates that the dcss should be exclusive for this linux image | ||
455 | * return values: | ||
456 | * -EIO : could not perform load diagnose (segment gone!) | ||
457 | * -ENOENT : no such segment (segment gone!) | ||
458 | * -EAGAIN : segment is in use by other exploiters, try later | ||
459 | * -EINVAL : no segment with the given name is currently loaded - name invalid | ||
460 | * 0 : operation succeeded | ||
461 | */ | ||
462 | int | ||
463 | segment_modify_shared (char *name, int do_nonshared) | ||
464 | { | ||
465 | struct dcss_segment *seg; | ||
466 | unsigned long dummy; | ||
467 | int dcss_command, rc, diag_cc; | ||
468 | |||
469 | spin_lock (&dcss_lock); | ||
470 | seg = segment_by_name (name); | ||
471 | if (seg == NULL) { | ||
472 | rc = -EINVAL; | ||
473 | goto out_unlock; | ||
474 | } | ||
475 | if (do_nonshared == seg->do_nonshared) { | ||
476 | PRINT_INFO ("segment_modify_shared: not reloading segment %s" | ||
477 | " - already in requested mode\n",name); | ||
478 | rc = 0; | ||
479 | goto out_unlock; | ||
480 | } | ||
481 | if (atomic_read (&seg->ref_count) != 1) { | ||
482 | PRINT_WARN ("segment_modify_shared: not reloading segment %s - " | ||
483 | "segment is in use by other driver(s)\n",name); | ||
484 | rc = -EAGAIN; | ||
485 | goto out_unlock; | ||
486 | } | ||
487 | dcss_diag(DCSS_PURGESEG, seg->dcss_name, | ||
488 | &dummy, &dummy); | ||
489 | if (do_nonshared) | ||
490 | dcss_command = DCSS_LOADNSR; | ||
491 | else | ||
492 | dcss_command = DCSS_LOADNOLY; | ||
493 | diag_cc = dcss_diag(dcss_command, seg->dcss_name, | ||
494 | &seg->start_addr, &seg->end); | ||
495 | if (diag_cc > 1) { | ||
496 | PRINT_WARN ("segment_modify_shared: could not reload segment %s" | ||
497 | " - diag returned error (%ld)\n",name,seg->end); | ||
498 | rc = dcss_diag_translate_rc (seg->end); | ||
499 | goto out_del; | ||
500 | } | ||
501 | seg->do_nonshared = do_nonshared; | ||
502 | rc = 0; | ||
503 | goto out_unlock; | ||
504 | out_del: | ||
505 | list_del(&seg->list); | ||
506 | dcss_diag(DCSS_PURGESEG, seg->dcss_name, | ||
507 | &dummy, &dummy); | ||
508 | kfree (seg); | ||
509 | out_unlock: | ||
510 | spin_unlock(&dcss_lock); | ||
511 | return rc; | ||
512 | } | ||
513 | |||
514 | /* | ||
515 | * Decrease the use count of a DCSS segment and remove | ||
516 | * it from the address space if nobody is using it | ||
517 | * any longer. | ||
518 | */ | ||
519 | void | ||
520 | segment_unload(char *name) | ||
521 | { | ||
522 | unsigned long dummy; | ||
523 | struct dcss_segment *seg; | ||
524 | |||
525 | if (!MACHINE_IS_VM) | ||
526 | return; | ||
527 | |||
528 | spin_lock(&dcss_lock); | ||
529 | seg = segment_by_name (name); | ||
530 | if (seg == NULL) { | ||
531 | PRINT_ERR ("could not find segment %s in segment_unload, " | ||
532 | "please report to linux390@de.ibm.com\n",name); | ||
533 | goto out_unlock; | ||
534 | } | ||
535 | if (atomic_dec_return(&seg->ref_count) == 0) { | ||
536 | list_del(&seg->list); | ||
537 | dcss_diag(DCSS_PURGESEG, seg->dcss_name, | ||
538 | &dummy, &dummy); | ||
539 | kfree(seg); | ||
540 | } | ||
541 | out_unlock: | ||
542 | spin_unlock(&dcss_lock); | ||
543 | } | ||
544 | |||
545 | /* | ||
546 | * save segment content permanently | ||
547 | */ | ||
548 | void | ||
549 | segment_save(char *name) | ||
550 | { | ||
551 | struct dcss_segment *seg; | ||
552 | int startpfn = 0; | ||
553 | int endpfn = 0; | ||
554 | char cmd1[160]; | ||
555 | char cmd2[80]; | ||
556 | int i; | ||
557 | |||
558 | if (!MACHINE_IS_VM) | ||
559 | return; | ||
560 | |||
561 | spin_lock(&dcss_lock); | ||
562 | seg = segment_by_name (name); | ||
563 | |||
564 | if (seg == NULL) { | ||
565 | PRINT_ERR ("could not find segment %s in segment_save, please report to linux390@de.ibm.com\n",name); | ||
566 | return; | ||
567 | } | ||
568 | |||
569 | startpfn = seg->start_addr >> PAGE_SHIFT; | ||
570 | endpfn = (seg->end) >> PAGE_SHIFT; | ||
571 | sprintf(cmd1, "DEFSEG %s", name); | ||
572 | for (i=0; i<seg->segcnt; i++) { | ||
573 | sprintf(cmd1+strlen(cmd1), " %X-%X %s", | ||
574 | seg->range[i].start >> PAGE_SHIFT, | ||
575 | seg->range[i].end >> PAGE_SHIFT, | ||
576 | segtype_string[seg->range[i].start & 0xff]); | ||
577 | } | ||
578 | sprintf(cmd2, "SAVESEG %s", name); | ||
579 | cpcmd(cmd1, NULL, 0); | ||
580 | cpcmd(cmd2, NULL, 0); | ||
581 | spin_unlock(&dcss_lock); | ||
582 | } | ||
583 | |||
584 | EXPORT_SYMBOL(segment_load); | ||
585 | EXPORT_SYMBOL(segment_unload); | ||
586 | EXPORT_SYMBOL(segment_save); | ||
587 | EXPORT_SYMBOL(segment_type); | ||
588 | EXPORT_SYMBOL(segment_modify_shared); | ||
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c new file mode 100644 index 000000000000..80306bc8c799 --- /dev/null +++ b/arch/s390/mm/fault.c | |||
@@ -0,0 +1,586 @@ | |||
1 | /* | ||
2 | * arch/s390/mm/fault.c | ||
3 | * | ||
4 | * S390 version | ||
5 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation | ||
6 | * Author(s): Hartmut Penner (hp@de.ibm.com) | ||
7 | * Ulrich Weigand (uweigand@de.ibm.com) | ||
8 | * | ||
9 | * Derived from "arch/i386/mm/fault.c" | ||
10 | * Copyright (C) 1995 Linus Torvalds | ||
11 | */ | ||
12 | |||
13 | #include <linux/config.h> | ||
14 | #include <linux/signal.h> | ||
15 | #include <linux/sched.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/string.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/ptrace.h> | ||
21 | #include <linux/mman.h> | ||
22 | #include <linux/mm.h> | ||
23 | #include <linux/smp.h> | ||
24 | #include <linux/smp_lock.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/console.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/hardirq.h> | ||
29 | |||
30 | #include <asm/system.h> | ||
31 | #include <asm/uaccess.h> | ||
32 | #include <asm/pgtable.h> | ||
33 | |||
34 | #ifndef CONFIG_ARCH_S390X | ||
35 | #define __FAIL_ADDR_MASK 0x7ffff000 | ||
36 | #define __FIXUP_MASK 0x7fffffff | ||
37 | #define __SUBCODE_MASK 0x0200 | ||
38 | #define __PF_RES_FIELD 0ULL | ||
39 | #else /* CONFIG_ARCH_S390X */ | ||
40 | #define __FAIL_ADDR_MASK -4096L | ||
41 | #define __FIXUP_MASK ~0L | ||
42 | #define __SUBCODE_MASK 0x0600 | ||
43 | #define __PF_RES_FIELD 0x8000000000000000ULL | ||
44 | #endif /* CONFIG_ARCH_S390X */ | ||
45 | |||
46 | #ifdef CONFIG_SYSCTL | ||
47 | extern int sysctl_userprocess_debug; | ||
48 | #endif | ||
49 | |||
50 | extern void die(const char *,struct pt_regs *,long); | ||
51 | |||
52 | extern spinlock_t timerlist_lock; | ||
53 | |||
54 | /* | ||
55 | * Unlock any spinlocks which will prevent us from getting the | ||
56 | * message out (timerlist_lock is acquired through the | ||
57 | * console unblank code) | ||
58 | */ | ||
59 | void bust_spinlocks(int yes) | ||
60 | { | ||
61 | if (yes) { | ||
62 | oops_in_progress = 1; | ||
63 | } else { | ||
64 | int loglevel_save = console_loglevel; | ||
65 | console_unblank(); | ||
66 | oops_in_progress = 0; | ||
67 | /* | ||
68 | * OK, the message is on the console. Now we call printk() | ||
69 | * without oops_in_progress set so that printk will give klogd | ||
70 | * a poke. Hold onto your hats... | ||
71 | */ | ||
72 | console_loglevel = 15; | ||
73 | printk(" "); | ||
74 | console_loglevel = loglevel_save; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * Check which address space is addressed by the access | ||
80 | * register in S390_lowcore.exc_access_id. | ||
81 | * Returns 1 for user space and 0 for kernel space. | ||
82 | */ | ||
83 | static int __check_access_register(struct pt_regs *regs, int error_code) | ||
84 | { | ||
85 | int areg = S390_lowcore.exc_access_id; | ||
86 | |||
87 | if (areg == 0) | ||
88 | /* Access via access register 0 -> kernel address */ | ||
89 | return 0; | ||
90 | save_access_regs(current->thread.acrs); | ||
91 | if (regs && areg < NUM_ACRS && current->thread.acrs[areg] <= 1) | ||
92 | /* | ||
93 | * access register contains 0 -> kernel address, | ||
94 | * access register contains 1 -> user space address | ||
95 | */ | ||
96 | return current->thread.acrs[areg]; | ||
97 | |||
98 | /* Something unhealthy was done with the access registers... */ | ||
99 | die("page fault via unknown access register", regs, error_code); | ||
100 | do_exit(SIGKILL); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | /* | ||
105 | * Check which address space the address belongs to. | ||
106 | * Returns 1 for user space and 0 for kernel space. | ||
107 | */ | ||
108 | static inline int check_user_space(struct pt_regs *regs, int error_code) | ||
109 | { | ||
110 | /* | ||
111 | * The lowest two bits of S390_lowcore.trans_exc_code indicate | ||
112 | * which paging table was used: | ||
113 | * 0: Primary Segment Table Descriptor | ||
114 | * 1: STD determined via access register | ||
115 | * 2: Secondary Segment Table Descriptor | ||
116 | * 3: Home Segment Table Descriptor | ||
117 | */ | ||
118 | int descriptor = S390_lowcore.trans_exc_code & 3; | ||
119 | if (unlikely(descriptor == 1)) | ||
120 | return __check_access_register(regs, error_code); | ||
121 | if (descriptor == 2) | ||
122 | return current->thread.mm_segment.ar4; | ||
123 | return descriptor != 0; | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * Send SIGSEGV to task. This is an external routine | ||
128 | * to keep the stack usage of do_page_fault small. | ||
129 | */ | ||
130 | static void do_sigsegv(struct pt_regs *regs, unsigned long error_code, | ||
131 | int si_code, unsigned long address) | ||
132 | { | ||
133 | struct siginfo si; | ||
134 | |||
135 | #if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG) | ||
136 | #if defined(CONFIG_SYSCTL) | ||
137 | if (sysctl_userprocess_debug) | ||
138 | #endif | ||
139 | { | ||
140 | printk("User process fault: interruption code 0x%lX\n", | ||
141 | error_code); | ||
142 | printk("failing address: %lX\n", address); | ||
143 | show_regs(regs); | ||
144 | } | ||
145 | #endif | ||
146 | si.si_signo = SIGSEGV; | ||
147 | si.si_code = si_code; | ||
148 | si.si_addr = (void *) address; | ||
149 | force_sig_info(SIGSEGV, &si, current); | ||
150 | } | ||
151 | |||
152 | /* | ||
153 | * This routine handles page faults. It determines the address, | ||
154 | * and the problem, and then passes it off to one of the appropriate | ||
155 | * routines. | ||
156 | * | ||
157 | * error_code: | ||
158 | * 04 Protection -> Write-Protection (suprression) | ||
159 | * 10 Segment translation -> Not present (nullification) | ||
160 | * 11 Page translation -> Not present (nullification) | ||
161 | * 3b Region third trans. -> Not present (nullification) | ||
162 | */ | ||
163 | extern inline void | ||
164 | do_exception(struct pt_regs *regs, unsigned long error_code, int is_protection) | ||
165 | { | ||
166 | struct task_struct *tsk; | ||
167 | struct mm_struct *mm; | ||
168 | struct vm_area_struct * vma; | ||
169 | unsigned long address; | ||
170 | int user_address; | ||
171 | const struct exception_table_entry *fixup; | ||
172 | int si_code = SEGV_MAPERR; | ||
173 | |||
174 | tsk = current; | ||
175 | mm = tsk->mm; | ||
176 | |||
177 | /* | ||
178 | * Check for low-address protection. This needs to be treated | ||
179 | * as a special case because the translation exception code | ||
180 | * field is not guaranteed to contain valid data in this case. | ||
181 | */ | ||
182 | if (is_protection && !(S390_lowcore.trans_exc_code & 4)) { | ||
183 | |||
184 | /* Low-address protection hit in kernel mode means | ||
185 | NULL pointer write access in kernel mode. */ | ||
186 | if (!(regs->psw.mask & PSW_MASK_PSTATE)) { | ||
187 | address = 0; | ||
188 | user_address = 0; | ||
189 | goto no_context; | ||
190 | } | ||
191 | |||
192 | /* Low-address protection hit in user mode 'cannot happen'. */ | ||
193 | die ("Low-address protection", regs, error_code); | ||
194 | do_exit(SIGKILL); | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | * get the failing address | ||
199 | * more specific the segment and page table portion of | ||
200 | * the address | ||
201 | */ | ||
202 | address = S390_lowcore.trans_exc_code & __FAIL_ADDR_MASK; | ||
203 | user_address = check_user_space(regs, error_code); | ||
204 | |||
205 | /* | ||
206 | * Verify that the fault happened in user space, that | ||
207 | * we are not in an interrupt and that there is a | ||
208 | * user context. | ||
209 | */ | ||
210 | if (user_address == 0 || in_interrupt() || !mm) | ||
211 | goto no_context; | ||
212 | |||
213 | /* | ||
214 | * When we get here, the fault happened in the current | ||
215 | * task's user address space, so we can switch on the | ||
216 | * interrupts again and then search the VMAs | ||
217 | */ | ||
218 | local_irq_enable(); | ||
219 | |||
220 | down_read(&mm->mmap_sem); | ||
221 | |||
222 | vma = find_vma(mm, address); | ||
223 | if (!vma) | ||
224 | goto bad_area; | ||
225 | if (vma->vm_start <= address) | ||
226 | goto good_area; | ||
227 | if (!(vma->vm_flags & VM_GROWSDOWN)) | ||
228 | goto bad_area; | ||
229 | if (expand_stack(vma, address)) | ||
230 | goto bad_area; | ||
231 | /* | ||
232 | * Ok, we have a good vm_area for this memory access, so | ||
233 | * we can handle it.. | ||
234 | */ | ||
235 | good_area: | ||
236 | si_code = SEGV_ACCERR; | ||
237 | if (!is_protection) { | ||
238 | /* page not present, check vm flags */ | ||
239 | if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) | ||
240 | goto bad_area; | ||
241 | } else { | ||
242 | if (!(vma->vm_flags & VM_WRITE)) | ||
243 | goto bad_area; | ||
244 | } | ||
245 | |||
246 | survive: | ||
247 | /* | ||
248 | * If for any reason at all we couldn't handle the fault, | ||
249 | * make sure we exit gracefully rather than endlessly redo | ||
250 | * the fault. | ||
251 | */ | ||
252 | switch (handle_mm_fault(mm, vma, address, is_protection)) { | ||
253 | case VM_FAULT_MINOR: | ||
254 | tsk->min_flt++; | ||
255 | break; | ||
256 | case VM_FAULT_MAJOR: | ||
257 | tsk->maj_flt++; | ||
258 | break; | ||
259 | case VM_FAULT_SIGBUS: | ||
260 | goto do_sigbus; | ||
261 | case VM_FAULT_OOM: | ||
262 | goto out_of_memory; | ||
263 | default: | ||
264 | BUG(); | ||
265 | } | ||
266 | |||
267 | up_read(&mm->mmap_sem); | ||
268 | /* | ||
269 | * The instruction that caused the program check will | ||
270 | * be repeated. Don't signal single step via SIGTRAP. | ||
271 | */ | ||
272 | clear_tsk_thread_flag(current, TIF_SINGLE_STEP); | ||
273 | return; | ||
274 | |||
275 | /* | ||
276 | * Something tried to access memory that isn't in our memory map.. | ||
277 | * Fix it, but check if it's kernel or user first.. | ||
278 | */ | ||
279 | bad_area: | ||
280 | up_read(&mm->mmap_sem); | ||
281 | |||
282 | /* User mode accesses just cause a SIGSEGV */ | ||
283 | if (regs->psw.mask & PSW_MASK_PSTATE) { | ||
284 | tsk->thread.prot_addr = address; | ||
285 | tsk->thread.trap_no = error_code; | ||
286 | do_sigsegv(regs, error_code, si_code, address); | ||
287 | return; | ||
288 | } | ||
289 | |||
290 | no_context: | ||
291 | /* Are we prepared to handle this kernel fault? */ | ||
292 | fixup = search_exception_tables(regs->psw.addr & __FIXUP_MASK); | ||
293 | if (fixup) { | ||
294 | regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE; | ||
295 | return; | ||
296 | } | ||
297 | |||
298 | /* | ||
299 | * Oops. The kernel tried to access some bad page. We'll have to | ||
300 | * terminate things with extreme prejudice. | ||
301 | */ | ||
302 | if (user_address == 0) | ||
303 | printk(KERN_ALERT "Unable to handle kernel pointer dereference" | ||
304 | " at virtual kernel address %p\n", (void *)address); | ||
305 | else | ||
306 | printk(KERN_ALERT "Unable to handle kernel paging request" | ||
307 | " at virtual user address %p\n", (void *)address); | ||
308 | |||
309 | die("Oops", regs, error_code); | ||
310 | do_exit(SIGKILL); | ||
311 | |||
312 | |||
313 | /* | ||
314 | * We ran out of memory, or some other thing happened to us that made | ||
315 | * us unable to handle the page fault gracefully. | ||
316 | */ | ||
317 | out_of_memory: | ||
318 | up_read(&mm->mmap_sem); | ||
319 | if (tsk->pid == 1) { | ||
320 | yield(); | ||
321 | goto survive; | ||
322 | } | ||
323 | printk("VM: killing process %s\n", tsk->comm); | ||
324 | if (regs->psw.mask & PSW_MASK_PSTATE) | ||
325 | do_exit(SIGKILL); | ||
326 | goto no_context; | ||
327 | |||
328 | do_sigbus: | ||
329 | up_read(&mm->mmap_sem); | ||
330 | |||
331 | /* | ||
332 | * Send a sigbus, regardless of whether we were in kernel | ||
333 | * or user mode. | ||
334 | */ | ||
335 | tsk->thread.prot_addr = address; | ||
336 | tsk->thread.trap_no = error_code; | ||
337 | force_sig(SIGBUS, tsk); | ||
338 | |||
339 | /* Kernel mode? Handle exceptions or die */ | ||
340 | if (!(regs->psw.mask & PSW_MASK_PSTATE)) | ||
341 | goto no_context; | ||
342 | } | ||
343 | |||
344 | void do_protection_exception(struct pt_regs *regs, unsigned long error_code) | ||
345 | { | ||
346 | regs->psw.addr -= (error_code >> 16); | ||
347 | do_exception(regs, 4, 1); | ||
348 | } | ||
349 | |||
350 | void do_dat_exception(struct pt_regs *regs, unsigned long error_code) | ||
351 | { | ||
352 | do_exception(regs, error_code & 0xff, 0); | ||
353 | } | ||
354 | |||
355 | #ifndef CONFIG_ARCH_S390X | ||
356 | |||
357 | typedef struct _pseudo_wait_t { | ||
358 | struct _pseudo_wait_t *next; | ||
359 | wait_queue_head_t queue; | ||
360 | unsigned long address; | ||
361 | int resolved; | ||
362 | } pseudo_wait_t; | ||
363 | |||
364 | static pseudo_wait_t *pseudo_lock_queue = NULL; | ||
365 | static spinlock_t pseudo_wait_spinlock; /* spinlock to protect lock queue */ | ||
366 | |||
367 | /* | ||
368 | * This routine handles 'pagex' pseudo page faults. | ||
369 | */ | ||
370 | asmlinkage void | ||
371 | do_pseudo_page_fault(struct pt_regs *regs, unsigned long error_code) | ||
372 | { | ||
373 | pseudo_wait_t wait_struct; | ||
374 | pseudo_wait_t *ptr, *last, *next; | ||
375 | unsigned long address; | ||
376 | |||
377 | /* | ||
378 | * get the failing address | ||
379 | * more specific the segment and page table portion of | ||
380 | * the address | ||
381 | */ | ||
382 | address = S390_lowcore.trans_exc_code & 0xfffff000; | ||
383 | |||
384 | if (address & 0x80000000) { | ||
385 | /* high bit set -> a page has been swapped in by VM */ | ||
386 | address &= 0x7fffffff; | ||
387 | spin_lock(&pseudo_wait_spinlock); | ||
388 | last = NULL; | ||
389 | ptr = pseudo_lock_queue; | ||
390 | while (ptr != NULL) { | ||
391 | next = ptr->next; | ||
392 | if (address == ptr->address) { | ||
393 | /* | ||
394 | * This is one of the processes waiting | ||
395 | * for the page. Unchain from the queue. | ||
396 | * There can be more than one process | ||
397 | * waiting for the same page. VM presents | ||
398 | * an initial and a completion interrupt for | ||
399 | * every process that tries to access a | ||
400 | * page swapped out by VM. | ||
401 | */ | ||
402 | if (last == NULL) | ||
403 | pseudo_lock_queue = next; | ||
404 | else | ||
405 | last->next = next; | ||
406 | /* now wake up the process */ | ||
407 | ptr->resolved = 1; | ||
408 | wake_up(&ptr->queue); | ||
409 | } else | ||
410 | last = ptr; | ||
411 | ptr = next; | ||
412 | } | ||
413 | spin_unlock(&pseudo_wait_spinlock); | ||
414 | } else { | ||
415 | /* Pseudo page faults in kernel mode is a bad idea */ | ||
416 | if (!(regs->psw.mask & PSW_MASK_PSTATE)) { | ||
417 | /* | ||
418 | * VM presents pseudo page faults if the interrupted | ||
419 | * state was not disabled for interrupts. So we can | ||
420 | * get pseudo page fault interrupts while running | ||
421 | * in kernel mode. We simply access the page here | ||
422 | * while we are running disabled. VM will then swap | ||
423 | * in the page synchronously. | ||
424 | */ | ||
425 | if (check_user_space(regs, error_code) == 0) | ||
426 | /* dereference a virtual kernel address */ | ||
427 | __asm__ __volatile__ ( | ||
428 | " ic 0,0(%0)" | ||
429 | : : "a" (address) : "0"); | ||
430 | else | ||
431 | /* dereference a virtual user address */ | ||
432 | __asm__ __volatile__ ( | ||
433 | " la 2,0(%0)\n" | ||
434 | " sacf 512\n" | ||
435 | " ic 2,0(2)\n" | ||
436 | "0:sacf 0\n" | ||
437 | ".section __ex_table,\"a\"\n" | ||
438 | " .align 4\n" | ||
439 | " .long 0b,0b\n" | ||
440 | ".previous" | ||
441 | : : "a" (address) : "2" ); | ||
442 | |||
443 | return; | ||
444 | } | ||
445 | /* initialize and add element to pseudo_lock_queue */ | ||
446 | init_waitqueue_head (&wait_struct.queue); | ||
447 | wait_struct.address = address; | ||
448 | wait_struct.resolved = 0; | ||
449 | spin_lock(&pseudo_wait_spinlock); | ||
450 | wait_struct.next = pseudo_lock_queue; | ||
451 | pseudo_lock_queue = &wait_struct; | ||
452 | spin_unlock(&pseudo_wait_spinlock); | ||
453 | /* | ||
454 | * The instruction that caused the program check will | ||
455 | * be repeated. Don't signal single step via SIGTRAP. | ||
456 | */ | ||
457 | clear_tsk_thread_flag(current, TIF_SINGLE_STEP); | ||
458 | /* go to sleep */ | ||
459 | wait_event(wait_struct.queue, wait_struct.resolved); | ||
460 | } | ||
461 | } | ||
462 | #endif /* CONFIG_ARCH_S390X */ | ||
463 | |||
464 | #ifdef CONFIG_PFAULT | ||
465 | /* | ||
466 | * 'pfault' pseudo page faults routines. | ||
467 | */ | ||
468 | static int pfault_disable = 0; | ||
469 | |||
470 | static int __init nopfault(char *str) | ||
471 | { | ||
472 | pfault_disable = 1; | ||
473 | return 1; | ||
474 | } | ||
475 | |||
476 | __setup("nopfault", nopfault); | ||
477 | |||
478 | typedef struct { | ||
479 | __u16 refdiagc; | ||
480 | __u16 reffcode; | ||
481 | __u16 refdwlen; | ||
482 | __u16 refversn; | ||
483 | __u64 refgaddr; | ||
484 | __u64 refselmk; | ||
485 | __u64 refcmpmk; | ||
486 | __u64 reserved; | ||
487 | } __attribute__ ((packed)) pfault_refbk_t; | ||
488 | |||
489 | int pfault_init(void) | ||
490 | { | ||
491 | pfault_refbk_t refbk = | ||
492 | { 0x258, 0, 5, 2, __LC_CURRENT, 1ULL << 48, 1ULL << 48, | ||
493 | __PF_RES_FIELD }; | ||
494 | int rc; | ||
495 | |||
496 | if (pfault_disable) | ||
497 | return -1; | ||
498 | __asm__ __volatile__( | ||
499 | " diag %1,%0,0x258\n" | ||
500 | "0: j 2f\n" | ||
501 | "1: la %0,8\n" | ||
502 | "2:\n" | ||
503 | ".section __ex_table,\"a\"\n" | ||
504 | " .align 4\n" | ||
505 | #ifndef CONFIG_ARCH_S390X | ||
506 | " .long 0b,1b\n" | ||
507 | #else /* CONFIG_ARCH_S390X */ | ||
508 | " .quad 0b,1b\n" | ||
509 | #endif /* CONFIG_ARCH_S390X */ | ||
510 | ".previous" | ||
511 | : "=d" (rc) : "a" (&refbk) : "cc" ); | ||
512 | __ctl_set_bit(0, 9); | ||
513 | return rc; | ||
514 | } | ||
515 | |||
516 | void pfault_fini(void) | ||
517 | { | ||
518 | pfault_refbk_t refbk = | ||
519 | { 0x258, 1, 5, 2, 0ULL, 0ULL, 0ULL, 0ULL }; | ||
520 | |||
521 | if (pfault_disable) | ||
522 | return; | ||
523 | __ctl_clear_bit(0,9); | ||
524 | __asm__ __volatile__( | ||
525 | " diag %0,0,0x258\n" | ||
526 | "0:\n" | ||
527 | ".section __ex_table,\"a\"\n" | ||
528 | " .align 4\n" | ||
529 | #ifndef CONFIG_ARCH_S390X | ||
530 | " .long 0b,0b\n" | ||
531 | #else /* CONFIG_ARCH_S390X */ | ||
532 | " .quad 0b,0b\n" | ||
533 | #endif /* CONFIG_ARCH_S390X */ | ||
534 | ".previous" | ||
535 | : : "a" (&refbk) : "cc" ); | ||
536 | } | ||
537 | |||
538 | asmlinkage void | ||
539 | pfault_interrupt(struct pt_regs *regs, __u16 error_code) | ||
540 | { | ||
541 | struct task_struct *tsk; | ||
542 | __u16 subcode; | ||
543 | |||
544 | /* | ||
545 | * Get the external interruption subcode & pfault | ||
546 | * initial/completion signal bit. VM stores this | ||
547 | * in the 'cpu address' field associated with the | ||
548 | * external interrupt. | ||
549 | */ | ||
550 | subcode = S390_lowcore.cpu_addr; | ||
551 | if ((subcode & 0xff00) != __SUBCODE_MASK) | ||
552 | return; | ||
553 | |||
554 | /* | ||
555 | * Get the token (= address of the task structure of the affected task). | ||
556 | */ | ||
557 | tsk = *(struct task_struct **) __LC_PFAULT_INTPARM; | ||
558 | |||
559 | if (subcode & 0x0080) { | ||
560 | /* signal bit is set -> a page has been swapped in by VM */ | ||
561 | if (xchg(&tsk->thread.pfault_wait, -1) != 0) { | ||
562 | /* Initial interrupt was faster than the completion | ||
563 | * interrupt. pfault_wait is valid. Set pfault_wait | ||
564 | * back to zero and wake up the process. This can | ||
565 | * safely be done because the task is still sleeping | ||
566 | * and can't procude new pfaults. */ | ||
567 | tsk->thread.pfault_wait = 0; | ||
568 | wake_up_process(tsk); | ||
569 | } | ||
570 | } else { | ||
571 | /* signal bit not set -> a real page is missing. */ | ||
572 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
573 | if (xchg(&tsk->thread.pfault_wait, 1) != 0) { | ||
574 | /* Completion interrupt was faster than the initial | ||
575 | * interrupt (swapped in a -1 for pfault_wait). Set | ||
576 | * pfault_wait back to zero and exit. This can be | ||
577 | * done safely because tsk is running in kernel | ||
578 | * mode and can't produce new pfaults. */ | ||
579 | tsk->thread.pfault_wait = 0; | ||
580 | set_task_state(tsk, TASK_RUNNING); | ||
581 | } else | ||
582 | set_tsk_need_resched(tsk); | ||
583 | } | ||
584 | } | ||
585 | #endif | ||
586 | |||
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c new file mode 100644 index 000000000000..8e723bc7f795 --- /dev/null +++ b/arch/s390/mm/init.c | |||
@@ -0,0 +1,310 @@ | |||
1 | /* | ||
2 | * arch/s390/mm/init.c | ||
3 | * | ||
4 | * S390 version | ||
5 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation | ||
6 | * Author(s): Hartmut Penner (hp@de.ibm.com) | ||
7 | * | ||
8 | * Derived from "arch/i386/mm/init.c" | ||
9 | * Copyright (C) 1995 Linus Torvalds | ||
10 | */ | ||
11 | |||
12 | #include <linux/config.h> | ||
13 | #include <linux/signal.h> | ||
14 | #include <linux/sched.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/string.h> | ||
18 | #include <linux/types.h> | ||
19 | #include <linux/ptrace.h> | ||
20 | #include <linux/mman.h> | ||
21 | #include <linux/mm.h> | ||
22 | #include <linux/swap.h> | ||
23 | #include <linux/smp.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/pagemap.h> | ||
26 | #include <linux/bootmem.h> | ||
27 | |||
28 | #include <asm/processor.h> | ||
29 | #include <asm/system.h> | ||
30 | #include <asm/uaccess.h> | ||
31 | #include <asm/pgtable.h> | ||
32 | #include <asm/pgalloc.h> | ||
33 | #include <asm/dma.h> | ||
34 | #include <asm/lowcore.h> | ||
35 | #include <asm/tlb.h> | ||
36 | #include <asm/tlbflush.h> | ||
37 | |||
38 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | ||
39 | |||
40 | pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE))); | ||
41 | char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); | ||
42 | |||
43 | void diag10(unsigned long addr) | ||
44 | { | ||
45 | if (addr >= 0x7ff00000) | ||
46 | return; | ||
47 | #ifdef __s390x__ | ||
48 | asm volatile ( | ||
49 | " sam31\n" | ||
50 | " diag %0,%0,0x10\n" | ||
51 | "0: sam64\n" | ||
52 | ".section __ex_table,\"a\"\n" | ||
53 | " .align 8\n" | ||
54 | " .quad 0b, 0b\n" | ||
55 | ".previous\n" | ||
56 | : : "a" (addr)); | ||
57 | #else | ||
58 | asm volatile ( | ||
59 | " diag %0,%0,0x10\n" | ||
60 | "0:\n" | ||
61 | ".section __ex_table,\"a\"\n" | ||
62 | " .align 4\n" | ||
63 | " .long 0b, 0b\n" | ||
64 | ".previous\n" | ||
65 | : : "a" (addr)); | ||
66 | #endif | ||
67 | } | ||
68 | |||
69 | void show_mem(void) | ||
70 | { | ||
71 | int i, total = 0, reserved = 0; | ||
72 | int shared = 0, cached = 0; | ||
73 | |||
74 | printk("Mem-info:\n"); | ||
75 | show_free_areas(); | ||
76 | printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); | ||
77 | i = max_mapnr; | ||
78 | while (i-- > 0) { | ||
79 | total++; | ||
80 | if (PageReserved(mem_map+i)) | ||
81 | reserved++; | ||
82 | else if (PageSwapCache(mem_map+i)) | ||
83 | cached++; | ||
84 | else if (page_count(mem_map+i)) | ||
85 | shared += page_count(mem_map+i) - 1; | ||
86 | } | ||
87 | printk("%d pages of RAM\n",total); | ||
88 | printk("%d reserved pages\n",reserved); | ||
89 | printk("%d pages shared\n",shared); | ||
90 | printk("%d pages swap cached\n",cached); | ||
91 | } | ||
92 | |||
93 | /* References to section boundaries */ | ||
94 | |||
95 | extern unsigned long _text; | ||
96 | extern unsigned long _etext; | ||
97 | extern unsigned long _edata; | ||
98 | extern unsigned long __bss_start; | ||
99 | extern unsigned long _end; | ||
100 | |||
101 | extern unsigned long __init_begin; | ||
102 | extern unsigned long __init_end; | ||
103 | |||
104 | /* | ||
105 | * paging_init() sets up the page tables | ||
106 | */ | ||
107 | |||
108 | #ifndef CONFIG_ARCH_S390X | ||
109 | void __init paging_init(void) | ||
110 | { | ||
111 | pgd_t * pg_dir; | ||
112 | pte_t * pg_table; | ||
113 | pte_t pte; | ||
114 | int i; | ||
115 | unsigned long tmp; | ||
116 | unsigned long pfn = 0; | ||
117 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE; | ||
118 | static const int ssm_mask = 0x04000000L; | ||
119 | |||
120 | /* unmap whole virtual address space */ | ||
121 | |||
122 | pg_dir = swapper_pg_dir; | ||
123 | |||
124 | for (i=0;i<KERNEL_PGD_PTRS;i++) | ||
125 | pmd_clear((pmd_t*)pg_dir++); | ||
126 | |||
127 | /* | ||
128 | * map whole physical memory to virtual memory (identity mapping) | ||
129 | */ | ||
130 | |||
131 | pg_dir = swapper_pg_dir; | ||
132 | |||
133 | while (pfn < max_low_pfn) { | ||
134 | /* | ||
135 | * pg_table is physical at this point | ||
136 | */ | ||
137 | pg_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); | ||
138 | |||
139 | pg_dir->pgd0 = (_PAGE_TABLE | __pa(pg_table)); | ||
140 | pg_dir->pgd1 = (_PAGE_TABLE | (__pa(pg_table)+1024)); | ||
141 | pg_dir->pgd2 = (_PAGE_TABLE | (__pa(pg_table)+2048)); | ||
142 | pg_dir->pgd3 = (_PAGE_TABLE | (__pa(pg_table)+3072)); | ||
143 | pg_dir++; | ||
144 | |||
145 | for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) { | ||
146 | pte = pfn_pte(pfn, PAGE_KERNEL); | ||
147 | if (pfn >= max_low_pfn) | ||
148 | pte_clear(&init_mm, 0, &pte); | ||
149 | set_pte(pg_table, pte); | ||
150 | pfn++; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | S390_lowcore.kernel_asce = pgdir_k; | ||
155 | |||
156 | /* enable virtual mapping in kernel mode */ | ||
157 | __asm__ __volatile__(" LCTL 1,1,%0\n" | ||
158 | " LCTL 7,7,%0\n" | ||
159 | " LCTL 13,13,%0\n" | ||
160 | " SSM %1" | ||
161 | : : "m" (pgdir_k), "m" (ssm_mask)); | ||
162 | |||
163 | local_flush_tlb(); | ||
164 | |||
165 | { | ||
166 | unsigned long zones_size[MAX_NR_ZONES] = { 0, 0, 0}; | ||
167 | |||
168 | zones_size[ZONE_DMA] = max_low_pfn; | ||
169 | free_area_init(zones_size); | ||
170 | } | ||
171 | return; | ||
172 | } | ||
173 | |||
174 | #else /* CONFIG_ARCH_S390X */ | ||
175 | void __init paging_init(void) | ||
176 | { | ||
177 | pgd_t * pg_dir; | ||
178 | pmd_t * pm_dir; | ||
179 | pte_t * pt_dir; | ||
180 | pte_t pte; | ||
181 | int i,j,k; | ||
182 | unsigned long pfn = 0; | ||
183 | unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | | ||
184 | _KERN_REGION_TABLE; | ||
185 | static const int ssm_mask = 0x04000000L; | ||
186 | |||
187 | unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0}; | ||
188 | unsigned long dma_pfn, high_pfn; | ||
189 | |||
190 | dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT; | ||
191 | high_pfn = max_low_pfn; | ||
192 | |||
193 | if (dma_pfn > high_pfn) | ||
194 | zones_size[ZONE_DMA] = high_pfn; | ||
195 | else { | ||
196 | zones_size[ZONE_DMA] = dma_pfn; | ||
197 | zones_size[ZONE_NORMAL] = high_pfn - dma_pfn; | ||
198 | } | ||
199 | |||
200 | /* Initialize mem_map[]. */ | ||
201 | free_area_init(zones_size); | ||
202 | |||
203 | |||
204 | /* | ||
205 | * map whole physical memory to virtual memory (identity mapping) | ||
206 | */ | ||
207 | |||
208 | pg_dir = swapper_pg_dir; | ||
209 | |||
210 | for (i = 0 ; i < PTRS_PER_PGD ; i++,pg_dir++) { | ||
211 | |||
212 | if (pfn >= max_low_pfn) { | ||
213 | pgd_clear(pg_dir); | ||
214 | continue; | ||
215 | } | ||
216 | |||
217 | pm_dir = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE*4); | ||
218 | pgd_populate(&init_mm, pg_dir, pm_dir); | ||
219 | |||
220 | for (j = 0 ; j < PTRS_PER_PMD ; j++,pm_dir++) { | ||
221 | if (pfn >= max_low_pfn) { | ||
222 | pmd_clear(pm_dir); | ||
223 | continue; | ||
224 | } | ||
225 | |||
226 | pt_dir = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE); | ||
227 | pmd_populate_kernel(&init_mm, pm_dir, pt_dir); | ||
228 | |||
229 | for (k = 0 ; k < PTRS_PER_PTE ; k++,pt_dir++) { | ||
230 | pte = pfn_pte(pfn, PAGE_KERNEL); | ||
231 | if (pfn >= max_low_pfn) { | ||
232 | pte_clear(&init_mm, 0, &pte); | ||
233 | continue; | ||
234 | } | ||
235 | set_pte(pt_dir, pte); | ||
236 | pfn++; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
241 | S390_lowcore.kernel_asce = pgdir_k; | ||
242 | |||
243 | /* enable virtual mapping in kernel mode */ | ||
244 | __asm__ __volatile__("lctlg 1,1,%0\n\t" | ||
245 | "lctlg 7,7,%0\n\t" | ||
246 | "lctlg 13,13,%0\n\t" | ||
247 | "ssm %1" | ||
248 | : :"m" (pgdir_k), "m" (ssm_mask)); | ||
249 | |||
250 | local_flush_tlb(); | ||
251 | |||
252 | return; | ||
253 | } | ||
254 | #endif /* CONFIG_ARCH_S390X */ | ||
255 | |||
256 | void __init mem_init(void) | ||
257 | { | ||
258 | unsigned long codesize, reservedpages, datasize, initsize; | ||
259 | |||
260 | max_mapnr = num_physpages = max_low_pfn; | ||
261 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE); | ||
262 | |||
263 | /* clear the zero-page */ | ||
264 | memset(empty_zero_page, 0, PAGE_SIZE); | ||
265 | |||
266 | /* this will put all low memory onto the freelists */ | ||
267 | totalram_pages += free_all_bootmem(); | ||
268 | |||
269 | reservedpages = 0; | ||
270 | |||
271 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | ||
272 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; | ||
273 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | ||
274 | printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n", | ||
275 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), | ||
276 | max_mapnr << (PAGE_SHIFT-10), | ||
277 | codesize >> 10, | ||
278 | reservedpages << (PAGE_SHIFT-10), | ||
279 | datasize >>10, | ||
280 | initsize >> 10); | ||
281 | } | ||
282 | |||
283 | void free_initmem(void) | ||
284 | { | ||
285 | unsigned long addr; | ||
286 | |||
287 | addr = (unsigned long)(&__init_begin); | ||
288 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { | ||
289 | ClearPageReserved(virt_to_page(addr)); | ||
290 | set_page_count(virt_to_page(addr), 1); | ||
291 | free_page(addr); | ||
292 | totalram_pages++; | ||
293 | } | ||
294 | printk ("Freeing unused kernel memory: %ldk freed\n", | ||
295 | ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10); | ||
296 | } | ||
297 | |||
298 | #ifdef CONFIG_BLK_DEV_INITRD | ||
299 | void free_initrd_mem(unsigned long start, unsigned long end) | ||
300 | { | ||
301 | if (start < end) | ||
302 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); | ||
303 | for (; start < end; start += PAGE_SIZE) { | ||
304 | ClearPageReserved(virt_to_page(start)); | ||
305 | set_page_count(virt_to_page(start), 1); | ||
306 | free_page(start); | ||
307 | totalram_pages++; | ||
308 | } | ||
309 | } | ||
310 | #endif | ||
diff --git a/arch/s390/mm/ioremap.c b/arch/s390/mm/ioremap.c new file mode 100644 index 000000000000..c6c39d868bc8 --- /dev/null +++ b/arch/s390/mm/ioremap.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | * arch/s390/mm/ioremap.c | ||
3 | * | ||
4 | * S390 version | ||
5 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation | ||
6 | * Author(s): Hartmut Penner (hp@de.ibm.com) | ||
7 | * | ||
8 | * Derived from "arch/i386/mm/extable.c" | ||
9 | * (C) Copyright 1995 1996 Linus Torvalds | ||
10 | * | ||
11 | * Re-map IO memory to kernel address space so that we can access it. | ||
12 | * This is needed for high PCI addresses that aren't mapped in the | ||
13 | * 640k-1MB IO memory area on PC's | ||
14 | */ | ||
15 | |||
16 | #include <linux/vmalloc.h> | ||
17 | #include <linux/mm.h> | ||
18 | #include <asm/io.h> | ||
19 | #include <asm/pgalloc.h> | ||
20 | #include <asm/cacheflush.h> | ||
21 | #include <asm/tlbflush.h> | ||
22 | |||
23 | static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size, | ||
24 | unsigned long phys_addr, unsigned long flags) | ||
25 | { | ||
26 | unsigned long end; | ||
27 | unsigned long pfn; | ||
28 | |||
29 | address &= ~PMD_MASK; | ||
30 | end = address + size; | ||
31 | if (end > PMD_SIZE) | ||
32 | end = PMD_SIZE; | ||
33 | if (address >= end) | ||
34 | BUG(); | ||
35 | pfn = phys_addr >> PAGE_SHIFT; | ||
36 | do { | ||
37 | if (!pte_none(*pte)) { | ||
38 | printk("remap_area_pte: page already exists\n"); | ||
39 | BUG(); | ||
40 | } | ||
41 | set_pte(pte, pfn_pte(pfn, __pgprot(flags))); | ||
42 | address += PAGE_SIZE; | ||
43 | pfn++; | ||
44 | pte++; | ||
45 | } while (address && (address < end)); | ||
46 | } | ||
47 | |||
48 | static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size, | ||
49 | unsigned long phys_addr, unsigned long flags) | ||
50 | { | ||
51 | unsigned long end; | ||
52 | |||
53 | address &= ~PGDIR_MASK; | ||
54 | end = address + size; | ||
55 | if (end > PGDIR_SIZE) | ||
56 | end = PGDIR_SIZE; | ||
57 | phys_addr -= address; | ||
58 | if (address >= end) | ||
59 | BUG(); | ||
60 | do { | ||
61 | pte_t * pte = pte_alloc_kernel(&init_mm, pmd, address); | ||
62 | if (!pte) | ||
63 | return -ENOMEM; | ||
64 | remap_area_pte(pte, address, end - address, address + phys_addr, flags); | ||
65 | address = (address + PMD_SIZE) & PMD_MASK; | ||
66 | pmd++; | ||
67 | } while (address && (address < end)); | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static int remap_area_pages(unsigned long address, unsigned long phys_addr, | ||
72 | unsigned long size, unsigned long flags) | ||
73 | { | ||
74 | int error; | ||
75 | pgd_t * dir; | ||
76 | unsigned long end = address + size; | ||
77 | |||
78 | phys_addr -= address; | ||
79 | dir = pgd_offset(&init_mm, address); | ||
80 | flush_cache_all(); | ||
81 | if (address >= end) | ||
82 | BUG(); | ||
83 | spin_lock(&init_mm.page_table_lock); | ||
84 | do { | ||
85 | pmd_t *pmd; | ||
86 | pmd = pmd_alloc(&init_mm, dir, address); | ||
87 | error = -ENOMEM; | ||
88 | if (!pmd) | ||
89 | break; | ||
90 | if (remap_area_pmd(pmd, address, end - address, | ||
91 | phys_addr + address, flags)) | ||
92 | break; | ||
93 | error = 0; | ||
94 | address = (address + PGDIR_SIZE) & PGDIR_MASK; | ||
95 | dir++; | ||
96 | } while (address && (address < end)); | ||
97 | spin_unlock(&init_mm.page_table_lock); | ||
98 | flush_tlb_all(); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * Generic mapping function (not visible outside): | ||
104 | */ | ||
105 | |||
106 | /* | ||
107 | * Remap an arbitrary physical address space into the kernel virtual | ||
108 | * address space. Needed when the kernel wants to access high addresses | ||
109 | * directly. | ||
110 | */ | ||
111 | void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags) | ||
112 | { | ||
113 | void * addr; | ||
114 | struct vm_struct * area; | ||
115 | |||
116 | if (phys_addr < virt_to_phys(high_memory)) | ||
117 | return phys_to_virt(phys_addr); | ||
118 | if (phys_addr & ~PAGE_MASK) | ||
119 | return NULL; | ||
120 | size = PAGE_ALIGN(size); | ||
121 | if (!size || size > phys_addr + size) | ||
122 | return NULL; | ||
123 | area = get_vm_area(size, VM_IOREMAP); | ||
124 | if (!area) | ||
125 | return NULL; | ||
126 | addr = area->addr; | ||
127 | if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { | ||
128 | vfree(addr); | ||
129 | return NULL; | ||
130 | } | ||
131 | return addr; | ||
132 | } | ||
133 | |||
134 | void iounmap(void *addr) | ||
135 | { | ||
136 | if (addr > high_memory) | ||
137 | vfree(addr); | ||
138 | } | ||
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c new file mode 100644 index 000000000000..fb187e5a54b4 --- /dev/null +++ b/arch/s390/mm/mmap.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * linux/arch/s390/mm/mmap.c | ||
3 | * | ||
4 | * flexible mmap layout support | ||
5 | * | ||
6 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. | ||
7 | * All Rights Reserved. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * | ||
24 | * Started by Ingo Molnar <mingo@elte.hu> | ||
25 | */ | ||
26 | |||
27 | #include <linux/personality.h> | ||
28 | #include <linux/mm.h> | ||
29 | #include <linux/module.h> | ||
30 | |||
31 | /* | ||
32 | * Top of mmap area (just below the process stack). | ||
33 | * | ||
34 | * Leave an at least ~128 MB hole. | ||
35 | */ | ||
36 | #define MIN_GAP (128*1024*1024) | ||
37 | #define MAX_GAP (TASK_SIZE/6*5) | ||
38 | |||
39 | static inline unsigned long mmap_base(void) | ||
40 | { | ||
41 | unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur; | ||
42 | |||
43 | if (gap < MIN_GAP) | ||
44 | gap = MIN_GAP; | ||
45 | else if (gap > MAX_GAP) | ||
46 | gap = MAX_GAP; | ||
47 | |||
48 | return TASK_SIZE - (gap & PAGE_MASK); | ||
49 | } | ||
50 | |||
51 | static inline int mmap_is_legacy(void) | ||
52 | { | ||
53 | #ifdef CONFIG_ARCH_S390X | ||
54 | /* | ||
55 | * Force standard allocation for 64 bit programs. | ||
56 | */ | ||
57 | if (!test_thread_flag(TIF_31BIT)) | ||
58 | return 1; | ||
59 | #endif | ||
60 | return sysctl_legacy_va_layout || | ||
61 | (current->personality & ADDR_COMPAT_LAYOUT) || | ||
62 | current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * This function, called very early during the creation of a new | ||
67 | * process VM image, sets up which VM layout function to use: | ||
68 | */ | ||
69 | void arch_pick_mmap_layout(struct mm_struct *mm) | ||
70 | { | ||
71 | /* | ||
72 | * Fall back to the standard layout if the personality | ||
73 | * bit is set, or if the expected stack growth is unlimited: | ||
74 | */ | ||
75 | if (mmap_is_legacy()) { | ||
76 | mm->mmap_base = TASK_UNMAPPED_BASE; | ||
77 | mm->get_unmapped_area = arch_get_unmapped_area; | ||
78 | mm->unmap_area = arch_unmap_area; | ||
79 | } else { | ||
80 | mm->mmap_base = mmap_base(); | ||
81 | mm->get_unmapped_area = arch_get_unmapped_area_topdown; | ||
82 | mm->unmap_area = arch_unmap_area_topdown; | ||
83 | } | ||
84 | } | ||
85 | EXPORT_SYMBOL_GPL(arch_pick_mmap_layout); | ||
86 | |||