fault_32.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. #ifdef CONFIG_X86_32
  58. /*
  59. * Return EIP plus the CS segment base. The segment limit is also
  60. * adjusted, clamped to the kernel/user address space (whichever is
  61. * appropriate), and returned in *eip_limit.
  62. *
  63. * The segment is checked, because it might have been changed by another
  64. * task between the original faulting instruction and here.
  65. *
  66. * If CS is no longer a valid code segment, or if EIP is beyond the
  67. * limit, or if it is a kernel address when CS is not a kernel segment,
  68. * then the returned value will be greater than *eip_limit.
  69. *
  70. * This is slow, but is very rarely executed.
  71. */
  72. static inline unsigned long get_segment_eip(struct pt_regs *regs,
  73. unsigned long *eip_limit)
  74. {
  75. unsigned long ip = regs->ip;
  76. unsigned seg = regs->cs & 0xffff;
  77. u32 seg_ar, seg_limit, base, *desc;
  78. /* Unlikely, but must come before segment checks. */
  79. if (unlikely(regs->flags & VM_MASK)) {
  80. base = seg << 4;
  81. *eip_limit = base + 0xffff;
  82. return base + (ip & 0xffff);
  83. }
  84. /* The standard kernel/user address space limit. */
  85. *eip_limit = user_mode(regs) ? USER_DS.seg : KERNEL_DS.seg;
  86. /* By far the most common cases. */
  87. if (likely(SEGMENT_IS_FLAT_CODE(seg)))
  88. return ip;
  89. /* Check the segment exists, is within the current LDT/GDT size,
  90. that kernel/user (ring 0..3) has the appropriate privilege,
  91. that it's a code segment, and get the limit. */
  92. __asm__ ("larl %3,%0; lsll %3,%1"
  93. : "=&r" (seg_ar), "=r" (seg_limit) : "0" (0), "rm" (seg));
  94. if ((~seg_ar & 0x9800) || ip > seg_limit) {
  95. *eip_limit = 0;
  96. return 1; /* So that returned ip > *eip_limit. */
  97. }
  98. /* Get the GDT/LDT descriptor base.
  99. When you look for races in this code remember that
  100. LDT and other horrors are only used in user space. */
  101. if (seg & (1<<2)) {
  102. /* Must lock the LDT while reading it. */
  103. mutex_lock(&current->mm->context.lock);
  104. desc = current->mm->context.ldt;
  105. desc = (void *)desc + (seg & ~7);
  106. } else {
  107. /* Must disable preemption while reading the GDT. */
  108. desc = (u32 *)get_cpu_gdt_table(get_cpu());
  109. desc = (void *)desc + (seg & ~7);
  110. }
  111. /* Decode the code segment base from the descriptor */
  112. base = get_desc_base((struct desc_struct *)desc);
  113. if (seg & (1<<2))
  114. mutex_unlock(&current->mm->context.lock);
  115. else
  116. put_cpu();
  117. /* Adjust EIP and segment limit, and clamp at the kernel limit.
  118. It's legitimate for segments to wrap at 0xffffffff. */
  119. seg_limit += base;
  120. if (seg_limit < *eip_limit && seg_limit >= base)
  121. *eip_limit = seg_limit;
  122. return ip + base;
  123. }
  124. #endif
  125. /*
  126. * X86_32
  127. * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
  128. * Check that here and ignore it.
  129. *
  130. * X86_64
  131. * Sometimes the CPU reports invalid exceptions on prefetch.
  132. * Check that here and ignore it.
  133. *
  134. * Opcode checker based on code by Richard Brunner
  135. */
  136. static int is_prefetch(struct pt_regs *regs, unsigned long addr,
  137. unsigned long error_code)
  138. {
  139. unsigned char *instr;
  140. int scan_more = 1;
  141. int prefetch = 0;
  142. unsigned char *max_instr;
  143. #ifdef CONFIG_X86_32
  144. unsigned long limit;
  145. if (unlikely(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  146. boot_cpu_data.x86 >= 6)) {
  147. /* Catch an obscure case of prefetch inside an NX page. */
  148. if (nx_enabled && (error_code & PF_INSTR))
  149. return 0;
  150. } else {
  151. return 0;
  152. }
  153. instr = (unsigned char *)get_segment_eip(regs, &limit);
  154. #else
  155. /* If it was a exec fault ignore */
  156. if (error_code & PF_INSTR)
  157. return 0;
  158. instr = (unsigned char __user *)convert_rip_to_linear(current, regs);
  159. #endif
  160. max_instr = instr + 15;
  161. #ifdef CONFIG_X86_64
  162. if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE)
  163. return 0;
  164. #endif
  165. while (scan_more && instr < max_instr) {
  166. unsigned char opcode;
  167. unsigned char instr_hi;
  168. unsigned char instr_lo;
  169. #ifdef CONFIG_X86_32
  170. if (instr > (unsigned char *)limit)
  171. break;
  172. #endif
  173. if (probe_kernel_address(instr, opcode))
  174. break;
  175. instr_hi = opcode & 0xf0;
  176. instr_lo = opcode & 0x0f;
  177. instr++;
  178. switch (instr_hi) {
  179. case 0x20:
  180. case 0x30:
  181. /*
  182. * Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes.
  183. * In X86_64 long mode, the CPU will signal invalid
  184. * opcode if some of these prefixes are present so
  185. * X86_64 will never get here anyway
  186. */
  187. scan_more = ((instr_lo & 7) == 0x6);
  188. break;
  189. #ifdef CONFIG_X86_64
  190. case 0x40:
  191. /*
  192. * In AMD64 long mode 0x40..0x4F are valid REX prefixes
  193. * Need to figure out under what instruction mode the
  194. * instruction was issued. Could check the LDT for lm,
  195. * but for now it's good enough to assume that long
  196. * mode only uses well known segments or kernel.
  197. */
  198. scan_more = (!user_mode(regs)) || (regs->cs == __USER_CS);
  199. break;
  200. #endif
  201. case 0x60:
  202. /* 0x64 thru 0x67 are valid prefixes in all modes. */
  203. scan_more = (instr_lo & 0xC) == 0x4;
  204. break;
  205. case 0xF0:
  206. /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
  207. scan_more = !instr_lo || (instr_lo>>1) == 1;
  208. break;
  209. case 0x00:
  210. /* Prefetch instruction is 0x0F0D or 0x0F18 */
  211. scan_more = 0;
  212. #ifdef CONFIG_X86_32
  213. if (instr > (unsigned char *)limit)
  214. break;
  215. #endif
  216. if (probe_kernel_address(instr, opcode))
  217. break;
  218. prefetch = (instr_lo == 0xF) &&
  219. (opcode == 0x0D || opcode == 0x18);
  220. break;
  221. default:
  222. scan_more = 0;
  223. break;
  224. }
  225. }
  226. return prefetch;
  227. }
  228. static noinline void force_sig_info_fault(int si_signo, int si_code,
  229. unsigned long address, struct task_struct *tsk)
  230. {
  231. siginfo_t info;
  232. info.si_signo = si_signo;
  233. info.si_errno = 0;
  234. info.si_code = si_code;
  235. info.si_addr = (void __user *)address;
  236. force_sig_info(si_signo, &info, tsk);
  237. }
  238. void do_invalid_op(struct pt_regs *, unsigned long);
  239. static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
  240. {
  241. unsigned index = pgd_index(address);
  242. pgd_t *pgd_k;
  243. pud_t *pud, *pud_k;
  244. pmd_t *pmd, *pmd_k;
  245. pgd += index;
  246. pgd_k = init_mm.pgd + index;
  247. if (!pgd_present(*pgd_k))
  248. return NULL;
  249. /*
  250. * set_pgd(pgd, *pgd_k); here would be useless on PAE
  251. * and redundant with the set_pmd() on non-PAE. As would
  252. * set_pud.
  253. */
  254. pud = pud_offset(pgd, address);
  255. pud_k = pud_offset(pgd_k, address);
  256. if (!pud_present(*pud_k))
  257. return NULL;
  258. pmd = pmd_offset(pud, address);
  259. pmd_k = pmd_offset(pud_k, address);
  260. if (!pmd_present(*pmd_k))
  261. return NULL;
  262. if (!pmd_present(*pmd)) {
  263. set_pmd(pmd, *pmd_k);
  264. arch_flush_lazy_mmu_mode();
  265. } else
  266. BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
  267. return pmd_k;
  268. }
  269. #ifdef CONFIG_X86_64
  270. static const char errata93_warning[] =
  271. KERN_ERR "******* Your BIOS seems to not contain a fix for K8 errata #93\n"
  272. KERN_ERR "******* Working around it, but it may cause SEGVs or burn power.\n"
  273. KERN_ERR "******* Please consider a BIOS update.\n"
  274. KERN_ERR "******* Disabling USB legacy in the BIOS may also help.\n";
  275. /* Workaround for K8 erratum #93 & buggy BIOS.
  276. BIOS SMM functions are required to use a specific workaround
  277. to avoid corruption of the 64bit RIP register on C stepping K8.
  278. A lot of BIOS that didn't get tested properly miss this.
  279. The OS sees this as a page fault with the upper 32bits of RIP cleared.
  280. Try to work around it here.
  281. Note we only handle faults in kernel here. */
  282. static int is_errata93(struct pt_regs *regs, unsigned long address)
  283. {
  284. static int warned;
  285. if (address != regs->ip)
  286. return 0;
  287. if ((address >> 32) != 0)
  288. return 0;
  289. address |= 0xffffffffUL << 32;
  290. if ((address >= (u64)_stext && address <= (u64)_etext) ||
  291. (address >= MODULES_VADDR && address <= MODULES_END)) {
  292. if (!warned) {
  293. printk(errata93_warning);
  294. warned = 1;
  295. }
  296. regs->ip = address;
  297. return 1;
  298. }
  299. return 0;
  300. }
  301. #endif
  302. /*
  303. * Handle a fault on the vmalloc or module mapping area
  304. *
  305. * This assumes no large pages in there.
  306. */
  307. static inline int vmalloc_fault(unsigned long address)
  308. {
  309. unsigned long pgd_paddr;
  310. pmd_t *pmd_k;
  311. pte_t *pte_k;
  312. /*
  313. * Synchronize this task's top level page-table
  314. * with the 'reference' page table.
  315. *
  316. * Do _not_ use "current" here. We might be inside
  317. * an interrupt in the middle of a task switch..
  318. */
  319. pgd_paddr = read_cr3();
  320. pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
  321. if (!pmd_k)
  322. return -1;
  323. pte_k = pte_offset_kernel(pmd_k, address);
  324. if (!pte_present(*pte_k))
  325. return -1;
  326. return 0;
  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. /* get the address */
  347. address = read_cr2();
  348. tsk = current;
  349. si_code = SEGV_MAPERR;
  350. /*
  351. * We fault-in kernel-space virtual memory on-demand. The
  352. * 'reference' page table is init_mm.pgd.
  353. *
  354. * NOTE! We MUST NOT take any locks for this case. We may
  355. * be in an interrupt or a critical region, and should
  356. * only copy the information from the master page table,
  357. * nothing more.
  358. *
  359. * This verifies that the fault happens in kernel space
  360. * (error_code & 4) == 0, and that the fault was not a
  361. * protection error (error_code & 9) == 0.
  362. */
  363. if (unlikely(address >= TASK_SIZE)) {
  364. if (!(error_code & 0x0000000d) && vmalloc_fault(address) >= 0)
  365. return;
  366. if (notify_page_fault(regs))
  367. return;
  368. /*
  369. * Don't take the mm semaphore here. If we fixup a prefetch
  370. * fault we could otherwise deadlock.
  371. */
  372. goto bad_area_nosemaphore;
  373. }
  374. if (notify_page_fault(regs))
  375. return;
  376. /* It's safe to allow irq's after cr2 has been saved and the vmalloc
  377. fault has been handled. */
  378. if (regs->flags & (X86_EFLAGS_IF|VM_MASK))
  379. local_irq_enable();
  380. mm = tsk->mm;
  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. /*
  467. * Did it hit the DOS screen memory VA from vm86 mode?
  468. */
  469. if (regs->flags & VM_MASK) {
  470. unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
  471. if (bit < 32)
  472. tsk->thread.screen_bitmap |= 1 << bit;
  473. }
  474. up_read(&mm->mmap_sem);
  475. return;
  476. /*
  477. * Something tried to access memory that isn't in our memory map..
  478. * Fix it, but check if it's kernel or user first..
  479. */
  480. bad_area:
  481. up_read(&mm->mmap_sem);
  482. bad_area_nosemaphore:
  483. /* User mode accesses just cause a SIGSEGV */
  484. if (error_code & PF_USER) {
  485. /*
  486. * It's possible to have interrupts off here.
  487. */
  488. local_irq_enable();
  489. /*
  490. * Valid to do another page fault here because this one came
  491. * from user space.
  492. */
  493. if (is_prefetch(regs, address, error_code))
  494. return;
  495. if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
  496. printk_ratelimit()) {
  497. printk("%s%s[%d]: segfault at %08lx ip %08lx "
  498. "sp %08lx error %lx\n",
  499. task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
  500. tsk->comm, task_pid_nr(tsk), address, regs->ip,
  501. regs->sp, error_code);
  502. }
  503. tsk->thread.cr2 = address;
  504. /* Kernel addresses are always protection faults */
  505. tsk->thread.error_code = error_code | (address >= TASK_SIZE);
  506. tsk->thread.trap_no = 14;
  507. force_sig_info_fault(SIGSEGV, si_code, address, tsk);
  508. return;
  509. }
  510. #ifdef CONFIG_X86_F00F_BUG
  511. /*
  512. * Pentium F0 0F C7 C8 bug workaround.
  513. */
  514. if (boot_cpu_data.f00f_bug) {
  515. unsigned long nr;
  516. nr = (address - idt_descr.address) >> 3;
  517. if (nr == 6) {
  518. do_invalid_op(regs, 0);
  519. return;
  520. }
  521. }
  522. #endif
  523. no_context:
  524. /* Are we prepared to handle this kernel fault? */
  525. if (fixup_exception(regs))
  526. return;
  527. /*
  528. * Valid to do another page fault here, because if this fault
  529. * had been triggered by is_prefetch fixup_exception would have
  530. * handled it.
  531. */
  532. if (is_prefetch(regs, address, error_code))
  533. return;
  534. /*
  535. * Oops. The kernel tried to access some bad page. We'll have to
  536. * terminate things with extreme prejudice.
  537. */
  538. bust_spinlocks(1);
  539. if (oops_may_print()) {
  540. __typeof__(pte_val(__pte(0))) page;
  541. #ifdef CONFIG_X86_PAE
  542. if (error_code & 16) {
  543. pte_t *pte = lookup_address(address);
  544. if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))
  545. printk(KERN_CRIT "kernel tried to execute "
  546. "NX-protected page - exploit attempt? "
  547. "(uid: %d)\n", current->uid);
  548. }
  549. #endif
  550. if (address < PAGE_SIZE)
  551. printk(KERN_ALERT "BUG: unable to handle kernel NULL "
  552. "pointer dereference");
  553. else
  554. printk(KERN_ALERT "BUG: unable to handle kernel paging"
  555. " request");
  556. printk(" at virtual address %08lx\n", address);
  557. printk(KERN_ALERT "printing ip: %08lx ", regs->ip);
  558. page = read_cr3();
  559. page = ((__typeof__(page) *) __va(page))[address >> PGDIR_SHIFT];
  560. #ifdef CONFIG_X86_PAE
  561. printk("*pdpt = %016Lx ", page);
  562. if ((page >> PAGE_SHIFT) < max_low_pfn
  563. && page & _PAGE_PRESENT) {
  564. page &= PAGE_MASK;
  565. page = ((__typeof__(page) *) __va(page))[(address >> PMD_SHIFT)
  566. & (PTRS_PER_PMD - 1)];
  567. printk(KERN_CONT "*pde = %016Lx ", page);
  568. page &= ~_PAGE_NX;
  569. }
  570. #else
  571. printk("*pde = %08lx ", page);
  572. #endif
  573. /*
  574. * We must not directly access the pte in the highpte
  575. * case if the page table is located in highmem.
  576. * And let's rather not kmap-atomic the pte, just in case
  577. * it's allocated already.
  578. */
  579. if ((page >> PAGE_SHIFT) < max_low_pfn
  580. && (page & _PAGE_PRESENT)
  581. && !(page & _PAGE_PSE)) {
  582. page &= PAGE_MASK;
  583. page = ((__typeof__(page) *) __va(page))[(address >> PAGE_SHIFT)
  584. & (PTRS_PER_PTE - 1)];
  585. printk("*pte = %0*Lx ", sizeof(page)*2, (u64)page);
  586. }
  587. printk("\n");
  588. }
  589. tsk->thread.cr2 = address;
  590. tsk->thread.trap_no = 14;
  591. tsk->thread.error_code = error_code;
  592. die("Oops", regs, error_code);
  593. bust_spinlocks(0);
  594. do_exit(SIGKILL);
  595. /*
  596. * We ran out of memory, or some other thing happened to us that made
  597. * us unable to handle the page fault gracefully.
  598. */
  599. out_of_memory:
  600. up_read(&mm->mmap_sem);
  601. if (is_global_init(tsk)) {
  602. yield();
  603. down_read(&mm->mmap_sem);
  604. goto survive;
  605. }
  606. printk("VM: killing process %s\n", tsk->comm);
  607. if (error_code & 4)
  608. do_group_exit(SIGKILL);
  609. goto no_context;
  610. do_sigbus:
  611. up_read(&mm->mmap_sem);
  612. /* Kernel mode? Handle exceptions or die */
  613. if (!(error_code & PF_USER))
  614. goto no_context;
  615. /* User space => ok to do another page fault */
  616. if (is_prefetch(regs, address, error_code))
  617. return;
  618. tsk->thread.cr2 = address;
  619. tsk->thread.error_code = error_code;
  620. tsk->thread.trap_no = 14;
  621. force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
  622. }
  623. void vmalloc_sync_all(void)
  624. {
  625. /*
  626. * Note that races in the updates of insync and start aren't
  627. * problematic: insync can only get set bits added, and updates to
  628. * start are only improving performance (without affecting correctness
  629. * if undone).
  630. */
  631. static DECLARE_BITMAP(insync, PTRS_PER_PGD);
  632. static unsigned long start = TASK_SIZE;
  633. unsigned long address;
  634. if (SHARED_KERNEL_PMD)
  635. return;
  636. BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
  637. for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
  638. if (!test_bit(pgd_index(address), insync)) {
  639. unsigned long flags;
  640. struct page *page;
  641. spin_lock_irqsave(&pgd_lock, flags);
  642. for (page = pgd_list; page; page =
  643. (struct page *)page->index)
  644. if (!vmalloc_sync_one(page_address(page),
  645. address)) {
  646. BUG_ON(page != pgd_list);
  647. break;
  648. }
  649. spin_unlock_irqrestore(&pgd_lock, flags);
  650. if (!page)
  651. set_bit(pgd_index(address), insync);
  652. }
  653. if (address == start && test_bit(pgd_index(address), insync))
  654. start = address + PGDIR_SIZE;
  655. }
  656. }