fault.c 17 KB

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