fault.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999
  4. * Author(s): Hartmut Penner (hp@de.ibm.com)
  5. * Ulrich Weigand (uweigand@de.ibm.com)
  6. *
  7. * Derived from "arch/i386/mm/fault.c"
  8. * Copyright (C) 1995 Linus Torvalds
  9. */
  10. #include <linux/kernel_stat.h>
  11. #include <linux/perf_event.h>
  12. #include <linux/signal.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/types.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/mman.h>
  20. #include <linux/mm.h>
  21. #include <linux/compat.h>
  22. #include <linux/smp.h>
  23. #include <linux/kdebug.h>
  24. #include <linux/init.h>
  25. #include <linux/console.h>
  26. #include <linux/module.h>
  27. #include <linux/hardirq.h>
  28. #include <linux/kprobes.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/hugetlb.h>
  31. #include <asm/asm-offsets.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/irq.h>
  34. #include <asm/mmu_context.h>
  35. #include <asm/facility.h>
  36. #include "../kernel/entry.h"
  37. #ifndef CONFIG_64BIT
  38. #define __FAIL_ADDR_MASK 0x7ffff000
  39. #define __SUBCODE_MASK 0x0200
  40. #define __PF_RES_FIELD 0ULL
  41. #else /* CONFIG_64BIT */
  42. #define __FAIL_ADDR_MASK -4096L
  43. #define __SUBCODE_MASK 0x0600
  44. #define __PF_RES_FIELD 0x8000000000000000ULL
  45. #endif /* CONFIG_64BIT */
  46. #define VM_FAULT_BADCONTEXT 0x010000
  47. #define VM_FAULT_BADMAP 0x020000
  48. #define VM_FAULT_BADACCESS 0x040000
  49. #define VM_FAULT_SIGNAL 0x080000
  50. static unsigned long store_indication __read_mostly;
  51. #ifdef CONFIG_64BIT
  52. static int __init fault_init(void)
  53. {
  54. if (test_facility(75))
  55. store_indication = 0xc00;
  56. return 0;
  57. }
  58. early_initcall(fault_init);
  59. #endif
  60. static inline int notify_page_fault(struct pt_regs *regs)
  61. {
  62. int ret = 0;
  63. /* kprobe_running() needs smp_processor_id() */
  64. if (kprobes_built_in() && !user_mode(regs)) {
  65. preempt_disable();
  66. if (kprobe_running() && kprobe_fault_handler(regs, 14))
  67. ret = 1;
  68. preempt_enable();
  69. }
  70. return ret;
  71. }
  72. /*
  73. * Unlock any spinlocks which will prevent us from getting the
  74. * message out.
  75. */
  76. void bust_spinlocks(int yes)
  77. {
  78. if (yes) {
  79. oops_in_progress = 1;
  80. } else {
  81. int loglevel_save = console_loglevel;
  82. console_unblank();
  83. oops_in_progress = 0;
  84. /*
  85. * OK, the message is on the console. Now we call printk()
  86. * without oops_in_progress set so that printk will give klogd
  87. * a poke. Hold onto your hats...
  88. */
  89. console_loglevel = 15;
  90. printk(" ");
  91. console_loglevel = loglevel_save;
  92. }
  93. }
  94. /*
  95. * Returns the address space associated with the fault.
  96. * Returns 0 for kernel space and 1 for user space.
  97. */
  98. static inline int user_space_fault(unsigned long trans_exc_code)
  99. {
  100. /*
  101. * The lowest two bits of the translation exception
  102. * identification indicate which paging table was used.
  103. */
  104. trans_exc_code &= 3;
  105. if (trans_exc_code == 2)
  106. /* Access via secondary space, set_fs setting decides */
  107. return current->thread.mm_segment.ar4;
  108. if (s390_user_mode == HOME_SPACE_MODE)
  109. /* User space if the access has been done via home space. */
  110. return trans_exc_code == 3;
  111. /*
  112. * If the user space is not the home space the kernel runs in home
  113. * space. Access via secondary space has already been covered,
  114. * access via primary space or access register is from user space
  115. * and access via home space is from the kernel.
  116. */
  117. return trans_exc_code != 3;
  118. }
  119. static inline void report_user_fault(struct pt_regs *regs, long signr)
  120. {
  121. if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
  122. return;
  123. if (!unhandled_signal(current, signr))
  124. return;
  125. if (!printk_ratelimit())
  126. return;
  127. printk(KERN_ALERT "User process fault: interruption code 0x%X ",
  128. regs->int_code);
  129. print_vma_addr(KERN_CONT "in ", regs->psw.addr & PSW_ADDR_INSN);
  130. printk(KERN_CONT "\n");
  131. printk(KERN_ALERT "failing address: %lX\n",
  132. regs->int_parm_long & __FAIL_ADDR_MASK);
  133. show_regs(regs);
  134. }
  135. /*
  136. * Send SIGSEGV to task. This is an external routine
  137. * to keep the stack usage of do_page_fault small.
  138. */
  139. static noinline void do_sigsegv(struct pt_regs *regs, int si_code)
  140. {
  141. struct siginfo si;
  142. report_user_fault(regs, SIGSEGV);
  143. si.si_signo = SIGSEGV;
  144. si.si_code = si_code;
  145. si.si_addr = (void __user *)(regs->int_parm_long & __FAIL_ADDR_MASK);
  146. force_sig_info(SIGSEGV, &si, current);
  147. }
  148. static noinline void do_no_context(struct pt_regs *regs)
  149. {
  150. const struct exception_table_entry *fixup;
  151. unsigned long address;
  152. /* Are we prepared to handle this kernel fault? */
  153. fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
  154. if (fixup) {
  155. regs->psw.addr = extable_fixup(fixup) | PSW_ADDR_AMODE;
  156. return;
  157. }
  158. /*
  159. * Oops. The kernel tried to access some bad page. We'll have to
  160. * terminate things with extreme prejudice.
  161. */
  162. address = regs->int_parm_long & __FAIL_ADDR_MASK;
  163. if (!user_space_fault(regs->int_parm_long))
  164. printk(KERN_ALERT "Unable to handle kernel pointer dereference"
  165. " at virtual kernel address %p\n", (void *)address);
  166. else
  167. printk(KERN_ALERT "Unable to handle kernel paging request"
  168. " at virtual user address %p\n", (void *)address);
  169. die(regs, "Oops");
  170. do_exit(SIGKILL);
  171. }
  172. static noinline void do_low_address(struct pt_regs *regs)
  173. {
  174. /* Low-address protection hit in kernel mode means
  175. NULL pointer write access in kernel mode. */
  176. if (regs->psw.mask & PSW_MASK_PSTATE) {
  177. /* Low-address protection hit in user mode 'cannot happen'. */
  178. die (regs, "Low-address protection");
  179. do_exit(SIGKILL);
  180. }
  181. do_no_context(regs);
  182. }
  183. static noinline void do_sigbus(struct pt_regs *regs)
  184. {
  185. struct task_struct *tsk = current;
  186. struct siginfo si;
  187. /*
  188. * Send a sigbus, regardless of whether we were in kernel
  189. * or user mode.
  190. */
  191. si.si_signo = SIGBUS;
  192. si.si_errno = 0;
  193. si.si_code = BUS_ADRERR;
  194. si.si_addr = (void __user *)(regs->int_parm_long & __FAIL_ADDR_MASK);
  195. force_sig_info(SIGBUS, &si, tsk);
  196. }
  197. static noinline void do_fault_error(struct pt_regs *regs, int fault)
  198. {
  199. int si_code;
  200. switch (fault) {
  201. case VM_FAULT_BADACCESS:
  202. case VM_FAULT_BADMAP:
  203. /* Bad memory access. Check if it is kernel or user space. */
  204. if (user_mode(regs)) {
  205. /* User mode accesses just cause a SIGSEGV */
  206. si_code = (fault == VM_FAULT_BADMAP) ?
  207. SEGV_MAPERR : SEGV_ACCERR;
  208. do_sigsegv(regs, si_code);
  209. return;
  210. }
  211. case VM_FAULT_BADCONTEXT:
  212. do_no_context(regs);
  213. break;
  214. case VM_FAULT_SIGNAL:
  215. if (!user_mode(regs))
  216. do_no_context(regs);
  217. break;
  218. default: /* fault & VM_FAULT_ERROR */
  219. if (fault & VM_FAULT_OOM) {
  220. if (!user_mode(regs))
  221. do_no_context(regs);
  222. else
  223. pagefault_out_of_memory();
  224. } else if (fault & VM_FAULT_SIGBUS) {
  225. /* Kernel mode? Handle exceptions or die */
  226. if (!user_mode(regs))
  227. do_no_context(regs);
  228. else
  229. do_sigbus(regs);
  230. } else
  231. BUG();
  232. break;
  233. }
  234. }
  235. /*
  236. * This routine handles page faults. It determines the address,
  237. * and the problem, and then passes it off to one of the appropriate
  238. * routines.
  239. *
  240. * interruption code (int_code):
  241. * 04 Protection -> Write-Protection (suprression)
  242. * 10 Segment translation -> Not present (nullification)
  243. * 11 Page translation -> Not present (nullification)
  244. * 3b Region third trans. -> Not present (nullification)
  245. */
  246. static inline int do_exception(struct pt_regs *regs, int access)
  247. {
  248. struct task_struct *tsk;
  249. struct mm_struct *mm;
  250. struct vm_area_struct *vma;
  251. unsigned long trans_exc_code;
  252. unsigned long address;
  253. unsigned int flags;
  254. int fault;
  255. tsk = current;
  256. /*
  257. * The instruction that caused the program check has
  258. * been nullified. Don't signal single step via SIGTRAP.
  259. */
  260. clear_tsk_thread_flag(tsk, TIF_PER_TRAP);
  261. if (notify_page_fault(regs))
  262. return 0;
  263. mm = tsk->mm;
  264. trans_exc_code = regs->int_parm_long;
  265. /*
  266. * Verify that the fault happened in user space, that
  267. * we are not in an interrupt and that there is a
  268. * user context.
  269. */
  270. fault = VM_FAULT_BADCONTEXT;
  271. if (unlikely(!user_space_fault(trans_exc_code) || in_atomic() || !mm))
  272. goto out;
  273. address = trans_exc_code & __FAIL_ADDR_MASK;
  274. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  275. flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
  276. if (user_mode(regs))
  277. flags |= FAULT_FLAG_USER;
  278. if (access == VM_WRITE || (trans_exc_code & store_indication) == 0x400)
  279. flags |= FAULT_FLAG_WRITE;
  280. down_read(&mm->mmap_sem);
  281. #ifdef CONFIG_PGSTE
  282. if ((current->flags & PF_VCPU) && S390_lowcore.gmap) {
  283. address = __gmap_fault(address,
  284. (struct gmap *) S390_lowcore.gmap);
  285. if (address == -EFAULT) {
  286. fault = VM_FAULT_BADMAP;
  287. goto out_up;
  288. }
  289. if (address == -ENOMEM) {
  290. fault = VM_FAULT_OOM;
  291. goto out_up;
  292. }
  293. }
  294. #endif
  295. retry:
  296. fault = VM_FAULT_BADMAP;
  297. vma = find_vma(mm, address);
  298. if (!vma)
  299. goto out_up;
  300. if (unlikely(vma->vm_start > address)) {
  301. if (!(vma->vm_flags & VM_GROWSDOWN))
  302. goto out_up;
  303. if (expand_stack(vma, address))
  304. goto out_up;
  305. }
  306. /*
  307. * Ok, we have a good vm_area for this memory access, so
  308. * we can handle it..
  309. */
  310. fault = VM_FAULT_BADACCESS;
  311. if (unlikely(!(vma->vm_flags & access)))
  312. goto out_up;
  313. if (is_vm_hugetlb_page(vma))
  314. address &= HPAGE_MASK;
  315. /*
  316. * If for any reason at all we couldn't handle the fault,
  317. * make sure we exit gracefully rather than endlessly redo
  318. * the fault.
  319. */
  320. fault = handle_mm_fault(mm, vma, address, flags);
  321. /* No reason to continue if interrupted by SIGKILL. */
  322. if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
  323. fault = VM_FAULT_SIGNAL;
  324. goto out;
  325. }
  326. if (unlikely(fault & VM_FAULT_ERROR))
  327. goto out_up;
  328. /*
  329. * Major/minor page fault accounting is only done on the
  330. * initial attempt. If we go through a retry, it is extremely
  331. * likely that the page will be found in page cache at that point.
  332. */
  333. if (flags & FAULT_FLAG_ALLOW_RETRY) {
  334. if (fault & VM_FAULT_MAJOR) {
  335. tsk->maj_flt++;
  336. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
  337. regs, address);
  338. } else {
  339. tsk->min_flt++;
  340. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
  341. regs, address);
  342. }
  343. if (fault & VM_FAULT_RETRY) {
  344. /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
  345. * of starvation. */
  346. flags &= ~FAULT_FLAG_ALLOW_RETRY;
  347. flags |= FAULT_FLAG_TRIED;
  348. down_read(&mm->mmap_sem);
  349. goto retry;
  350. }
  351. }
  352. fault = 0;
  353. out_up:
  354. up_read(&mm->mmap_sem);
  355. out:
  356. return fault;
  357. }
  358. void __kprobes do_protection_exception(struct pt_regs *regs)
  359. {
  360. unsigned long trans_exc_code;
  361. int fault;
  362. trans_exc_code = regs->int_parm_long;
  363. /*
  364. * Protection exceptions are suppressing, decrement psw address.
  365. * The exception to this rule are aborted transactions, for these
  366. * the PSW already points to the correct location.
  367. */
  368. if (!(regs->int_code & 0x200))
  369. regs->psw.addr = __rewind_psw(regs->psw, regs->int_code >> 16);
  370. /*
  371. * Check for low-address protection. This needs to be treated
  372. * as a special case because the translation exception code
  373. * field is not guaranteed to contain valid data in this case.
  374. */
  375. if (unlikely(!(trans_exc_code & 4))) {
  376. do_low_address(regs);
  377. return;
  378. }
  379. fault = do_exception(regs, VM_WRITE);
  380. if (unlikely(fault))
  381. do_fault_error(regs, fault);
  382. }
  383. void __kprobes do_dat_exception(struct pt_regs *regs)
  384. {
  385. int access, fault;
  386. access = VM_READ | VM_EXEC | VM_WRITE;
  387. fault = do_exception(regs, access);
  388. if (unlikely(fault))
  389. do_fault_error(regs, fault);
  390. }
  391. #ifdef CONFIG_64BIT
  392. void __kprobes do_asce_exception(struct pt_regs *regs)
  393. {
  394. struct mm_struct *mm = current->mm;
  395. struct vm_area_struct *vma;
  396. unsigned long trans_exc_code;
  397. /*
  398. * The instruction that caused the program check has
  399. * been nullified. Don't signal single step via SIGTRAP.
  400. */
  401. clear_tsk_thread_flag(current, TIF_PER_TRAP);
  402. trans_exc_code = regs->int_parm_long;
  403. if (unlikely(!user_space_fault(trans_exc_code) || in_atomic() || !mm))
  404. goto no_context;
  405. down_read(&mm->mmap_sem);
  406. vma = find_vma(mm, trans_exc_code & __FAIL_ADDR_MASK);
  407. up_read(&mm->mmap_sem);
  408. if (vma) {
  409. update_mm(mm, current);
  410. return;
  411. }
  412. /* User mode accesses just cause a SIGSEGV */
  413. if (user_mode(regs)) {
  414. do_sigsegv(regs, SEGV_MAPERR);
  415. return;
  416. }
  417. no_context:
  418. do_no_context(regs);
  419. }
  420. #endif
  421. int __handle_fault(unsigned long uaddr, unsigned long pgm_int_code, int write)
  422. {
  423. struct pt_regs regs;
  424. int access, fault;
  425. /* Emulate a uaccess fault from kernel mode. */
  426. regs.psw.mask = psw_kernel_bits | PSW_MASK_DAT | PSW_MASK_MCHECK;
  427. if (!irqs_disabled())
  428. regs.psw.mask |= PSW_MASK_IO | PSW_MASK_EXT;
  429. regs.psw.addr = (unsigned long) __builtin_return_address(0);
  430. regs.psw.addr |= PSW_ADDR_AMODE;
  431. regs.int_code = pgm_int_code;
  432. regs.int_parm_long = (uaddr & PAGE_MASK) | 2;
  433. access = write ? VM_WRITE : VM_READ;
  434. fault = do_exception(&regs, access);
  435. /*
  436. * Since the fault happened in kernel mode while performing a uaccess
  437. * all we need to do now is emulating a fixup in case "fault" is not
  438. * zero.
  439. * For the calling uaccess functions this results always in -EFAULT.
  440. */
  441. return fault ? -EFAULT : 0;
  442. }
  443. #ifdef CONFIG_PFAULT
  444. /*
  445. * 'pfault' pseudo page faults routines.
  446. */
  447. static int pfault_disable;
  448. static int __init nopfault(char *str)
  449. {
  450. pfault_disable = 1;
  451. return 1;
  452. }
  453. __setup("nopfault", nopfault);
  454. struct pfault_refbk {
  455. u16 refdiagc;
  456. u16 reffcode;
  457. u16 refdwlen;
  458. u16 refversn;
  459. u64 refgaddr;
  460. u64 refselmk;
  461. u64 refcmpmk;
  462. u64 reserved;
  463. } __attribute__ ((packed, aligned(8)));
  464. int pfault_init(void)
  465. {
  466. struct pfault_refbk refbk = {
  467. .refdiagc = 0x258,
  468. .reffcode = 0,
  469. .refdwlen = 5,
  470. .refversn = 2,
  471. .refgaddr = __LC_CURRENT_PID,
  472. .refselmk = 1ULL << 48,
  473. .refcmpmk = 1ULL << 48,
  474. .reserved = __PF_RES_FIELD };
  475. int rc;
  476. if (pfault_disable)
  477. return -1;
  478. asm volatile(
  479. " diag %1,%0,0x258\n"
  480. "0: j 2f\n"
  481. "1: la %0,8\n"
  482. "2:\n"
  483. EX_TABLE(0b,1b)
  484. : "=d" (rc) : "a" (&refbk), "m" (refbk) : "cc");
  485. return rc;
  486. }
  487. void pfault_fini(void)
  488. {
  489. struct pfault_refbk refbk = {
  490. .refdiagc = 0x258,
  491. .reffcode = 1,
  492. .refdwlen = 5,
  493. .refversn = 2,
  494. };
  495. if (pfault_disable)
  496. return;
  497. asm volatile(
  498. " diag %0,0,0x258\n"
  499. "0:\n"
  500. EX_TABLE(0b,0b)
  501. : : "a" (&refbk), "m" (refbk) : "cc");
  502. }
  503. static DEFINE_SPINLOCK(pfault_lock);
  504. static LIST_HEAD(pfault_list);
  505. static void pfault_interrupt(struct ext_code ext_code,
  506. unsigned int param32, unsigned long param64)
  507. {
  508. struct task_struct *tsk;
  509. __u16 subcode;
  510. pid_t pid;
  511. /*
  512. * Get the external interruption subcode & pfault
  513. * initial/completion signal bit. VM stores this
  514. * in the 'cpu address' field associated with the
  515. * external interrupt.
  516. */
  517. subcode = ext_code.subcode;
  518. if ((subcode & 0xff00) != __SUBCODE_MASK)
  519. return;
  520. inc_irq_stat(IRQEXT_PFL);
  521. /* Get the token (= pid of the affected task). */
  522. pid = sizeof(void *) == 4 ? param32 : param64;
  523. rcu_read_lock();
  524. tsk = find_task_by_pid_ns(pid, &init_pid_ns);
  525. if (tsk)
  526. get_task_struct(tsk);
  527. rcu_read_unlock();
  528. if (!tsk)
  529. return;
  530. spin_lock(&pfault_lock);
  531. if (subcode & 0x0080) {
  532. /* signal bit is set -> a page has been swapped in by VM */
  533. if (tsk->thread.pfault_wait == 1) {
  534. /* Initial interrupt was faster than the completion
  535. * interrupt. pfault_wait is valid. Set pfault_wait
  536. * back to zero and wake up the process. This can
  537. * safely be done because the task is still sleeping
  538. * and can't produce new pfaults. */
  539. tsk->thread.pfault_wait = 0;
  540. list_del(&tsk->thread.list);
  541. wake_up_process(tsk);
  542. put_task_struct(tsk);
  543. } else {
  544. /* Completion interrupt was faster than initial
  545. * interrupt. Set pfault_wait to -1 so the initial
  546. * interrupt doesn't put the task to sleep.
  547. * If the task is not running, ignore the completion
  548. * interrupt since it must be a leftover of a PFAULT
  549. * CANCEL operation which didn't remove all pending
  550. * completion interrupts. */
  551. if (tsk->state == TASK_RUNNING)
  552. tsk->thread.pfault_wait = -1;
  553. }
  554. } else {
  555. /* signal bit not set -> a real page is missing. */
  556. if (WARN_ON_ONCE(tsk != current))
  557. goto out;
  558. if (tsk->thread.pfault_wait == 1) {
  559. /* Already on the list with a reference: put to sleep */
  560. __set_task_state(tsk, TASK_UNINTERRUPTIBLE);
  561. set_tsk_need_resched(tsk);
  562. } else if (tsk->thread.pfault_wait == -1) {
  563. /* Completion interrupt was faster than the initial
  564. * interrupt (pfault_wait == -1). Set pfault_wait
  565. * back to zero and exit. */
  566. tsk->thread.pfault_wait = 0;
  567. } else {
  568. /* Initial interrupt arrived before completion
  569. * interrupt. Let the task sleep.
  570. * An extra task reference is needed since a different
  571. * cpu may set the task state to TASK_RUNNING again
  572. * before the scheduler is reached. */
  573. get_task_struct(tsk);
  574. tsk->thread.pfault_wait = 1;
  575. list_add(&tsk->thread.list, &pfault_list);
  576. __set_task_state(tsk, TASK_UNINTERRUPTIBLE);
  577. set_tsk_need_resched(tsk);
  578. }
  579. }
  580. out:
  581. spin_unlock(&pfault_lock);
  582. put_task_struct(tsk);
  583. }
  584. static int pfault_cpu_notify(struct notifier_block *self, unsigned long action,
  585. void *hcpu)
  586. {
  587. struct thread_struct *thread, *next;
  588. struct task_struct *tsk;
  589. switch (action & ~CPU_TASKS_FROZEN) {
  590. case CPU_DEAD:
  591. spin_lock_irq(&pfault_lock);
  592. list_for_each_entry_safe(thread, next, &pfault_list, list) {
  593. thread->pfault_wait = 0;
  594. list_del(&thread->list);
  595. tsk = container_of(thread, struct task_struct, thread);
  596. wake_up_process(tsk);
  597. put_task_struct(tsk);
  598. }
  599. spin_unlock_irq(&pfault_lock);
  600. break;
  601. default:
  602. break;
  603. }
  604. return NOTIFY_OK;
  605. }
  606. static int __init pfault_irq_init(void)
  607. {
  608. int rc;
  609. rc = register_external_interrupt(0x2603, pfault_interrupt);
  610. if (rc)
  611. goto out_extint;
  612. rc = pfault_init() == 0 ? 0 : -EOPNOTSUPP;
  613. if (rc)
  614. goto out_pfault;
  615. irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
  616. hotcpu_notifier(pfault_cpu_notify, 0);
  617. return 0;
  618. out_pfault:
  619. unregister_external_interrupt(0x2603, pfault_interrupt);
  620. out_extint:
  621. pfault_disable = 1;
  622. return rc;
  623. }
  624. early_initcall(pfault_irq_init);
  625. #endif /* CONFIG_PFAULT */