fault_32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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 dump_pagetable(unsigned long address)
  159. {
  160. __typeof__(pte_val(__pte(0))) page;
  161. page = read_cr3();
  162. page = ((__typeof__(page) *) __va(page))[address >> PGDIR_SHIFT];
  163. #ifdef CONFIG_X86_PAE
  164. printk("*pdpt = %016Lx ", page);
  165. if ((page >> PAGE_SHIFT) < max_low_pfn
  166. && page & _PAGE_PRESENT) {
  167. page &= PAGE_MASK;
  168. page = ((__typeof__(page) *) __va(page))[(address >> PMD_SHIFT)
  169. & (PTRS_PER_PMD - 1)];
  170. printk(KERN_CONT "*pde = %016Lx ", page);
  171. page &= ~_PAGE_NX;
  172. }
  173. #else
  174. printk("*pde = %08lx ", page);
  175. #endif
  176. /*
  177. * We must not directly access the pte in the highpte
  178. * case if the page table is located in highmem.
  179. * And let's rather not kmap-atomic the pte, just in case
  180. * it's allocated already.
  181. */
  182. if ((page >> PAGE_SHIFT) < max_low_pfn
  183. && (page & _PAGE_PRESENT)
  184. && !(page & _PAGE_PSE)) {
  185. page &= PAGE_MASK;
  186. page = ((__typeof__(page) *) __va(page))[(address >> PAGE_SHIFT)
  187. & (PTRS_PER_PTE - 1)];
  188. printk("*pte = %0*Lx ", sizeof(page)*2, (u64)page);
  189. }
  190. printk("\n");
  191. }
  192. void do_invalid_op(struct pt_regs *, unsigned long);
  193. static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
  194. {
  195. unsigned index = pgd_index(address);
  196. pgd_t *pgd_k;
  197. pud_t *pud, *pud_k;
  198. pmd_t *pmd, *pmd_k;
  199. pgd += index;
  200. pgd_k = init_mm.pgd + index;
  201. if (!pgd_present(*pgd_k))
  202. return NULL;
  203. /*
  204. * set_pgd(pgd, *pgd_k); here would be useless on PAE
  205. * and redundant with the set_pmd() on non-PAE. As would
  206. * set_pud.
  207. */
  208. pud = pud_offset(pgd, address);
  209. pud_k = pud_offset(pgd_k, address);
  210. if (!pud_present(*pud_k))
  211. return NULL;
  212. pmd = pmd_offset(pud, address);
  213. pmd_k = pmd_offset(pud_k, address);
  214. if (!pmd_present(*pmd_k))
  215. return NULL;
  216. if (!pmd_present(*pmd)) {
  217. set_pmd(pmd, *pmd_k);
  218. arch_flush_lazy_mmu_mode();
  219. } else
  220. BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
  221. return pmd_k;
  222. }
  223. #ifdef CONFIG_X86_64
  224. static const char errata93_warning[] =
  225. KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n"
  226. KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n"
  227. KERN_ERR "******* Please consider a BIOS update.\n"
  228. KERN_ERR "******* Disabling USB legacy in the BIOS may also help.\n";
  229. #endif
  230. /* Workaround for K8 erratum #93 & buggy BIOS.
  231. BIOS SMM functions are required to use a specific workaround
  232. to avoid corruption of the 64bit RIP register on C stepping K8.
  233. A lot of BIOS that didn't get tested properly miss this.
  234. The OS sees this as a page fault with the upper 32bits of RIP cleared.
  235. Try to work around it here.
  236. Note we only handle faults in kernel here.
  237. Does nothing for X86_32
  238. */
  239. static int is_errata93(struct pt_regs *regs, unsigned long address)
  240. {
  241. #ifdef CONFIG_X86_64
  242. static int warned;
  243. if (address != regs->ip)
  244. return 0;
  245. if ((address >> 32) != 0)
  246. return 0;
  247. address |= 0xffffffffUL << 32;
  248. if ((address >= (u64)_stext && address <= (u64)_etext) ||
  249. (address >= MODULES_VADDR && address <= MODULES_END)) {
  250. if (!warned) {
  251. printk(errata93_warning);
  252. warned = 1;
  253. }
  254. regs->ip = address;
  255. return 1;
  256. }
  257. #endif
  258. return 0;
  259. }
  260. /*
  261. * Handle a fault on the vmalloc or module mapping area
  262. *
  263. * This assumes no large pages in there.
  264. */
  265. static inline int vmalloc_fault(unsigned long address)
  266. {
  267. #ifdef CONFIG_X86_32
  268. unsigned long pgd_paddr;
  269. pmd_t *pmd_k;
  270. pte_t *pte_k;
  271. /*
  272. * Synchronize this task's top level page-table
  273. * with the 'reference' page table.
  274. *
  275. * Do _not_ use "current" here. We might be inside
  276. * an interrupt in the middle of a task switch..
  277. */
  278. pgd_paddr = read_cr3();
  279. pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
  280. if (!pmd_k)
  281. return -1;
  282. pte_k = pte_offset_kernel(pmd_k, address);
  283. if (!pte_present(*pte_k))
  284. return -1;
  285. return 0;
  286. #else
  287. pgd_t *pgd, *pgd_ref;
  288. pud_t *pud, *pud_ref;
  289. pmd_t *pmd, *pmd_ref;
  290. pte_t *pte, *pte_ref;
  291. /* Copy kernel mappings over when needed. This can also
  292. happen within a race in page table update. In the later
  293. case just flush. */
  294. pgd = pgd_offset(current->mm ?: &init_mm, address);
  295. pgd_ref = pgd_offset_k(address);
  296. if (pgd_none(*pgd_ref))
  297. return -1;
  298. if (pgd_none(*pgd))
  299. set_pgd(pgd, *pgd_ref);
  300. else
  301. BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
  302. /* Below here mismatches are bugs because these lower tables
  303. are shared */
  304. pud = pud_offset(pgd, address);
  305. pud_ref = pud_offset(pgd_ref, address);
  306. if (pud_none(*pud_ref))
  307. return -1;
  308. if (pud_none(*pud) || pud_page_vaddr(*pud) != pud_page_vaddr(*pud_ref))
  309. BUG();
  310. pmd = pmd_offset(pud, address);
  311. pmd_ref = pmd_offset(pud_ref, address);
  312. if (pmd_none(*pmd_ref))
  313. return -1;
  314. if (pmd_none(*pmd) || pmd_page(*pmd) != pmd_page(*pmd_ref))
  315. BUG();
  316. pte_ref = pte_offset_kernel(pmd_ref, address);
  317. if (!pte_present(*pte_ref))
  318. return -1;
  319. pte = pte_offset_kernel(pmd, address);
  320. /* Don't use pte_page here, because the mappings can point
  321. outside mem_map, and the NUMA hash lookup cannot handle
  322. that. */
  323. if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref))
  324. BUG();
  325. return 0;
  326. #endif
  327. }
  328. int show_unhandled_signals = 1;
  329. /*
  330. * This routine handles page faults. It determines the address,
  331. * and the problem, and then passes it off to one of the appropriate
  332. * routines.
  333. */
  334. void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
  335. {
  336. struct task_struct *tsk;
  337. struct mm_struct *mm;
  338. struct vm_area_struct *vma;
  339. unsigned long address;
  340. int write, si_code;
  341. int fault;
  342. /*
  343. * We can fault from pretty much anywhere, with unknown IRQ state.
  344. */
  345. trace_hardirqs_fixup();
  346. tsk = current;
  347. mm = tsk->mm;
  348. prefetchw(&mm->mmap_sem);
  349. /* get the address */
  350. address = read_cr2();
  351. si_code = SEGV_MAPERR;
  352. if (notify_page_fault(regs))
  353. return;
  354. /*
  355. * We fault-in kernel-space virtual memory on-demand. The
  356. * 'reference' page table is init_mm.pgd.
  357. *
  358. * NOTE! We MUST NOT take any locks for this case. We may
  359. * be in an interrupt or a critical region, and should
  360. * only copy the information from the master page table,
  361. * nothing more.
  362. *
  363. * This verifies that the fault happens in kernel space
  364. * (error_code & 4) == 0, and that the fault was not a
  365. * protection error (error_code & 9) == 0.
  366. */
  367. if (unlikely(address >= TASK_SIZE)) {
  368. if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
  369. vmalloc_fault(address) >= 0)
  370. return;
  371. /*
  372. * Don't take the mm semaphore here. If we fixup a prefetch
  373. * fault we could otherwise deadlock.
  374. */
  375. goto bad_area_nosemaphore;
  376. }
  377. /* It's safe to allow irq's after cr2 has been saved and the vmalloc
  378. fault has been handled. */
  379. if (regs->flags & (X86_EFLAGS_IF|VM_MASK))
  380. local_irq_enable();
  381. /*
  382. * If we're in an interrupt, have no user context or are running in an
  383. * atomic region then we must not take the fault.
  384. */
  385. if (in_atomic() || !mm)
  386. goto bad_area_nosemaphore;
  387. /* When running in the kernel we expect faults to occur only to
  388. * addresses in user space. All other faults represent errors in the
  389. * kernel and should generate an OOPS. Unfortunately, in the case of an
  390. * erroneous fault occurring in a code path which already holds mmap_sem
  391. * we will deadlock attempting to validate the fault against the
  392. * address space. Luckily the kernel only validly references user
  393. * space from well defined areas of code, which are listed in the
  394. * exceptions table.
  395. *
  396. * As the vast majority of faults will be valid we will only perform
  397. * the source reference check when there is a possibility of a deadlock.
  398. * Attempt to lock the address space, if we cannot we then validate the
  399. * source. If this is invalid we can skip the address space check,
  400. * thus avoiding the deadlock.
  401. */
  402. if (!down_read_trylock(&mm->mmap_sem)) {
  403. if ((error_code & PF_USER) == 0 &&
  404. !search_exception_tables(regs->ip))
  405. goto bad_area_nosemaphore;
  406. down_read(&mm->mmap_sem);
  407. }
  408. vma = find_vma(mm, address);
  409. if (!vma)
  410. goto bad_area;
  411. if (vma->vm_start <= address)
  412. goto good_area;
  413. if (!(vma->vm_flags & VM_GROWSDOWN))
  414. goto bad_area;
  415. if (error_code & PF_USER) {
  416. /*
  417. * Accessing the stack below %sp is always a bug.
  418. * The large cushion allows instructions like enter
  419. * and pusha to work. ("enter $65535,$31" pushes
  420. * 32 pointers and then decrements %sp by 65535.)
  421. */
  422. if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
  423. goto bad_area;
  424. }
  425. if (expand_stack(vma, address))
  426. goto bad_area;
  427. /*
  428. * Ok, we have a good vm_area for this memory access, so
  429. * we can handle it..
  430. */
  431. good_area:
  432. si_code = SEGV_ACCERR;
  433. write = 0;
  434. switch (error_code & (PF_PROT|PF_WRITE)) {
  435. default: /* 3: write, present */
  436. /* fall through */
  437. case PF_WRITE: /* write, not present */
  438. if (!(vma->vm_flags & VM_WRITE))
  439. goto bad_area;
  440. write++;
  441. break;
  442. case PF_PROT: /* read, present */
  443. goto bad_area;
  444. case 0: /* read, not present */
  445. if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
  446. goto bad_area;
  447. }
  448. survive:
  449. /*
  450. * If for any reason at all we couldn't handle the fault,
  451. * make sure we exit gracefully rather than endlessly redo
  452. * the fault.
  453. */
  454. fault = handle_mm_fault(mm, vma, address, write);
  455. if (unlikely(fault & VM_FAULT_ERROR)) {
  456. if (fault & VM_FAULT_OOM)
  457. goto out_of_memory;
  458. else if (fault & VM_FAULT_SIGBUS)
  459. goto do_sigbus;
  460. BUG();
  461. }
  462. if (fault & VM_FAULT_MAJOR)
  463. tsk->maj_flt++;
  464. else
  465. tsk->min_flt++;
  466. #ifdef CONFIG_X86_32
  467. /*
  468. * Did it hit the DOS screen memory VA from vm86 mode?
  469. */
  470. if (v8086_mode(regs)) {
  471. unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
  472. if (bit < 32)
  473. tsk->thread.screen_bitmap |= 1 << bit;
  474. }
  475. #endif
  476. up_read(&mm->mmap_sem);
  477. return;
  478. /*
  479. * Something tried to access memory that isn't in our memory map..
  480. * Fix it, but check if it's kernel or user first..
  481. */
  482. bad_area:
  483. up_read(&mm->mmap_sem);
  484. bad_area_nosemaphore:
  485. /* User mode accesses just cause a SIGSEGV */
  486. if (error_code & PF_USER) {
  487. /*
  488. * It's possible to have interrupts off here.
  489. */
  490. local_irq_enable();
  491. /*
  492. * Valid to do another page fault here because this one came
  493. * from user space.
  494. */
  495. if (is_prefetch(regs, address, error_code))
  496. return;
  497. if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
  498. printk_ratelimit()) {
  499. printk(
  500. #ifdef CONFIG_X86_32
  501. "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
  502. #else
  503. "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
  504. #endif
  505. task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
  506. tsk->comm, task_pid_nr(tsk), address, regs->ip,
  507. regs->sp, error_code);
  508. print_vma_addr(" in ", regs->ip);
  509. printk("\n");
  510. }
  511. tsk->thread.cr2 = address;
  512. /* Kernel addresses are always protection faults */
  513. tsk->thread.error_code = error_code | (address >= TASK_SIZE);
  514. tsk->thread.trap_no = 14;
  515. force_sig_info_fault(SIGSEGV, si_code, address, tsk);
  516. return;
  517. }
  518. #ifdef CONFIG_X86_F00F_BUG
  519. /*
  520. * Pentium F0 0F C7 C8 bug workaround.
  521. */
  522. if (boot_cpu_data.f00f_bug) {
  523. unsigned long nr;
  524. nr = (address - idt_descr.address) >> 3;
  525. if (nr == 6) {
  526. do_invalid_op(regs, 0);
  527. return;
  528. }
  529. }
  530. #endif
  531. no_context:
  532. /* Are we prepared to handle this kernel fault? */
  533. if (fixup_exception(regs))
  534. return;
  535. /*
  536. * Valid to do another page fault here, because if this fault
  537. * had been triggered by is_prefetch fixup_exception would have
  538. * handled it.
  539. */
  540. if (is_prefetch(regs, address, error_code))
  541. return;
  542. if (is_errata93(regs, address))
  543. return;
  544. /*
  545. * Oops. The kernel tried to access some bad page. We'll have to
  546. * terminate things with extreme prejudice.
  547. */
  548. bust_spinlocks(1);
  549. if (oops_may_print()) {
  550. #ifdef CONFIG_X86_PAE
  551. if (error_code & PF_INSTR) {
  552. int level;
  553. pte_t *pte = lookup_address(address, &level);
  554. if (pte && pte_present(*pte) && !pte_exec(*pte))
  555. printk(KERN_CRIT "kernel tried to execute "
  556. "NX-protected page - exploit attempt? "
  557. "(uid: %d)\n", current->uid);
  558. }
  559. #endif
  560. if (address < PAGE_SIZE)
  561. printk(KERN_ALERT "BUG: unable to handle kernel NULL "
  562. "pointer dereference");
  563. else
  564. printk(KERN_ALERT "BUG: unable to handle kernel paging"
  565. " request");
  566. printk(" at virtual address %08lx\n", address);
  567. printk(KERN_ALERT "printing ip: %08lx ", regs->ip);
  568. dump_pagetable(address);
  569. }
  570. tsk->thread.cr2 = address;
  571. tsk->thread.trap_no = 14;
  572. tsk->thread.error_code = error_code;
  573. die("Oops", regs, error_code);
  574. bust_spinlocks(0);
  575. do_exit(SIGKILL);
  576. /*
  577. * We ran out of memory, or some other thing happened to us that made
  578. * us unable to handle the page fault gracefully.
  579. */
  580. out_of_memory:
  581. up_read(&mm->mmap_sem);
  582. if (is_global_init(tsk)) {
  583. yield();
  584. down_read(&mm->mmap_sem);
  585. goto survive;
  586. }
  587. printk("VM: killing process %s\n", tsk->comm);
  588. if (error_code & PF_USER)
  589. do_group_exit(SIGKILL);
  590. goto no_context;
  591. do_sigbus:
  592. up_read(&mm->mmap_sem);
  593. /* Kernel mode? Handle exceptions or die */
  594. if (!(error_code & PF_USER))
  595. goto no_context;
  596. /* User space => ok to do another page fault */
  597. if (is_prefetch(regs, address, error_code))
  598. return;
  599. tsk->thread.cr2 = address;
  600. tsk->thread.error_code = error_code;
  601. tsk->thread.trap_no = 14;
  602. force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
  603. }
  604. void vmalloc_sync_all(void)
  605. {
  606. /*
  607. * Note that races in the updates of insync and start aren't
  608. * problematic: insync can only get set bits added, and updates to
  609. * start are only improving performance (without affecting correctness
  610. * if undone).
  611. */
  612. static DECLARE_BITMAP(insync, PTRS_PER_PGD);
  613. static unsigned long start = TASK_SIZE;
  614. unsigned long address;
  615. if (SHARED_KERNEL_PMD)
  616. return;
  617. BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
  618. for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
  619. if (!test_bit(pgd_index(address), insync)) {
  620. unsigned long flags;
  621. struct page *page;
  622. spin_lock_irqsave(&pgd_lock, flags);
  623. for (page = pgd_list; page; page =
  624. (struct page *)page->index)
  625. if (!vmalloc_sync_one(page_address(page),
  626. address)) {
  627. BUG_ON(page != pgd_list);
  628. break;
  629. }
  630. spin_unlock_irqrestore(&pgd_lock, flags);
  631. if (!page)
  632. set_bit(pgd_index(address), insync);
  633. }
  634. if (address == start && test_bit(pgd_index(address), insync))
  635. start = address + PGDIR_SIZE;
  636. }
  637. }