blob: 8b924b359774a40abb9042c2737b5ac9f6c637a2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#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/smp.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070023#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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>
Michael Grundy4ba069b2006-09-20 15:58:39 +020029#include <linux/kprobes.h>
Martin Schwidefskybe5ec362007-04-27 16:01:44 +020030#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/pgtable.h>
Heiko Carstens29b08d22006-12-04 15:40:40 +010034#include <asm/s390_ext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080036#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define __FAIL_ADDR_MASK 0x7ffff000
38#define __FIXUP_MASK 0x7fffffff
39#define __SUBCODE_MASK 0x0200
40#define __PF_RES_FIELD 0ULL
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080041#else /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define __FAIL_ADDR_MASK -4096L
43#define __FIXUP_MASK ~0L
44#define __SUBCODE_MASK 0x0600
45#define __PF_RES_FIELD 0x8000000000000000ULL
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080046#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#ifdef CONFIG_SYSCTL
49extern int sysctl_userprocess_debug;
50#endif
51
52extern void die(const char *,struct pt_regs *,long);
53
Michael Grundy4ba069b2006-09-20 15:58:39 +020054#ifdef CONFIG_KPROBES
Martin Schwidefsky10c10312007-04-27 16:01:43 +020055static inline int notify_page_fault(struct pt_regs *regs, long err)
56{
Christoph Hellwig33464e32007-05-04 18:47:46 +020057 int ret = 0;
58
59 /* kprobe_running() needs smp_processor_id() */
60 if (!user_mode(regs)) {
61 preempt_disable();
62 if (kprobe_running() && kprobe_fault_handler(regs, 14))
63 ret = 1;
64 preempt_enable();
65 }
66
67 return ret;
Michael Grundy4ba069b2006-09-20 15:58:39 +020068}
69#else
Martin Schwidefsky10c10312007-04-27 16:01:43 +020070static inline int notify_page_fault(struct pt_regs *regs, long err)
Michael Grundy4ba069b2006-09-20 15:58:39 +020071{
Christoph Hellwig33464e32007-05-04 18:47:46 +020072 return 0;
Michael Grundy4ba069b2006-09-20 15:58:39 +020073}
74#endif
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * Unlock any spinlocks which will prevent us from getting the
Kirill Korotaevcefc8be2007-02-10 01:46:18 -080079 * message out.
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
81void bust_spinlocks(int yes)
82{
83 if (yes) {
84 oops_in_progress = 1;
85 } else {
86 int loglevel_save = console_loglevel;
87 console_unblank();
88 oops_in_progress = 0;
89 /*
90 * OK, the message is on the console. Now we call printk()
91 * without oops_in_progress set so that printk will give klogd
92 * a poke. Hold onto your hats...
93 */
94 console_loglevel = 15;
95 printk(" ");
96 console_loglevel = loglevel_save;
97 }
98}
99
100/*
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100101 * Returns the address space associated with the fault.
102 * Returns 0 for kernel space, 1 for user space and
103 * 2 for code execution in user space with noexec=on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100105static inline int check_space(struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 /*
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100108 * The lowest two bits of S390_lowcore.trans_exc_code
109 * indicate which paging table was used.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 */
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100111 int desc = S390_lowcore.trans_exc_code & 3;
112
113 if (desc == 3) /* Home Segment Table Descriptor */
114 return switch_amode == 0;
115 if (desc == 2) /* Secondary Segment Table Descriptor */
116 return tsk->thread.mm_segment.ar4;
117#ifdef CONFIG_S390_SWITCH_AMODE
118 if (unlikely(desc == 1)) { /* STD determined via access register */
119 /* %a0 always indicates primary space. */
120 if (S390_lowcore.exc_access_id != 0) {
121 save_access_regs(tsk->thread.acrs);
122 /*
123 * An alet of 0 indicates primary space.
124 * An alet of 1 indicates secondary space.
125 * Any other alet values generate an
126 * alen-translation exception.
127 */
128 if (tsk->thread.acrs[S390_lowcore.exc_access_id])
129 return tsk->thread.mm_segment.ar4;
130 }
131 }
132#endif
133 /* Primary Segment Table Descriptor */
134 return switch_amode << s390_noexec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
137/*
138 * Send SIGSEGV to task. This is an external routine
139 * to keep the stack usage of do_page_fault small.
140 */
141static void do_sigsegv(struct pt_regs *regs, unsigned long error_code,
142 int si_code, unsigned long address)
143{
144 struct siginfo si;
145
146#if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG)
147#if defined(CONFIG_SYSCTL)
148 if (sysctl_userprocess_debug)
149#endif
150 {
151 printk("User process fault: interruption code 0x%lX\n",
152 error_code);
153 printk("failing address: %lX\n", address);
154 show_regs(regs);
155 }
156#endif
157 si.si_signo = SIGSEGV;
158 si.si_code = si_code;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200159 si.si_addr = (void __user *) address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 force_sig_info(SIGSEGV, &si, current);
161}
162
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200163static void do_no_context(struct pt_regs *regs, unsigned long error_code,
164 unsigned long address)
165{
166 const struct exception_table_entry *fixup;
167
168 /* Are we prepared to handle this kernel fault? */
169 fixup = search_exception_tables(regs->psw.addr & __FIXUP_MASK);
170 if (fixup) {
171 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
172 return;
173 }
174
175 /*
176 * Oops. The kernel tried to access some bad page. We'll have to
177 * terminate things with extreme prejudice.
178 */
179 if (check_space(current) == 0)
180 printk(KERN_ALERT "Unable to handle kernel pointer dereference"
181 " at virtual kernel address %p\n", (void *)address);
182 else
183 printk(KERN_ALERT "Unable to handle kernel paging request"
184 " at virtual user address %p\n", (void *)address);
185
186 die("Oops", regs, error_code);
187 do_exit(SIGKILL);
188}
189
190static void do_low_address(struct pt_regs *regs, unsigned long error_code)
191{
192 /* Low-address protection hit in kernel mode means
193 NULL pointer write access in kernel mode. */
194 if (regs->psw.mask & PSW_MASK_PSTATE) {
195 /* Low-address protection hit in user mode 'cannot happen'. */
196 die ("Low-address protection", regs, error_code);
197 do_exit(SIGKILL);
198 }
199
200 do_no_context(regs, error_code, 0);
201}
202
203/*
204 * We ran out of memory, or some other thing happened to us that made
205 * us unable to handle the page fault gracefully.
206 */
207static int do_out_of_memory(struct pt_regs *regs, unsigned long error_code,
208 unsigned long address)
209{
210 struct task_struct *tsk = current;
211 struct mm_struct *mm = tsk->mm;
212
213 up_read(&mm->mmap_sem);
214 if (is_init(tsk)) {
215 yield();
216 down_read(&mm->mmap_sem);
217 return 1;
218 }
219 printk("VM: killing process %s\n", tsk->comm);
220 if (regs->psw.mask & PSW_MASK_PSTATE)
221 do_exit(SIGKILL);
222 do_no_context(regs, error_code, address);
223 return 0;
224}
225
226static void do_sigbus(struct pt_regs *regs, unsigned long error_code,
227 unsigned long address)
228{
229 struct task_struct *tsk = current;
230 struct mm_struct *mm = tsk->mm;
231
232 up_read(&mm->mmap_sem);
233 /*
234 * Send a sigbus, regardless of whether we were in kernel
235 * or user mode.
236 */
237 tsk->thread.prot_addr = address;
238 tsk->thread.trap_no = error_code;
239 force_sig(SIGBUS, tsk);
240
241 /* Kernel mode? Handle exceptions or die */
242 if (!(regs->psw.mask & PSW_MASK_PSTATE))
243 do_no_context(regs, error_code, address);
244}
245
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100246#ifdef CONFIG_S390_EXEC_PROTECT
247extern long sys_sigreturn(struct pt_regs *regs);
248extern long sys_rt_sigreturn(struct pt_regs *regs);
249extern long sys32_sigreturn(struct pt_regs *regs);
250extern long sys32_rt_sigreturn(struct pt_regs *regs);
251
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100252static int signal_return(struct mm_struct *mm, struct pt_regs *regs,
253 unsigned long address, unsigned long error_code)
254{
Martin Schwidefskybe5ec362007-04-27 16:01:44 +0200255 u16 instruction;
256 int rc, compat;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100257
Martin Schwidefskybe5ec362007-04-27 16:01:44 +0200258 pagefault_disable();
259 rc = __get_user(instruction, (u16 __user *) regs->psw.addr);
260 pagefault_enable();
261 if (rc)
262 return -EFAULT;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100263
Martin Schwidefskybe5ec362007-04-27 16:01:44 +0200264 up_read(&mm->mmap_sem);
265 clear_tsk_thread_flag(current, TIF_SINGLE_STEP);
266#ifdef CONFIG_COMPAT
267 compat = test_tsk_thread_flag(current, TIF_31BIT);
268 if (compat && instruction == 0x0a77)
269 sys32_sigreturn(regs);
270 else if (compat && instruction == 0x0aad)
271 sys32_rt_sigreturn(regs);
272 else
273#endif
274 if (instruction == 0x0a77)
275 sys_sigreturn(regs);
276 else if (instruction == 0x0aad)
277 sys_rt_sigreturn(regs);
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100278 else {
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100279 current->thread.prot_addr = address;
280 current->thread.trap_no = error_code;
281 do_sigsegv(regs, error_code, SEGV_MAPERR, address);
282 }
283 return 0;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100284}
285#endif /* CONFIG_S390_EXEC_PROTECT */
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*
288 * This routine handles page faults. It determines the address,
289 * and the problem, and then passes it off to one of the appropriate
290 * routines.
291 *
292 * error_code:
293 * 04 Protection -> Write-Protection (suprression)
294 * 10 Segment translation -> Not present (nullification)
295 * 11 Page translation -> Not present (nullification)
296 * 3b Region third trans. -> Not present (nullification)
297 */
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100298static inline void
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200299do_exception(struct pt_regs *regs, unsigned long error_code, int write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200301 struct task_struct *tsk;
302 struct mm_struct *mm;
303 struct vm_area_struct *vma;
304 unsigned long address;
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100305 int space;
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200306 int si_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Christoph Hellwig33464e32007-05-04 18:47:46 +0200308 if (notify_page_fault(regs, error_code))
Michael Grundy4ba069b2006-09-20 15:58:39 +0200309 return;
310
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200311 tsk = current;
312 mm = tsk->mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200314 /* get the failing address and the affected space */
315 address = S390_lowcore.trans_exc_code & __FAIL_ADDR_MASK;
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100316 space = check_space(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 /*
319 * Verify that the fault happened in user space, that
320 * we are not in an interrupt and that there is a
321 * user context.
322 */
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100323 if (unlikely(space == 0 || in_atomic() || !mm))
324 goto no_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /*
327 * When we get here, the fault happened in the current
328 * task's user address space, so we can switch on the
329 * interrupts again and then search the VMAs
330 */
331 local_irq_enable();
332
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200333 down_read(&mm->mmap_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100335 si_code = SEGV_MAPERR;
336 vma = find_vma(mm, address);
337 if (!vma)
338 goto bad_area;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100339
340#ifdef CONFIG_S390_EXEC_PROTECT
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100341 if (unlikely((space == 2) && !(vma->vm_flags & VM_EXEC)))
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100342 if (!signal_return(mm, regs, address, error_code))
343 /*
344 * signal_return() has done an up_read(&mm->mmap_sem)
345 * if it returns 0.
346 */
347 return;
348#endif
349
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200350 if (vma->vm_start <= address)
351 goto good_area;
352 if (!(vma->vm_flags & VM_GROWSDOWN))
353 goto bad_area;
354 if (expand_stack(vma, address))
355 goto bad_area;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/*
357 * Ok, we have a good vm_area for this memory access, so
358 * we can handle it..
359 */
360good_area:
361 si_code = SEGV_ACCERR;
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200362 if (!write) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* page not present, check vm flags */
364 if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
365 goto bad_area;
366 } else {
367 if (!(vma->vm_flags & VM_WRITE))
368 goto bad_area;
369 }
370
371survive:
372 /*
373 * If for any reason at all we couldn't handle the fault,
374 * make sure we exit gracefully rather than endlessly redo
375 * the fault.
376 */
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200377 switch (handle_mm_fault(mm, vma, address, write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 case VM_FAULT_MINOR:
379 tsk->min_flt++;
380 break;
381 case VM_FAULT_MAJOR:
382 tsk->maj_flt++;
383 break;
384 case VM_FAULT_SIGBUS:
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200385 do_sigbus(regs, error_code, address);
386 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 case VM_FAULT_OOM:
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200388 if (do_out_of_memory(regs, error_code, address))
389 goto survive;
390 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 default:
392 BUG();
393 }
394
395 up_read(&mm->mmap_sem);
396 /*
397 * The instruction that caused the program check will
398 * be repeated. Don't signal single step via SIGTRAP.
399 */
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100400 clear_tsk_thread_flag(tsk, TIF_SINGLE_STEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return;
402
403/*
404 * Something tried to access memory that isn't in our memory map..
405 * Fix it, but check if it's kernel or user first..
406 */
407bad_area:
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200408 up_read(&mm->mmap_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200410 /* User mode accesses just cause a SIGSEGV */
411 if (regs->psw.mask & PSW_MASK_PSTATE) {
412 tsk->thread.prot_addr = address;
413 tsk->thread.trap_no = error_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 do_sigsegv(regs, error_code, si_code, address);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200415 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
418no_context:
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200419 do_no_context(regs, error_code, address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100422void __kprobes do_protection_exception(struct pt_regs *regs,
423 unsigned long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200425 /* Protection exception is supressing, decrement psw address. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 regs->psw.addr -= (error_code >> 16);
Martin Schwidefsky10c10312007-04-27 16:01:43 +0200427 /*
428 * Check for low-address protection. This needs to be treated
429 * as a special case because the translation exception code
430 * field is not guaranteed to contain valid data in this case.
431 */
432 if (unlikely(!(S390_lowcore.trans_exc_code & 4))) {
433 do_low_address(regs, error_code);
434 return;
435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 do_exception(regs, 4, 1);
437}
438
Gerald Schaefer482b05d2007-03-05 23:35:54 +0100439void __kprobes do_dat_exception(struct pt_regs *regs, unsigned long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 do_exception(regs, error_code & 0xff, 0);
442}
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#ifdef CONFIG_PFAULT
445/*
446 * 'pfault' pseudo page faults routines.
447 */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100448static ext_int_info_t ext_int_pfault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449static int pfault_disable = 0;
450
451static int __init nopfault(char *str)
452{
453 pfault_disable = 1;
454 return 1;
455}
456
457__setup("nopfault", nopfault);
458
459typedef struct {
460 __u16 refdiagc;
461 __u16 reffcode;
462 __u16 refdwlen;
463 __u16 refversn;
464 __u64 refgaddr;
465 __u64 refselmk;
466 __u64 refcmpmk;
467 __u64 reserved;
468} __attribute__ ((packed)) pfault_refbk_t;
469
470int pfault_init(void)
471{
472 pfault_refbk_t refbk =
473 { 0x258, 0, 5, 2, __LC_CURRENT, 1ULL << 48, 1ULL << 48,
474 __PF_RES_FIELD };
475 int rc;
476
Heiko Carstens29b08d22006-12-04 15:40:40 +0100477 if (!MACHINE_IS_VM || pfault_disable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -1;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200479 asm volatile(
480 " diag %1,%0,0x258\n"
481 "0: j 2f\n"
482 "1: la %0,8\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 "2:\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200484 EX_TABLE(0b,1b)
485 : "=d" (rc) : "a" (&refbk), "m" (refbk) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 __ctl_set_bit(0, 9);
487 return rc;
488}
489
490void pfault_fini(void)
491{
492 pfault_refbk_t refbk =
493 { 0x258, 1, 5, 2, 0ULL, 0ULL, 0ULL, 0ULL };
494
Heiko Carstens29b08d22006-12-04 15:40:40 +0100495 if (!MACHINE_IS_VM || pfault_disable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return;
497 __ctl_clear_bit(0,9);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200498 asm volatile(
499 " diag %0,0,0x258\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 "0:\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200501 EX_TABLE(0b,0b)
502 : : "a" (&refbk), "m" (refbk) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100505static void pfault_interrupt(__u16 error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
507 struct task_struct *tsk;
508 __u16 subcode;
509
510 /*
511 * Get the external interruption subcode & pfault
512 * initial/completion signal bit. VM stores this
513 * in the 'cpu address' field associated with the
514 * external interrupt.
515 */
516 subcode = S390_lowcore.cpu_addr;
517 if ((subcode & 0xff00) != __SUBCODE_MASK)
518 return;
519
520 /*
521 * Get the token (= address of the task structure of the affected task).
522 */
523 tsk = *(struct task_struct **) __LC_PFAULT_INTPARM;
524
525 if (subcode & 0x0080) {
526 /* signal bit is set -> a page has been swapped in by VM */
527 if (xchg(&tsk->thread.pfault_wait, -1) != 0) {
528 /* Initial interrupt was faster than the completion
529 * interrupt. pfault_wait is valid. Set pfault_wait
530 * back to zero and wake up the process. This can
531 * safely be done because the task is still sleeping
Martin Schwidefskyb6d09442005-09-03 15:58:02 -0700532 * and can't produce new pfaults. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 tsk->thread.pfault_wait = 0;
534 wake_up_process(tsk);
Martin Schwidefskyb6d09442005-09-03 15:58:02 -0700535 put_task_struct(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
537 } else {
538 /* signal bit not set -> a real page is missing. */
Martin Schwidefskyb6d09442005-09-03 15:58:02 -0700539 get_task_struct(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 set_task_state(tsk, TASK_UNINTERRUPTIBLE);
541 if (xchg(&tsk->thread.pfault_wait, 1) != 0) {
542 /* Completion interrupt was faster than the initial
543 * interrupt (swapped in a -1 for pfault_wait). Set
544 * pfault_wait back to zero and exit. This can be
545 * done safely because tsk is running in kernel
546 * mode and can't produce new pfaults. */
547 tsk->thread.pfault_wait = 0;
548 set_task_state(tsk, TASK_RUNNING);
Martin Schwidefskyb6d09442005-09-03 15:58:02 -0700549 put_task_struct(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 } else
551 set_tsk_need_resched(tsk);
552 }
553}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Heiko Carstens29b08d22006-12-04 15:40:40 +0100555void __init pfault_irq_init(void)
556{
557 if (!MACHINE_IS_VM)
558 return;
559
560 /*
561 * Try to get pfault pseudo page faults going.
562 */
563 if (register_early_external_interrupt(0x2603, pfault_interrupt,
564 &ext_int_pfault) != 0)
565 panic("Couldn't request external interrupt 0x2603");
566
567 if (pfault_init() == 0)
568 return;
569
570 /* Tough luck, no pfault. */
571 pfault_disable = 1;
572 unregister_early_external_interrupt(0x2603, pfault_interrupt,
573 &ext_int_pfault);
574}
575#endif