fault_64.c 19 KB

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