fault_32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. */
  4. #include <linux/signal.h>
  5. #include <linux/sched.h>
  6. #include <linux/kernel.h>
  7. #include <linux/errno.h>
  8. #include <linux/string.h>
  9. #include <linux/types.h>
  10. #include <linux/ptrace.h>
  11. #include <linux/mman.h>
  12. #include <linux/mm.h>
  13. #include <linux/smp.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/init.h>
  16. #include <linux/tty.h>
  17. #include <linux/vt_kern.h> /* For unblank_screen() */
  18. #include <linux/highmem.h>
  19. #include <linux/bootmem.h> /* for max_low_pfn */
  20. #include <linux/vmalloc.h>
  21. #include <linux/module.h>
  22. #include <linux/kprobes.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/kdebug.h>
  25. #include <asm/system.h>
  26. #include <asm/desc.h>
  27. #include <asm/segment.h>
  28. /*
  29. * Page fault error code bits
  30. * bit 0 == 0 means no page found, 1 means protection fault
  31. * bit 1 == 0 means read, 1 means write
  32. * bit 2 == 0 means kernel, 1 means user-mode
  33. * bit 3 == 1 means use of reserved bit detected
  34. * bit 4 == 1 means fault was an instruction fetch
  35. */
  36. #define PF_PROT (1<<0)
  37. #define PF_WRITE (1<<1)
  38. #define PF_USER (1<<2)
  39. #define PF_RSVD (1<<3)
  40. #define PF_INSTR (1<<4)
  41. static inline int notify_page_fault(struct pt_regs *regs)
  42. {
  43. #ifdef CONFIG_KPROBES
  44. int ret = 0;
  45. /* kprobe_running() needs smp_processor_id() */
  46. if (!user_mode_vm(regs)) {
  47. preempt_disable();
  48. if (kprobe_running() && kprobe_fault_handler(regs, 14))
  49. ret = 1;
  50. preempt_enable();
  51. }
  52. return ret;
  53. #else
  54. return 0;
  55. #endif
  56. }
  57. /*
  58. * X86_32
  59. * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
  60. * Check that here and ignore it.
  61. *
  62. * X86_64
  63. * Sometimes the CPU reports invalid exceptions on prefetch.
  64. * Check that here and ignore it.
  65. *
  66. * Opcode checker based on code by Richard Brunner
  67. */
  68. static int is_prefetch(struct pt_regs *regs, unsigned long addr,
  69. unsigned long error_code)
  70. {
  71. unsigned char *instr;
  72. int scan_more = 1;
  73. int prefetch = 0;
  74. unsigned char *max_instr;
  75. #ifdef CONFIG_X86_32
  76. if (unlikely(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  77. boot_cpu_data.x86 >= 6)) {
  78. /* Catch an obscure case of prefetch inside an NX page. */
  79. if (nx_enabled && (error_code & PF_INSTR))
  80. return 0;
  81. } else {
  82. return 0;
  83. }
  84. #else
  85. /* If it was a exec fault ignore */
  86. if (error_code & PF_INSTR)
  87. return 0;
  88. #endif
  89. instr = (unsigned char *)convert_ip_to_linear(current, regs);
  90. max_instr = instr + 15;
  91. if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE)
  92. return 0;
  93. while (scan_more && instr < max_instr) {
  94. unsigned char opcode;
  95. unsigned char instr_hi;
  96. unsigned char instr_lo;
  97. if (probe_kernel_address(instr, opcode))
  98. break;
  99. instr_hi = opcode & 0xf0;
  100. instr_lo = opcode & 0x0f;
  101. instr++;
  102. switch (instr_hi) {
  103. case 0x20:
  104. case 0x30:
  105. /*
  106. * Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes.
  107. * In X86_64 long mode, the CPU will signal invalid
  108. * opcode if some of these prefixes are present so
  109. * X86_64 will never get here anyway
  110. */
  111. scan_more = ((instr_lo & 7) == 0x6);
  112. break;
  113. #ifdef CONFIG_X86_64
  114. case 0x40:
  115. /*
  116. * In AMD64 long mode 0x40..0x4F are valid REX prefixes
  117. * Need to figure out under what instruction mode the
  118. * instruction was issued. Could check the LDT for lm,
  119. * but for now it's good enough to assume that long
  120. * mode only uses well known segments or kernel.
  121. */
  122. scan_more = (!user_mode(regs)) || (regs->cs == __USER_CS);
  123. break;
  124. #endif
  125. case 0x60:
  126. /* 0x64 thru 0x67 are valid prefixes in all modes. */
  127. scan_more = (instr_lo & 0xC) == 0x4;
  128. break;
  129. case 0xF0:
  130. /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
  131. scan_more = !instr_lo || (instr_lo>>1) == 1;
  132. break;
  133. case 0x00:
  134. /* Prefetch instruction is 0x0F0D or 0x0F18 */
  135. scan_more = 0;
  136. if (probe_kernel_address(instr, opcode))
  137. break;
  138. prefetch = (instr_lo == 0xF) &&
  139. (opcode == 0x0D || opcode == 0x18);
  140. break;
  141. default:
  142. scan_more = 0;
  143. break;
  144. }
  145. }
  146. return prefetch;
  147. }
  148. static void force_sig_info_fault(int si_signo, int si_code,
  149. unsigned long address, struct task_struct *tsk)
  150. {
  151. siginfo_t info;
  152. info.si_signo = si_signo;
  153. info.si_errno = 0;
  154. info.si_code = si_code;
  155. info.si_addr = (void __user *)address;
  156. force_sig_info(si_signo, &info, tsk);
  157. }
  158. void do_invalid_op(struct pt_regs *, unsigned long);
  159. static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
  160. {
  161. unsigned index = pgd_index(address);
  162. pgd_t *pgd_k;
  163. pud_t *pud, *pud_k;
  164. pmd_t *pmd, *pmd_k;
  165. pgd += index;
  166. pgd_k = init_mm.pgd + index;
  167. if (!pgd_present(*pgd_k))
  168. return NULL;
  169. /*
  170. * set_pgd(pgd, *pgd_k); here would be useless on PAE
  171. * and redundant with the set_pmd() on non-PAE. As would
  172. * set_pud.
  173. */
  174. pud = pud_offset(pgd, address);
  175. pud_k = pud_offset(pgd_k, address);
  176. if (!pud_present(*pud_k))
  177. return NULL;
  178. pmd = pmd_offset(pud, address);
  179. pmd_k = pmd_offset(pud_k, address);
  180. if (!pmd_present(*pmd_k))
  181. return NULL;
  182. if (!pmd_present(*pmd)) {
  183. set_pmd(pmd, *pmd_k);
  184. arch_flush_lazy_mmu_mode();
  185. } else
  186. BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
  187. return pmd_k;
  188. }
  189. #ifdef CONFIG_X86_64
  190. static const char errata93_warning[] =
  191. KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n"
  192. KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n"
  193. KERN_ERR "******* Please consider a BIOS update.\n"
  194. KERN_ERR "******* Disabling USB legacy in the BIOS may also help.\n";
  195. #endif
  196. /* Workaround for K8 erratum #93 & buggy BIOS.
  197. BIOS SMM functions are required to use a specific workaround
  198. to avoid corruption of the 64bit RIP register on C stepping K8.
  199. A lot of BIOS that didn't get tested properly miss this.
  200. The OS sees this as a page fault with the upper 32bits of RIP cleared.
  201. Try to work around it here.
  202. Note we only handle faults in kernel here.
  203. Does nothing for X86_32
  204. */
  205. static int is_errata93(struct pt_regs *regs, unsigned long address)
  206. {
  207. #ifdef CONFIG_X86_64
  208. static int warned;
  209. if (address != regs->ip)
  210. return 0;
  211. if ((address >> 32) != 0)
  212. return 0;
  213. address |= 0xffffffffUL << 32;
  214. if ((address >= (u64)_stext && address <= (u64)_etext) ||
  215. (address >= MODULES_VADDR && address <= MODULES_END)) {
  216. if (!warned) {
  217. printk(errata93_warning);
  218. warned = 1;
  219. }
  220. regs->ip = address;
  221. return 1;
  222. }
  223. #endif
  224. return 0;
  225. }
  226. /*
  227. * Handle a fault on the vmalloc or module mapping area
  228. *
  229. * This assumes no large pages in there.
  230. */
  231. static inline int vmalloc_fault(unsigned long address)
  232. {
  233. #ifdef CONFIG_X86_32
  234. unsigned long pgd_paddr;
  235. pmd_t *pmd_k;
  236. pte_t *pte_k;
  237. /*
  238. * Synchronize this task's top level page-table
  239. * with the 'reference' page table.
  240. *
  241. * Do _not_ use "current" here. We might be inside
  242. * an interrupt in the middle of a task switch..
  243. */
  244. pgd_paddr = read_cr3();
  245. pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
  246. if (!pmd_k)
  247. return -1;
  248. pte_k = pte_offset_kernel(pmd_k, address);
  249. if (!pte_present(*pte_k))
  250. return -1;
  251. return 0;
  252. #else
  253. pgd_t *pgd, *pgd_ref;
  254. pud_t *pud, *pud_ref;
  255. pmd_t *pmd, *pmd_ref;
  256. pte_t *pte, *pte_ref;
  257. /* Copy kernel mappings over when needed. This can also
  258. happen within a race in page table update. In the later
  259. case just flush. */
  260. pgd = pgd_offset(current->mm ?: &init_mm, address);
  261. pgd_ref = pgd_offset_k(address);
  262. if (pgd_none(*pgd_ref))
  263. return -1;
  264. if (pgd_none(*pgd))
  265. set_pgd(pgd, *pgd_ref);
  266. else
  267. BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
  268. /* Below here mismatches are bugs because these lower tables
  269. are shared */
  270. pud = pud_offset(pgd, address);
  271. pud_ref = pud_offset(pgd_ref, address);
  272. if (pud_none(*pud_ref))
  273. return -1;
  274. if (pud_none(*pud) || pud_page_vaddr(*pud) != pud_page_vaddr(*pud_ref))
  275. BUG();
  276. pmd = pmd_offset(pud, address);
  277. pmd_ref = pmd_offset(pud_ref, address);
  278. if (pmd_none(*pmd_ref))
  279. return -1;
  280. if (pmd_none(*pmd) || pmd_page(*pmd) != pmd_page(*pmd_ref))
  281. BUG();
  282. pte_ref = pte_offset_kernel(pmd_ref, address);
  283. if (!pte_present(*pte_ref))
  284. return -1;
  285. pte = pte_offset_kernel(pmd, address);
  286. /* Don't use pte_page here, because the mappings can point
  287. outside mem_map, and the NUMA hash lookup cannot handle
  288. that. */
  289. if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref))
  290. BUG();
  291. return 0;
  292. #endif
  293. }
  294. int show_unhandled_signals = 1;
  295. /*
  296. * This routine handles page faults. It determines the address,
  297. * and the problem, and then passes it off to one of the appropriate
  298. * routines.
  299. */
  300. void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
  301. {
  302. struct task_struct *tsk;
  303. struct mm_struct *mm;
  304. struct vm_area_struct *vma;
  305. unsigned long address;
  306. int write, si_code;
  307. int fault;
  308. /*
  309. * We can fault from pretty much anywhere, with unknown IRQ state.
  310. */
  311. trace_hardirqs_fixup();
  312. tsk = current;
  313. mm = tsk->mm;
  314. prefetchw(&mm->mmap_sem);
  315. /* get the address */
  316. address = read_cr2();
  317. si_code = SEGV_MAPERR;
  318. if (notify_page_fault(regs))
  319. return;
  320. /*
  321. * We fault-in kernel-space virtual memory on-demand. The
  322. * 'reference' page table is init_mm.pgd.
  323. *
  324. * NOTE! We MUST NOT take any locks for this case. We may
  325. * be in an interrupt or a critical region, and should
  326. * only copy the information from the master page table,
  327. * nothing more.
  328. *
  329. * This verifies that the fault happens in kernel space
  330. * (error_code & 4) == 0, and that the fault was not a
  331. * protection error (error_code & 9) == 0.
  332. */
  333. if (unlikely(address >= TASK_SIZE)) {
  334. if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
  335. vmalloc_fault(address) >= 0)
  336. return;
  337. /*
  338. * Don't take the mm semaphore here. If we fixup a prefetch
  339. * fault we could otherwise deadlock.
  340. */
  341. goto bad_area_nosemaphore;
  342. }
  343. /* It's safe to allow irq's after cr2 has been saved and the vmalloc
  344. fault has been handled. */
  345. if (regs->flags & (X86_EFLAGS_IF|VM_MASK))
  346. local_irq_enable();
  347. /*
  348. * If we're in an interrupt, have no user context or are running in an
  349. * atomic region then we must not take the fault.
  350. */
  351. if (in_atomic() || !mm)
  352. goto bad_area_nosemaphore;
  353. /* When running in the kernel we expect faults to occur only to
  354. * addresses in user space. All other faults represent errors in the
  355. * kernel and should generate an OOPS. Unfortunately, in the case of an
  356. * erroneous fault occurring in a code path which already holds mmap_sem
  357. * we will deadlock attempting to validate the fault against the
  358. * address space. Luckily the kernel only validly references user
  359. * space from well defined areas of code, which are listed in the
  360. * exceptions table.
  361. *
  362. * As the vast majority of faults will be valid we will only perform
  363. * the source reference check when there is a possibility of a deadlock.
  364. * Attempt to lock the address space, if we cannot we then validate the
  365. * source. If this is invalid we can skip the address space check,
  366. * thus avoiding the deadlock.
  367. */
  368. if (!down_read_trylock(&mm->mmap_sem)) {
  369. if ((error_code & PF_USER) == 0 &&
  370. !search_exception_tables(regs->ip))
  371. goto bad_area_nosemaphore;
  372. down_read(&mm->mmap_sem);
  373. }
  374. vma = find_vma(mm, address);
  375. if (!vma)
  376. goto bad_area;
  377. if (vma->vm_start <= address)
  378. goto good_area;
  379. if (!(vma->vm_flags & VM_GROWSDOWN))
  380. goto bad_area;
  381. if (error_code & PF_USER) {
  382. /*
  383. * Accessing the stack below %sp is always a bug.
  384. * The large cushion allows instructions like enter
  385. * and pusha to work. ("enter $65535,$31" pushes
  386. * 32 pointers and then decrements %sp by 65535.)
  387. */
  388. if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
  389. goto bad_area;
  390. }
  391. if (expand_stack(vma, address))
  392. goto bad_area;
  393. /*
  394. * Ok, we have a good vm_area for this memory access, so
  395. * we can handle it..
  396. */
  397. good_area:
  398. si_code = SEGV_ACCERR;
  399. write = 0;
  400. switch (error_code & (PF_PROT|PF_WRITE)) {
  401. default: /* 3: write, present */
  402. /* fall through */
  403. case PF_WRITE: /* write, not present */
  404. if (!(vma->vm_flags & VM_WRITE))
  405. goto bad_area;
  406. write++;
  407. break;
  408. case PF_PROT: /* read, present */
  409. goto bad_area;
  410. case 0: /* read, not present */
  411. if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
  412. goto bad_area;
  413. }
  414. survive:
  415. /*
  416. * If for any reason at all we couldn't handle the fault,
  417. * make sure we exit gracefully rather than endlessly redo
  418. * the fault.
  419. */
  420. fault = handle_mm_fault(mm, vma, address, write);
  421. if (unlikely(fault & VM_FAULT_ERROR)) {
  422. if (fault & VM_FAULT_OOM)
  423. goto out_of_memory;
  424. else if (fault & VM_FAULT_SIGBUS)
  425. goto do_sigbus;
  426. BUG();
  427. }
  428. if (fault & VM_FAULT_MAJOR)
  429. tsk->maj_flt++;
  430. else
  431. tsk->min_flt++;
  432. /*
  433. * Did it hit the DOS screen memory VA from vm86 mode?
  434. */
  435. if (regs->flags & VM_MASK) {
  436. unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
  437. if (bit < 32)
  438. tsk->thread.screen_bitmap |= 1 << bit;
  439. }
  440. up_read(&mm->mmap_sem);
  441. return;
  442. /*
  443. * Something tried to access memory that isn't in our memory map..
  444. * Fix it, but check if it's kernel or user first..
  445. */
  446. bad_area:
  447. up_read(&mm->mmap_sem);
  448. bad_area_nosemaphore:
  449. /* User mode accesses just cause a SIGSEGV */
  450. if (error_code & PF_USER) {
  451. /*
  452. * It's possible to have interrupts off here.
  453. */
  454. local_irq_enable();
  455. /*
  456. * Valid to do another page fault here because this one came
  457. * from user space.
  458. */
  459. if (is_prefetch(regs, address, error_code))
  460. return;
  461. if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
  462. printk_ratelimit()) {
  463. printk(
  464. #ifdef CONFIG_X86_32
  465. "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
  466. #else
  467. "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
  468. #endif
  469. task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
  470. tsk->comm, task_pid_nr(tsk), address, regs->ip,
  471. regs->sp, error_code);
  472. print_vma_addr(" in ", regs->ip);
  473. printk("\n");
  474. }
  475. tsk->thread.cr2 = address;
  476. /* Kernel addresses are always protection faults */
  477. tsk->thread.error_code = error_code | (address >= TASK_SIZE);
  478. tsk->thread.trap_no = 14;
  479. force_sig_info_fault(SIGSEGV, si_code, address, tsk);
  480. return;
  481. }
  482. #ifdef CONFIG_X86_F00F_BUG
  483. /*
  484. * Pentium F0 0F C7 C8 bug workaround.
  485. */
  486. if (boot_cpu_data.f00f_bug) {
  487. unsigned long nr;
  488. nr = (address - idt_descr.address) >> 3;
  489. if (nr == 6) {
  490. do_invalid_op(regs, 0);
  491. return;
  492. }
  493. }
  494. #endif
  495. no_context:
  496. /* Are we prepared to handle this kernel fault? */
  497. if (fixup_exception(regs))
  498. return;
  499. /*
  500. * Valid to do another page fault here, because if this fault
  501. * had been triggered by is_prefetch fixup_exception would have
  502. * handled it.
  503. */
  504. if (is_prefetch(regs, address, error_code))
  505. return;
  506. if (is_errata93(regs, address))
  507. return;
  508. /*
  509. * Oops. The kernel tried to access some bad page. We'll have to
  510. * terminate things with extreme prejudice.
  511. */
  512. bust_spinlocks(1);
  513. if (oops_may_print()) {
  514. __typeof__(pte_val(__pte(0))) page;
  515. #ifdef CONFIG_X86_PAE
  516. if (error_code & PF_INSTR) {
  517. pte_t *pte = lookup_address(address);
  518. if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))
  519. printk(KERN_CRIT "kernel tried to execute "
  520. "NX-protected page - exploit attempt? "
  521. "(uid: %d)\n", current->uid);
  522. }
  523. #endif
  524. if (address < PAGE_SIZE)
  525. printk(KERN_ALERT "BUG: unable to handle kernel NULL "
  526. "pointer dereference");
  527. else
  528. printk(KERN_ALERT "BUG: unable to handle kernel paging"
  529. " request");
  530. printk(" at virtual address %08lx\n", address);
  531. printk(KERN_ALERT "printing ip: %08lx ", regs->ip);
  532. page = read_cr3();
  533. page = ((__typeof__(page) *) __va(page))[address >> PGDIR_SHIFT];
  534. #ifdef CONFIG_X86_PAE
  535. printk("*pdpt = %016Lx ", page);
  536. if ((page >> PAGE_SHIFT) < max_low_pfn
  537. && page & _PAGE_PRESENT) {
  538. page &= PAGE_MASK;
  539. page = ((__typeof__(page) *) __va(page))[(address >> PMD_SHIFT)
  540. & (PTRS_PER_PMD - 1)];
  541. printk(KERN_CONT "*pde = %016Lx ", page);
  542. page &= ~_PAGE_NX;
  543. }
  544. #else
  545. printk("*pde = %08lx ", page);
  546. #endif
  547. /*
  548. * We must not directly access the pte in the highpte
  549. * case if the page table is located in highmem.
  550. * And let's rather not kmap-atomic the pte, just in case
  551. * it's allocated already.
  552. */
  553. if ((page >> PAGE_SHIFT) < max_low_pfn
  554. && (page & _PAGE_PRESENT)
  555. && !(page & _PAGE_PSE)) {
  556. page &= PAGE_MASK;
  557. page = ((__typeof__(page) *) __va(page))[(address >> PAGE_SHIFT)
  558. & (PTRS_PER_PTE - 1)];
  559. printk("*pte = %0*Lx ", sizeof(page)*2, (u64)page);
  560. }
  561. printk("\n");
  562. }
  563. tsk->thread.cr2 = address;
  564. tsk->thread.trap_no = 14;
  565. tsk->thread.error_code = error_code;
  566. die("Oops", regs, error_code);
  567. bust_spinlocks(0);
  568. do_exit(SIGKILL);
  569. /*
  570. * We ran out of memory, or some other thing happened to us that made
  571. * us unable to handle the page fault gracefully.
  572. */
  573. out_of_memory:
  574. up_read(&mm->mmap_sem);
  575. if (is_global_init(tsk)) {
  576. yield();
  577. down_read(&mm->mmap_sem);
  578. goto survive;
  579. }
  580. printk("VM: killing process %s\n", tsk->comm);
  581. if (error_code & PF_USER)
  582. do_group_exit(SIGKILL);
  583. goto no_context;
  584. do_sigbus:
  585. up_read(&mm->mmap_sem);
  586. /* Kernel mode? Handle exceptions or die */
  587. if (!(error_code & PF_USER))
  588. goto no_context;
  589. /* User space => ok to do another page fault */
  590. if (is_prefetch(regs, address, error_code))
  591. return;
  592. tsk->thread.cr2 = address;
  593. tsk->thread.error_code = error_code;
  594. tsk->thread.trap_no = 14;
  595. force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
  596. }
  597. void vmalloc_sync_all(void)
  598. {
  599. /*
  600. * Note that races in the updates of insync and start aren't
  601. * problematic: insync can only get set bits added, and updates to
  602. * start are only improving performance (without affecting correctness
  603. * if undone).
  604. */
  605. static DECLARE_BITMAP(insync, PTRS_PER_PGD);
  606. static unsigned long start = TASK_SIZE;
  607. unsigned long address;
  608. if (SHARED_KERNEL_PMD)
  609. return;
  610. BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
  611. for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
  612. if (!test_bit(pgd_index(address), insync)) {
  613. unsigned long flags;
  614. struct page *page;
  615. spin_lock_irqsave(&pgd_lock, flags);
  616. for (page = pgd_list; page; page =
  617. (struct page *)page->index)
  618. if (!vmalloc_sync_one(page_address(page),
  619. address)) {
  620. BUG_ON(page != pgd_list);
  621. break;
  622. }
  623. spin_unlock_irqrestore(&pgd_lock, flags);
  624. if (!page)
  625. set_bit(pgd_index(address), insync);
  626. }
  627. if (address == start && test_bit(pgd_index(address), insync))
  628. start = address + PGDIR_SIZE;
  629. }
  630. }